import { CSSResultGroup, html, LitElement, PropertyValues, TemplateResult, unsafeCSS, } from 'lit'; import { customElement, property } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; import { KeyAssignerController } from '../components-lib/key-assigner-controller'; import { KeyboardShortcut } from '../config/schema/view'; import { localize } from '../localize/localize'; import keyAssignerStyle from '../scss/key-assigner.scss'; import './icon'; @customElement('advanced-camera-card-key-assigner') export class AdvancedCameraCardKeyAssigner extends LitElement { @property({ attribute: false }) public label?: string; @property({ attribute: false }) public value?: KeyboardShortcut | null; protected _controller = new KeyAssignerController(this); protected willUpdate(changedProps: PropertyValues): void { if (changedProps.has('value')) { this._controller.setValue(this.value ?? null); } } protected render(): TemplateResult | void { if (!this.label) { return; } const renderKey = (key: string) => { return html`
${key}
`; }; return html`
${this.label}
{ this._controller.toggleAssigning(); }} > ${this._controller.isAssigning() ? '' : localize('key_assigner.assign')} ${ this._controller.hasValue() ? html` { this._controller.setValue(null); }} > ${localize('key_assigner.unassign')} ` : '' }
${this.value?.ctrl ? renderKey(localize('key_assigner.modifiers.ctrl')) : ''} ${this.value?.shift ? renderKey(localize('key_assigner.modifiers.shift')) : ''} ${this.value?.meta ? renderKey(localize('key_assigner.modifiers.meta')) : ''} ${this.value?.alt ? renderKey(localize('key_assigner.modifiers.alt')) : ''} ${this.value?.key ? renderKey(this.value.key) : ''}
`; } static get styles(): CSSResultGroup { return unsafeCSS(keyAssignerStyle); } } declare global { interface HTMLElementTagNameMap { 'advanced-camera-card-key-assigner': AdvancedCameraCardKeyAssigner; } }