import {classMap} from "lit/directives/class-map.js"; import {type CSSResultGroup, html, unsafeCSS} from 'lit'; import {HasSlotController} from "../../internal/slot"; import {property} from 'lit/decorators.js'; import ZincElement from '../../internal/zinc-element'; import styles from './form-group.scss'; /** * @summary Short summary of the component's intended use. * @documentation https://zinc.style/components/form-group * @status experimental * @since 1.0 * * @slot - The default slot. * */ export default class ZnFormGroup extends ZincElement { static styles: CSSResultGroup = unsafeCSS(styles); private readonly hasSlotController = new HasSlotController(this, 'help-text', 'label'); /** * The form group's label. Required for proper accessibility. If you need to display HTML, use the `label` slot * instead. */ @property() label = ''; /** * Text that appears in a tooltip next to the label. If you need to display HTML in the tooltip, use the * `label-tooltip` slot instead. */ @property({attribute: 'label-tooltip'}) labelTooltip = ''; /** The form groups help text. If you need to display HTML, use the `help-text` slot instead. */ @property({attribute: 'help-text'}) helpText = ''; render() { const hasLabelSlot = this.hasSlotController.test('label'); const hasLabelTooltipSlot = this.hasSlotController.test('label-tooltip'); const hasHelpTextSlot = this.hasSlotController.test('help-text'); const hasLabel = this.label ? true : hasLabelSlot; const hasLabelTooltip = this.labelTooltip ? true : hasLabelTooltipSlot; const hasHelpText = this.helpText ? true : hasHelpTextSlot; return html`
${hasLabel ? html`
${hasHelpText ? html`
${this.helpText}
` : html``}
` : html``}
`; } }