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,
324 lines (319 loc) • 17.2 kB
JavaScript
export * from 'primeng/types/scrolltop';
import { isPlatformBrowser, NgTemplateOutlet } from '@angular/common';
import * as i0 from '@angular/core';
import { Injectable, InjectionToken, inject, input, numberAttribute, contentChild, computed, signal, afterEveryRender, ViewEncapsulation, ChangeDetectionStrategy, Component, NgModule } from '@angular/core';
import { ChevronUp } from '@primeicons/angular/chevron-up';
import { getWindowScrollTop } from '@primeuix/utils';
import { SharedModule } from 'primeng/api';
import { BaseComponent, PARENT_INSTANCE } from 'primeng/basecomponent';
import * as i1 from 'primeng/bind';
import { Bind } from 'primeng/bind';
import { ButtonDirective } from 'primeng/button';
import { MotionDirective } from 'primeng/motion';
import { ZIndexUtils } from 'primeng/utils';
import { style } from '@primeuix/styles/scrolltop';
import { BaseStyle } from 'primeng/base';
const classes = {
root: ({ instance }) => ['p-scrolltop', { 'p-scrolltop-sticky': instance.target() !== 'window' }],
icon: 'p-scrolltop-icon'
};
class ScrollTopStyle extends BaseStyle {
name = 'scrolltop';
style = style;
classes = classes;
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ScrollTopStyle, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ScrollTopStyle });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ScrollTopStyle, decorators: [{
type: Injectable
}] });
/**
*
* ScrollTop gets displayed after a certain scroll position and used to navigates to the top of the page quickly.
*
* [Live Demo](https://www.primeng.org/scrolltop/)
*
* @module scrolltopstyle
*
*/
var ScrollTopClasses;
(function (ScrollTopClasses) {
/**
* Class name of the root element
*/
ScrollTopClasses["root"] = "p-scrolltop";
/**
* Class name of the icon element
*/
ScrollTopClasses["icon"] = "p-scrolltop-icon";
})(ScrollTopClasses || (ScrollTopClasses = {}));
const SCROLLTOP_INSTANCE = new InjectionToken('SCROLLTOP_INSTANCE');
/**
* ScrollTop gets displayed after a certain scroll position and used to navigates to the top of the page quickly.
* @group Components
*/
class ScrollTop extends BaseComponent {
componentName = 'ScrollTop';
$pcScrollTop = inject(SCROLLTOP_INSTANCE, { optional: true, skipSelf: true }) ?? undefined;
bindDirectiveInstance = inject(Bind, { self: true });
/**
* Class of the element.
* @group Props
*/
styleClass = input(/* @ts-ignore */
...(ngDevMode ? [undefined, { debugName: "styleClass" }] : /* istanbul ignore next */ []));
/**
* Inline style of the element.
* @group Props
*/
style = input(/* @ts-ignore */
...(ngDevMode ? [undefined, { debugName: "style" }] : /* istanbul ignore next */ []));
/**
* Target of the ScrollTop.
* @group Props
*/
target = input('window', /* @ts-ignore */
...(ngDevMode ? [{ debugName: "target" }] : /* istanbul ignore next */ []));
/**
* Defines the threshold value of the vertical scroll position of the target to toggle the visibility.
* @group Props
*/
threshold = input(400, { ...(ngDevMode ? { debugName: "threshold" } : /* istanbul ignore next */ {}), transform: numberAttribute });
/**
* Name of the icon or JSX.Element for icon.
* @group Props
*/
_icon = input(undefined, { ...(ngDevMode ? { debugName: "_icon" } : /* istanbul ignore next */ {}), alias: 'icon' });
/**
* Defines the scrolling behavior, "smooth" adds an animation and "auto" scrolls with a jump.
* @group Props
*/
behavior = input('smooth', /* @ts-ignore */
...(ngDevMode ? [{ debugName: "behavior" }] : /* istanbul ignore next */ []));
/**
* The motion options.
* @group Props
*/
motionOptions = input(/* @ts-ignore */
...(ngDevMode ? [undefined, { debugName: "motionOptions" }] : /* istanbul ignore next */ []));
/**
* Establishes a string value that labels the scroll-top button.
* @group Props
*/
buttonAriaLabel = input(/* @ts-ignore */
...(ngDevMode ? [undefined, { debugName: "buttonAriaLabel" }] : /* istanbul ignore next */ []));
/**
* Configuration object forwarded to the underlying button.
* @group Props
*/
buttonProps = input({ rounded: true }, /* @ts-ignore */
...(ngDevMode ? [{ debugName: "buttonProps" }] : /* istanbul ignore next */ []));
/**
* Custom icon template.
* @param {ScrollTopIconTemplateContext} context - icon context.
* @see {@link ScrollTopIconTemplateContext}
* @group Templates
*/
iconTemplate = contentChild('icon', { ...(ngDevMode ? { debugName: "iconTemplate" } : /* istanbul ignore next */ {}), descendants: false });
computedMotionOptions = computed(() => {
return {
...this.ptm('motion'),
...this.motionOptions()
};
}, /* @ts-ignore */
...(ngDevMode ? [{ debugName: "computedMotionOptions" }] : /* istanbul ignore next */ []));
getIconTemplateContext() {
return { styleClass: this.cx('icon') };
}
documentScrollListener;
parentScrollListener;
visible = signal(false, /* @ts-ignore */
...(ngDevMode ? [{ debugName: "visible" }] : /* istanbul ignore next */ []));
render = signal(false, /* @ts-ignore */
...(ngDevMode ? [{ debugName: "render" }] : /* istanbul ignore next */ []));
overlay = null;
_componentStyle = inject(ScrollTopStyle);
constructor() {
super();
const ref = afterEveryRender(() => {
if (this.target() !== 'parent' || this.parentScrollListener) {
ref.destroy();
return;
}
if (this.el.nativeElement.parentElement) {
this.bindParentScrollListener();
ref.destroy();
}
});
}
onAfterViewChecked() {
this.bindDirectiveInstance.setAttrs(this.ptms(['host', 'root']));
}
onInit() {
if (this.target() === 'window')
this.bindDocumentScrollListener();
else if (this.target() === 'parent')
this.bindParentScrollListener();
}
onClick() {
const scrollElement = this.target() === 'window' ? this.document.defaultView : this.el.nativeElement.parentElement;
scrollElement?.scroll({
top: 0,
behavior: this.behavior()
});
}
onBeforeEnter(event) {
this.overlay = event.element;
this.overlay.style.position = this.target() === 'parent' ? 'sticky' : 'fixed';
ZIndexUtils.set('overlay', this.overlay, this.config.zIndex.overlay);
}
onBeforeLeave() {
ZIndexUtils.clear(this.overlay);
this.overlay = null;
}
onAfterLeave() {
this.render.set(false);
}
checkVisibility(scrollY) {
if (scrollY > this.threshold()) {
this.visible.set(true);
if (!this.render()) {
this.render.set(true);
}
}
else {
this.visible.set(false);
}
}
bindParentScrollListener() {
if (!isPlatformBrowser(this.platformId))
return;
if (this.parentScrollListener)
return;
const parent = this.el.nativeElement.parentElement;
if (!parent)
return;
this.parentScrollListener = this.renderer.listen(parent, 'scroll', () => {
this.checkVisibility(parent.scrollTop);
});
}
bindDocumentScrollListener() {
if (isPlatformBrowser(this.platformId)) {
this.documentScrollListener = this.renderer.listen(this.document.defaultView, 'scroll', () => {
this.checkVisibility(getWindowScrollTop());
});
}
}
unbindParentScrollListener() {
if (this.parentScrollListener) {
this.parentScrollListener();
this.parentScrollListener = null;
}
}
unbindDocumentScrollListener() {
if (this.documentScrollListener) {
this.documentScrollListener();
this.documentScrollListener = null;
}
}
onDestroy() {
if (this.target() === 'window')
this.unbindDocumentScrollListener();
else if (this.target() === 'parent')
this.unbindParentScrollListener();
if (this.overlay) {
ZIndexUtils.clear(this.overlay);
this.overlay = null;
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ScrollTop, deps: [], target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: ScrollTop, isStandalone: true, selector: "p-scrolltop, p-scroll-top", inputs: { styleClass: { classPropertyName: "styleClass", publicName: "styleClass", isSignal: true, isRequired: false, transformFunction: null }, style: { classPropertyName: "style", publicName: "style", isSignal: true, isRequired: false, transformFunction: null }, target: { classPropertyName: "target", publicName: "target", isSignal: true, isRequired: false, transformFunction: null }, threshold: { classPropertyName: "threshold", publicName: "threshold", isSignal: true, isRequired: false, transformFunction: null }, _icon: { classPropertyName: "_icon", publicName: "icon", isSignal: true, isRequired: false, transformFunction: null }, behavior: { classPropertyName: "behavior", publicName: "behavior", isSignal: true, isRequired: false, transformFunction: null }, motionOptions: { classPropertyName: "motionOptions", publicName: "motionOptions", isSignal: true, isRequired: false, transformFunction: null }, buttonAriaLabel: { classPropertyName: "buttonAriaLabel", publicName: "buttonAriaLabel", isSignal: true, isRequired: false, transformFunction: null }, buttonProps: { classPropertyName: "buttonProps", publicName: "buttonProps", isSignal: true, isRequired: false, transformFunction: null } }, providers: [ScrollTopStyle, { provide: SCROLLTOP_INSTANCE, useExisting: ScrollTop }, { provide: PARENT_INSTANCE, useExisting: ScrollTop }], queries: [{ propertyName: "iconTemplate", first: true, predicate: ["icon"], isSignal: true }], usesInheritance: true, hostDirectives: [{ directive: i1.Bind }], ngImport: i0, template: `
(render()) {
<button
type="button"
iconOnly
[pButton]="buttonProps()"
[pMotion]="visible()"
[pMotionAppear]="true"
[pMotionName]="'p-scrolltop'"
[pMotionOptions]="computedMotionOptions()"
[class]="cn(cx('root'), styleClass())"
[style]="style()"
[attr.aria-label]="buttonAriaLabel()"
[pButtonPT]="ptm('pcButton')"
[pButtonUnstyled]="unstyled()"
(pMotionOnBeforeEnter)="onBeforeEnter($event)"
(pMotionOnBeforeLeave)="onBeforeLeave()"
(pMotionOnAfterLeave)="onAfterLeave()"
(click)="onClick()"
>
(iconTemplate()) {
<ng-container [ngTemplateOutlet]="iconTemplate()!" [ngTemplateOutletContext]="getIconTemplateContext()"></ng-container>
} if (_icon()) {
<span [class]="cn(cx('icon'), _icon())"></span>
} {
<svg data-p-icon="chevron-up" [class]="cx('icon')" />
}
</button>
}
`, isInline: true, dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: ChevronUp, selector: "svg[data-p-icon=\"chevron-up\"]" }, { kind: "directive", type: ButtonDirective, selector: "[pButton]", inputs: ["pButton", "pButtonPT", "pButtonUnstyled", "hostName", "text", "plain", "raised", "size", "outlined", "link", "rounded", "fluid", "variant", "iconOnly", "loading", "severity"] }, { kind: "ngmodule", type: SharedModule }, { kind: "directive", type: MotionDirective, selector: "[pMotion]", inputs: ["pMotion", "pMotionName", "pMotionType", "pMotionSafe", "pMotionDisabled", "pMotionAppear", "pMotionEnter", "pMotionLeave", "pMotionDuration", "pMotionHideStrategy", "pMotionEnterFromClass", "pMotionEnterToClass", "pMotionEnterActiveClass", "pMotionLeaveFromClass", "pMotionLeaveToClass", "pMotionLeaveActiveClass", "pMotionOptions"], outputs: ["pMotionOnBeforeEnter", "pMotionOnEnter", "pMotionOnAfterEnter", "pMotionOnEnterCancelled", "pMotionOnBeforeLeave", "pMotionOnLeave", "pMotionOnAfterLeave", "pMotionOnLeaveCancelled"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ScrollTop, decorators: [{
type: Component,
args: [{
selector: 'p-scrolltop, p-scroll-top',
standalone: true,
imports: [NgTemplateOutlet, ChevronUp, ButtonDirective, SharedModule, MotionDirective],
template: `
(render()) {
<button
type="button"
iconOnly
[pButton]="buttonProps()"
[pMotion]="visible()"
[pMotionAppear]="true"
[pMotionName]="'p-scrolltop'"
[pMotionOptions]="computedMotionOptions()"
[class]="cn(cx('root'), styleClass())"
[style]="style()"
[attr.aria-label]="buttonAriaLabel()"
[pButtonPT]="ptm('pcButton')"
[pButtonUnstyled]="unstyled()"
(pMotionOnBeforeEnter)="onBeforeEnter($event)"
(pMotionOnBeforeLeave)="onBeforeLeave()"
(pMotionOnAfterLeave)="onAfterLeave()"
(click)="onClick()"
>
(iconTemplate()) {
<ng-container [ngTemplateOutlet]="iconTemplate()!" [ngTemplateOutletContext]="getIconTemplateContext()"></ng-container>
} if (_icon()) {
<span [class]="cn(cx('icon'), _icon())"></span>
} {
<svg data-p-icon="chevron-up" [class]="cx('icon')" />
}
</button>
}
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
providers: [ScrollTopStyle, { provide: SCROLLTOP_INSTANCE, useExisting: ScrollTop }, { provide: PARENT_INSTANCE, useExisting: ScrollTop }],
hostDirectives: [Bind]
}]
}], ctorParameters: () => [], propDecorators: { styleClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "styleClass", required: false }] }], style: [{ type: i0.Input, args: [{ isSignal: true, alias: "style", required: false }] }], target: [{ type: i0.Input, args: [{ isSignal: true, alias: "target", required: false }] }], threshold: [{ type: i0.Input, args: [{ isSignal: true, alias: "threshold", required: false }] }], _icon: [{ type: i0.Input, args: [{ isSignal: true, alias: "icon", required: false }] }], behavior: [{ type: i0.Input, args: [{ isSignal: true, alias: "behavior", required: false }] }], motionOptions: [{ type: i0.Input, args: [{ isSignal: true, alias: "motionOptions", required: false }] }], buttonAriaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "buttonAriaLabel", required: false }] }], buttonProps: [{ type: i0.Input, args: [{ isSignal: true, alias: "buttonProps", required: false }] }], iconTemplate: [{ type: i0.ContentChild, args: ['icon', { ...{ descendants: false }, isSignal: true }] }] } });
class ScrollTopModule {
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ScrollTopModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.0.6", ngImport: i0, type: ScrollTopModule, imports: [ScrollTop, SharedModule], exports: [ScrollTop, SharedModule] });
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ScrollTopModule, imports: [ScrollTop, SharedModule, SharedModule] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ScrollTopModule, decorators: [{
type: NgModule,
args: [{
imports: [ScrollTop, SharedModule],
exports: [ScrollTop, SharedModule]
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { ScrollTop, ScrollTopClasses, ScrollTopModule, ScrollTopStyle };
//# sourceMappingURL=primeng-scrolltop.mjs.map