mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 07:16:39 +00:00
Add Color RGB Selector (#12039)
This commit is contained in:
parent
db78b046a2
commit
5c53bc4225
@ -173,10 +173,11 @@ const SCHEMAS: {
|
|||||||
name: "Location with radius",
|
name: "Location with radius",
|
||||||
selector: { location: { radius: true, icon: "mdi:home" } },
|
selector: { location: { radius: true, icon: "mdi:home" } },
|
||||||
},
|
},
|
||||||
"color-temp": {
|
color_temp: {
|
||||||
name: "Color Temperature",
|
name: "Color Temperature",
|
||||||
selector: { color_temp: {} },
|
selector: { color_temp: {} },
|
||||||
},
|
},
|
||||||
|
color_rgb: { name: "Color", selector: { color_rgb: {} } },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
58
src/components/ha-selector/ha-selector-color-rgb.ts
Normal file
58
src/components/ha-selector/ha-selector-color-rgb.ts
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import { css, html, LitElement } from "lit";
|
||||||
|
import { customElement, property } from "lit/decorators";
|
||||||
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import type { ColorRGBSelector } from "../../data/selector";
|
||||||
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
|
import { hex2rgb, rgb2hex } from "../../common/color/convert-color";
|
||||||
|
import "../ha-textfield";
|
||||||
|
|
||||||
|
@customElement("ha-selector-color_rgb")
|
||||||
|
export class HaColorRGBSelector extends LitElement {
|
||||||
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public selector!: ColorRGBSelector;
|
||||||
|
|
||||||
|
@property() public value?: string;
|
||||||
|
|
||||||
|
@property() public label?: string;
|
||||||
|
|
||||||
|
@property({ type: Boolean, reflect: true }) public disabled = false;
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
return html`
|
||||||
|
<ha-textfield
|
||||||
|
type="color"
|
||||||
|
.value=${this.value ? rgb2hex(this.value as any) : ""}
|
||||||
|
.label=${this.label || ""}
|
||||||
|
@change=${this._valueChanged}
|
||||||
|
></ha-textfield>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _valueChanged(ev: CustomEvent) {
|
||||||
|
const value = (ev.target as any).value;
|
||||||
|
fireEvent(this, "value-changed", {
|
||||||
|
value: hex2rgb(value),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static styles = css`
|
||||||
|
:host {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
ha-textfield {
|
||||||
|
--text-field-padding: 8px;
|
||||||
|
min-width: 75px;
|
||||||
|
flex-grow: 1;
|
||||||
|
margin: 0 4px;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-selector-color_rgb": HaColorRGBSelector;
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@ import "./ha-selector-addon";
|
|||||||
import "./ha-selector-area";
|
import "./ha-selector-area";
|
||||||
import "./ha-selector-attribute";
|
import "./ha-selector-attribute";
|
||||||
import "./ha-selector-boolean";
|
import "./ha-selector-boolean";
|
||||||
|
import "./ha-selector-color-rgb";
|
||||||
import "./ha-selector-device";
|
import "./ha-selector-device";
|
||||||
import "./ha-selector-duration";
|
import "./ha-selector-duration";
|
||||||
import "./ha-selector-entity";
|
import "./ha-selector-entity";
|
||||||
|
@ -17,7 +17,8 @@ export type Selector =
|
|||||||
| MediaSelector
|
| MediaSelector
|
||||||
| ThemeSelector
|
| ThemeSelector
|
||||||
| LocationSelector
|
| LocationSelector
|
||||||
| ColorTempSelector;
|
| ColorTempSelector
|
||||||
|
| ColorRGBSelector;
|
||||||
|
|
||||||
export interface EntitySelector {
|
export interface EntitySelector {
|
||||||
entity: {
|
entity: {
|
||||||
@ -34,6 +35,11 @@ export interface AttributeSelector {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ColorRGBSelector {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
|
color_rgb: {};
|
||||||
|
}
|
||||||
|
|
||||||
export interface DeviceSelector {
|
export interface DeviceSelector {
|
||||||
device: {
|
device: {
|
||||||
integration?: string;
|
integration?: string;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user