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

1,185 lines (1,162 loc) 49.2 kB
import * as i1 from '@angular/common'; import { CommonModule, isPlatformBrowser } from '@angular/common'; import * as i0 from '@angular/core'; import { Injectable, inject, forwardRef, booleanAttribute, ContentChildren, ContentChild, Input, Component, EventEmitter, numberAttribute, ViewChild, Output, HostBinding, ViewEncapsulation, ChangeDetectionStrategy, NgModule } from '@angular/core'; import { uuid, findSingle, getAttribute, focus, getOuterWidth, getOffset, find, getWidth } from '@primeuix/utils'; import { SharedModule, PrimeTemplate } from 'primeng/api'; import { BaseComponent } from 'primeng/basecomponent'; import { TimesIcon, ChevronLeftIcon, ChevronRightIcon } from 'primeng/icons'; import { Ripple } from 'primeng/ripple'; import * as i2 from 'primeng/tooltip'; import { TooltipModule } from 'primeng/tooltip'; import { BaseStyle } from 'primeng/base'; const theme = ({ dt }) => ` .p-tabs { display: flex; flex-direction: column; } .p-tablist { display: flex; position: relative; } .p-tabs-scrollable > .p-tablist { overflow: hidden; } .p-tablist-viewport { overflow-x: auto; overflow-y: hidden; scroll-behavior: smooth; scrollbar-width: none; overscroll-behavior: contain auto; } .p-tablist-viewport::-webkit-scrollbar { display: none; } .p-tablist-tab-list { position: relative; display: flex; background: ${dt('tabs.tablist.background')}; border-style: solid; border-color: ${dt('tabs.tablist.border.color')}; border-width: ${dt('tabs.tablist.border.width')}; } .p-tablist-content { flex-grow: 1; } .p-tablist-nav-button { all: unset; position: absolute !important; flex-shrink: 0; top: 0; z-index: 2; height: 100%; display: flex; align-items: center; justify-content: center; background: ${dt('tabs.nav.button.background')}; color: ${dt('tabs.nav.button.color')}; width: ${dt('tabs.nav.button.width')}; transition: color ${dt('tabs.transition.duration')}, outline-color ${dt('tabs.transition.duration')}, box-shadow ${dt('tabs.transition.duration')}; box-shadow: ${dt('tabs.nav.button.shadow')}; outline-color: transparent; cursor: pointer; } .p-tablist-nav-button:focus-visible { z-index: 1; box-shadow: ${dt('tabs.nav.button.focus.ring.shadow')}; outline: ${dt('tabs.nav.button.focus.ring.width')} ${dt('tabs.nav.button.focus.ring.style')} ${dt('tabs.nav.button.focus.ring.color')}; outline-offset: ${dt('tabs.nav.button.focus.ring.offset')}; } .p-tablist-nav-button:hover { color: ${dt('tabs.nav.button.hover.color')}; } .p-tablist-prev-button { left: 0; } .p-tablist-next-button { right: 0; } .p-tab { display: flex; align-items: center; flex-shrink: 0; cursor: pointer; user-select: none; position: relative; border-style: solid; white-space: nowrap; gap: ${dt('tabs.tab.gap')}; background: ${dt('tabs.tab.background')}; border-width: ${dt('tabs.tab.border.width')}; border-color: ${dt('tabs.tab.border.color')}; color: ${dt('tabs.tab.color')}; padding: ${dt('tabs.tab.padding')}; font-weight: ${dt('tabs.tab.font.weight')}; transition: background ${dt('tabs.transition.duration')}, border-color ${dt('tabs.transition.duration')}, color ${dt('tabs.transition.duration')}, outline-color ${dt('tabs.transition.duration')}, box-shadow ${dt('tabs.transition.duration')}; margin: ${dt('tabs.tab.margin')}; outline-color: transparent; } .p-tab:not(.p-disabled):focus-visible { z-index: 1; box-shadow: ${dt('tabs.tab.focus.ring.shadow')}; outline: ${dt('tabs.tab.focus.ring.width')} ${dt('tabs.tab.focus.ring.style')} ${dt('tabs.tab.focus.ring.color')}; outline-offset: ${dt('tabs.tab.focus.ring.offset')}; } .p-tab:not(.p-tab-active):not(.p-disabled):hover { background: ${dt('tabs.tab.hover.background')}; border-color: ${dt('tabs.tab.hover.border.color')}; color: ${dt('tabs.tab.hover.color')}; } .p-tab-active { background: ${dt('tabs.tab.active.background')}; border-color: ${dt('tabs.tab.active.border.color')}; color: ${dt('tabs.tab.active.color')}; } .p-tabpanels { background: ${dt('tabs.tabpanel.background')}; color: ${dt('tabs.tabpanel.color')}; padding: ${dt('tabs.tabpanel.padding')}; outline: 0 none; } .p-tabpanel:focus-visible { box-shadow: ${dt('tabs.tabpanel.focus.ring.shadow')}; outline: ${dt('tabs.tabpanel.focus.ring.width')} ${dt('tabs.tabpanel.focus.ring.style')} ${dt('tabs.tabpanel.focus.ring.color')}; outline-offset: ${dt('tabs.tabpanel.focus.ring.offset')}; } .p-tablist-active-bar { z-index: 1; display: block; position: absolute; bottom: ${dt('tabs.active.bar.bottom')}; height: ${dt('tabs.active.bar.height')}; background: ${dt('tabs.active.bar.background')}; transition: 250ms cubic-bezier(0.35, 0, 0.25, 1); } `; const classes = { root: ({ props }) => [ 'p-tabs p-component', { 'p-tabs-scrollable': props.scrollable } ] }; class TabsStyle extends BaseStyle { name = 'tabs'; theme = theme; classes = classes; static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: TabsStyle, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: TabsStyle }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: TabsStyle, decorators: [{ type: Injectable }] }); /** * * Tabs facilitates seamless switching between different views. * * [Live Demo](https://www.primeng.org/tabs/) * * @module tabsstyle * */ var TabsClasses; (function (TabsClasses) { /** * Class name of the root element */ TabsClasses["root"] = "p-tabs"; /** * Class name of the wrapper element */ TabsClasses["list"] = "p-tablist"; /** * Class name of the content element */ TabsClasses["content"] = "p-tablist-content"; /** * Class name of the tab list element */ TabsClasses["tablist"] = "p-tablist-tab-list"; /** * Class name of the tab list element */ TabsClasses["tab"] = "p-tab"; /** * Class name of the inkbar element */ TabsClasses["inkbar"] = "p-tablist-active-bar"; /** * Class name of the navigation buttons */ TabsClasses["button"] = "p-tablist-nav-button"; /** * Class name of the tab panels wrapper */ TabsClasses["tabpanels"] = "p-tabpanels"; /** * Class name of the tab panel element */ TabsClasses["tabpanel"] = "p-tabs-panel"; })(TabsClasses || (TabsClasses = {})); /** * TabPanel is a helper component for TabView component. * @group Components */ class TabPanel extends BaseComponent { /** * Defines if tab can be removed. * @group Props */ closable = false; /** * Inline style of the tab header. * @group Props */ get headerStyle() { return this._headerStyle; } set headerStyle(headerStyle) { this._headerStyle = headerStyle; this.tabView.cd.markForCheck(); } /** * Style class of the tab header. * @group Props */ get headerStyleClass() { return this._headerStyleClass; } set headerStyleClass(headerStyleClass) { this._headerStyleClass = headerStyleClass; this.tabView.cd.markForCheck(); } /** * Whether a lazy loaded panel should avoid getting loaded again on reselection. * @group Props */ cache = true; /** * Advisory information to display in a tooltip on hover. * @group Props */ tooltip; /** * Position of the tooltip. * @group Props */ tooltipPosition = 'top'; /** * Type of CSS position. * @group Props */ tooltipPositionStyle = 'absolute'; /** * Style class of the tooltip. * @group Props */ tooltipStyleClass; /** * Defines if tab is active. * @defaultValue false * @group Props */ get selected() { return !!this._selected; } set selected(val) { this._selected = val; if (!this.loaded) { this.cd.detectChanges(); } if (val) this.loaded = true; } /** * When true, tab cannot be activated. * @defaultValue false * @group Props */ get disabled() { return !!this._disabled; } set disabled(disabled) { this._disabled = disabled; this.tabView.cd.markForCheck(); } /** * Title of the tabPanel. * @group Props */ get header() { return this._header; } set header(header) { this._header = header; // We have to wait for the rendering and then retrieve the actual size element from the DOM. // in future `Promise.resolve` can be changed to `queueMicrotask` (if ie11 support will be dropped) Promise.resolve().then(() => { this.tabView.updateInkBar(); this.tabView.cd.markForCheck(); }); } /** * Left icon of the tabPanel. * @group Props * @deprecated since v15.4.2, use `lefticon` template instead. */ get leftIcon() { return this._leftIcon; } set leftIcon(leftIcon) { this._leftIcon = leftIcon; this.tabView.cd.markForCheck(); } /** * Left icon of the tabPanel. * @group Props * @deprecated since v15.4.2, use `righticon` template instead. */ get rightIcon() { return this._rightIcon; } set rightIcon(rightIcon) { this._rightIcon = rightIcon; this.tabView.cd.markForCheck(); } closed = false; _headerStyle; _headerStyleClass; _selected; _disabled; _header; _leftIcon; _rightIcon = undefined; loaded = false; id = uuid('pn_id_'); contentTemplate; headerTemplate; leftIconTemplate; rightIconTemplate; closeIconTemplate; templates; tabView = inject(forwardRef(() => TabView)); _componentStyle = inject(TabsStyle); _headerTemplate; _contentTemplate; _rightIconTemplate; _leftIconTemplate; _closeIconTemplate; ngAfterContentInit() { this.templates.forEach((item) => { switch (item.getType()) { case 'header': this._headerTemplate = item.template; break; case 'content': this._contentTemplate = item.template; break; case 'righticon': this._rightIconTemplate = item.template; break; case 'lefticon': this._leftIconTemplate = item.template; break; case 'closeicon': this._closeIconTemplate = item.template; break; default: this._contentTemplate = item.template; break; } }); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: TabPanel, deps: null, target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "19.2.2", type: TabPanel, isStandalone: true, selector: "p-tabPanel, p-tabpanel", inputs: { closable: ["closable", "closable", booleanAttribute], headerStyle: "headerStyle", headerStyleClass: "headerStyleClass", cache: ["cache", "cache", booleanAttribute], tooltip: "tooltip", tooltipPosition: "tooltipPosition", tooltipPositionStyle: "tooltipPositionStyle", tooltipStyleClass: "tooltipStyleClass", selected: "selected", disabled: "disabled", header: "header", leftIcon: "leftIcon", rightIcon: "rightIcon" }, providers: [TabsStyle], queries: [{ propertyName: "contentTemplate", first: true, predicate: ["content"], descendants: true }, { propertyName: "headerTemplate", first: true, predicate: ["header"], descendants: true }, { propertyName: "leftIconTemplate", first: true, predicate: ["lefticon"], descendants: true }, { propertyName: "rightIconTemplate", first: true, predicate: ["righticon"], descendants: true }, { propertyName: "closeIconTemplate", first: true, predicate: ["closeicon"], descendants: true }, { propertyName: "templates", predicate: PrimeTemplate }], usesInheritance: true, ngImport: i0, template: ` <div *ngIf="!closed" class="p-tabview-panel" role="tabpanel" [hidden]="!selected" [attr.id]="tabView.getTabContentId(id)" [attr.aria-hidden]="!selected" [attr.aria-labelledby]="tabView.getTabHeaderActionId(id)" [attr.data-pc-name]="'tabpanel'" > <ng-content></ng-content> <ng-container *ngIf="(contentTemplate || _contentTemplate) && (cache ? loaded : selected)"> <ng-container *ngTemplateOutlet="contentTemplate || _contentTemplate"></ng-container> </ng-container> </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: "ngmodule", type: SharedModule }] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: TabPanel, decorators: [{ type: Component, args: [{ selector: 'p-tabPanel, p-tabpanel', standalone: true, imports: [CommonModule, SharedModule], template: ` <div *ngIf="!closed" class="p-tabview-panel" role="tabpanel" [hidden]="!selected" [attr.id]="tabView.getTabContentId(id)" [attr.aria-hidden]="!selected" [attr.aria-labelledby]="tabView.getTabHeaderActionId(id)" [attr.data-pc-name]="'tabpanel'" > <ng-content></ng-content> <ng-container *ngIf="(contentTemplate || _contentTemplate) && (cache ? loaded : selected)"> <ng-container *ngTemplateOutlet="contentTemplate || _contentTemplate"></ng-container> </ng-container> </div> `, providers: [TabsStyle] }] }], propDecorators: { closable: [{ type: Input, args: [{ transform: booleanAttribute }] }], headerStyle: [{ type: Input }], headerStyleClass: [{ type: Input }], cache: [{ type: Input, args: [{ transform: booleanAttribute }] }], tooltip: [{ type: Input }], tooltipPosition: [{ type: Input }], tooltipPositionStyle: [{ type: Input }], tooltipStyleClass: [{ type: Input }], selected: [{ type: Input }], disabled: [{ type: Input }], header: [{ type: Input }], leftIcon: [{ type: Input }], rightIcon: [{ type: Input }], contentTemplate: [{ type: ContentChild, args: ['content'] }], headerTemplate: [{ type: ContentChild, args: ['header'] }], leftIconTemplate: [{ type: ContentChild, args: ['lefticon'] }], rightIconTemplate: [{ type: ContentChild, args: ['righticon'] }], closeIconTemplate: [{ type: ContentChild, args: ['closeicon'] }], templates: [{ type: ContentChildren, args: [PrimeTemplate] }] } }); /** * TabView is a container component to group content with tabs. * @group Components */ class TabView extends BaseComponent { get hostClass() { return this.styleClass; } get hostStyle() { return this.style; } /** * Inline style of the component. * @group Props */ style; /** * Style class of the component. * @group Props */ styleClass; /** * Whether tab close is controlled at onClose event or not. * @defaultValue false * @group Props */ controlClose; /** * When enabled displays buttons at each side of the tab headers to scroll the tab list. * @defaultValue false * @group Props */ scrollable; /** * Index of the active tab to change selected tab programmatically. * @group Props */ get activeIndex() { return this._activeIndex; } set activeIndex(val) { this._activeIndex = val; if (this.preventActiveIndexPropagation) { this.preventActiveIndexPropagation = false; return; } if (this.tabs && this.tabs.length && this._activeIndex != null && this.tabs.length > this._activeIndex) { this.findSelectedTab().selected = false; this.tabs[this._activeIndex].selected = true; this.tabChanged = true; this.updateScrollBar(val); } } /** * When enabled, the focused tab is activated. * @group Props */ selectOnFocus = false; /** * Used to define a string aria label attribute the forward navigation button. * @group Props */ nextButtonAriaLabel; /** * Used to define a string aria label attribute the backward navigation button. * @group Props */ prevButtonAriaLabel; /** * When activated, navigation buttons will automatically hide or show based on the available space within the container. * @group Props */ autoHideButtons = true; /** * Index of the element in tabbing order. * @group Props */ tabindex = 0; /** * Callback to invoke on tab change. * @param {TabViewChangeEvent} event - Custom tab change event * @group Emits */ onChange = new EventEmitter(); /** * Callback to invoke on tab close. * @param {TabViewCloseEvent} event - Custom tab close event * @group Emits */ onClose = new EventEmitter(); /** * Callback to invoke on the active tab change. * @param {number} index - New active index * @group Emits */ activeIndexChange = new EventEmitter(); content; navbar; prevBtn; nextBtn; inkbar; tabPanels; initialized; tabs; _activeIndex; preventActiveIndexPropagation; tabChanged; backwardIsDisabled = true; forwardIsDisabled = false; tabChangesSubscription; resizeObserver; container; list; buttonVisible; elementToObserve; previousIconTemplate; nextIconTemplate; _previousIconTemplate; _nextIconTemplate; _componentStyle = inject(TabsStyle); templates; ngOnInit() { super.ngOnInit(); console.log('TabView component is deprecated as of v18. Use Tabs component instead.'); } ngAfterContentInit() { this.initTabs(); this.tabChangesSubscription = this.tabPanels.changes.subscribe((_) => { this.initTabs(); this.refreshButtonState(); }); this.templates.forEach((item) => { switch (item.getType()) { case 'previousicon': this._previousIconTemplate = item.template; break; case 'nexticon': this._nextIconTemplate = item.template; break; } }); } ngAfterViewInit() { super.ngAfterViewInit(); if (isPlatformBrowser(this.platformId)) { if (this.autoHideButtons) { this.bindResizeObserver(); } } } bindResizeObserver() { this.container = findSingle(this.el.nativeElement, '[data-pc-section="navcontent"]'); this.list = findSingle(this.el.nativeElement, '[data-pc-section="nav"]'); this.resizeObserver = new ResizeObserver(() => { if (this.list.offsetWidth >= this.container.offsetWidth) { this.buttonVisible = true; } else { this.buttonVisible = false; } this.updateButtonState(); this.cd.detectChanges(); }); this.resizeObserver.observe(this.container); } unbindResizeObserver() { this.resizeObserver.unobserve(this.elementToObserve.nativeElement); this.resizeObserver = null; } ngAfterViewChecked() { if (isPlatformBrowser(this.platformId)) { if (this.tabChanged) { this.updateInkBar(); this.tabChanged = false; } } } ngOnDestroy() { if (this.tabChangesSubscription) { this.tabChangesSubscription.unsubscribe(); } if (this.resizeObserver) { this.unbindResizeObserver(); } super.ngOnDestroy(); } getTabHeaderActionId(tabId) { return `${tabId}_header_action`; } getTabContentId(tabId) { return `${tabId}_content`; } initTabs() { this.tabs = this.tabPanels.toArray(); let selectedTab = this.findSelectedTab(); if (!selectedTab && this.tabs.length) { if (this.activeIndex != null && this.tabs.length > this.activeIndex) this.tabs[this.activeIndex].selected = true; else this.tabs[0].selected = true; this.tabChanged = true; } this.cd.markForCheck(); } onTabKeyDown(event, tab) { switch (event.code) { case 'ArrowLeft': this.onTabArrowLeftKey(event); break; case 'ArrowRight': this.onTabArrowRightKey(event); break; case 'Home': this.onTabHomeKey(event); break; case 'End': this.onTabEndKey(event); break; case 'PageDown': this.onTabEndKey(event); break; case 'PageUp': this.onTabHomeKey(event); break; case 'Enter': case 'Space': this.open(event, tab); break; default: break; } } onTabArrowLeftKey(event) { const prevHeaderAction = this.findPrevHeaderAction(event.currentTarget); const index = getAttribute(prevHeaderAction, 'data-pc-index'); prevHeaderAction ? this.changeFocusedTab(event, prevHeaderAction, index) : this.onTabEndKey(event); event.preventDefault(); } onTabArrowRightKey(event) { const nextHeaderAction = this.findNextHeaderAction(event.currentTarget); const index = getAttribute(nextHeaderAction, 'data-pc-index'); nextHeaderAction ? this.changeFocusedTab(event, nextHeaderAction, index) : this.onTabHomeKey(event); event.preventDefault(); } onTabHomeKey(event) { const firstHeaderAction = this.findFirstHeaderAction(); const index = getAttribute(firstHeaderAction, 'data-pc-index'); this.changeFocusedTab(event, firstHeaderAction, index); event.preventDefault(); } onTabEndKey(event) { const lastHeaderAction = this.findLastHeaderAction(); const index = getAttribute(lastHeaderAction, 'data-pc-index'); this.changeFocusedTab(event, lastHeaderAction, index); event.preventDefault(); } changeFocusedTab(event, element, index) { if (element) { focus(element); element.scrollIntoView({ block: 'nearest' }); if (this.selectOnFocus) { const tab = this.tabs[index]; this.open(event, tab); } } } findNextHeaderAction(tabElement, selfCheck = false) { const headerElement = selfCheck ? tabElement : tabElement.nextElementSibling; return headerElement ? (getAttribute(headerElement, 'data-p-disabled') || getAttribute(headerElement, 'data-pc-section') === 'inkbar' ? this.findNextHeaderAction(headerElement) : headerElement) : null; } findPrevHeaderAction(tabElement, selfCheck = false) { const headerElement = selfCheck ? tabElement : tabElement.previousElementSibling; return headerElement ? (getAttribute(headerElement, 'data-p-disabled') || getAttribute(headerElement, 'data-pc-section') === 'inkbar' ? this.findPrevHeaderAction(headerElement) : headerElement) : null; } findFirstHeaderAction() { const firstEl = this.navbar.nativeElement.firstElementChild; return this.findNextHeaderAction(firstEl, true); } findLastHeaderAction() { const lastEl = this.navbar.nativeElement.lastElementChild; const lastHeaderAction = getAttribute(lastEl, 'data-pc-section') === 'inkbar' ? lastEl.previousElementSibling : lastEl; return this.findPrevHeaderAction(lastHeaderAction, true); } open(event, tab) { if (tab.disabled) { if (event) { event.preventDefault(); } return; } if (!tab.selected) { let selectedTab = this.findSelectedTab(); if (selectedTab) { selectedTab.selected = false; } this.tabChanged = true; tab.selected = true; let selectedTabIndex = this.findTabIndex(tab); this.preventActiveIndexPropagation = true; this.activeIndexChange.emit(selectedTabIndex); this.onChange.emit({ originalEvent: event, index: selectedTabIndex }); this.updateScrollBar(selectedTabIndex); } if (event) { event.preventDefault(); } } close(event, tab) { if (this.controlClose) { this.onClose.emit({ originalEvent: event, index: this.findTabIndex(tab), close: () => { this.closeTab(tab); } }); } else { this.closeTab(tab); this.onClose.emit({ originalEvent: event, index: this.findTabIndex(tab) }); } event.stopPropagation(); } closeTab(tab) { if (tab.disabled) { return; } if (tab.selected) { this.tabChanged = true; tab.selected = false; for (let i = 0; i < this.tabs.length; i++) { let tabPanel = this.tabs[i]; if (!tabPanel.closed && !tab.disabled) { tabPanel.selected = true; break; } } } tab.closed = true; } findSelectedTab() { for (let i = 0; i < this.tabs.length; i++) { if (this.tabs[i].selected) { return this.tabs[i]; } } return null; } findTabIndex(tab) { let index = -1; for (let i = 0; i < this.tabs.length; i++) { if (this.tabs[i] == tab) { index = i; break; } } return index; } getBlockableElement() { return this.el.nativeElement.children[0]; } updateInkBar() { if (isPlatformBrowser(this.platformId)) { if (this.navbar) { const tabHeader = findSingle(this.navbar.nativeElement, '[data-pc-section="headeraction"][data-p-active="true"]'); if (!tabHeader) { return; } this.inkbar.nativeElement.style.width = getOuterWidth(tabHeader) + 'px'; this.inkbar.nativeElement.style.left = getOffset(tabHeader).left - getOffset(this.navbar.nativeElement).left + 'px'; } } } updateScrollBar(index) { let tabHeader = find(this.navbar.nativeElement, '[data-pc-section="headeraction"]')[index]; if (tabHeader) { tabHeader.scrollIntoView({ block: 'nearest' }); } } updateButtonState() { const content = this.content.nativeElement; const { scrollLeft, scrollWidth } = content; const width = getWidth(content); this.backwardIsDisabled = scrollLeft === 0; this.forwardIsDisabled = Math.round(scrollLeft) === scrollWidth - width; } refreshButtonState() { this.container = findSingle(this.el.nativeElement, '[data-pc-section="navcontent"]'); this.list = findSingle(this.el.nativeElement, '[data-pc-section="nav"]'); if (this.list.offsetWidth >= this.container.offsetWidth) { if (this.list.offsetWidth >= this.container.offsetWidth) { this.buttonVisible = true; } else { this.buttonVisible = false; } this.updateButtonState(); this.cd.markForCheck(); } } onScroll(event) { this.scrollable && this.updateButtonState(); event.preventDefault(); } getVisibleButtonWidths() { return [this.prevBtn?.nativeElement, this.nextBtn?.nativeElement].reduce((acc, el) => (el ? acc + getWidth(el) : acc), 0); } navBackward() { const content = this.content.nativeElement; const width = getWidth(content) - this.getVisibleButtonWidths(); const pos = content.scrollLeft - width; content.scrollLeft = pos <= 0 ? 0 : pos; } navForward() { const content = this.content.nativeElement; const width = getWidth(content) - this.getVisibleButtonWidths(); const pos = content.scrollLeft + width; const lastPos = content.scrollWidth - width; content.scrollLeft = pos >= lastPos ? lastPos : pos; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: TabView, deps: null, target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.2", type: TabView, isStandalone: true, selector: "p-tabView, p-tabview", inputs: { style: "style", styleClass: "styleClass", controlClose: ["controlClose", "controlClose", booleanAttribute], scrollable: ["scrollable", "scrollable", booleanAttribute], activeIndex: "activeIndex", selectOnFocus: ["selectOnFocus", "selectOnFocus", booleanAttribute], nextButtonAriaLabel: "nextButtonAriaLabel", prevButtonAriaLabel: "prevButtonAriaLabel", autoHideButtons: ["autoHideButtons", "autoHideButtons", booleanAttribute], tabindex: ["tabindex", "tabindex", numberAttribute] }, outputs: { onChange: "onChange", onClose: "onClose", activeIndexChange: "activeIndexChange" }, host: { properties: { "class.p-tabs": "true", "class.p-tabs-scrollable": "scrollable", "class.p-component": "true", "attr.data-pc-name": "\"tabview\"", "class": "this.hostClass", "style": "this.hostStyle" } }, providers: [TabsStyle], queries: [{ propertyName: "previousIconTemplate", first: true, predicate: ["previousicon"], descendants: true }, { propertyName: "nextIconTemplate", first: true, predicate: ["nexticon"], descendants: true }, { propertyName: "tabPanels", predicate: TabPanel }, { propertyName: "templates", predicate: PrimeTemplate }], viewQueries: [{ propertyName: "content", first: true, predicate: ["content"], descendants: true }, { propertyName: "navbar", first: true, predicate: ["navbar"], descendants: true }, { propertyName: "prevBtn", first: true, predicate: ["prevBtn"], descendants: true }, { propertyName: "nextBtn", first: true, predicate: ["nextBtn"], descendants: true }, { propertyName: "inkbar", first: true, predicate: ["inkbar"], descendants: true }, { propertyName: "elementToObserve", first: true, predicate: ["elementToObserve"], descendants: true }], usesInheritance: true, ngImport: i0, template: ` <div #elementToObserve class="p-tablist"> <button *ngIf="scrollable && !backwardIsDisabled && autoHideButtons" #prevBtn class="p-tablist-prev-button p-tablist-nav-button" (click)="navBackward()" [attr.tabindex]="tabindex" [attr.aria-label]="prevButtonAriaLabel" type="button" pRipple > <ChevronLeftIcon *ngIf="!previousIconTemplate && !_previousIconTemplate" [attr.aria-hidden]="true" /> <ng-template *ngTemplateOutlet="previousIconTemplate && _previousIconTemplate"></ng-template> </button> <div #content class="p-tablist-content" [ngClass]="{ 'p-tablist-viewport': scrollable }" (scroll)="onScroll($event)" [attr.data-pc-section]="'navcontent'"> <div #navbar class="p-tablist-tab-list" role="tablist" [attr.data-pc-section]="'nav'"> @for (tab of tabs; track tab; let i = $index) { @if (!tab.closed) { <button [ngClass]="{ 'p-tab': true, 'p-tab-active': tab.selected, 'p-disabled': tab.disabled }" [attr.role]="'tab'" [class]="tab.headerStyleClass" [ngStyle]="tab.headerStyle" [pTooltip]="tab.tooltip" [tooltipPosition]="tab.tooltipPosition" [positionStyle]="tab.tooltipPositionStyle" [tooltipStyleClass]="tab.tooltipStyleClass" [attr.id]="getTabHeaderActionId(tab.id)" [attr.aria-controls]="getTabContentId(tab.id)" [attr.aria-selected]="tab.selected" [attr.tabindex]="tab.disabled || !tab.selected ? '-1' : tabindex" [attr.aria-disabled]="tab.disabled" [disabled]="tab.disabled" [attr.data-pc-index]="i" [attr.data-p-disabled]="tab.disabled" [attr.data-pc-section]="'headeraction'" [attr.data-p-active]="tab.selected" (click)="open($event, tab)" (keydown)="onTabKeyDown($event, tab)" pRipple > @if (tab.headerTemplate || tab._headerTemplate) { <ng-container *ngTemplateOutlet="tab.headerTemplate || tab._headerTemplate"></ng-container> } @else { @if (tab.leftIconTemplate || tab._leftIconTemplate) { <ng-template *ngTemplateOutlet="tab.leftIconTemplate || tab._leftIconTemplate"></ng-template> } @else if (tab.leftIcon && !tab.leftIconTemplate && !tab._leftIconTemplate) { <span class="p-tabview-left-icon" [ngClass]="tab.leftIcon"></span> } {{ tab.header }} @if (tab.rightIconTemplate || tab._rightIconTemplate) { <ng-template *ngTemplateOutlet="tab.rightIconTemplate || tab._rightIconTemplate"></ng-template> } @else if (tab.rightIcon && !tab.rightIconTemplate && !tab._rightIconTemplate) { <span class="p-tabview-right-icon" [ngClass]="tab.rightIcon"></span> } @if (tab.closable) { @if (tab.closeIconTemplate || tab._closeIconTemplate) { <ng-template *ngTemplateOutlet="tab.closeIconTemplate || tab._closeIconTemplate"></ng-template> } @else { <TimesIcon (click)="close($event, tab)" /> } } } </button> <span #inkbar class="p-tablist-active-bar" role="presentation" [attr.aria-hidden]="true" [attr.data-pc-section]="'inkbar'"></span> } } </div> </div> <button *ngIf="scrollable && !forwardIsDisabled && buttonVisible" #nextBtn [attr.tabindex]="tabindex" [attr.aria-label]="nextButtonAriaLabel" class="p-tablist-next-button p-tablist-nav-button" (click)="navForward()" type="button" pRipple> @if (nextIconTemplate || _nextIconTemplate) { <ng-template *ngTemplateOutlet="nextIconTemplate || _nextIconTemplate"></ng-template> } @else { <ChevronRightIcon [attr.aria-hidden]="true" /> } </button> </div> <div class="p-tabpanels"> <ng-content></ng-content> </div> `, isInline: true, dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { 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: SharedModule }, { kind: "ngmodule", type: TooltipModule }, { kind: "directive", type: i2.Tooltip, selector: "[pTooltip]", inputs: ["tooltipPosition", "tooltipEvent", "appendTo", "positionStyle", "tooltipStyleClass", "tooltipZIndex", "escape", "showDelay", "hideDelay", "life", "positionTop", "positionLeft", "autoHide", "fitContent", "hideOnEscape", "pTooltip", "tooltipDisabled", "tooltipOptions"] }, { kind: "directive", type: Ripple, selector: "[pRipple]" }, { kind: "component", type: TimesIcon, selector: "TimesIcon" }, { kind: "component", type: ChevronLeftIcon, selector: "ChevronLeftIcon" }, { kind: "component", type: ChevronRightIcon, selector: "ChevronRightIcon" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: TabView, decorators: [{ type: Component, args: [{ selector: 'p-tabView, p-tabview', standalone: true, imports: [CommonModule, SharedModule, TooltipModule, Ripple, TimesIcon, ChevronLeftIcon, ChevronRightIcon], template: ` <div #elementToObserve class="p-tablist"> <button *ngIf="scrollable && !backwardIsDisabled && autoHideButtons" #prevBtn class="p-tablist-prev-button p-tablist-nav-button" (click)="navBackward()" [attr.tabindex]="tabindex" [attr.aria-label]="prevButtonAriaLabel" type="button" pRipple > <ChevronLeftIcon *ngIf="!previousIconTemplate && !_previousIconTemplate" [attr.aria-hidden]="true" /> <ng-template *ngTemplateOutlet="previousIconTemplate && _previousIconTemplate"></ng-template> </button> <div #content class="p-tablist-content" [ngClass]="{ 'p-tablist-viewport': scrollable }" (scroll)="onScroll($event)" [attr.data-pc-section]="'navcontent'"> <div #navbar class="p-tablist-tab-list" role="tablist" [attr.data-pc-section]="'nav'"> @for (tab of tabs; track tab; let i = $index) { @if (!tab.closed) { <button [ngClass]="{ 'p-tab': true, 'p-tab-active': tab.selected, 'p-disabled': tab.disabled }" [attr.role]="'tab'" [class]="tab.headerStyleClass" [ngStyle]="tab.headerStyle" [pTooltip]="tab.tooltip" [tooltipPosition]="tab.tooltipPosition" [positionStyle]="tab.tooltipPositionStyle" [tooltipStyleClass]="tab.tooltipStyleClass" [attr.id]="getTabHeaderActionId(tab.id)" [attr.aria-controls]="getTabContentId(tab.id)" [attr.aria-selected]="tab.selected" [attr.tabindex]="tab.disabled || !tab.selected ? '-1' : tabindex" [attr.aria-disabled]="tab.disabled" [disabled]="tab.disabled" [attr.data-pc-index]="i" [attr.data-p-disabled]="tab.disabled" [attr.data-pc-section]="'headeraction'" [attr.data-p-active]="tab.selected" (click)="open($event, tab)" (keydown)="onTabKeyDown($event, tab)" pRipple > @if (tab.headerTemplate || tab._headerTemplate) { <ng-container *ngTemplateOutlet="tab.headerTemplate || tab._headerTemplate"></ng-container> } @else { @if (tab.leftIconTemplate || tab._leftIconTemplate) { <ng-template *ngTemplateOutlet="tab.leftIconTemplate || tab._leftIconTemplate"></ng-template> } @else if (tab.leftIcon && !tab.leftIconTemplate && !tab._leftIconTemplate) { <span class="p-tabview-left-icon" [ngClass]="tab.leftIcon"></span> } {{ tab.header }} @if (tab.rightIconTemplate || tab._rightIconTemplate) { <ng-template *ngTemplateOutlet="tab.rightIconTemplate || tab._rightIconTemplate"></ng-template> } @else if (tab.rightIcon && !tab.rightIconTemplate && !tab._rightIconTemplate) { <span class="p-tabview-right-icon" [ngClass]="tab.rightIcon"></span> } @if (tab.closable) { @if (tab.closeIconTemplate || tab._closeIconTemplate) { <ng-template *ngTemplateOutlet="tab.closeIconTemplate || tab._closeIconTemplate"></ng-template> } @else { <TimesIcon (click)="close($event, tab)" /> } } } </button> <span #inkbar class="p-tablist-active-bar" role="presentation" [attr.aria-hidden]="true" [attr.data-pc-section]="'inkbar'"></span> } } </div> </div> <button *ngIf="scrollable && !forwardIsDisabled && buttonVisible" #nextBtn [attr.tabindex]="tabindex" [attr.aria-label]="nextButtonAriaLabel" class="p-tablist-next-button p-tablist-nav-button" (click)="navForward()" type="button" pRipple> @if (nextIconTemplate || _nextIconTemplate) { <ng-template *ngTemplateOutlet="nextIconTemplate || _nextIconTemplate"></ng-template> } @else { <ChevronRightIcon [attr.aria-hidden]="true" /> } </button> </div> <div class="p-tabpanels"> <ng-content></ng-content> </div> `, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: { '[class.p-tabs]': 'true', '[class.p-tabs-scrollable]': 'scrollable', '[class.p-component]': 'true', '[attr.data-pc-name]': '"tabview"' }, providers: [TabsStyle] }] }], propDecorators: { hostClass: [{ type: HostBinding, args: ['class'] }], hostStyle: [{ type: HostBinding, args: ['style'] }], style: [{ type: Input }], styleClass: [{ type: Input }], controlClose: [{ type: Input, args: [{ transform: booleanAttribute }] }], scrollable: [{ type: Input, args: [{ transform: booleanAttribute }] }], activeIndex: [{ type: Input }], selectOnFocus: [{ type: Input, args: [{ transform: booleanAttribute }] }], nextButtonAriaLabel: [{ type: Input }], prevButtonAriaLabel: [{ type: Input }], autoHideButtons: [{ type: Input, args: [{ transform: booleanAttribute }] }], tabindex: [{ type: Input, args: [{ transform: numberAttribute }] }], onChange: [{ type: Output }], onClose: [{ type: Output }], activeIndexChange: [{ type: Output }], content: [{ type: ViewChild, args: ['content'] }], navbar: [{ type: ViewChild, args: ['navbar'] }], prevBtn: [{ type: ViewChild, args: ['prevBtn'] }], nextBtn: [{ type: ViewChild, args: ['nextBtn'] }], inkbar: [{ type: ViewChild, args: ['inkbar'] }], tabPanels: [{ type: ContentChildren, args: [TabPanel] }], elementToObserve: [{ type: ViewChild, args: ['elementToObserve'] }], previousIconTemplate: [{ type: ContentChild, args: ['previousicon'] }], nextIconTemplate: [{ type: ContentChild, args: ['nexticon'] }], templates: [{ type: ContentChildren, args: [PrimeTemplate] }] } }); class TabViewModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: TabViewModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: TabViewModule, imports: [TabView, TabPanel, SharedModule], exports: [TabView, TabPanel, SharedModule] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: TabViewModule, imports: [TabView, TabPanel, SharedModule, SharedModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: TabViewModule, decorators: [{ type: NgModule, args: [{ imports: [TabView, TabPanel, SharedModule], exports: [TabView, TabPanel, SharedModule] }] }] }); /** * Generated bundle index. Do not edit. */ export { TabPanel, TabView, TabViewModule, TabsClasses, TabsStyle }; //# sourceMappingURL=primeng-tabview.mjs.map