primevue
Version:
PrimeVue is an open source UI library for Vue 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 PrimeBloc
2 lines (1 loc) • 3.08 kB
JavaScript
"use strict";var e=require("primevue/icons/chevronup"),t=require("primevue/utils"),n=require("primevue/basecomponent"),r=require("primevue/scrolltop/style"),i=require("vue");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=o(e),s={name:"ScrollTop",extends:{name:"BaseScrollTop",extends:o(n).default,props:{target:{type:String,default:"window"},threshold:{type:Number,default:400},icon:{type:String,default:void 0},behavior:{type:String,default:"smooth"}},style:o(r).default,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&&(t.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(t.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){t.ZIndexUtils.set("overlay",e,this.$primevue.config.zIndex.overlay)},onAfterLeave:function(e){t.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}},c=["aria-label"];s.render=function(e,t,n,r,o,l){return i.openBlock(),i.createBlock(i.Transition,i.mergeProps({name:"p-scrolltop",appear:"",onEnter:l.onEnter,onAfterLeave:l.onAfterLeave},e.ptm("transition")),{default:i.withCtx((function(){return[o.visible?(i.openBlock(),i.createElementBlock("button",i.mergeProps({key:0,ref:l.containerRef,class:e.cx("root"),onClick:t[0]||(t[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,c)):i.createCommentVNode("",!0)]})),_:3},16,["onEnter","onAfterLeave"])},module.exports=s;