Skip to content

Commit f83ca01

Browse files
author
Marko Petzold
committed
fix: refactor theme registration and update handling in WidgetValue
1 parent 1be3140 commit f83ca01

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/widget-value.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class WidgetValue extends LitElement {
5050
protected firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>) {
5151
this.valueContainer = this?.shadowRoot?.querySelector('.value-container') as HTMLDivElement
5252

53+
this.registerTheme(this.theme)
5354
this.sizingSetup()
5455
this.applyInputData()
5556
}
@@ -61,17 +62,21 @@ export class WidgetValue extends LitElement {
6162
}
6263

6364
if (changedProperties.has('theme')) {
64-
const cssTextColor = getComputedStyle(this).getPropertyValue('--re-text-color').trim()
65-
const cssBgColor = getComputedStyle(this).getPropertyValue('--re-background-color').trim()
66-
this.themeBgColor = cssBgColor || this.theme?.theme_object?.backgroundColor
67-
this.themeTitleColor = cssTextColor || this.theme?.theme_object?.title?.textStyle?.color
68-
this.themeSubtitleColor =
69-
cssTextColor || this.theme?.theme_object?.title?.subtextStyle?.color || this.themeTitleColor
65+
this.registerTheme(this.theme)
7066
}
7167

7268
super.update(changedProperties)
7369
}
7470

71+
registerTheme(theme?: Theme) {
72+
const cssTextColor = getComputedStyle(this).getPropertyValue('--re-text-color').trim()
73+
const cssBgColor = getComputedStyle(this).getPropertyValue('--re-background-color').trim()
74+
this.themeBgColor = cssBgColor || this.theme?.theme_object?.backgroundColor
75+
this.themeTitleColor = cssTextColor || this.theme?.theme_object?.title?.textStyle?.color
76+
this.themeSubtitleColor =
77+
cssTextColor || this.theme?.theme_object?.title?.subtextStyle?.color || this.themeTitleColor
78+
}
79+
7580
sizingSetup() {
7681
if (this.origWidth !== 0 && this.origHeight !== 0) return
7782

0 commit comments

Comments
 (0)