primeng
Version:
PrimeNG is a premium UI library for Angular featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBlock,
298 lines (293 loc) • 16.2 kB
JavaScript
export * from 'primeng/types/toggleswitch';
import { NgTemplateOutlet } from '@angular/common';
import * as i0 from '@angular/core';
import { Injectable, InjectionToken, forwardRef, inject, input, numberAttribute, booleanAttribute, output, contentChild, viewChild, signal, computed, HostListener, ViewEncapsulation, ChangeDetectionStrategy, Component, NgModule } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { SharedModule } from 'primeng/api';
import { AutoFocus } from 'primeng/autofocus';
import { PARENT_INSTANCE } from 'primeng/basecomponent';
import { BaseEditableHolder } from 'primeng/baseeditableholder';
import * as i1 from 'primeng/bind';
import { Bind, BindModule } from 'primeng/bind';
import { style } from '@primeuix/styles/toggleswitch';
import { BaseStyle } from 'primeng/base';
const inlineStyles = {
root: { position: 'relative' }
};
const classes = {
root: ({ instance }) => [
'p-toggleswitch p-component',
{
'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';
style = style;
classes = classes;
inlineStyles = inlineStyles;
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ToggleSwitchStyle, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ToggleSwitchStyle });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", 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_INSTANCE = new InjectionToken('TOGGLESWITCH_INSTANCE');
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 {
componentName = 'ToggleSwitch';
$pcToggleSwitch = inject(TOGGLESWITCH_INSTANCE, { optional: true, skipSelf: true }) ?? undefined;
bindDirectiveInstance = inject(Bind, { self: true });
_componentStyle = inject(ToggleSwitchStyle);
/**
* Index of the element in tabbing order.
* @group Props
*/
tabindex = input(undefined, { ...(ngDevMode ? { debugName: "tabindex" } : /* istanbul ignore next */ {}), transform: numberAttribute });
/**
* Identifier of the input element.
* @group Props
*/
inputId = input(/* @ts-ignore */
...(ngDevMode ? [undefined, { debugName: "inputId" }] : /* istanbul ignore next */ []));
/**
* When present, it specifies that the component cannot be edited.
* @group Props
*/
readonly = input(false, { ...(ngDevMode ? { debugName: "readonly" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
/**
* Value in checked state.
* @group Props
*/
trueValue = input(true, /* @ts-ignore */
...(ngDevMode ? [{ debugName: "trueValue" }] : /* istanbul ignore next */ []));
/**
* Value in unchecked state.
* @group Props
*/
falseValue = input(false, /* @ts-ignore */
...(ngDevMode ? [{ debugName: "falseValue" }] : /* istanbul ignore next */ []));
/**
* Used to define a string that autocomplete attribute the current element.
* @group Props
*/
ariaLabel = input(/* @ts-ignore */
...(ngDevMode ? [undefined, { debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
/**
* Specifies the size of the component.
* @defaultValue undefined
* @group Props
*/
size = input(/* @ts-ignore */
...(ngDevMode ? [undefined, { debugName: "size" }] : /* istanbul ignore next */ []));
/**
* Establishes relationships between the component and label(s) where its value should be one or more element IDs.
* @group Props
*/
ariaLabelledBy = input(/* @ts-ignore */
...(ngDevMode ? [undefined, { debugName: "ariaLabelledBy" }] : /* istanbul ignore next */ []));
/**
* When present, it specifies that the component should automatically get focus on load.
* @group Props
*/
autofocus = input(false, { ...(ngDevMode ? { debugName: "autofocus" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
/**
* Callback to invoke when the on value change.
* @param {ToggleSwitchChangeEvent} event - Custom change event.
* @group Emits
*/
onChange = output();
/**
* Custom handle template.
* @param {ToggleSwitchHandleTemplateContext} context - handle context.
* @see {@link ToggleSwitchHandleTemplateContext}
* @group Templates
*/
handleTemplate = contentChild('handle', { ...(ngDevMode ? { debugName: "handleTemplate" } : /* istanbul ignore next */ {}), descendants: false });
inputEl = viewChild.required('input', /* @ts-ignore */
...(ngDevMode ? [{ debugName: "inputEl" }] : /* istanbul ignore next */ []));
focused = signal(false, /* @ts-ignore */
...(ngDevMode ? [{ debugName: "focused" }] : /* istanbul ignore next */ []));
$checked = computed(() => this.modelValue() === this.trueValue(), /* @ts-ignore */
...(ngDevMode ? [{ debugName: "$checked" }] : /* istanbul ignore next */ []));
attrRequired = computed(() => (this.required() ? '' : undefined), /* @ts-ignore */
...(ngDevMode ? [{ debugName: "attrRequired" }] : /* istanbul ignore next */ []));
attrDisabled = computed(() => (this.$disabled() ? '' : undefined), /* @ts-ignore */
...(ngDevMode ? [{ debugName: "attrDisabled" }] : /* istanbul ignore next */ []));
dataP = computed(() => this.cn({
checked: this.$checked(),
disabled: this.$disabled(),
invalid: this.invalid()
}), /* @ts-ignore */
...(ngDevMode ? [{ debugName: "dataP" }] : /* istanbul ignore next */ []));
onAfterViewChecked() {
this.bindDirectiveInstance.setAttrs(this.ptms(['host', 'root']));
}
onHostClick(event) {
this.onClick(event);
}
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.inputEl().nativeElement.focus();
}
}
onFocus() {
this.focused.set(true);
}
onBlur() {
this.focused.set(false);
this.onModelTouched();
}
getHandleContext() {
return { checked: this.$checked() };
}
/**
* @override
*
* @see {@link BaseEditableHolder.writeControlValue}
* Writes the value to the control.
*/
writeControlValue(value, setModelValue) {
setModelValue(value);
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ToggleSwitch, deps: null, target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: ToggleSwitch, isStandalone: true, selector: "p-toggleswitch, p-toggle-switch", inputs: { tabindex: { classPropertyName: "tabindex", publicName: "tabindex", isSignal: true, isRequired: false, transformFunction: null }, inputId: { classPropertyName: "inputId", publicName: "inputId", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, trueValue: { classPropertyName: "trueValue", publicName: "trueValue", isSignal: true, isRequired: false, transformFunction: null }, falseValue: { classPropertyName: "falseValue", publicName: "falseValue", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, ariaLabelledBy: { classPropertyName: "ariaLabelledBy", publicName: "ariaLabelledBy", isSignal: true, isRequired: false, transformFunction: null }, autofocus: { classPropertyName: "autofocus", publicName: "autofocus", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { onChange: "onChange" }, host: { listeners: { "click": "onHostClick($event)" }, properties: { "class": "cx('root')", "style": "sx('root')", "attr.data-p-checked": "$checked()", "attr.data-p-disabled": "$disabled()", "attr.data-p": "dataP()" } }, providers: [TOGGLESWITCH_VALUE_ACCESSOR, ToggleSwitchStyle, { provide: TOGGLESWITCH_INSTANCE, useExisting: ToggleSwitch }, { provide: PARENT_INSTANCE, useExisting: ToggleSwitch }], queries: [{ propertyName: "handleTemplate", first: true, predicate: ["handle"], isSignal: true }], viewQueries: [{ propertyName: "inputEl", first: true, predicate: ["input"], descendants: true, isSignal: true }], usesInheritance: true, hostDirectives: [{ directive: i1.Bind }], ngImport: i0, template: `
<input
#input
[attr.id]="inputId()"
type="checkbox"
role="switch"
[class]="cx('input')"
[checked]="$checked()"
[attr.required]="attrRequired()"
[attr.disabled]="attrDisabled()"
[attr.aria-checked]="$checked()"
[attr.aria-labelledby]="ariaLabelledBy()"
[attr.aria-label]="ariaLabel()"
[attr.name]="name()"
[attr.tabindex]="tabindex()"
(focus)="onFocus()"
(blur)="onBlur()"
[pAutoFocus]="autofocus()"
[pBind]="ptm('input')"
/>
<div [class]="cx('slider')" [pBind]="ptm('slider')" [attr.data-p]="dataP()">
<div [class]="cx('handle')" [pBind]="ptm('handle')" [attr.data-p]="dataP()">
(handleTemplate()) {
<ng-container *ngTemplateOutlet="handleTemplate(); context: getHandleContext()" />
}
</div>
</div>
`, isInline: true, dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: AutoFocus, selector: "[pAutoFocus]", inputs: ["pAutoFocus"] }, { kind: "ngmodule", type: SharedModule }, { kind: "ngmodule", type: BindModule }, { kind: "directive", type: i1.Bind, selector: "[pBind]", inputs: ["pBind"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ToggleSwitch, decorators: [{
type: Component,
args: [{
selector: 'p-toggleswitch, p-toggle-switch',
standalone: true,
imports: [NgTemplateOutlet, AutoFocus, SharedModule, BindModule],
template: `
<input
#input
[attr.id]="inputId()"
type="checkbox"
role="switch"
[class]="cx('input')"
[checked]="$checked()"
[attr.required]="attrRequired()"
[attr.disabled]="attrDisabled()"
[attr.aria-checked]="$checked()"
[attr.aria-labelledby]="ariaLabelledBy()"
[attr.aria-label]="ariaLabel()"
[attr.name]="name()"
[attr.tabindex]="tabindex()"
(focus)="onFocus()"
(blur)="onBlur()"
[pAutoFocus]="autofocus()"
[pBind]="ptm('input')"
/>
<div [class]="cx('slider')" [pBind]="ptm('slider')" [attr.data-p]="dataP()">
<div [class]="cx('handle')" [pBind]="ptm('handle')" [attr.data-p]="dataP()">
(handleTemplate()) {
<ng-container *ngTemplateOutlet="handleTemplate(); context: getHandleContext()" />
}
</div>
</div>
`,
providers: [TOGGLESWITCH_VALUE_ACCESSOR, ToggleSwitchStyle, { provide: TOGGLESWITCH_INSTANCE, useExisting: ToggleSwitch }, { provide: PARENT_INSTANCE, useExisting: ToggleSwitch }],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
host: {
'[class]': "cx('root')",
'[style]': "sx('root')",
'[attr.data-p-checked]': '$checked()',
'[attr.data-p-disabled]': '$disabled()',
'[attr.data-p]': 'dataP()'
},
hostDirectives: [Bind]
}]
}], propDecorators: { tabindex: [{ type: i0.Input, args: [{ isSignal: true, alias: "tabindex", required: false }] }], inputId: [{ type: i0.Input, args: [{ isSignal: true, alias: "inputId", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], trueValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "trueValue", required: false }] }], falseValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "falseValue", required: false }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], ariaLabelledBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabelledBy", required: false }] }], autofocus: [{ type: i0.Input, args: [{ isSignal: true, alias: "autofocus", required: false }] }], onChange: [{ type: i0.Output, args: ["onChange"] }], handleTemplate: [{ type: i0.ContentChild, args: ['handle', { ...{ descendants: false }, isSignal: true }] }], inputEl: [{ type: i0.ViewChild, args: ['input', { isSignal: true }] }], onHostClick: [{
type: HostListener,
args: ['click', ['$event']]
}] } });
class ToggleSwitchModule {
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ToggleSwitchModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.0.6", ngImport: i0, type: ToggleSwitchModule, imports: [ToggleSwitch, SharedModule], exports: [ToggleSwitch, SharedModule] });
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ToggleSwitchModule, imports: [ToggleSwitch, SharedModule, SharedModule] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", 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