import {HTMLTemplateResult, LitElement, html, unsafeCSS} from 'lit'; import {customElement, property} from 'lit/decorators.js'; import compentStyle from './automation-button.css?inline'; import {classMap} from 'lit/directives/class-map.js'; import '../../icons/icon-forward'; import '../../icons/icon-forward-fast'; import '../../icons/icon-forward-stopped'; import '../../icons/icon-backward'; import '../../icons/icon-backward-fast'; import '../../icons/icon-backward-stopped'; import '../../icons/icon-standby'; import '../../icons/icon-arrow-up-google'; import '../../icons/icon-arrow-down-google'; import '../../icons/icon-arrow-left-google'; import '../../icons/icon-arrow-right-google'; export enum AutomationButtonSize { small = 'small', regular = 'regular', large = 'large', xl = 'xl', } export enum AutomationButtonVariant { regular = 'regular', double = 'double', switch = 'switch', } export enum AutomationButtonState { closed = 'closed', open = 'open', openEnhanced = 'open-enhanced', openMedium = 'open-medium', static = 'static', } export enum AutomationButtonLabelSize { small = 'small', regular = 'regular', enhanced = 'enhanced', } export enum AutomationBottonLabelStyle { regular = 'regular', enhanced = 'enhanced', active = 'active', } export interface AutomationButtonStateLabel { type: 'state'; text: string; bold: boolean; } export interface AutomationButtonTagLabel { type: 'tag'; text: string; showHash: boolean; } export interface AutomationButtonDirectonValueLabel { type: 'direction'; value: number; nDigits: number; unit: 'percent'; direction: 'up' | 'down' | 'left' | 'right'; } export enum AutomationButtonLabelPosition { top = 'top', bottom = 'bottom', left = 'left', right = 'right', } export enum AutomationButtonDirection { forward = 'forward', forwardFast = 'forward-fast', forwardStopped = 'forward-stopped', backward = 'backward', backwardFast = 'backward-fast', backwardStopped = 'backward-stopped', standby = 'standby', } export type AutomationButtonLabel = | AutomationButtonStateLabel | AutomationButtonTagLabel | AutomationButtonDirectonValueLabel; function renderLabel(label: AutomationButtonLabel): HTMLTemplateResult { if (label.type === 'state') { return html`
${label.text}
`; } else if (label.type === 'tag') { return html`
${label.showHash ? html`
#
` : null} ${label.text}
`; } else { const v = label.value.toFixed(0); const zeroPadding = v.length < label.nDigits ? '0'.repeat(label.nDigits - v.length) : ''; let directionIcon: HTMLTemplateResult; if (label.direction === 'up') { directionIcon = html``; } else if (label.direction === 'down') { directionIcon = html``; } else if (label.direction === 'left') { directionIcon = html``; } else if (label.direction === 'right') { directionIcon = html``; } else { throw new Error('Invalid direction'); } return html`
${directionIcon} ${zeroPadding} ${v} ${label.unit === 'percent' ? '%' : label.unit}
`; } } @customElement('obc-automation-button') export class ObcAutomationButton extends LitElement { @property({type: String}) size: AutomationButtonSize = AutomationButtonSize.regular; @property({type: String}) variant: AutomationButtonVariant = AutomationButtonVariant.regular; @property({type: String}) state: AutomationButtonState = AutomationButtonState.open; @property({type: Array, attribute: false}) labels: AutomationButtonLabel[] = []; @property({type: String}) labelPosition: AutomationButtonLabelPosition = AutomationButtonLabelPosition.bottom; @property({type: String}) labelSize: AutomationButtonLabelSize = AutomationButtonLabelSize.regular; @property({type: String}) labelStyle: AutomationBottonLabelStyle = AutomationBottonLabelStyle.regular; @property({type: Boolean}) alert: boolean = false; @property({type: Boolean}) progress: boolean = false; @property({type: String}) direction: AutomationButtonDirection = AutomationButtonDirection.forward; override render() { const labels = this.labels.map(renderLabel); const progressSpinner = this.getProgressSpinner(); const direction = this.getDirectionIcon(); return html`
`; } static override styles = unsafeCSS(compentStyle); private getProgressSpinner(): null | HTMLTemplateResult { if (!this.progress) { return null; } let spinnerWidth: number; if (this.size === AutomationButtonSize.small) { spinnerWidth = 40; } else if (this.size === AutomationButtonSize.regular) { spinnerWidth = 56; } else if (this.size === AutomationButtonSize.large) { spinnerWidth = 72; } else { spinnerWidth = 104; } const progressSpinner = html` `; return progressSpinner; } private getDirectionIcon(): null | HTMLTemplateResult { if (this.variant !== AutomationButtonVariant.double) { return null; } else if (this.direction === AutomationButtonDirection.forward) { return html` `; } else if (this.direction === AutomationButtonDirection.forwardFast) { return html` `; } else if (this.direction === AutomationButtonDirection.forwardStopped) { return html` `; } else if (this.direction === AutomationButtonDirection.backward) { return html` `; } else if (this.direction === AutomationButtonDirection.backwardFast) { return html` `; } else if (this.direction === AutomationButtonDirection.backwardStopped) { return html` `; } else if (this.direction === AutomationButtonDirection.standby) { return html``; } throw new Error('Invalid direction'); } } declare global { interface HTMLElementTagNameMap { 'obc-automation-button': ObcAutomationButton; } }