UNPKG

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,

305 lines (300 loc) 16.2 kB
export * from 'primeng/types/chip'; import { NgTemplateOutlet } from '@angular/common'; import * as i0 from '@angular/core'; import { Injectable, InjectionToken, inject, input, booleanAttribute, output, contentChild, signal, computed, ViewEncapsulation, ChangeDetectionStrategy, Component, NgModule } from '@angular/core'; import { TranslationKeys, SharedModule } from 'primeng/api'; import { BaseComponent, PARENT_INSTANCE } from 'primeng/basecomponent'; import * as i1 from 'primeng/bind'; import { Bind } from 'primeng/bind'; import { style } from '@primeuix/styles/chip'; import { BaseStyle } from 'primeng/base'; import { TimesCircle } from '@primeicons/angular/times-circle'; const inlineStyles = { root: ({ instance }) => ({ display: !instance.visible() && 'none' }) }; const classes = { root: ({ instance }) => [ 'p-chip p-component', { 'p-disabled': instance.disabled() } ], image: 'p-chip-image', icon: 'p-chip-icon', label: 'p-chip-label', removeIcon: 'p-chip-remove-icon' }; class ChipStyle extends BaseStyle { name = 'chip'; style = style; classes = classes; inlineStyles = inlineStyles; static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ChipStyle, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ChipStyle }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ChipStyle, decorators: [{ type: Injectable }] }); /** * * Chip represents people using icons, labels and images. * * [Live Demo](https://www.primeng.org/chip) * * @module chipstyle * */ var ChipClasses; (function (ChipClasses) { /** * Class name of the root element */ ChipClasses["root"] = "p-chip"; /** * Class name of the image element */ ChipClasses["image"] = "p-chip-image"; /** * Class name of the icon element */ ChipClasses["icon"] = "p-chip-icon"; /** * Class name of the label element */ ChipClasses["label"] = "p-chip-label"; /** * Class name of the remove icon element */ ChipClasses["removeIcon"] = "p-chip-remove-icon"; })(ChipClasses || (ChipClasses = {})); const CHIP_INSTANCE = new InjectionToken('CHIP_INSTANCE'); /** * Chip represents people using icons, labels and images. * @group Components */ class Chip extends BaseComponent { componentName = 'Chip'; $pcChip = inject(CHIP_INSTANCE, { optional: true, skipSelf: true }) ?? undefined; bindDirectiveInstance = inject(Bind, { self: true }); onAfterViewChecked() { this.bindDirectiveInstance.setAttrs(this.ptms(['host', 'root'])); } /** * Defines the text to display. * @group Props */ label = input(/* @ts-ignore */ ...(ngDevMode ? [undefined, { debugName: "label" }] : /* istanbul ignore next */ [])); /** * Defines the icon to display. * @group Props */ icon = input(/* @ts-ignore */ ...(ngDevMode ? [undefined, { debugName: "icon" }] : /* istanbul ignore next */ [])); /** * Defines the image to display. * @group Props */ image = input(/* @ts-ignore */ ...(ngDevMode ? [undefined, { debugName: "image" }] : /* istanbul ignore next */ [])); /** * Alt attribute of the image. * @group Props */ alt = input(/* @ts-ignore */ ...(ngDevMode ? [undefined, { debugName: "alt" }] : /* istanbul ignore next */ [])); /** * When present, it specifies that the element should be disabled. * @group Props */ disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute }); /** * Whether to display a remove icon. * @group Props */ removable = input(false, { ...(ngDevMode ? { debugName: "removable" } : /* istanbul ignore next */ {}), transform: booleanAttribute }); /** * Icon of the remove element. * @group Props */ removeIcon = input(/* @ts-ignore */ ...(ngDevMode ? [undefined, { debugName: "removeIcon" }] : /* istanbul ignore next */ [])); /** * Used to pass all properties of the chipProps to the Chip component. * @group Props */ chipProps = input(/* @ts-ignore */ ...(ngDevMode ? [undefined, { debugName: "chipProps" }] : /* istanbul ignore next */ [])); /** * Callback to invoke when a chip is removed. * @param {MouseEvent} event - Mouse event. * @group Emits */ onRemove = output(); /** * This event is triggered if an error occurs while loading an image file. * @param {Event} event - Browser event. * @group Emits */ onImageError = output(); /** * Custom remove icon template. * @group Templates */ removeIconTemplate = contentChild('removeicon', { ...(ngDevMode ? { debugName: "removeIconTemplate" } : /* istanbul ignore next */ {}), descendants: false }); visible = signal(true, /* @ts-ignore */ ...(ngDevMode ? [{ debugName: "visible" }] : /* istanbul ignore next */ [])); _componentStyle = inject(ChipStyle); _label = computed(() => this.chipProps()?.label ?? this.label(), /* @ts-ignore */ ...(ngDevMode ? [{ debugName: "_label" }] : /* istanbul ignore next */ [])); _icon = computed(() => this.chipProps()?.icon ?? this.icon(), /* @ts-ignore */ ...(ngDevMode ? [{ debugName: "_icon" }] : /* istanbul ignore next */ [])); _image = computed(() => this.chipProps()?.image ?? this.image(), /* @ts-ignore */ ...(ngDevMode ? [{ debugName: "_image" }] : /* istanbul ignore next */ [])); _alt = computed(() => this.chipProps()?.alt ?? this.alt(), /* @ts-ignore */ ...(ngDevMode ? [{ debugName: "_alt" }] : /* istanbul ignore next */ [])); _removable = computed(() => this.chipProps()?.removable ?? this.removable(), /* @ts-ignore */ ...(ngDevMode ? [{ debugName: "_removable" }] : /* istanbul ignore next */ [])); _removeIcon = computed(() => this.chipProps()?.removeIcon ?? this.removeIcon(), /* @ts-ignore */ ...(ngDevMode ? [{ debugName: "_removeIcon" }] : /* istanbul ignore next */ [])); removeAriaLabel = computed(() => this.translate(TranslationKeys.ARIA, 'removeLabel'), /* @ts-ignore */ ...(ngDevMode ? [{ debugName: "removeAriaLabel" }] : /* istanbul ignore next */ [])); removeIconTabindex = computed(() => (this.disabled() ? -1 : 0), /* @ts-ignore */ ...(ngDevMode ? [{ debugName: "removeIconTabindex" }] : /* istanbul ignore next */ [])); dataP = computed(() => this.cn({ removable: this._removable() }), /* @ts-ignore */ ...(ngDevMode ? [{ debugName: "dataP" }] : /* istanbul ignore next */ [])); close(event) { this.visible.set(false); this.onRemove.emit(event); } onKeydown(event) { if (event.key === 'Enter' || event.key === 'Backspace') { this.close(event); } } imageError(event) { this.onImageError.emit(event); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: Chip, deps: null, target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: Chip, isStandalone: true, selector: "p-chip", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, icon: { classPropertyName: "icon", publicName: "icon", isSignal: true, isRequired: false, transformFunction: null }, image: { classPropertyName: "image", publicName: "image", isSignal: true, isRequired: false, transformFunction: null }, alt: { classPropertyName: "alt", publicName: "alt", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, removable: { classPropertyName: "removable", publicName: "removable", isSignal: true, isRequired: false, transformFunction: null }, removeIcon: { classPropertyName: "removeIcon", publicName: "removeIcon", isSignal: true, isRequired: false, transformFunction: null }, chipProps: { classPropertyName: "chipProps", publicName: "chipProps", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { onRemove: "onRemove", onImageError: "onImageError" }, host: { properties: { "class": "cx('root')", "style": "sx('root')", "attr.aria-label": "_label()", "attr.data-p": "dataP()" } }, providers: [ChipStyle, { provide: CHIP_INSTANCE, useExisting: Chip }, { provide: PARENT_INSTANCE, useExisting: Chip }], queries: [{ propertyName: "removeIconTemplate", first: true, predicate: ["removeicon"], isSignal: true }], usesInheritance: true, hostDirectives: [{ directive: i1.Bind }], ngImport: i0, template: ` <ng-content /> @if (_image()) { <img [pBind]="ptm('image')" [class]="cx('image')" [src]="_image()" (error)="imageError($event)" [alt]="_alt()" /> } @else if (_icon()) { <span [pBind]="ptm('icon')" [class]="cn(cx('icon'), _icon())"></span> } @if (_label()) { <div [pBind]="ptm('label')" [class]="cx('label')">{{ _label() }}</div> } @if (_removable()) { @if (!removeIconTemplate()) { @if (_removeIcon()) { <span [pBind]="ptm('removeIcon')" [class]="cn(cx('removeIcon'), _removeIcon())" (click)="close($event)" (keydown)="onKeydown($event)" [attr.tabindex]="removeIconTabindex()" [attr.aria-label]="removeAriaLabel()" role="button" ></span> } @else { <svg [pBind]="ptm('removeIcon')" data-p-icon="times-circle" [class]="cx('removeIcon')" (click)="close($event)" (keydown)="onKeydown($event)" [attr.tabindex]="removeIconTabindex()" [attr.aria-label]="removeAriaLabel()" role="button" /> } } @else { <span [pBind]="ptm('removeIcon')" [attr.tabindex]="removeIconTabindex()" [class]="cx('removeIcon')" (click)="close($event)" (keydown)="onKeydown($event)" [attr.aria-label]="removeAriaLabel()" role="button"> <ng-template *ngTemplateOutlet="removeIconTemplate()"></ng-template> </span> } } `, isInline: true, dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "ngmodule", type: SharedModule }, { kind: "directive", type: Bind, selector: "[pBind]", inputs: ["pBind"] }, { kind: "component", type: TimesCircle, selector: "svg[data-p-icon=\"times-circle\"]" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: Chip, decorators: [{ type: Component, args: [{ selector: 'p-chip', standalone: true, imports: [NgTemplateOutlet, SharedModule, Bind, TimesCircle], template: ` <ng-content /> @if (_image()) { <img [pBind]="ptm('image')" [class]="cx('image')" [src]="_image()" (error)="imageError($event)" [alt]="_alt()" /> } @else if (_icon()) { <span [pBind]="ptm('icon')" [class]="cn(cx('icon'), _icon())"></span> } @if (_label()) { <div [pBind]="ptm('label')" [class]="cx('label')">{{ _label() }}</div> } @if (_removable()) { @if (!removeIconTemplate()) { @if (_removeIcon()) { <span [pBind]="ptm('removeIcon')" [class]="cn(cx('removeIcon'), _removeIcon())" (click)="close($event)" (keydown)="onKeydown($event)" [attr.tabindex]="removeIconTabindex()" [attr.aria-label]="removeAriaLabel()" role="button" ></span> } @else { <svg [pBind]="ptm('removeIcon')" data-p-icon="times-circle" [class]="cx('removeIcon')" (click)="close($event)" (keydown)="onKeydown($event)" [attr.tabindex]="removeIconTabindex()" [attr.aria-label]="removeAriaLabel()" role="button" /> } } @else { <span [pBind]="ptm('removeIcon')" [attr.tabindex]="removeIconTabindex()" [class]="cx('removeIcon')" (click)="close($event)" (keydown)="onKeydown($event)" [attr.aria-label]="removeAriaLabel()" role="button"> <ng-template *ngTemplateOutlet="removeIconTemplate()"></ng-template> </span> } } `, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, providers: [ChipStyle, { provide: CHIP_INSTANCE, useExisting: Chip }, { provide: PARENT_INSTANCE, useExisting: Chip }], host: { '[class]': "cx('root')", '[style]': "sx('root')", '[attr.aria-label]': '_label()', '[attr.data-p]': 'dataP()' }, hostDirectives: [Bind] }] }], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], icon: [{ type: i0.Input, args: [{ isSignal: true, alias: "icon", required: false }] }], image: [{ type: i0.Input, args: [{ isSignal: true, alias: "image", required: false }] }], alt: [{ type: i0.Input, args: [{ isSignal: true, alias: "alt", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], removable: [{ type: i0.Input, args: [{ isSignal: true, alias: "removable", required: false }] }], removeIcon: [{ type: i0.Input, args: [{ isSignal: true, alias: "removeIcon", required: false }] }], chipProps: [{ type: i0.Input, args: [{ isSignal: true, alias: "chipProps", required: false }] }], onRemove: [{ type: i0.Output, args: ["onRemove"] }], onImageError: [{ type: i0.Output, args: ["onImageError"] }], removeIconTemplate: [{ type: i0.ContentChild, args: ['removeicon', { ...{ descendants: false }, isSignal: true }] }] } }); class ChipModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ChipModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.0.6", ngImport: i0, type: ChipModule, imports: [Chip, SharedModule], exports: [Chip, SharedModule] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ChipModule, imports: [Chip, SharedModule, SharedModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ChipModule, decorators: [{ type: NgModule, args: [{ imports: [Chip, SharedModule], exports: [Chip, SharedModule] }] }] }); /** * Generated bundle index. Do not edit. */ export { Chip, ChipClasses, ChipModule, ChipStyle }; //# sourceMappingURL=primeng-chip.mjs.map