Skip to content

Commit 699459c

Browse files
author
Marko Petzold
committed
fix: update widget-textbox version and refactor theme registration logic
1 parent 635bdce commit 699459c

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

demo/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
const theme = { theme_name: 'vintage', theme_object: themeObject }
3333
render(
3434
html`
35-
<widget-textbox-1.1.2 .theme="${theme}" .inputData=${data}>
35+
<widget-textbox-1.1.3 .theme="${theme}" .inputData=${data}>
3636
web component is not registered. Make sure to use the tag with the correct version
3737
string from the package.json
38-
</widget-textbox-1.1.2>
38+
</widget-textbox-1.1.3>
3939
`,
4040
document.getElementById('demo')
4141
)

src/widget-textbox.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { html, css, LitElement } from 'lit'
1+
import { html, css, LitElement, PropertyValues } from 'lit'
22
import { property, state } from 'lit/decorators.js'
33
import { TextboxConfiguration } from './definition-schema.js'
44

@@ -21,17 +21,25 @@ export class WidgetTextbox extends LitElement {
2121

2222
update(changedProperties: Map<string, any>) {
2323
if (changedProperties.has('theme')) {
24-
const cssTextColor = getComputedStyle(this).getPropertyValue('--re-text-color').trim()
25-
const cssBgColor = getComputedStyle(this).getPropertyValue('--re-background-color').trim()
26-
this.themeBgColor = cssBgColor || this.theme?.theme_object?.backgroundColor
27-
this.themeTitleColor = cssTextColor || this.theme?.theme_object?.title?.textStyle?.color
28-
this.themeSubtitleColor =
29-
cssTextColor || this.theme?.theme_object?.title?.subtextStyle?.color || this.themeTitleColor
24+
this.registerTheme(this.theme)
3025
}
3126

3227
super.update(changedProperties)
3328
}
3429

30+
protected firstUpdated(_changedProperties: PropertyValues): void {
31+
this.registerTheme(this.theme)
32+
}
33+
34+
registerTheme(theme?: Theme) {
35+
const cssTextColor = getComputedStyle(this).getPropertyValue('--re-text-color').trim()
36+
const cssBgColor = getComputedStyle(this).getPropertyValue('--re-background-color').trim()
37+
this.themeBgColor = cssBgColor || this.theme?.theme_object?.backgroundColor
38+
this.themeTitleColor = cssTextColor || this.theme?.theme_object?.title?.textStyle?.color
39+
this.themeSubtitleColor =
40+
cssTextColor || this.theme?.theme_object?.title?.subtextStyle?.color || this.themeTitleColor
41+
}
42+
3543
static styles = css`
3644
:host {
3745
display: block;

0 commit comments

Comments
 (0)