UNPKG

@edugouvfr/ngx-dsfr

Version:

NgxDsfr est un portage Angular des éléments d'interface du Système de Design de l'État Français (DSFR).

76 lines 13 kB
import { Component, forwardRef, Input, ViewEncapsulation } from '@angular/core'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; import { DefaultControlComponent, DsfrPositionConst } from '../../shared'; import * as i0 from "@angular/core"; import * as i1 from "../../shared"; import * as i2 from "@angular/common"; import * as i3 from "@angular/forms"; export class DsfrFormToggleComponent extends DefaultControlComponent { constructor(i18n) { super(); this.i18n = i18n; /** Position du libellé, à droite par défaut. */ this.labelPosition = DsfrPositionConst.RIGHT; /** * Permet d'afficher le libellé, court, décrivant l'état de l’interrupteur (activé / désactivé), placé en dessous du * switch. Il est affiché par défaut, il est conseillé de le mettre afin de faciliter la compréhension de * l’utilisateur - Optionnel. */ this.showCheckedHint = true; } get hintId() { return this.inputId + '-hint-text'; } /** * Permet d'initialiser de forcer la valeur initiale à une valeur booléenne * @internal */ writeValue(value) { super.writeValue(value ?? false); } /** * @ignore */ getDataLabelChecked() { return this.showCheckedHint ? this.checkedHintLabel || this.i18n.t('toggle.dataLabelChecked') : ''; } /** * @ignore */ getDataLabelUnchecked() { return this.showCheckedHint ? this.uncheckedHintLabel || this.i18n.t('toggle.dataLabelUnchecked') : ''; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DsfrFormToggleComponent, deps: [{ token: i1.I18nService }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: DsfrFormToggleComponent, selector: "dsfr-form-toggle", inputs: { labelPosition: "labelPosition", showCheckedHint: "showCheckedHint", checkedHintLabel: "checkedHintLabel", uncheckedHintLabel: "uncheckedHintLabel", showSeparator: "showSeparator", error: "error", valid: "valid" }, providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => DsfrFormToggleComponent), multi: true, }, ], usesInheritance: true, ngImport: i0, template: "<div\n class=\"fr-toggle\"\n [ngClass]=\"{\n 'fr-toggle--label-left': labelPosition === 'left',\n 'fr-toggle--border-bottom': showSeparator,\n 'fr-toggle--valid': valid && !error,\n 'fr-toggle--error': error\n }\">\n <input\n type=\"checkbox\"\n class=\"fr-toggle__input\"\n [id]=\"inputId\"\n [attr.name]=\"name ? name : null\"\n [attr.aria-describedby]=\"hint ? hintId : null\"\n [disabled]=\"disabled ?? false\"\n [attr.checked]=\"value ? true : null\"\n [(ngModel)]=\"value\" />\n <label\n class=\"fr-toggle__label\"\n [attr.for]=\"inputId\"\n [attr.data-fr-checked-label]=\"getDataLabelChecked()\"\n [attr.data-fr-unchecked-label]=\"getDataLabelUnchecked()\">\n <ng-container *ngIf=\"label\">{{ label }}</ng-container>\n <ng-content *ngIf=\"!label\"></ng-content>\n </label>\n <p *ngIf=\"hint\" [id]=\"hintId\" class=\"fr-hint-text\">{{ hint }}</p>\n</div>\n", dependencies: [{ kind: "directive", type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i3.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }], encapsulation: i0.ViewEncapsulation.None }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DsfrFormToggleComponent, decorators: [{ type: Component, args: [{ selector: 'dsfr-form-toggle', encapsulation: ViewEncapsulation.None, providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => DsfrFormToggleComponent), multi: true, }, ], template: "<div\n class=\"fr-toggle\"\n [ngClass]=\"{\n 'fr-toggle--label-left': labelPosition === 'left',\n 'fr-toggle--border-bottom': showSeparator,\n 'fr-toggle--valid': valid && !error,\n 'fr-toggle--error': error\n }\">\n <input\n type=\"checkbox\"\n class=\"fr-toggle__input\"\n [id]=\"inputId\"\n [attr.name]=\"name ? name : null\"\n [attr.aria-describedby]=\"hint ? hintId : null\"\n [disabled]=\"disabled ?? false\"\n [attr.checked]=\"value ? true : null\"\n [(ngModel)]=\"value\" />\n <label\n class=\"fr-toggle__label\"\n [attr.for]=\"inputId\"\n [attr.data-fr-checked-label]=\"getDataLabelChecked()\"\n [attr.data-fr-unchecked-label]=\"getDataLabelUnchecked()\">\n <ng-container *ngIf=\"label\">{{ label }}</ng-container>\n <ng-content *ngIf=\"!label\"></ng-content>\n </label>\n <p *ngIf=\"hint\" [id]=\"hintId\" class=\"fr-hint-text\">{{ hint }}</p>\n</div>\n" }] }], ctorParameters: function () { return [{ type: i1.I18nService }]; }, propDecorators: { labelPosition: [{ type: Input }], showCheckedHint: [{ type: Input }], checkedHintLabel: [{ type: Input }], uncheckedHintLabel: [{ type: Input }], showSeparator: [{ type: Input }], error: [{ type: Input }], valid: [{ type: Input }] } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9ybS10b2dnbGUuY29tcG9uZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vcHJvamVjdHMvbmd4LWRzZnItY29tcG9uZW50cy9zcmMvbGliL2Zvcm1zL2Zvcm0tdG9nZ2xlL2Zvcm0tdG9nZ2xlLmNvbXBvbmVudC50cyIsIi4uLy4uLy4uLy4uLy4uLy4uL3Byb2plY3RzL25neC1kc2ZyLWNvbXBvbmVudHMvc3JjL2xpYi9mb3Jtcy9mb3JtLXRvZ2dsZS9mb3JtLXRvZ2dsZS5jb21wb25lbnQuaHRtbCJdLCJ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