1 line
13 KiB
Plaintext
1 line
13 KiB
Plaintext
{"version":3,"file":"primeng-togglebutton.mjs","sources":["../../src/app/components/togglebutton/togglebutton.ts","../../src/app/components/togglebutton/primeng-togglebutton.ts"],"sourcesContent":["import { CommonModule } from '@angular/common';\nimport { booleanAttribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChildren, EventEmitter, forwardRef, Input, NgModule, numberAttribute, Output, QueryList, TemplateRef } from '@angular/core';\nimport { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';\nimport { RippleModule } from 'primeng/ripple';\nimport { ToggleButtonChangeEvent } from './togglebutton.interface';\nimport { Nullable } from 'primeng/ts-helpers';\nimport { PrimeTemplate, SharedModule } from 'primeng/api';\nimport { AutoFocusModule } from 'primeng/autofocus';\n\ntype ToggleButtonIconPosition = 'left' | 'right';\n\nexport const TOGGLEBUTTON_VALUE_ACCESSOR: any = {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => ToggleButton),\n multi: true\n};\n/**\n * ToggleButton is used to select a boolean value using a button.\n * @group Components\n */\n@Component({\n selector: 'p-toggleButton',\n template: `\n <div\n [ngClass]=\"{ 'p-togglebutton p-button p-component': true, 'p-button-icon-only': onIcon && offIcon && !hasOnLabel && !hasOffLabel, 'p-highlight': checked, 'p-disabled': disabled }\"\n [ngStyle]=\"style\"\n [class]=\"styleClass\"\n (click)=\"toggle($event)\"\n (keydown)=\"onKeyDown($event)\"\n [attr.tabindex]=\"disabled ? null : tabindex\"\n role=\"switch\"\n [attr.aria-checked]=\"checked\"\n [attr.aria-labelledby]=\"ariaLabelledBy\"\n [attr.aria-label]=\"ariaLabel\"\n pRipple\n [attr.data-pc-name]=\"'togglebutton'\"\n [attr.data-pc-section]=\"'root'\"\n pAutoFocus\n [autofocus]=\"autofocus\"\n >\n @if(!iconTemplate) {\n <span\n *ngIf=\"onIcon || offIcon\"\n [class]=\"checked ? this.onIcon : this.offIcon\"\n [ngClass]=\"{ 'p-button-icon': true, 'p-button-icon-left': iconPos === 'left', 'p-button-icon-right': iconPos === 'right' }\"\n [attr.data-pc-section]=\"'icon'\"\n ></span>\n } @else {\n <ng-container *ngTemplateOutlet=\"iconTemplate; context: { $implicit: checked }\"></ng-container>\n }\n <span class=\"p-button-label\" *ngIf=\"onLabel || offLabel\" [attr.data-pc-section]=\"'label'\">{{ checked ? (hasOnLabel ? onLabel : '') : hasOffLabel ? offLabel : '' }}</span>\n </div>\n `,\n providers: [TOGGLEBUTTON_VALUE_ACCESSOR],\n changeDetection: ChangeDetectionStrategy.OnPush,\n styleUrls: ['../button/button.css'],\n host: {\n class: 'p-element'\n }\n})\nexport class ToggleButton implements ControlValueAccessor {\n /**\n * Label for the on state.\n * @group Props\n */\n @Input() onLabel: string | undefined;\n /**\n * Label for the off state.\n * @group Props\n */\n @Input() offLabel: string | undefined;\n /**\n * Icon for the on state.\n * @group Props\n */\n @Input() onIcon: string | undefined;\n /**\n * Icon for the off state.\n * @group Props\n */\n @Input() offIcon: string | undefined;\n /**\n * Defines a string that labels the input for accessibility.\n * @group Props\n */\n @Input() ariaLabel: string | undefined;\n /**\n * Establishes relationships between the component and label(s) where its value should be one or more element IDs.\n * @group Props\n */\n @Input() ariaLabelledBy: string | undefined;\n /**\n * When present, it specifies that the element should be disabled.\n * @group Props\n */\n @Input({ transform: booleanAttribute }) disabled: boolean | undefined;\n /**\n * Inline style of the element.\n * @group Props\n */\n @Input() style: any;\n /**\n * Style class of the element.\n * @group Props\n */\n @Input() styleClass: string | undefined;\n /**\n * Identifier of the focus input to match a label defined for the component.\n * @group Props\n */\n @Input() inputId: string | undefined;\n /**\n * Index of the element in tabbing order.\n * @group Props\n */\n @Input({ transform: numberAttribute }) tabindex: number | undefined = 0;\n /**\n * Position of the icon.\n * @group Props\n */\n @Input() iconPos: 'left' | 'right' = 'left';\n /**\n * When present, it specifies that the component should automatically get focus on load.\n * @group Props\n */\n @Input({ transform: booleanAttribute }) autofocus: boolean | undefined;\n /**\n * Callback to invoke on value change.\n * @param {ToggleButtonChangeEvent} event - Custom change event.\n * @group Emits\n */\n @Output() onChange: EventEmitter<ToggleButtonChangeEvent> = new EventEmitter<ToggleButtonChangeEvent>();\n\n @ContentChildren(PrimeTemplate) templates!: QueryList<PrimeTemplate>;\n\n iconTemplate: Nullable<TemplateRef<any>>;\n\n checked: boolean = false;\n\n onModelChange: Function = () => {};\n\n onModelTouched: Function = () => {};\n\n constructor(public cd: ChangeDetectorRef) {}\n\n ngAfterContentInit() {\n this.templates.forEach((item) => {\n switch (item.getType()) {\n case 'icon':\n this.iconTemplate = item.template;\n break;\n default:\n this.iconTemplate = item.template;\n break;\n }\n });\n }\n\n toggle(event: Event) {\n if (!this.disabled) {\n this.checked = !this.checked;\n this.onModelChange(this.checked);\n this.onModelTouched();\n this.onChange.emit({\n originalEvent: event,\n checked: this.checked\n });\n\n this.cd.markForCheck();\n }\n }\n\n onKeyDown(event: KeyboardEvent) {\n switch (event.code) {\n case 'Enter':\n this.toggle(event);\n event.preventDefault();\n break;\n case 'Space':\n this.toggle(event);\n event.preventDefault();\n break;\n }\n }\n\n onBlur() {\n this.onModelTouched();\n }\n\n writeValue(value: any): void {\n this.checked = value;\n this.cd.markForCheck();\n }\n\n registerOnChange(fn: Function): void {\n this.onModelChange = fn;\n }\n\n registerOnTouched(fn: Function): void {\n this.onModelTouched = fn;\n }\n\n setDisabledState(val: boolean): void {\n this.disabled = val;\n this.cd.markForCheck();\n }\n\n get hasOnLabel(): boolean {\n return (this.onLabel && this.onLabel.length > 0) as boolean;\n }\n\n get hasOffLabel(): boolean {\n return (this.onLabel && this.onLabel.length > 0) as boolean;\n }\n}\n\n@NgModule({\n imports: [CommonModule, RippleModule, SharedModule, AutoFocusModule],\n exports: [ToggleButton, SharedModule],\n declarations: [ToggleButton]\n})\nexport class ToggleButtonModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;;;;;;AAWa,MAAA,2BAA2B,GAAQ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