UNPKG

primevue

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primevue.svg)](https://badge.fury.io/js/primevue) [![Discord Chat](https://img.shields.io/discord/55794023

2 lines (1 loc) 3.74 kB
"use strict";var e=require("primevue/icons/chevronup"),n=require("primevue/utils"),t=require("primevue/basecomponent"),o=require("primevue/usestyle"),i=require("vue");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=r(e),s=r(t),c=o.useStyle("\n.p-scrolltop {\n position: fixed;\n bottom: 20px;\n right: 20px;\n display: flex;\n align-items: center;\n justify-content: center;\n}\n\n.p-scrolltop-sticky {\n position: sticky;\n}\n\n.p-scrolltop-sticky.p-link {\n margin-left: auto;\n}\n\n.p-scrolltop-enter-from {\n opacity: 0;\n}\n\n.p-scrolltop-enter-active {\n transition: opacity 0.15s;\n}\n\n.p-scrolltop.p-scrolltop-leave-to {\n opacity: 0;\n}\n\n.p-scrolltop-leave-active {\n transition: opacity 0.15s;\n}\n",{name:"scrolltop",manual:!0}),a={name:"ScrollTop",extends:{name:"BaseScrollTop",extends:s.default,props:{target:{type:String,default:"window"},threshold:{type:Number,default:400},icon:{type:String,default:void 0},behavior:{type:String,default:"smooth"}},css:{classes:{root:function(e){return["p-scrolltop p-link p-component",{"p-scrolltop-sticky":"window"!==e.props.target}]},icon:"p-scrolltop-icon"},loadStyle:c.load},provide:function(){return{$parentInstance:this}}},scrollListener:null,container:null,data:function(){return{visible:!1}},mounted:function(){"window"===this.target?this.bindDocumentScrollListener():"parent"===this.target&&this.bindParentScrollListener()},beforeUnmount:function(){"window"===this.target?this.unbindDocumentScrollListener():"parent"===this.target&&this.unbindParentScrollListener(),this.container&&(n.ZIndexUtils.clear(this.container),this.overlay=null)},methods:{onClick:function(){("window"===this.target?window:this.$el.parentElement).scroll({top:0,behavior:this.behavior})},checkVisibility:function(e){this.visible=e>this.threshold},bindParentScrollListener:function(){var e=this;this.scrollListener=function(){e.checkVisibility(e.$el.parentElement.scrollTop)},this.$el.parentElement.addEventListener("scroll",this.scrollListener)},bindDocumentScrollListener:function(){var e=this;this.scrollListener=function(){e.checkVisibility(n.DomHandler.getWindowScrollTop())},window.addEventListener("scroll",this.scrollListener)},unbindParentScrollListener:function(){this.scrollListener&&(this.$el.parentElement.removeEventListener("scroll",this.scrollListener),this.scrollListener=null)},unbindDocumentScrollListener:function(){this.scrollListener&&(window.removeEventListener("scroll",this.scrollListener),this.scrollListener=null)},onEnter:function(e){n.ZIndexUtils.set("overlay",e,this.$primevue.config.zIndex.overlay)},onAfterLeave:function(e){n.ZIndexUtils.clear(e)},containerRef:function(e){this.container=e}},computed:{scrollTopAriaLabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.scrollTop:void 0}},components:{ChevronUpIcon:l.default}},p=["aria-label"];a.render=function(e,n,t,o,r,l){return i.openBlock(),i.createBlock(i.Transition,{name:"p-scrolltop",appear:"",onEnter:l.onEnter,onAfterLeave:l.onAfterLeave},{default:i.withCtx((function(){return[r.visible?(i.openBlock(),i.createElementBlock("button",i.mergeProps({key:0,ref:l.containerRef,class:e.cx("root"),onClick:n[0]||(n[0]=function(){return l.onClick&&l.onClick.apply(l,arguments)}),type:"button","aria-label":l.scrollTopAriaLabel},e.ptm("root"),{"data-pc-name":"scrolltop"}),[i.renderSlot(e.$slots,"icon",{class:i.normalizeClass(e.cx("icon"))},(function(){return[(i.openBlock(),i.createBlock(i.resolveDynamicComponent(e.icon?"span":"ChevronUpIcon"),i.mergeProps({class:[e.cx("icon"),e.icon]},e.ptm("icon")),null,16,["class"]))]}))],16,p)):i.createCommentVNode("",!0)]})),_:3},8,["onEnter","onAfterLeave"])},module.exports=a;