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
541 lines (536 loc) • 24.4 kB
JavaScript
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { Injectable, EventEmitter, inject, signal, ContentChildren, ContentChild, ViewChild, Output, Input, ViewEncapsulation, ChangeDetectionStrategy, Component, NgModule } from '@angular/core';
import * as i2 from '@angular/router';
import { RouterModule } from '@angular/router';
import { uuid, resolve, find, findSingle } from '@primeuix/utils';
import { SharedModule, PrimeTemplate } from 'primeng/api';
import { BaseComponent } from 'primeng/basecomponent';
import { Ripple } from 'primeng/ripple';
import * as i3 from 'primeng/tooltip';
import { TooltipModule } from 'primeng/tooltip';
import { style } from '@primeuix/styles/dock';
import { BaseStyle } from 'primeng/base';
const classes = {
root: ({ instance }) => [
'p-dock p-component',
`p-dock-${instance.position}`,
{
'p-dock-mobile': instance.queryMatches()
}
],
listContainer: 'p-dock-list-container',
list: 'p-dock-list',
item: ({ instance, item, id }) => [
'p-dock-item',
{
'p-focus': instance.isItemActive(id),
'p-disabled': instance.disabled(item)
}
],
itemContent: 'p-dock-item-content',
itemLink: 'p-dock-item-link',
itemIcon: 'p-dock-item-icon'
};
class DockStyle extends BaseStyle {
name = 'dock';
theme = style;
classes = classes;
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: DockStyle, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: DockStyle });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: DockStyle, decorators: [{
type: Injectable
}] });
/**
*
* Dock is a navigation component consisting of menuitems.
*
* [Live Demo](https://www.primeng.org/dock/)
*
* @module dockstyle
*
*/
var DockClasses;
(function (DockClasses) {
/**
* Class name of the root element
*/
DockClasses["root"] = "p-dock";
/**
* Class name of the list container element
*/
DockClasses["listContainer"] = "p-dock-list-container";
/**
* Class name of the list element
*/
DockClasses["list"] = "p-dock-list";
/**
* Class name of the item element
*/
DockClasses["item"] = "p-dock-item";
/**
* Class name of the item content element
*/
DockClasses["itemContent"] = "p-dock-item-content";
/**
* Class name of the item link element
*/
DockClasses["itemLink"] = "p-dock-item-link";
/**
* Class name of the item icon element
*/
DockClasses["itemIcon"] = "p-dock-item-icon";
})(DockClasses || (DockClasses = {}));
/**
* Dock is a navigation component consisting of menuitems.
* @group Components
*/
class Dock extends BaseComponent {
cd;
/**
* Current id state as a string.
* @group Props
*/
id;
/**
* Class of the element.
* @deprecated since v20.0.0, use `class` instead.
* @group Props
*/
styleClass;
/**
* MenuModel instance to define the action items.
* @group Props
*/
model = null;
/**
* Position of element.
* @group Props
*/
position = 'bottom';
/**
* Defines a string that labels the input for accessibility.
* @group Props
*/
ariaLabel;
/**
* The breakpoint to define the maximum width boundary.
* @defaultValue 960px
* @group Props
*/
breakpoint = '960px';
/**
* Defines a string that labels the dropdown button for accessibility.
* @group Props
*/
ariaLabelledBy;
/**
* Callback to execute when button is focused.
* @param {FocusEvent} event - Focus event.
* @group Emits
*/
onFocus = new EventEmitter();
/**
* Callback to invoke when the component loses focus.
* @param {FocusEvent} event - Focus event.
* @group Emits
*/
onBlur = new EventEmitter();
listViewChild;
currentIndex;
tabindex = 0;
focused = false;
focusedOptionIndex = -1;
_componentStyle = inject(DockStyle);
matchMediaListener;
query;
queryMatches = signal(false, ...(ngDevMode ? [{ debugName: "queryMatches" }] : []));
mobileActive = signal(false, ...(ngDevMode ? [{ debugName: "mobileActive" }] : []));
get focusedOptionId() {
return this.focusedOptionIndex !== -1 ? this.focusedOptionIndex : null;
}
constructor(cd) {
super();
this.cd = cd;
this.currentIndex = -3;
}
ngOnInit() {
super.ngOnInit();
this.id = this.id || uuid('pn_id_');
this.bindMatchMediaListener();
}
ngOnDestroy() {
super.ngOnDestroy();
this.unbindMatchMediaListener();
}
itemTemplate;
_itemTemplate;
getItemId(item, index) {
return item && item?.id ? item.id : `${index}`;
}
getItemProp(processedItem, name) {
return processedItem && processedItem.item ? resolve(processedItem.item[name]) : undefined;
}
disabled(item) {
return typeof item.disabled === 'function' ? item.disabled() : item.disabled;
}
isItemActive(id) {
return id === this.focusedOptionIndex;
}
onListMouseLeave() {
this.currentIndex = -3;
this.cd.markForCheck();
}
onItemMouseEnter(index) {
this.currentIndex = index;
if (index === 1) {
}
this.cd.markForCheck();
}
onItemClick(e, item) {
if (item.command) {
item.command({ originalEvent: e, item });
}
}
onListFocus(event) {
this.focused = true;
this.changeFocusedOptionIndex(0);
this.onFocus.emit(event);
}
onListBlur(event) {
this.focused = false;
this.focusedOptionIndex = -1;
this.onBlur.emit(event);
}
onListKeyDown(event) {
switch (event.code) {
case 'ArrowDown': {
if (this.position === 'left' || this.position === 'right')
this.onArrowDownKey();
event.preventDefault();
break;
}
case 'ArrowUp': {
if (this.position === 'left' || this.position === 'right')
this.onArrowUpKey();
event.preventDefault();
break;
}
case 'ArrowRight': {
if (this.position === 'top' || this.position === 'bottom')
this.onArrowDownKey();
event.preventDefault();
break;
}
case 'ArrowLeft': {
if (this.position === 'top' || this.position === 'bottom')
this.onArrowUpKey();
event.preventDefault();
break;
}
case 'Home': {
this.onHomeKey();
event.preventDefault();
break;
}
case 'End': {
this.onEndKey();
event.preventDefault();
break;
}
case 'Enter':
case 'Space': {
this.onSpaceKey();
event.preventDefault();
break;
}
default:
break;
}
}
onArrowDownKey() {
const optionIndex = this.findNextOptionIndex(this.focusedOptionIndex);
this.changeFocusedOptionIndex(optionIndex);
}
onArrowUpKey() {
const optionIndex = this.findPrevOptionIndex(this.focusedOptionIndex);
this.changeFocusedOptionIndex(optionIndex);
}
onHomeKey() {
this.changeFocusedOptionIndex(0);
}
onEndKey() {
this.changeFocusedOptionIndex(find(this.listViewChild.nativeElement, 'li[data-pc-section="menuitem"][data-p-disabled="false"]').length - 1);
}
onSpaceKey() {
const element = findSingle(this.listViewChild.nativeElement, `li[id="${`${this.focusedOptionIndex}`}"]`);
const anchorElement = element && findSingle(element, '[data-pc-section="action"]');
anchorElement ? anchorElement.click() : element && element.click();
}
findNextOptionIndex(index) {
const menuitems = find(this.listViewChild.nativeElement, 'li[data-pc-section="menuitem"][data-p-disabled="false"]');
const matchedOptionIndex = [...menuitems].findIndex((link) => link.id === index);
return matchedOptionIndex > -1 ? matchedOptionIndex + 1 : 0;
}
changeFocusedOptionIndex(index) {
const menuitems = find(this.listViewChild.nativeElement, 'li[data-pc-section="menuitem"][data-p-disabled="false"]');
let order = index >= menuitems.length ? menuitems.length - 1 : index < 0 ? 0 : index;
this.focusedOptionIndex = menuitems[order].getAttribute('id');
}
findPrevOptionIndex(index) {
const menuitems = find(this.listViewChild.nativeElement, 'li[data-pc-section="menuitem"][data-p-disabled="false"]');
const matchedOptionIndex = [...menuitems].findIndex((link) => link.id === index);
return matchedOptionIndex > -1 ? matchedOptionIndex - 1 : 0;
}
isClickableRouterLink(item) {
return item.routerLink && !item.disabled;
}
templates;
ngAfterContentInit() {
this.templates?.forEach((item) => {
switch (item.getType()) {
case 'item':
this._itemTemplate = item.template;
break;
default:
this._itemTemplate = item.template;
break;
}
});
}
bindMatchMediaListener() {
if (!this.matchMediaListener) {
const query = window.matchMedia(`(max-width: ${this.breakpoint})`);
this.query = query;
this.queryMatches.set(query.matches);
this.matchMediaListener = () => {
this.queryMatches.set(query.matches);
this.mobileActive.set(false);
};
this.renderer.listen(this.query, 'change', this.matchMediaListener.bind(this));
}
}
unbindMatchMediaListener() {
if (this.matchMediaListener) {
this.matchMediaListener();
this.matchMediaListener = null;
this.query = null;
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: Dock, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.1.3", type: Dock, isStandalone: true, selector: "p-dock", inputs: { id: "id", styleClass: "styleClass", model: "model", position: "position", ariaLabel: "ariaLabel", breakpoint: "breakpoint", ariaLabelledBy: "ariaLabelledBy" }, outputs: { onFocus: "onFocus", onBlur: "onBlur" }, host: { attributes: { "data-pc-name": "dock" }, properties: { "class": "cn(cx(\"root\"), styleClass)" } }, providers: [DockStyle], queries: [{ propertyName: "itemTemplate", first: true, predicate: ["item"], descendants: true }, { propertyName: "templates", predicate: PrimeTemplate }], viewQueries: [{ propertyName: "listViewChild", first: true, predicate: ["list"], descendants: true }], usesInheritance: true, ngImport: i0, template: `
<div [class]="cx('listContainer')">
<ul
#list
[attr.id]="id"
[class]="cx('list')"
role="menu"
[attr.aria-orientation]="position === 'bottom' || position === 'top' ? 'horizontal' : 'vertical'"
[attr.aria-activedescendant]="focused ? focusedOptionId : undefined"
[tabindex]="tabindex"
[attr.aria-label]="ariaLabel"
[attr.aria-labelledby]="ariaLabelledBy"
[attr.data-pc-section]="'menu'"
(focus)="onListFocus($event)"
(blur)="onListBlur($event)"
(keydown)="onListKeyDown($event)"
(mouseleave)="onListMouseLeave()"
>
(item of model; track item.label; let i = $index) {
<li
*ngIf="item.visible !== false"
[attr.id]="getItemId(item, i)"
[class]="cn(cx('item', { item, id: getItemId(item, i) }), item?.styleClass)"
role="menuitem"
[attr.aria-label]="item.label"
[attr.aria-disabled]="disabled(item)"
(click)="onItemClick($event, item)"
(mouseenter)="onItemMouseEnter(i)"
[attr.data-pc-section]="'menuitem'"
[attr.data-p-focused]="isItemActive(getItemId(item, i))"
[attr.data-p-disabled]="disabled(item) || false"
>
<div [class]="cx('itemContent')" [attr.data-pc-section]="'content'">
<a
*ngIf="isClickableRouterLink(item); else elseBlock"
pRipple
[routerLink]="item.routerLink"
[queryParams]="item.queryParams"
[class]="cx('itemLink')"
[routerLinkActiveOptions]="item.routerLinkActiveOptions || { exact: false }"
[target]="item.target"
[attr.tabindex]="item.disabled ? null : item.tabindex ? item.tabindex : '-1'"
pTooltip
[tooltipOptions]="item.tooltipOptions"
[fragment]="item.fragment"
[queryParamsHandling]="item.queryParamsHandling"
[preserveFragment]="item.preserveFragment"
[skipLocationChange]="item.skipLocationChange"
[replaceUrl]="item.replaceUrl"
[state]="item.state"
[attr.aria-hidden]="true"
>
<span [class]="cn(cx('itemIcon'), item.icon)" *ngIf="item.icon && !itemTemplate && !_itemTemplate" [ngStyle]="item.iconStyle"></span>
<ng-container *ngTemplateOutlet="itemTemplate || itemTemplate; context: { $implicit: item }"></ng-container>
</a>
<ng-template #elseBlock>
<a
[tooltipPosition]="item.tooltipPosition"
[attr.href]="item.url || null"
[class]="cx('itemLink')"
pRipple
pTooltip
[tooltipOptions]="item.tooltipOptions"
[target]="item.target"
[attr.tabindex]="item.disabled ? null : item.tabindex ? item.tabindex : '-1'"
[attr.aria-hidden]="true"
>
<span [class]="cn(cx('itemIcon'), item.icon)" *ngIf="item.icon && !itemTemplate && !_itemTemplate" [ngStyle]="item.iconStyle"></span>
<ng-container *ngTemplateOutlet="itemTemplate || _itemTemplate; context: { $implicit: item }"></ng-container>
</a>
</ng-template>
</div>
</li>
}
</ul>
</div>
`, isInline: true, dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "ngmodule", type: RouterModule }, { kind: "directive", type: i2.RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }, { kind: "directive", type: Ripple, selector: "[pRipple]" }, { kind: "ngmodule", type: TooltipModule }, { kind: "directive", type: i3.Tooltip, selector: "[pTooltip]", inputs: ["tooltipPosition", "tooltipEvent", "positionStyle", "tooltipStyleClass", "tooltipZIndex", "escape", "showDelay", "hideDelay", "life", "positionTop", "positionLeft", "autoHide", "fitContent", "hideOnEscape", "pTooltip", "tooltipDisabled", "tooltipOptions", "appendTo"] }, { 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: Dock, decorators: [{
type: Component,
args: [{
selector: 'p-dock',
standalone: true,
imports: [CommonModule, RouterModule, Ripple, TooltipModule, SharedModule],
template: `
<div [class]="cx('listContainer')">
<ul
#list
[attr.id]="id"
[class]="cx('list')"
role="menu"
[attr.aria-orientation]="position === 'bottom' || position === 'top' ? 'horizontal' : 'vertical'"
[attr.aria-activedescendant]="focused ? focusedOptionId : undefined"
[tabindex]="tabindex"
[attr.aria-label]="ariaLabel"
[attr.aria-labelledby]="ariaLabelledBy"
[attr.data-pc-section]="'menu'"
(focus)="onListFocus($event)"
(blur)="onListBlur($event)"
(keydown)="onListKeyDown($event)"
(mouseleave)="onListMouseLeave()"
>
(item of model; track item.label; let i = $index) {
<li
*ngIf="item.visible !== false"
[attr.id]="getItemId(item, i)"
[class]="cn(cx('item', { item, id: getItemId(item, i) }), item?.styleClass)"
role="menuitem"
[attr.aria-label]="item.label"
[attr.aria-disabled]="disabled(item)"
(click)="onItemClick($event, item)"
(mouseenter)="onItemMouseEnter(i)"
[attr.data-pc-section]="'menuitem'"
[attr.data-p-focused]="isItemActive(getItemId(item, i))"
[attr.data-p-disabled]="disabled(item) || false"
>
<div [class]="cx('itemContent')" [attr.data-pc-section]="'content'">
<a
*ngIf="isClickableRouterLink(item); else elseBlock"
pRipple
[routerLink]="item.routerLink"
[queryParams]="item.queryParams"
[class]="cx('itemLink')"
[routerLinkActiveOptions]="item.routerLinkActiveOptions || { exact: false }"
[target]="item.target"
[attr.tabindex]="item.disabled ? null : item.tabindex ? item.tabindex : '-1'"
pTooltip
[tooltipOptions]="item.tooltipOptions"
[fragment]="item.fragment"
[queryParamsHandling]="item.queryParamsHandling"
[preserveFragment]="item.preserveFragment"
[skipLocationChange]="item.skipLocationChange"
[replaceUrl]="item.replaceUrl"
[state]="item.state"
[attr.aria-hidden]="true"
>
<span [class]="cn(cx('itemIcon'), item.icon)" *ngIf="item.icon && !itemTemplate && !_itemTemplate" [ngStyle]="item.iconStyle"></span>
<ng-container *ngTemplateOutlet="itemTemplate || itemTemplate; context: { $implicit: item }"></ng-container>
</a>
<ng-template #elseBlock>
<a
[tooltipPosition]="item.tooltipPosition"
[attr.href]="item.url || null"
[class]="cx('itemLink')"
pRipple
pTooltip
[tooltipOptions]="item.tooltipOptions"
[target]="item.target"
[attr.tabindex]="item.disabled ? null : item.tabindex ? item.tabindex : '-1'"
[attr.aria-hidden]="true"
>
<span [class]="cn(cx('itemIcon'), item.icon)" *ngIf="item.icon && !itemTemplate && !_itemTemplate" [ngStyle]="item.iconStyle"></span>
<ng-container *ngTemplateOutlet="itemTemplate || _itemTemplate; context: { $implicit: item }"></ng-container>
</a>
</ng-template>
</div>
</li>
}
</ul>
</div>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
providers: [DockStyle],
host: {
'[class]': 'cn(cx("root"), styleClass)',
'data-pc-name': 'dock'
}
}]
}], ctorParameters: () => [{ type: i0.ChangeDetectorRef }], propDecorators: { id: [{
type: Input
}], styleClass: [{
type: Input
}], model: [{
type: Input
}], position: [{
type: Input
}], ariaLabel: [{
type: Input
}], breakpoint: [{
type: Input
}], ariaLabelledBy: [{
type: Input
}], onFocus: [{
type: Output
}], onBlur: [{
type: Output
}], listViewChild: [{
type: ViewChild,
args: ['list', { static: false }]
}], itemTemplate: [{
type: ContentChild,
args: ['item']
}], templates: [{
type: ContentChildren,
args: [PrimeTemplate]
}] } });
class DockModule {
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: DockModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.1.3", ngImport: i0, type: DockModule, imports: [Dock, SharedModule], exports: [Dock, SharedModule] });
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: DockModule, imports: [Dock, SharedModule, SharedModule] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: DockModule, decorators: [{
type: NgModule,
args: [{
imports: [Dock, SharedModule],
exports: [Dock, SharedModule]
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { Dock, DockClasses, DockModule, DockStyle };
//# sourceMappingURL=primeng-dock.mjs.map