{"version":3,"file":"talenra-ngx-base-checkbox.mjs","sources":["../../../projects/ngx-base/checkbox/src/checkbox/checkbox.types.ts","../../../projects/ngx-base/checkbox/src/checkbox/checkbox.component.ts","../../../projects/ngx-base/checkbox/src/checkbox/checkbox.component.html","../../../projects/ngx-base/checkbox/talenra-ngx-base-checkbox.ts"],"sourcesContent":["import { CheckboxComponent } from './checkbox.component';\n\n/**\n * Event emitted when the checkbox's `checked` value changes.\n *\n * ### Import\n *\n * ```typescript\n * import { CheckboxChange } from '@talenra/ngx-base/checkbox';\n * ```\n *\n * @see {@link CheckboxComponent}\n */\nexport interface CheckboxChange {\n  /** Reference to the emitting checkbox component */\n  source: CheckboxComponent;\n  /** Current value of the checked property */\n  checked: boolean;\n}\n\n/**\n * Values accepted by the `CheckboxComponent`'s `size` input.\n *\n * ```html\n * <talenra-checkbox formControlName=\"username\" label=\"Username\" size=\"s\"></talenra-checkbox>\n * ```\n *\n * ### Import\n *\n * ```typescript\n * import { CheckboxSize } from '@talenra/ngx-base/checkbox';\n * ```\n *\n * @see {@link CheckboxComponent}\n * @see {@link TCheckboxComponent}\n */\nexport const CheckboxSize = {\n  S: 's',\n  M: 'm',\n} as const;\n\n/**\n * Type of values accepted by the `CheckboxComponent`'s `size` input.\n *\n * ### Import\n *\n * ```typescript\n * import { TCheckboxSize } from '@talenra/ngx-base/checkbox';\n * ```\n *\n * @see {@link CheckboxComponent}\n * @see {@link CheckboxSize}\n */\nexport type TCheckboxSize = (typeof CheckboxSize)[keyof typeof CheckboxSize];\n\n/**\n * Values accepted by the `CheckboxComponent`'s `labelPosition` input. Determines\n * whether the label is displayed before or after the checkbox.\n *\n * ```html\n * <talenra-checkbox formControlName=\"selectAll\" label=\"Select all\" labelPosition=\"before\"></talenra-checkbox>\n * ```\n *\n * ### Import\n *\n * ```typescript\n * import { CheckboxLabelPosition } from '@talenra/ngx-base/checkbox';\n * ```\n *\n * @see {@link CheckboxComponent}\n * @see {@link TCheckboxLabelPosition}\n */\nexport const CheckboxLabelPosition = {\n  Before: 'before',\n  After: 'after',\n} as const;\n\n/**\n * Type of values accepted by the `CheckboxComponent`'s `labelPosition` input.\n *\n * ### Import\n *\n * ```typescript\n * import { TCheckboxLabelPosition } from '@talenra/ngx-base/checkbox';\n * ```\n *\n * @see {@link CheckboxComponent}\n * @see {@link CheckboxLabelPosition}\n */\nexport type TCheckboxLabelPosition = (typeof CheckboxLabelPosition)[keyof typeof CheckboxLabelPosition];\n","import {\n  AfterViewInit,\n  booleanAttribute,\n  ChangeDetectionStrategy,\n  ChangeDetectorRef,\n  Component,\n  EventEmitter,\n  forwardRef,\n  Input,\n  OnInit,\n  Output,\n  inject,\n} from '@angular/core';\nimport { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';\nimport { OnOffControlBaseComponent } from '@talenra/ngx-base/shared';\nimport {\n  CheckboxChange,\n  CheckboxSize,\n  CheckboxLabelPosition,\n  TCheckboxSize,\n  TCheckboxLabelPosition,\n} from './checkbox.types';\n\n/**\n * Used to create a \"unique\" ID for each radio button.\n *\n * @internal\n */\nlet nextId = 0;\n\n/**\n * `<talenra-checkbox>` is an on/off control.\n *\n * Other than a native checkbox element, `<talenra-checkbox>` keeps `value` and `checked`\n * properties in sync (both are either `true` or `false`).\n *\n * If property `indeterminate` is set true, the checkbox is presented in \"mixed\" state,\n * regardless of its value or checked state.\n *\n * #### Reactive form\n *\n * ```typescript\n * // Component class\n * sampleForm: FormGroup = new FormGroup({\n *   rememberMe: new FormControl(true),\n *   disabledCheckbox: new FormControl({ value: false, disabled: true }),\n * });\n * ```\n *\n * ```html\n * <!-- Component template -->\n * <form [formGroup]=\"sampleForm\">\n *   <talenra-checkbox formControlName=\"rememberMe\" label=\"Remember me\"></talenra-checkbox>\n *   <talenra-checkbox formControlName=\"disabledCheckbox\" label=\"Toggle (disabled)\"></talenra-checkbox>\n * </form>\n * ```\n *\n * #### Template driven form\n *\n * ```typescript\n * // Import `FormsModule` in the declaring module\n * import { FormsModule } from '@angular/forms';\n * @NgModule({\n *  // ...\n *  imports: [FormsModule],\n *})\n * ```\n *\n * ```typescript\n * // Component class\n * sampleValue = true;\n * ```\n *\n * ```html\n * <!-- Component template -->\n * <form #templateDrivenForm=\"ngForm\">\n *   <talenra-checkbox name=\"sampleValue\" [(ngModel)]=\"sampleValue\" label=\"Sample value\"></talenra-checkbox>\n * </form>\n * ```\n *\n * #### Formless\n *\n * ```typescript\n * // Component class\n * sampleValue = true;\n * ```\n *\n * ```html\n * <!-- Component template -->\n * <talenra-checkbox [(ngModel)]=\"sampleValue\" label=\"Sample value\"></talenra-checkbox>\n * ```\n *\n * ### Import\n *\n * ```typescript\n * import { CheckboxModule } from '@talenra/ngx-base/checkbox';\n * ```\n *\n * <example-url>../../#/on-off-controls</example-url>\n */\n@Component({\n  selector: 'talenra-checkbox',\n  templateUrl: './checkbox.component.html',\n  styleUrls: ['./checkbox.component.scss'],\n  changeDetection: ChangeDetectionStrategy.OnPush,\n  host: {\n    '[class]': 'hostClass',\n  },\n  providers: [\n    {\n      provide: NG_VALUE_ACCESSOR,\n      useExisting: forwardRef(() => CheckboxComponent),\n      multi: true,\n    },\n  ],\n})\nexport class CheckboxComponent\n  extends OnOffControlBaseComponent\n  implements ControlValueAccessor, OnInit, AfterViewInit\n{\n  /**\n   * Determines the size of the rendered checkbox.\n   *\n   * ```html\n   * <talenra-checkbox formControlName=\"username\" label=\"Username\" size=\"s\"></talenra-checkbox>\n   * ```\n   */\n  @Input() public size: TCheckboxSize = CheckboxSize.M;\n\n  /**\n   * Determines whether the label is displayed before or after the checkbox.\n   *\n   * ```html\n   * <talenra-checkbox formControlName=\"selectAll\" label=\"Select all\" labelPosition=\"before\"></talenra-checkbox>\n   * ```\n   */\n  @Input() public labelPosition: TCheckboxLabelPosition = CheckboxLabelPosition.After;\n\n  private useTransition = false;\n\n  private hostClass = '';\n\n  /**\n   * The control's indeterminate state.\n   *\n   * \"Indeterminate\" means it is not possible to say whether the control is checked or unchecked.\n   * Check the MDN docs for more information and a use-case.\n   *\n   * The checkbox is presented in \"mixed\" state while `indeterminate` is `true`, regardless of\n   * its `checked` state or `value`.\n   *\n   * ```html\n   * <talenra-checkbox formControlName=\"selectAll\" label=\"Select all\" indeterminate></talenra-checkbox>\n   * <talenra-checkbox formControlName=\"selectAll\" label=\"Select all\" [indeterminate]=\"myCondition\"></talenra-checkbox>\n   * ```\n   *\n   * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input/checkbox#indeterminate_state_checkboxes|MDN: Indeterminate state checkboxes}\n   */\n  @Input({ transform: booleanAttribute })\n  /** Get the control's indeterminate state. */\n  get indeterminate() {\n    return this._indeterminate;\n  }\n  /** Set the control's indeterminate state. */\n  set indeterminate(value: boolean) {\n    if (value === this.indeterminate) return;\n    this._indeterminate = value;\n    this.indeterminateChange.emit(this.indeterminate);\n  }\n  /** @internal */\n  _indeterminate = false;\n\n  /**\n   * Disables handling of click events while the visual appearance of Checkbox is not modified (other than `disable`\n   * would). Disabling pointer events is useful when the checkbox is used as a state indicator only and logic is handled\n   * elsewhere.\n   *\n   * ```html\n   * <talenra-checkbox\n   *   pointerDisabled\n   *   [ngModel]=\"checkboxValue\"\n   *   (click)=\"handleCheckboxClick()\"\n   * ></talenra-checkbox>\n   * ```\n   */\n  @Input({ transform: booleanAttribute })\n  pointerDisabled = false;\n\n  /**\n   * Event emitted when the checkbox's `indeterminate` value changes.\n   *\n   * ```typescript\n   * // Component class\n   * indeterminateChange(indeterminate: boolean): void => {\n   *   console.log(`Checkbox is ${indeterminate ? '' : 'not '}indeterminate`);\n   * }\n   * ```\n   *\n   * ```html\n   * <!-- Component template -->\n   * <talenra-checkbox\n   *   formControlName=\"selectAll\"\n   *   label=\"Select all\"\n   *   indeterminate\n   *   (indeterminateChange)=\"indeterminateChange($event)\"></talenra-checkbox>\n   * ```\n   */\n  @Output() indeterminateChange = new EventEmitter<boolean>();\n\n  protected changeDetector: ChangeDetectorRef = inject(ChangeDetectorRef);\n\n  /** @internal */\n  ngOnInit(): void {\n    this.id = `talenra-checkbox--${nextId++}`;\n    this.updateHostClass();\n  }\n\n  /** @internal */\n  ngAfterViewInit(): void {\n    // Prevent animation on initialization\n    setTimeout(() => {\n      this.useTransition = true;\n      this.updateHostClass();\n    }, 50);\n  }\n\n  /**\n   * Event emitted when the checkbox's `checked` value changes.\n   *\n   * ```typescript\n   * // Component class\n   * import { CheckboxChange } from '@talenra/ngx-base/checkbox';\n   * checkboxChange: (change: CheckboxChange) => {\n   *   console.log(`Checkbox (id: ${change.source.id}) is ${change.checked ? '' : 'not '}checked`);\n   * }\n   * ```\n   *\n   * ```html\n   * <!-- Component template -->\n   * <talenra-checkbox\n   *   formControlName=\"selectAll\"\n   *   label=\"Select all\"\n   *   checked\n   *   (checkedChange)=\"checkboxChange($event)></talenra-checkbox>\n   * ```\n   */\n  @Output()\n  // eslint-disable-next-line @angular-eslint/no-output-native\n  checkedChange: EventEmitter<CheckboxChange> = new EventEmitter<CheckboxChange>();\n\n  /**\n   * Handle user click\n   *\n   * @internal\n   */\n  public handleClick(): void {\n    // Ignore click if disabled\n    if (this.disabled || this.pointerDisabled) return;\n    // A user click always ends indeterminate state\n    this.indeterminate = false;\n    this.value = !this.value;\n    this.checkedChange.emit({ source: this, checked: this.value } as CheckboxChange);\n  }\n\n  /** @internal */\n  setDisabledState(isDisabled: boolean): void {\n    super.setDisabledState(isDisabled);\n    this.updateHostClass();\n    this.changeDetector.markForCheck();\n  }\n\n  private updateHostClass(): void {\n    this.hostClass = [\n      this.disabled ? 'disabled' : '',\n      this.labelPosition === CheckboxLabelPosition.Before ? 'label-before' : '',\n      this.size === CheckboxSize.S ? 'size--s' : '',\n      this.useTransition ? 'use-transition' : '',\n      !this.label ? 'label-empty' : '',\n    ]\n      .filter((item) => item)\n      .join(' ');\n  }\n}\n","<input\n  type=\"checkbox\"\n  tabindex=\"0\"\n  [attr.aria-checked]=\"indeterminate ? 'mixed' : checked\"\n  [checked]=\"checked\"\n  [disabled]=\"disabled\"\n  [id]=\"id\"\n  [value]=\"value\"\n  (blur)=\"handleBlur()\"\n  (click)=\"handleClick()\" />\n<span class=\"checkbox\" (click)=\"handleClick()\">\n  <svg class=\"icon icon--checkmark\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\">\n    <path d=\"M6.2 10.1L4 7.9 2.6 9.3l3.6 3.6 8-8-1.4-1.4-6.6 6.6z\" />\n  </svg>\n  <svg class=\"icon icon--indeterminate\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\">\n    <path d=\"M13 7H3v2h10V7z\" />\n  </svg>\n  <svg class=\"icon icon--size-s icon--checkmark\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 12 12\">\n    <path d=\"M4.3 7.4L2.7 5.9l-1 1 2.6 2.6 6-6-1-1-5 4.9z\" />\n  </svg>\n  <svg class=\"icon icon--size-s icon--indeterminate\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 12 12\">\n    <path d=\"M10 5.2H2v1.5h8V5.2z\" />\n  </svg>\n</span>\n<label class=\"label\" [attr.for]=\"id\">{{ label }}</label>\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAoBA;;;;;;;;;;;;;;;AAeG;AACU,MAAA,YAAY,GAAG;AAC1B,IAAA,CAAC,EAAE,GAAG;AACN,IAAA,CAAC,EAAE,GAAG;;AAiBR;;;;;;;;;;;;;;;;AAgBG;AACU,MAAA,qBAAqB,GAAG;AACnC,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,KAAK,EAAE,OAAO;;;ACnDhB;;;;AAIG;AACH,IAAI,MAAM,GAAG,CAAC;AAEd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqEG;AAiBG,MAAO,iBACX,SAAQ,yBAAyB,CAAA;AAjBnC,IAAA,WAAA,GAAA;;AAoBE;;;;;;AAMG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