diff --git a/bubble/State Color Button/code.js b/bubble/State Color Button/code.js index 4db1515..f917a46 100644 --- a/bubble/State Color Button/code.js +++ b/bubble/State Color Button/code.js @@ -6,18 +6,20 @@ state = hass?.states[this.config?.entity]?.state || ''; } - let bg_color = 'var(--bubble-main-background-color)'; + let off_color = this.config?.state_color_button?.off_color + ? `var(--${this.config.state_color_button.off_color})` + : 'var(--bubble-main-background-color)'; // Use the configured color or default to accent color - let on_color = this.config?.state_color_button?.color - ? `var(--${this.config.state_color_button.color})` + let on_color = this.config?.state_color_button?.on_color + ? `var(--${this.config.state_color_button.on_color})` : 'var(--bubble-accent-color)'; // Main button background const mainButton = card?.querySelector('.bubble-button-background'); if (mainButton) { mainButton.style.opacity = '1'; - mainButton.style.backgroundColor = state === 'on' ? on_color : bg_color; + mainButton.style.backgroundColor = state === 'on' ? on_color : off_color; mainButton.style.transition = 'background-color 1s'; } diff --git a/bubble/State Color Button/editor.yaml b/bubble/State Color Button/editor.yaml index 65b687a..d482a0a 100644 --- a/bubble/State Color Button/editor.yaml +++ b/bubble/State Color Button/editor.yaml @@ -1,5 +1,10 @@ -- name: color - label: Color (CSS Variable) +- name: on_color + label: On Color (CSS Variable) + selector: + text: {} + required: false +- name: off_color + label: Off Color (CSS Variable) selector: text: {} required: false diff --git a/bubble/State Color Button/import.yaml b/bubble/State Color Button/import.yaml index 300c6a0..a4448c3 100644 --- a/bubble/State Color Button/import.yaml +++ b/bubble/State Color Button/import.yaml @@ -1,6 +1,6 @@ state_color_button: name: State Color Button - version: 1.2.0 + version: 2.0.0 creator: Tony Stork supported: - button @@ -14,7 +14,7 @@ state_color_button: alt_entity: sensor.your_face code: |- - ${(() => { + `${(() => { let state; if (this.config?.state_color_button?.alt_entity) { state = hass?.states[this.config?.state_color_button?.alt_entity]?.state || ''; @@ -22,18 +22,20 @@ state_color_button: state = hass?.states[this.config?.entity]?.state || ''; } - let bg_color = 'var(--bubble-main-background-color)'; + let off_color = this.config?.state_color_button?.off_color + ? `var(--${this.config.state_color_button.off_color})` + : 'var(--bubble-main-background-color)'; // Use the configured color or default to accent color - let on_color = this.config?.state_color_button?.color - ? `var(--${this.config.state_color_button.color})` + let on_color = this.config?.state_color_button?.on_color + ? `var(--${this.config.state_color_button.on_color})` : 'var(--bubble-accent-color)'; // Main button background const mainButton = card?.querySelector('.bubble-button-background'); if (mainButton) { mainButton.style.opacity = '1'; - mainButton.style.backgroundColor = state === 'on' ? on_color : bg_color; + mainButton.style.backgroundColor = state === 'on' ? on_color : off_color; mainButton.style.transition = 'background-color 1s'; } @@ -54,10 +56,15 @@ state_color_button: // No CSS string needed return ''; - })()} + })()}` editor: - - name: color - label: Color (CSS Variable) + - name: on_color + label: On Color (CSS Variable) + selector: + text: {} + required: false + - name: off_color + label: Off Color (CSS Variable) selector: text: {} required: false