UNPKG

primeng

Version:

PrimeNG is an open source UI library for Angular featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeB

331 lines (325 loc) 14.2 kB
import * as i1 from '@angular/common'; import { CommonModule } from '@angular/common'; import * as i0 from '@angular/core'; import { Injectable, forwardRef, input, EventEmitter, inject, booleanAttribute, numberAttribute, HostListener, ContentChildren, ContentChild, ViewChild, Output, Input, ViewEncapsulation, ChangeDetectionStrategy, Component, NgModule } from '@angular/core'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; import { SharedModule, PrimeTemplate } from 'primeng/api'; import { AutoFocus } from 'primeng/autofocus'; import { BaseEditableHolder } from 'primeng/baseeditableholder'; import { style } from '@primeuix/styles/toggleswitch'; import { BaseStyle } from 'primeng/base'; const theme = /*css*/ ` ${style} p-toggleswitch.ng-invalid.ng-dirty > .p-toggleswitch-slider { border-color: dt('toggleswitch.invalid.border.color'); } `; const inlineStyles = { root: { position: 'relative' } }; const classes = { root: ({ instance }) => [ 'p-toggleswitch p-component', { 'p-toggleswitch p-component': true, 'p-toggleswitch-checked': instance.checked(), 'p-disabled': instance.$disabled(), 'p-invalid': instance.invalid() } ], input: 'p-toggleswitch-input', slider: 'p-toggleswitch-slider', handle: 'p-toggleswitch-handle' }; class ToggleSwitchStyle extends BaseStyle { name = 'toggleswitch'; theme = theme; classes = classes; inlineStyles = inlineStyles; static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: ToggleSwitchStyle, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: ToggleSwitchStyle }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: ToggleSwitchStyle, decorators: [{ type: Injectable }] }); /** * * ToggleSwitch is used to select a boolean value. * * [Live Demo](https://www.primeng.org/toggleswitch/) * * @module toggleswitchstyle * */ var ToggleSwitchClasses; (function (ToggleSwitchClasses) { /** * Class name of the root element */ ToggleSwitchClasses["root"] = "p-toggleswitch"; /** * Class name of the input element */ ToggleSwitchClasses["input"] = "p-toggleswitch-input"; /** * Class name of the slider element */ ToggleSwitchClasses["slider"] = "p-toggleswitch-slider"; })(ToggleSwitchClasses || (ToggleSwitchClasses = {})); const TOGGLESWITCH_VALUE_ACCESSOR = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => ToggleSwitch), multi: true }; /** * ToggleSwitch is used to select a boolean value. * @group Components */ class ToggleSwitch extends BaseEditableHolder { /** * Style class of the component. * @deprecated since v20.0.0, use `class` instead. * @group Props */ styleClass; /** * Index of the element in tabbing order. * @group Props */ tabindex; /** * Identifier of the input element. * @group Props */ inputId; /** * When present, it specifies that the component cannot be edited. * @group Props */ readonly; /** * Value in checked state. * @group Props */ trueValue = true; /** * Value in unchecked state. * @group Props */ falseValue = false; /** * Used to define a string that autocomplete attribute the current element. * @group Props */ ariaLabel; /** * Specifies the size of the component. * @defaultValue undefined * @group Props */ size = input(...(ngDevMode ? [undefined, { debugName: "size" }] : [])); /** * Establishes relationships between the component and label(s) where its value should be one or more element IDs. * @group Props */ ariaLabelledBy; /** * When present, it specifies that the component should automatically get focus on load. * @group Props */ autofocus; /** * Callback to invoke when the on value change. * @param {ToggleSwitchChangeEvent} event - Custom change event. * @group Emits */ onChange = new EventEmitter(); input; /** * Callback to invoke when the on value change. * @type {TemplateRef<ToggleSwitchHandleTemplateContext>} context - Context of the template * @example * ```html * <ng-template #handle let-checked="checked"> </ng-template> * ``` * @see {@link ToggleSwitchHandleTemplateContext} * @group Templates */ handleTemplate; _handleTemplate; focused = false; _componentStyle = inject(ToggleSwitchStyle); templates; onHostClick(event) { this.onClick(event); } ngAfterContentInit() { this.templates.forEach((item) => { switch (item.getType()) { case 'handle': this._handleTemplate = item.template; break; default: this._handleTemplate = item.template; break; } }); } onClick(event) { if (!this.$disabled() && !this.readonly) { this.writeModelValue(this.checked() ? this.falseValue : this.trueValue); this.onModelChange(this.modelValue()); this.onChange.emit({ originalEvent: event, checked: this.modelValue() }); this.input.nativeElement.focus(); } } onFocus() { this.focused = true; } onBlur() { this.focused = false; this.onModelTouched(); } checked() { return this.modelValue() === this.trueValue; } /** * @override * * @see {@link BaseEditableHolder.writeControlValue} * Writes the value to the control. */ writeControlValue(value, setModelValue) { setModelValue(value); this.cd.markForCheck(); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: ToggleSwitch, deps: null, target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.1.3", type: ToggleSwitch, isStandalone: true, selector: "p-toggleswitch, p-toggleSwitch, p-toggle-switch", inputs: { styleClass: { classPropertyName: "styleClass", publicName: "styleClass", isSignal: false, isRequired: false, transformFunction: null }, tabindex: { classPropertyName: "tabindex", publicName: "tabindex", isSignal: false, isRequired: false, transformFunction: numberAttribute }, inputId: { classPropertyName: "inputId", publicName: "inputId", isSignal: false, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: false, isRequired: false, transformFunction: booleanAttribute }, trueValue: { classPropertyName: "trueValue", publicName: "trueValue", isSignal: false, isRequired: false, transformFunction: null }, falseValue: { classPropertyName: "falseValue", publicName: "falseValue", isSignal: false, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: false, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, ariaLabelledBy: { classPropertyName: "ariaLabelledBy", publicName: "ariaLabelledBy", isSignal: false, isRequired: false, transformFunction: null }, autofocus: { classPropertyName: "autofocus", publicName: "autofocus", isSignal: false, isRequired: false, transformFunction: booleanAttribute } }, outputs: { onChange: "onChange" }, host: { listeners: { "click": "onHostClick($event)" }, properties: { "class": "cn(cx('root'), styleClass)", "style": "sx('root')", "attr.data-pc-name": "'toggleswitch'", "attr.data-pc-section": "'root'" } }, providers: [TOGGLESWITCH_VALUE_ACCESSOR, ToggleSwitchStyle], queries: [{ propertyName: "handleTemplate", first: true, predicate: ["handle"] }, { propertyName: "templates", predicate: PrimeTemplate }], viewQueries: [{ propertyName: "input", first: true, predicate: ["input"], descendants: true }], usesInheritance: true, ngImport: i0, template: ` <input #input [attr.id]="inputId" type="checkbox" role="switch" [class]="cx('input')" [checked]="checked()" [attr.required]="required() ? '' : undefined" [attr.disabled]="$disabled() ? '' : undefined" [attr.aria-checked]="checked()" [attr.aria-labelledby]="ariaLabelledBy" [attr.aria-label]="ariaLabel" [attr.name]="name()" [attr.tabindex]="tabindex" (focus)="onFocus()" (blur)="onBlur()" [attr.data-pc-section]="'hiddenInput'" [pAutoFocus]="autofocus" /> <div [class]="cx('slider')" [attr.data-pc-section]="'slider'"> <div [class]="cx('handle')"> @if (handleTemplate || _handleTemplate) { <ng-container *ngTemplateOutlet="handleTemplate || _handleTemplate; context: { checked: checked() }" /> } </div> </div> `, isInline: true, dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: AutoFocus, selector: "[pAutoFocus]", inputs: ["pAutoFocus"] }, { kind: "ngmodule", type: SharedModule }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: ToggleSwitch, decorators: [{ type: Component, args: [{ selector: 'p-toggleswitch, p-toggleSwitch, p-toggle-switch', standalone: true, imports: [CommonModule, AutoFocus, SharedModule], template: ` <input #input [attr.id]="inputId" type="checkbox" role="switch" [class]="cx('input')" [checked]="checked()" [attr.required]="required() ? '' : undefined" [attr.disabled]="$disabled() ? '' : undefined" [attr.aria-checked]="checked()" [attr.aria-labelledby]="ariaLabelledBy" [attr.aria-label]="ariaLabel" [attr.name]="name()" [attr.tabindex]="tabindex" (focus)="onFocus()" (blur)="onBlur()" [attr.data-pc-section]="'hiddenInput'" [pAutoFocus]="autofocus" /> <div [class]="cx('slider')" [attr.data-pc-section]="'slider'"> <div [class]="cx('handle')"> @if (handleTemplate || _handleTemplate) { <ng-container *ngTemplateOutlet="handleTemplate || _handleTemplate; context: { checked: checked() }" /> } </div> </div> `, providers: [TOGGLESWITCH_VALUE_ACCESSOR, ToggleSwitchStyle], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: { '[class]': "cn(cx('root'), styleClass)", '[style]': "sx('root')", '[attr.data-pc-name]': "'toggleswitch'", '[attr.data-pc-section]': "'root'" } }] }], propDecorators: { styleClass: [{ type: Input }], tabindex: [{ type: Input, args: [{ transform: numberAttribute }] }], inputId: [{ type: Input }], readonly: [{ type: Input, args: [{ transform: booleanAttribute }] }], trueValue: [{ type: Input }], falseValue: [{ type: Input }], ariaLabel: [{ type: Input }], ariaLabelledBy: [{ type: Input }], autofocus: [{ type: Input, args: [{ transform: booleanAttribute }] }], onChange: [{ type: Output }], input: [{ type: ViewChild, args: ['input'] }], handleTemplate: [{ type: ContentChild, args: ['handle', { descendants: false }] }], templates: [{ type: ContentChildren, args: [PrimeTemplate] }], onHostClick: [{ type: HostListener, args: ['click', ['$event']] }] } }); class ToggleSwitchModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: ToggleSwitchModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.1.3", ngImport: i0, type: ToggleSwitchModule, imports: [ToggleSwitch, SharedModule], exports: [ToggleSwitch, SharedModule] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: ToggleSwitchModule, imports: [ToggleSwitch, SharedModule, SharedModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: ToggleSwitchModule, decorators: [{ type: NgModule, args: [{ imports: [ToggleSwitch, SharedModule], exports: [ToggleSwitch, SharedModule] }] }] }); /** * Generated bundle index. Do not edit. */ export { TOGGLESWITCH_VALUE_ACCESSOR, ToggleSwitch, ToggleSwitchClasses, ToggleSwitchModule, ToggleSwitchStyle }; //# sourceMappingURL=primeng-toggleswitch.mjs.map