{"version":3,"file":"fundamental-ngx-core-switch.mjs","sources":["../../../../libs/core/switch/switch.component.ts","../../../../libs/core/switch/switch.component.html","../../../../libs/core/switch/switch.module.ts","../../../../libs/core/switch/fundamental-ngx-core-switch.ts"],"sourcesContent":["import {\n    ChangeDetectionStrategy,\n    Component,\n    ElementRef,\n    EventEmitter,\n    Input,\n    OnDestroy,\n    OnInit,\n    Output,\n    ViewChild,\n    ViewEncapsulation,\n    inject\n} from '@angular/core';\nimport { FormsModule } from '@angular/forms';\nimport { CvaControl, CvaDirective, FD_FORM_FIELD_CONTROL } from '@fundamental-ngx/cdk/forms';\nimport { Nullable } from '@fundamental-ngx/cdk/utils';\nimport { ContentDensityObserver, contentDensityObserverProviders } from '@fundamental-ngx/core/content-density';\nimport { FormItemControl, registerFormItemControl } from '@fundamental-ngx/core/form';\nimport { IconComponent } from '@fundamental-ngx/core/icon';\nimport { FdTranslatePipe } from '@fundamental-ngx/i18n';\nimport { Subscription } from 'rxjs';\n\nlet switchUniqueId = 0;\n\n/**\n * The Switch component is used to activate or deactivate an element.\n * It uses a visual metaphor to inform the user of the state of the switch.\n */\n@Component({\n    selector: 'fd-switch',\n    templateUrl: './switch.component.html',\n    styleUrl: './switch.component.scss',\n    providers: [\n        CvaControl,\n        { provide: FD_FORM_FIELD_CONTROL, useExisting: SwitchComponent, multi: true },\n        registerFormItemControl(SwitchComponent),\n        contentDensityObserverProviders()\n    ],\n    host: {\n        class: 'fd-form__item fd-form__item--check fd-switch-custom',\n        '[attr.id]': 'id',\n        '(focusout)': '_cva.onTouched()'\n    },\n    hostDirectives: [\n        {\n            directive: CvaDirective,\n            inputs: ['state', 'stateMessage', 'disabled', 'name', 'readonly', 'ariaLabelledBy', 'ariaLabel']\n        }\n    ],\n    encapsulation: ViewEncapsulation.None,\n    changeDetection: ChangeDetectionStrategy.OnPush,\n    imports: [FormsModule, FdTranslatePipe, IconComponent]\n})\nexport class SwitchComponent implements OnInit, OnDestroy, FormItemControl {\n    /** @hidden */\n    @ViewChild('switchInput')\n    inputElement: ElementRef<HTMLInputElement>;\n\n    /** Optional text for the active state of the switch. */\n    @Input()\n    activeText = '';\n\n    /** Optional text for the inactive state of the switch. */\n    @Input()\n    inactiveText = '';\n\n    /** Id for the switch component. If omitted, a unique one is generated. */\n    @Input()\n    id = `fd-switch-${switchUniqueId++}`;\n\n    /** If it is mandatory field */\n    @Input()\n    required = false;\n\n    /** Whether the switch is checked. */\n    @Input()\n    set checked(value: boolean) {\n        this._cva.value = value;\n    }\n    get checked(): boolean {\n        return this._cva.value;\n    }\n\n    /** Whether the switch is semantic */\n    @Input()\n    semantic = false;\n\n    /** aria-label attribute of the inner input element. */\n    @Input()\n    ariaLabel: Nullable<string>;\n\n    /** aria-labelledby attribute of the inner input element. */\n    @Input()\n    ariaLabelledBy: Nullable<string>;\n\n    /**\n     * Event fired when the state of the switch changes.\n     * *$event* can be used to retrieve the new state of the switch.\n     */\n    @Output()\n    readonly checkedChange: EventEmitter<boolean> = new EventEmitter<boolean>();\n\n    /** @hidden */\n    @ViewChild('switchEl', { read: ElementRef })\n    _switchLabelWrapperEl: ElementRef;\n\n    /** @hidden */\n    readonly _cva = inject<CvaDirective<boolean>>(CvaDirective);\n\n    /** @hidden */\n    private _subscriptions = new Subscription();\n\n    /** @hidden */\n    private readonly _cvaControl = inject(CvaControl);\n\n    /** @hidden */\n    constructor(readonly _contentDensityObserver: ContentDensityObserver) {\n        // Set initial value.\n        this._cva.value = false;\n    }\n\n    /** @hidden */\n    ngOnInit(): void {\n        this._cvaControl.listenToChanges();\n    }\n\n    /** @hidden */\n    ngOnDestroy(): void {\n        this._subscriptions.unsubscribe();\n    }\n\n    /** Set focus on the input element. */\n    focus(): void {\n        this.inputElement.nativeElement.focus();\n    }\n\n    /** Get the id of the inner input element of the switch. */\n    get innerInputId(): string {\n        return `${this.id}-input`;\n    }\n\n    /** Get the id of the semantic label element of the switch. */\n    get _semanticLabelId(): string {\n        return `${this.id}-semantic-label`;\n    }\n\n    /** Checked property of the switch. */\n    set isChecked(value) {\n        this._switchLabelWrapperEl.nativeElement.classList.remove('fd-switch-no-animate');\n        this._cva.setValue(value);\n        this.checkedChange.emit(value);\n        setTimeout(() => {\n            // add the no-animate class after the transition duration, 100ms\n            this._switchLabelWrapperEl.nativeElement.classList.add('fd-switch-no-animate');\n        }, 100);\n    }\n    get isChecked(): boolean {\n        return this._cva.value;\n    }\n}\n","<label\n    class=\"fd-switch fd-switch-no-animate\"\n    (click)=\"focus()\"\n    [style.cursor]=\"_cva.disabled ? 'auto' : 'pointer'\"\n    [class.is-compact]=\"_contentDensityObserver.isCompactSignal()\"\n    [class.fd-switch--semantic]=\"semantic\"\n    [class.fd-switch--text]=\"activeText || inactiveText\"\n    [class.is-disabled]=\"_cva.disabled\"\n    [attr.aria-label]=\"_cva.ariaLabel\"\n    #switchEl\n>\n    <span class=\"fd-switch__control\">\n        <input\n            #switchInput\n            class=\"fd-switch__input\"\n            type=\"checkbox\"\n            role=\"switch\"\n            [id]=\"innerInputId\"\n            [attr.name]=\"_cva.name\"\n            [disabled]=\"_cva.disabled\"\n            [attr.aria-required]=\"_cva.required\"\n            [attr.aria-checked]=\"_cva.value\"\n            [attr.aria-labelledby]=\"_cva.ariaLabelledBy + ' ' + (semantic ? _semanticLabelId : '')\"\n            [(ngModel)]=\"isChecked\"\n        />\n        <div class=\"fd-switch__slider\">\n            <div class=\"fd-switch__track\" aria-hidden=\"true\">\n                @if (activeText) {\n                    <span class=\"fd-switch__text fd-switch__text--on\">\n                        {{ activeText }}\n                    </span>\n                } @else {\n                    <fd-icon role=\"presentation\" class=\"fd-switch__icon fd-switch__icon--on\" glyph=\"accept\"></fd-icon>\n                }\n                <span class=\"fd-switch__handle\" role=\"presentation\"></span>\n                @if (inactiveText) {\n                    <span class=\"fd-switch__text fd-switch__text--off\">\n                        {{ inactiveText }}\n                    </span>\n                } @else {\n                    <fd-icon\n                        role=\"presentation\"\n                        class=\"fd-switch__icon--off fd-switch__icon\"\n                        [glyph]=\"semantic ? 'decline' : 'less'\"\n                    ></fd-icon>\n                }\n            </div>\n            @if (semantic) {\n                <span [id]=\"_semanticLabelId\" aria-hidden=\"true\" class=\"fd-switch__invisible-text\">\n                    {{\n                        _cva.value\n                            ? ('coreSwitch.semanticAcceptLabel' | fdTranslate)()\n                            : ('coreSwitch.semanticDeclineLabel' | fdTranslate)()\n                    }}\n                </span>\n            }\n        </div>\n    </span>\n</label>\n","import { NgModule } from '@angular/core';\nimport { SwitchComponent } from './switch.component';\n\n/**\n * @deprecated\n * Use direct imports of components and directives.\n */\n@NgModule({\n    imports: [SwitchComponent],\n    exports: [SwitchComponent]\n})\nexport class SwitchModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;;;;AAsBA,IAAI,cAAc,GAAG,CAAC;AAEtB;;;AAGG;MA0BU,eAAe,CAAA;;IAsBxB,IACI,OAAO,CAAC,KAAc,EAAA;AACtB,QAAA,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK;IAC3B;AACA,IAAA,IAAI,OAAO,GAAA;AACP,QAAA,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK;IAC1B;;AAmCA,IAAA,WAAA,CAAqB,uBAA+C,EAAA;QAA/C,IAAA,CAAA,uBAAuB,GAAvB,uBAAuB;;QAxD5C,IAAA,CAAA,UAAU,GAAG,EAAE;;QAIf,IAAA,CAAA,YAAY,GAAG,EAAE;;AAIjB,QAAA,IAAA,CAAA,EAAE,GAAG,CAAA,UAAA,EAAa,cAAc,EAAE,EAAE;;QAIpC,IAAA,CAAA,QAAQ,GAAG,KAAK;;QAahB,IAAA,CAAA,QAAQ,GAAG,KAAK;AAUhB;;;AAGG;AAEM,QAAA,IAAA,CAAA,aAAa,GAA0B,IAAI,YAAY,EAAW;;AAOlE,QAAA,IAAA,CAAA,IAAI,GAAG,MAAM,CAAwB,YAAY,CAAC;;AAGnD,QAAA,IAAA,CAAA,cAAc,GAAG,IAAI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