{"version":3,"file":"odx-angular-components-toggle-button-group.mjs","sources":["../../../../libs/angular/components/toggle-button-group/src/lib/components/toggle-button/toggle-button.component.ts","../../../../libs/angular/components/toggle-button-group/src/lib/components/toggle-button/toggle-button.component.html","../../../../libs/angular/components/toggle-button-group/src/lib/toggle-button-group.component.ts","../../../../libs/angular/components/toggle-button-group/src/lib/toggle-button-group.component.html","../../../../libs/angular/components/toggle-button-group/src/lib/toggle-button-group.module.ts","../../../../libs/angular/components/toggle-button-group/src/odx-angular-components-toggle-button-group.ts"],"sourcesContent":["import { ChangeDetectionStrategy, Component, ElementRef, ViewChild, ViewEncapsulation } from '@angular/core';\nimport { DisabledController, ReadonlyController } from '@odx/angular';\nimport { RadioControlDirective } from '@odx/angular/cdk/radio-group-control';\nimport { CSSComponent } from '@odx/angular/internal';\nimport { injectElement } from '@odx/angular/utils';\n\n/**\n * ToggleButtonComponent represents an individual toggle button, akin to a radio button but styled distinctly.\n * It integrates with Angular's forms as part of a radio group control, allowing for keyboard navigation and\n * accessibility features. This component is designed to be used within a `ToggleButtonGroupComponent`.\n *\n * @template T - The type of the value handled by the toggle button.\n *\n * Extends RadioControlDirective to provide additional behavior.\n *\n * @see {RadioControlDirective}\n */\n@CSSComponent('toggle-button')\n@Component({\n  standalone: true,\n  selector: 'odx-toggle-button',\n  templateUrl: './toggle-button.component.html',\n  encapsulation: ViewEncapsulation.None,\n  changeDetection: ChangeDetectionStrategy.OnPush,\n  providers: [DisabledController.connect(), ReadonlyController.connect()],\n  host: {\n    role: 'button',\n  },\n})\nexport class ToggleButtonComponent<T = unknown> extends RadioControlDirective<T> {\n  @ViewChild('input')\n  protected inputElement!: ElementRef<HTMLInputElement>;\n\n  public readonly element = injectElement();\n\n  /**\n   * Sets focus to the input element of the toggle button.\n   */\n  public focus(): void {\n    this.inputElement.nativeElement?.focus();\n  }\n}\n","<label class=\"odx-toggle-button__label\">\n  <div class=\"odx-toggle-button__indicator\">\n    <input\n      class=\"odx-radio-button__input\"\n      type=\"radio\"\n      [attr.aria-checked]=\"ariaChecked\"\n      [attr.aria-invalid]=\"radioGroupControl.hasError || null\"\n      [attr.aria-readonly]=\"readonlyController?.readonly || null\"\n      [attr.aria-required]=\"radioGroupControl.isRequired || null\"\n      [checked]=\"isActive\"\n      [disabled]=\"disabledController?.disabled || readonlyController?.readonly\"\n      [name]=\"radioGroupControl.name\"\n      [readonly]=\"readonlyController?.readonly\"\n      [required]=\"radioGroupControl.isRequired\"\n      [value]=\"value\"\n      (change)=\"radioGroupControl.updateValue(value)\"\n      #input\n    />\n    <ng-content />\n  </div>\n</label>\n","import { CommonModule } from '@angular/common';\nimport { ChangeDetectionStrategy, Component, ContentChildren, forwardRef, inject, OnInit, QueryList, ViewEncapsulation } from '@angular/core';\nimport { DelegateFocusDirective, DisabledController, ReadonlyController } from '@odx/angular';\nimport { ActiveIndicatorDirective } from '@odx/angular/cdk/active-indicator';\nimport { RADIO_GROUP_CONTROL, RadioGroupControlDirective } from '@odx/angular/cdk/radio-group-control';\nimport { CSSComponent } from '@odx/angular/internal';\nimport { injectElement, untilDestroyed } from '@odx/angular/utils';\nimport { defer, map, merge, startWith, tap } from 'rxjs';\nimport { ToggleButtonComponent } from './components';\n\n/**\n * ToggleButtonGroupComponent acts as a container for a group of toggle buttons,\n * managing their state and focus within a group context.\n *\n * @template T - The type of the value handled by the toggle buttons.\n *\n * It extends the RadioGroupControlDirective, allowing it to control the selection and state\n * of contained toggle buttons similar to how radio buttons are managed.\n *\n * Has host directive DelegateFocusDirective.\n *\n * @see {RadioGroupControlDirective}\n * @see {DelegateFocusDirective}\n */\n@CSSComponent('toggle-button-group')\n@Component({\n  standalone: true,\n  selector: 'odx-toggle-button-group',\n  imports: [CommonModule, ActiveIndicatorDirective],\n  templateUrl: './toggle-button-group.component.html',\n  changeDetection: ChangeDetectionStrategy.OnPush,\n  encapsulation: ViewEncapsulation.None,\n  providers: [\n    {\n      provide: RADIO_GROUP_CONTROL,\n      useExisting: forwardRef(() => ToggleButtonGroupComponent),\n      multi: false,\n    },\n    DisabledController.connect(),\n    ReadonlyController.connect(),\n  ],\n  hostDirectives: [DelegateFocusDirective],\n})\nexport class ToggleButtonGroupComponent<T = unknown> extends RadioGroupControlDirective<T> implements OnInit {\n  private readonly delegateFocusDirective = inject(DelegateFocusDirective, { host: true });\n  private readonly takeUntilDestroyed = untilDestroyed();\n\n  protected activeElement$ = defer(() => merge(this.toggleButtons.changes, this.change$)).pipe(\n    startWith(undefined),\n    map(() => this.toggleButtons.find((button) => button.isActive)?.element.nativeElement ?? null),\n    tap((activeElement) => this.element.nativeElement.classList.toggle('is-active', !!activeElement)),\n  );\n\n  @ContentChildren(ToggleButtonComponent)\n  protected toggleButtons!: QueryList<ToggleButtonComponent>;\n\n  public readonly element = injectElement();\n\n  public ngOnInit(): void {\n    this.delegateFocusDirective.focused.pipe(this.takeUntilDestroyed()).subscribe(() => {\n      this.getFirstToggleButton()?.focus();\n    });\n  }\n\n  private getFirstToggleButton(): ToggleButtonComponent | null {\n    return this.toggleButtons?.toArray()[0] ?? null;\n  }\n}\n","<ng-content select=\"odx-toggle-button\" />\n<div class=\"odx-toggle-button-group__indicator\" [odxActiveIndicator]=\"activeElement$ | async\"></div>\n","import { NgModule } from '@angular/core';\nimport { CoreModule } from '@odx/angular';\nimport { ToggleButtonComponent } from './components';\nimport { ToggleButtonGroupComponent } from './toggle-button-group.component';\n\nconst modules = [ToggleButtonGroupComponent, ToggleButtonComponent];\n\n@NgModule({\n  imports: modules,\n  exports: [CoreModule, ...modules],\n})\nexport class ToggleButtonGroupModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;;;;AAMA;;;;;;;;;;AAUG;AAaI,IAAM,qBAAqB,GAA3B,MAAM,qBAAmC,SAAQ,qBAAwB,CAAA;AAAzE,IAAA,WAAA,GAAA;;QAIW,IAAA,CAAA,OAAO,GAAG,aAAa,EAAE;AAQ1C,IAAA;AANC;;AAEG;IACI,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