import { LitElement, type PropertyValues } from 'lit'; import { customElement, property } from 'lit/decorators.js'; import { type NuiType, nuiTypeProperty } from '../../types/nui-type.js'; import { createComponentStyles, syncStylesWhen, } from '../../utils/sync-stylesheet.js'; import { type NuiLabelViewState, renderLabel } from './logic.js'; import type { LabelSize } from './types.js'; const styles = createComponentStyles( 'nui-label', () => import('./styles.css', { with: { type: 'css' } }), ); @customElement('nui-label') export class NuiLabel extends LitElement implements NuiLabelViewState { @property({ type: String }) value = ''; @property({ type: String, attribute: 'for' }) htmlFor = ''; @property({ type: Boolean, reflect: true }) required = false; @property({ type: Boolean, reflect: true }) invalid = false; @property({ type: Boolean, reflect: true }) disabled = false; @property({ type: String, reflect: true }) size: LabelSize | '' = ''; @property({ type: Boolean }) unstyled = false; @nuiTypeProperty nuiType: NuiType = ''; @property({ type: String, attribute: 'label-class' }) labelClass = ''; protected createRenderRoot() { const root = super.createRenderRoot(); void styles.sync(root, { unstyled: this.unstyled }); return root; } protected updated(changed: PropertyValues) { syncStylesWhen(changed, 'unstyled', () => styles.sync(this.renderRoot, { unstyled: this.unstyled }), ); } render() { return renderLabel(this); } } declare global { interface HTMLElementTagNameMap { 'nui-label': NuiLabel; } }