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.63 kB
import n from"primevue/icons/chevronup";import{ZIndexUtils as t,DomHandler as e}from"primevue/utils";import o from"primevue/basecomponent";import{useStyle as i}from"primevue/usestyle";import{openBlock as r,createBlock as l,Transition as s,withCtx as c,createElementBlock as a,mergeProps as p,renderSlot as u,normalizeClass as h,resolveDynamicComponent as f,createCommentVNode as m}from"vue";var d=i("\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}),v={name:"ScrollTop",extends:{name:"BaseScrollTop",extends:o,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(n){return["p-scrolltop p-link p-component",{"p-scrolltop-sticky":"window"!==n.props.target}]},icon:"p-scrolltop-icon"},loadStyle:d.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&&(t.clear(this.container),this.overlay=null)},methods:{onClick:function(){("window"===this.target?window:this.$el.parentElement).scroll({top:0,behavior:this.behavior})},checkVisibility:function(n){this.visible=n>this.threshold},bindParentScrollListener:function(){var n=this;this.scrollListener=function(){n.checkVisibility(n.$el.parentElement.scrollTop)},this.$el.parentElement.addEventListener("scroll",this.scrollListener)},bindDocumentScrollListener:function(){var n=this;this.scrollListener=function(){n.checkVisibility(e.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(n){t.set("overlay",n,this.$primevue.config.zIndex.overlay)},onAfterLeave:function(n){t.clear(n)},containerRef:function(n){this.container=n}},computed:{scrollTopAriaLabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.scrollTop:void 0}},components:{ChevronUpIcon:n}},L=["aria-label"];v.render=function(n,t,e,o,i,d){return r(),l(s,{name:"p-scrolltop",appear:"",onEnter:d.onEnter,onAfterLeave:d.onAfterLeave},{default:c((function(){return[i.visible?(r(),a("button",p({key:0,ref:d.containerRef,class:n.cx("root"),onClick:t[0]||(t[0]=function(){return d.onClick&&d.onClick.apply(d,arguments)}),type:"button","aria-label":d.scrollTopAriaLabel},n.ptm("root"),{"data-pc-name":"scrolltop"}),[u(n.$slots,"icon",{class:h(n.cx("icon"))},(function(){return[(r(),l(f(n.icon?"span":"ChevronUpIcon"),p({class:[n.cx("icon"),n.icon]},n.ptm("icon")),null,16,["class"]))]}))],16,L)):m("",!0)]})),_:3},8,["onEnter","onAfterLeave"])};export{v as default};