{"version":3,"file":"ngwr-radio.mjs","sources":["../../../projects/lib/radio/tokens/radio-group.token.ts","../../../projects/lib/radio/radio.ts","../../../projects/lib/radio/radio.html","../../../projects/lib/radio/radio-group.ts","../../../projects/lib/radio/ngwr-radio.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 { InjectionToken, type Signal } from '@angular/core';\n\n/**\n * Contract a radio uses to talk to its parent `<wr-radio-group>`.\n *\n * @internal\n */\nexport interface WrRadioGroupContext {\n  /** Shared `name` attribute applied to every native input in the group. */\n  readonly name: Signal<string>;\n  /** Currently selected value. */\n  readonly value: Signal<unknown>;\n  /** Whether the entire group is disabled. */\n  readonly isDisabled: Signal<boolean>;\n  /** Select the given value. */\n  select(value: unknown): void;\n  /** Mark the group as touched (called on blur from any child). */\n  touch(): void;\n}\n\n/**\n * Token a `<wr-radio>` injects to participate in its parent `<wr-radio-group>`\n * — reads the selected value, shares the `name` attribute, and signals\n * selection / blur back up.\n *\n * @internal\n */\nexport const WR_RADIO_GROUP = new InjectionToken<WrRadioGroupContext>('WR_RADIO_GROUP');\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, inject, input } from '@angular/core';\n\nimport { WrIcon, type WrIconName } from 'ngwr/icon';\nimport { randomId } from 'ngwr/utils';\n\nimport { WR_RADIO_GROUP } from './tokens';\n\n/**\n * Single-choice option. Must be a child of `<wr-radio-group>`.\n *\n * @example\n * ```html\n * <wr-radio-group [(ngModel)]=\"size\">\n *   <wr-radio value=\"sm\">Small</wr-radio>\n *   <wr-radio value=\"md\">Medium</wr-radio>\n *   <wr-radio value=\"lg\">Large</wr-radio>\n * </wr-radio-group>\n * ```\n *\n * @see https://ngwr.dev/components/radio\n */\nexport type WrRadioSize = 'sm' | 'md' | 'lg';\n\n@Component({\n  selector: 'wr-radio',\n  templateUrl: './radio.html',\n  encapsulation: ViewEncapsulation.None,\n  host: { '[class]': 'classes()' },\n  imports: [WrIcon],\n})\nexport class WrRadio {\n  /** Stable id used to associate the native input with its label. */\n  readonly id = input<string>(randomId('wr-radio'));\n\n  /** Value selected when this radio is checked. */\n  readonly value = input.required<unknown>();\n\n  /**\n   * Optional icon name rendered inside the dot when checked, in place of the\n   * default solid circle. Use any registered NGWR icon.\n   */\n  readonly icon = input<WrIconName | null>(null);\n\n  /** Control size — shares the `--wr-control-*` contract. @default 'md' */\n  readonly size = input<WrRadioSize>('md');\n\n  /**\n   * Disable just this option. The group can also be disabled as a whole via\n   * `<wr-radio-group disabled>`; either source disables this radio.\n   *\n   * @default false\n   */\n  readonly disabled = input(false, { transform: coerceBooleanProperty });\n\n  private readonly group = inject(WR_RADIO_GROUP, { optional: true });\n\n  constructor() {\n    if (!this.group) {\n      throw new Error('[NGWR] <wr-radio> must be used inside <wr-radio-group>.');\n    }\n  }\n\n  protected readonly name = computed(() => this.group?.name() ?? '');\n  protected readonly checked = computed(() => this.group?.value() === this.value());\n  /** Effective disabled — this option's own `disabled` or the group's. */\n  protected readonly isDisabled = computed(() => this.disabled() || (this.group?.isDisabled() ?? false));\n\n  protected readonly classes = computed(() => {\n    const parts = ['wr-radio'];\n    const size = this.size();\n    if (size !== 'md') parts.push(`wr-radio--${size}`);\n    if (this.checked()) parts.push('wr-radio--checked');\n    if (this.isDisabled()) parts.push('wr-radio--disabled');\n    if (this.icon()) parts.push('wr-radio--has-icon');\n    return parts.join(' ');\n  });\n\n  protected onSelect(): void {\n    if (this.isDisabled()) return;\n    this.group?.select(this.value());\n  }\n\n  protected onBlur(): void {\n    this.group?.touch();\n  }\n}\n","<label class=\"wr-radio__label\" [for]=\"id()\">\n  <input\n    class=\"wr-radio__input\"\n    type=\"radio\"\n    [id]=\"id()\"\n    [name]=\"name()\"\n    [checked]=\"checked()\"\n    [disabled]=\"isDisabled()\"\n    (change)=\"onSelect()\"\n    (blur)=\"onBlur()\"\n  />\n\n  <span class=\"wr-radio__dot\" aria-hidden=\"true\">\n    @if (icon(); as iconName) {\n      <wr-icon class=\"wr-radio__icon\" [name]=\"iconName\" />\n    }\n  </span>\n\n  <span class=\"wr-radio__text\">\n    <ng-content />\n  </span>\n</label>\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, forwardRef, input, signal } from '@angular/core';\nimport { type ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';\n\nimport { noop, randomId } from 'ngwr/utils';\n\nimport { WR_RADIO_GROUP, type WrRadioGroupContext } from './tokens';\n\n/**\n * Hosts a group of `<wr-radio>` children as a single-value selection.\n *\n * Implements `ControlValueAccessor` — the group's `value` is the\n * currently selected radio's `value`.\n *\n * @example\n * ```html\n * <wr-radio-group [(ngModel)]=\"size\">\n *   <wr-radio value=\"sm\">Small</wr-radio>\n *   <wr-radio value=\"md\">Medium</wr-radio>\n *   <wr-radio value=\"lg\">Large</wr-radio>\n * </wr-radio-group>\n * ```\n *\n * @see https://ngwr.dev/components/radio\n */\n@Component({\n  selector: 'wr-radio-group',\n  template: '<ng-content />',\n  encapsulation: ViewEncapsulation.None,\n  host: { class: 'wr-radio-group', role: 'radiogroup' },\n  providers: [\n    {\n      provide: NG_VALUE_ACCESSOR,\n      // eslint-disable-next-line @angular-eslint/no-forward-ref\n      useExisting: forwardRef(() => WrRadioGroup),\n      multi: true,\n    },\n    {\n      provide: WR_RADIO_GROUP,\n      // eslint-disable-next-line @angular-eslint/no-forward-ref\n      useExisting: forwardRef(() => WrRadioGroup),\n    },\n  ],\n})\nexport class WrRadioGroup implements ControlValueAccessor, WrRadioGroupContext {\n  /**\n   * Shared `name` attribute. Defaults to a random id so multiple groups\n   * on the same page don't collide.\n   */\n  readonly name = input<string>(randomId('wr-radio-group'));\n\n  /**\n   * Disable the whole group. Also set by Angular forms via `setDisabledState`.\n   *\n   * @default false\n   */\n  readonly disabled = input(false, { transform: coerceBooleanProperty });\n\n  readonly value = signal<unknown>(null);\n\n  private readonly disabledFromCva = signal(false);\n\n  /** Effective disabled state — true if either source disables. */\n  readonly isDisabled = computed(() => this.disabled() || this.disabledFromCva());\n\n  private onChange: (value: unknown) => void = noop;\n  private onTouched: () => void = noop;\n\n  // WrRadioGroupContext\n\n  select(value: unknown): void {\n    if (this.isDisabled()) return;\n    this.value.set(value);\n    this.onChange(value);\n  }\n\n  touch(): void {\n    this.onTouched();\n  }\n\n  // ControlValueAccessor\n\n  writeValue(value: unknown): void {\n    this.value.set(value);\n  }\n\n  registerOnChange(fn: (value: unknown) => void): void {\n    this.onChange = fn;\n  }\n\n  registerOnTouched(fn: () => void): void {\n    this.onTouched = fn;\n  }\n\n  setDisabledState(isDisabled: boolean): void {\n    this.disabledFromCva.set(coerceBooleanProperty(isDisabled));\n  }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;AAAA;;;;;AAKG;AAsBH;;;;;;AAMG;MACU,cAAc,GAAG,IAAI,cAAc,CAAsB,gBAAgB;;AClCtF;;;;;AAKG;MAiCU,OAAO,CAAA;;AAET,IAAA,EAAE,GAAG,KAAK,CAAS,QAAQ,CAAC,UAAU,CAAC;2EAAC;;IAGxC,KAAK,GAAG,KAAK,CAAC,QAAQ;8EAAW;AAE1C;;;AAGG;IACM,IAAI,GAAG,KAAK,CAAoB,IAAI;6EAAC;;IAGrC,IAAI,GAAG,KAAK,CAAc,IAAI;6EAAC;AAExC;;;;;AAKG;IACM,QAAQ,GAAG,KAAK,CAAC,KAAK,gFAAI,SAAS,EAAE,qBAAqB,EAAA,CAAG;IAErD,KAAK,GAAG,MAAM,CAAC,cAAc,EA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