import {LitElement, html, unsafeCSS} from 'lit'; import {customElement, property} from 'lit/decorators.js'; import compentStyle from './instrument-field.css?inline'; import {classMap} from 'lit/directives/class-map.js'; export enum InstrumentFieldSize { small = 'small', regular = 'regular', enhanced = 'enhanced', large = 'large', largeEnhanced = 'large-enhanced', } @customElement('obc-instrument-field') export class ObcInstrumentField extends LitElement { @property({type: String}) size: InstrumentFieldSize = InstrumentFieldSize.regular; @property({type: Number}) setpoint = 0; @property({type: Boolean}) hasSetpoint = false; @property({type: Number}) value = 0; @property({type: Boolean}) degree = false; @property({type: Number}) maxDigits = 3; @property({type: Number}) fractionDigits = 0; @property({type: String}) tag = ''; @property({type: String}) unit = ''; @property({type: String}) source = ''; @property({type: Boolean}) hasSource = false; override render() { return html`
${this.hasSetpoint ? html`
${this.size === 'small' || this.size === 'regular' ? html` ` : html` `}
${this.setpointValueBlueNumbers}
` : null}
${this.hintZeros}
${this.valueBlueNumbers}
${this.degree ? html`
°
` : null}
${this.tag}
${this.unit}
${this.hasSource ? html`
${this.source}
` : null}
`; } get setpointValueBlueNumbers(): string { return this.setpoint.toFixed(this.fractionDigits); } get valueBlueNumbers(): string { return this.value.toFixed(this.fractionDigits); } get hintZeros(): string { if (this.value < 0) { return ''; } const nBlues = this.valueBlueNumbers.length; const nHints = this.maxDigits - nBlues; if (nHints > 0) { return '0'.repeat(nHints); } return ''; } static override styles = unsafeCSS(compentStyle); } declare global { interface HTMLElementTagNameMap { 'obc-instrument-field': ObcInstrumentField; } }