{"version":3,"file":"ngwr-form.mjs","sources":["../../../projects/lib/form/form-item.ts","../../../projects/lib/form/form-field.ts","../../../projects/lib/form/form-field.html","../../../projects/lib/form/ngwr-form.ts"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { coerceBooleanProperty } from '@angular/cdk/coercion';\nimport { Component, ViewEncapsulation, computed, input } from '@angular/core';\n\n/**\n * Wraps a label + control + error message into a single field row.\n *\n * Toggle `hasError` to apply error styling to the projected label and\n * any descendant input / textarea / checkbox.\n *\n * @example\n * ```html\n * <wr-form-item [hasError]=\"form.controls.email.invalid\">\n *   <label>Email</label>\n *   <wr-input formControlName=\"email\" />\n *   <wr-form-error>Invalid email</wr-form-error>\n * </wr-form-item>\n * ```\n *\n * @see https://ngwr.dev/components/form\n */\n@Component({\n  selector: 'wr-form-item',\n  template: '<ng-content />',\n  encapsulation: ViewEncapsulation.None,\n  host: { '[class]': 'classes()' },\n})\nexport class WrFormItem {\n  /**\n   * When `true`, applies error coloring to the projected label and inputs.\n   *\n   * @default false\n   */\n  readonly hasError = input(false, { transform: coerceBooleanProperty });\n\n  protected readonly classes = computed(() => {\n    const parts = ['wr-form-item'];\n    if (this.hasError()) parts.push('wr-form-item--error');\n    return parts.join(' ');\n  });\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { coerceBooleanProperty } from '@angular/cdk/coercion';\nimport { Component, ViewEncapsulation, computed, contentChild, input } from '@angular/core';\nimport { NgControl } from '@angular/forms';\n\nlet uid = 0;\n\n/**\n * Wraps a label + control + hint + error messages into a single block —\n * the layout primitive every form ends up reinventing.\n *\n * - Auto-binds `label[for]` to the projected control via a generated id\n *   (or use the form-control's `[id]` if you set one).\n * - Reads the projected control's `NgControl` to surface validation\n *   errors only when the control has been touched / submitted.\n * - Optional `[required]` / `[optional]` markers next to the label.\n *\n * @example\n * ```html\n * <wr-form-field label=\"Email\" hint=\"We'll never share it.\">\n *   <input wrInput [formControl]=\"email\" type=\"email\" />\n *   <wr-form-error key=\"required\">Email is required.</wr-form-error>\n *   <wr-form-error key=\"email\">Not a valid email.</wr-form-error>\n * </wr-form-field>\n * ```\n *\n * @see https://ngwr.dev/components/form-field\n */\n@Component({\n  selector: 'wr-form-field',\n  templateUrl: './form-field.html',\n  encapsulation: ViewEncapsulation.None,\n  host: { '[class]': 'classes()' },\n})\nexport class WrFormField {\n  /** Label text shown above the control. */\n  readonly label = input<string>('');\n\n  /** Hint text shown below the control. Hidden when an error is visible. */\n  readonly hint = input<string>('');\n\n  /** Show a `*` next to the label. @default false */\n  readonly required = input(false, { transform: coerceBooleanProperty });\n\n  /** Show `(optional)` next to the label. Mutually exclusive with `required`. @default false */\n  readonly optional = input(false, { transform: coerceBooleanProperty });\n\n  /** Force a specific id on the label's `for` attribute. Auto-generated otherwise. */\n  readonly controlId = input<string>(`wr-form-field-${++uid}`);\n\n  /** Projected `NgControl` — used to read touched / dirty / errors. */\n  protected readonly ngControl = contentChild(NgControl);\n\n  protected readonly errors = computed(() => {\n    const c = this.ngControl();\n    if (!c) return null;\n    if (!c.touched && !c.dirty) return null;\n    return c.errors;\n  });\n\n  protected readonly hasError = computed(() => {\n    const errs = this.errors();\n    return !!errs && Object.keys(errs).length > 0;\n  });\n\n  protected readonly classes = computed(() => {\n    const parts = ['wr-form-field'];\n    if (this.hasError()) parts.push('wr-form-field--invalid');\n    if (this.required()) parts.push('wr-form-field--required');\n    return parts.join(' ');\n  });\n}\n\n/**\n * One error message tied to a validator key. Renders only when the\n * parent form-field has a matching error in `control.errors`.\n *\n * @example\n * ```html\n * <wr-form-error key=\"required\">This field is required.</wr-form-error>\n * <wr-form-error key=\"email\">That doesn't look right.</wr-form-error>\n * ```\n */\n@Component({\n  selector: 'wr-form-error',\n  template: `<ng-content />`,\n  encapsulation: ViewEncapsulation.None,\n  host: {\n    class: 'wr-form-error wr-form-field__error',\n    role: 'alert',\n    '[attr.data-key]': 'key() ?? null',\n  },\n})\nexport class WrFormError {\n  /**\n   * Validator key this message corresponds to (e.g. `'required'`).\n   * Optional — without a key the message always renders, which is the\n   * plain inline-error usage inside `<wr-form-item>`.\n   */\n  readonly key = input<string>();\n}\n","@if (label()) {\n  <label class=\"wr-form-field__label\" [attr.for]=\"controlId()\">\n    {{ label() }}\n    @if (required()) {\n      <span class=\"wr-form-field__required\" aria-hidden=\"true\">*</span>\n    } @else if (optional()) {\n      <span class=\"wr-form-field__optional\">(optional)</span>\n    }\n  </label>\n}\n\n<div class=\"wr-form-field__control\"><ng-content /></div>\n\n@if (hasError()) {\n  <div class=\"wr-form-field__errors\">\n    <ng-content select=\"wr-form-error\" />\n  </div>\n} @else if (hint()) {\n  <small class=\"wr-form-field__hint\">{{ hint() }}</small>\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAAA;;;;;AAKG;AAKH;;;;;;;;;;;;;;;;AAgBG;MAOU,UAAU,CAAA;AACrB;;;;AAIG;IACM,QAAQ,GAAG,KAAK,CAAC,KAAK,gFAAI,SAAS,EAAE,qBAAqB,EAAA,CAAG;AAEnD,IAAA,OAAO,GAAG,QAAQ,CAAC,MAAK;AACzC,QAAA,MAAM,KAAK,GAAG,CAAC,cAAc,CAAC;QAC9B,IAAI,IAAI,CAAC,QAAQ,EAAE;AAAE,YAAA,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC;AACtD,QAAA,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;IACxB,CAAC;gFAAC;uGAZS,UAAU,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;AAAV,IAAA,OAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OA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