{"version":3,"sources":["../src/elements/field.ts","../src/styles/elements/field.ts"],"sourcesContent":["import { html, LitElement } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport { stylesBase } from '../styles/elements/field';\n\nimport KemetCombo from './combo';\nimport KemetInput from './input';\nimport KemetTextarea from './textarea';\nimport { EnumStatuses, TypeStatus } from '../utilities/constants';\n\n/**\n * @since 1.0.0\n * @status stable\n *\n * @tagname kemet-field\n * @summary Used in combination with Input, Select, and Textarea, to make a Field.\n *\n * @prop {string} slug - Uniquely identifies the control. Use the same slug for slotted subcomponents.\n * @prop {string} label - The label text\n * @prop {string} message - The validation message for error or success\n * @prop {boolean} focused - Determines if the containing input is focused\n * @prop {TypeStatus} status - The validation status of standard, error, or success\n * @prop {boolean} filled - Is true when the containing input has a value\n * @prop {number} length - The length of the containing input\n * @prop {boolean} disabled - Determines the disabled state of the control\n * @prop {string} errorIcon - The icon while in an error or warning state\n * @prop {string} successIcon - The icon while in a success state\n *\n * @slot component - Allows subcomponents of the field to display.\n *\n * @csspart label - The label of the field.\n * @csspart message - The validation message of the field.\n * @csspart text - The text in the label.\n *\n * @event kemet-input - Fires when input fires on the input slot\n *\n */\n\n@customElement('kemet-field')\nexport default class KemetField extends LitElement {\n  static styles = [stylesBase];\n\n  @property({ type: String })\n  slug: string;\n\n  @property({ type: String })\n  label: string;\n\n  @property({ type: String })\n  message: string;\n\n  @property({ type: Boolean, reflect: true })\n  focused: boolean;\n\n  @property({ type: String, reflect: true })\n  status: TypeStatus = EnumStatuses.Standard;\n\n  @property({ type: Boolean, reflect: true })\n  filled: boolean;\n\n  @property({ type: Number })\n  length: number;\n\n  @property({ type: Boolean, reflect: true })\n  disabled: boolean;\n\n  @property({ type: String, attribute: 'error-icon' })\n  errorIcon: string = 'exclamation-triangle-fill';\n\n  @property({ type: String, attribute: 'success-icon' })\n  successIcon: string = 'check-lg';\n\n  @state()\n  slotInput: KemetInput | KemetTextarea;\n\n  @state()\n  slotCombo: KemetCombo;\n\n  firstUpdated() {\n    this.slotInput = this.querySelector('[slot=\"input\"]');\n    this.slotCombo = this.querySelector('[slot=\"combo\"]');\n\n    this.slotInput.addEventListener('kemet-focus', (event: CustomEvent) => this.handleFocused(event));\n    this.slotInput.addEventListener('kemet-status-change', (event: CustomEvent) => this.handleStatus(event));\n    this.slotInput.addEventListener('kemet-input', (event: CustomEvent) => this.handleInput(event));\n    this.slotCombo?.addEventListener('kemet-selection', (event: CustomEvent) => this.handleSelection(event));\n\n    if (this.slotInput.value) {\n      this.length = this.slotInput.value.length;\n    } else {\n      this.length = 0;\n    }\n  }\n\n  render() {\n    return html`\n      <label for=\"${this.slug}\" id=\"${this.slug}-label\" part=\"label\">\n        <span part=\"text\">${this.label}</span>\n        <slot name=\"input\"></slot>\n      </label>\n      ${this.makeStatusMessage()}\n      <slot name=\"component\"></slot>\n    `;\n  }\n\n  makeStatusMessage() {\n    if (this.status !== 'standard') {\n      return html`<span class=\"message\" part=\"message\">${this.message}</span>`;\n    }\n\n    return null;\n  }\n\n  handleFocused(event: CustomEvent) {\n    this.focused = event.detail;\n\n    if (!this.focused && this.slotCombo && this.slotCombo.options.length < 1) {\n      this.slotCombo.show = false;\n    }\n  }\n\n  handleStatus(event: CustomEvent) {\n    this.status = event.detail.status;\n  }\n\n  handleInput(event: CustomEvent) {\n    this.length = event.detail.value.length ?? 0;\n    this.filled = event.detail.value !== '';\n  }\n\n  handleSelection(event: CustomEvent) {\n    console.log(event.detail);\n    this.slotInput.setAttribute('aria-activedescendant', event.detail);\n  }\n}\n\ndeclare global {\n  interface HTMLElementTagNameMap {\n    'kemet-field': KemetField\n  }\n}\n","import { css } from 'lit';\n\nexport const stylesBase = css`\n  *,\n  *::before,\n  *::after {\n    box-sizing: border-box;\n  }\n\n  :host {\n    display: block;\n  }\n\n  :host([disabled]) {\n    opacity: 0.5;\n  }\n\n  label {\n    position: relative;\n    display: block;\n  }\n\n  label span {\n    color: inherit;\n    display: inline-flex;\n    gap: 0.5rem;\n    align-items: center;\n    margin-bottom: 0.8rem;\n  }\n\n  .message {\n    font-size: 0.9rem;\n    line-height: 1;\n    display: block;\n    margin-top: 0.8rem;\n  }\n\n  :host([status='error']) .message {\n    color: rgb(var(--kemet-color-error));\n  }\n\n  :host([status='success']) .message {\n    color: rgb(var(--kemet-color-success));\n  }\n\n  :host([status='warning']) .message {\n    color: rgb(var(--kemet-color-warning));\n  }\n`;\n"],"mappings":";;;;;AAAA,SAAS,MAAM,kBAAkB;AACjC,SAAS,eAAe,UAAU,aAAa;;;ACD/C,SAAS,WAAW;AAEb,IAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ADoC1B,IAAqB,aAArB,cAAwC,WAAW;AAAA,EAAnD;AAAA;AAgBE;AAYA,qBAAoB;AAGpB,uBAAsB;AAAA;AAAA,EAQtB,eAAe;AACb,SAAK,YAAY,KAAK,cAAc,gBAAgB;AACpD,SAAK,YAAY,KAAK,cAAc,gBAAgB;AAEpD,SAAK,UAAU,iBAAiB,eAAe,CAAC,UAAuB,KAAK,cAAc,KAAK,CAAC;AAChG,SAAK,UAAU,iBAAiB,uBAAuB,CAAC,UAAuB,KAAK,aAAa,KAAK,CAAC;AACvG,SAAK,UAAU,iBAAiB,eAAe,CAAC,UAAuB,KAAK,YAAY,KAAK,CAAC;AAC9F,SAAK,WAAW,iBAAiB,mBAAmB,CAAC,UAAuB,KAAK,gBAAgB,KAAK,CAAC;AAEvG,QAAI,KAAK,UAAU,OAAO;AACxB,WAAK,SAAS,KAAK,UAAU,MAAM;AAAA,IACrC,OAAO;AACL,WAAK,SAAS;AAAA,I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