UNPKG

react-flyup-button

Version:

React component to scroll to the top of the page

23 lines (22 loc) 7.35 kB
"use strict";const j=require("react");var g={exports:{}},T={};/** * @license React * react-jsx-runtime.production.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var z;function te(){if(z)return T;z=1;var c=Symbol.for("react.transitional.element"),u=Symbol.for("react.fragment");function f(d,a,s){var m=null;if(s!==void 0&&(m=""+s),a.key!==void 0&&(m=""+a.key),"key"in a){s={};for(var E in a)E!=="key"&&(s[E]=a[E])}else s=a;return a=s.ref,{$$typeof:c,type:d,key:m,ref:a!==void 0?a:null,props:s}}return T.Fragment=u,T.jsx=f,T.jsxs=f,T}var p={};/** * @license React * react-jsx-runtime.development.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var J;function ne(){return J||(J=1,process.env.NODE_ENV!=="production"&&function(){function c(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===K?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case R:return"Fragment";case P:return"Profiler";case x:return"StrictMode";case B:return"Suspense";case H:return"SuspenseList";case Q:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case S:return"Portal";case G:return(e.displayName||"Context")+".Provider";case O:return(e._context.displayName||"Context")+".Consumer";case X:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Z:return r=e.displayName||null,r!==null?r:c(e.type)||"Memo";case F:r=e._payload,e=e._init;try{return c(e(r))}catch{}}return null}function u(e){return""+e}function f(e){try{u(e);var r=!1}catch{r=!0}if(r){r=console;var t=r.error,n=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",n),u(e)}}function d(e){if(e===R)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===F)return"<...>";try{var r=c(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function a(){var e=y.A;return e===null?null:e.getOwner()}function s(){return Error("react-stack-top-frame")}function m(e){if(D.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function E(e,r){function t(){L||(L=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}function A(){var e=c(this.type);return M[e]||(M[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function h(e,r,t,n,i,l,C,Y){return t=l.ref,e={$$typeof:w,type:e,key:r,props:l,_owner:i},(t!==void 0?t:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:A}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:C}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:Y}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function k(e,r,t,n,i,l,C,Y){var o=r.children;if(o!==void 0)if(n)if(ee(o)){for(n=0;n<o.length;n++)_(o[n]);Object.freeze&&Object.freeze(o)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else _(o);if(D.call(r,"key")){o=c(e);var v=Object.keys(r).filter(function(re){return re!=="key"});n=0<v.length?"{key: someKey, "+v.join(": ..., ")+": ...}":"{key: someKey}",q[o+n]||(v=0<v.length?"{"+v.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`,n,o,v,o),q[o+n]=!0)}if(o=null,t!==void 0&&(f(t),o=""+t),m(r)&&(f(r.key),o=""+r.key),"key"in r){t={};for(var I in r)I!=="key"&&(t[I]=r[I])}else t=r;return o&&E(t,typeof e=="function"?e.displayName||e.name||"Unknown":e),h(e,o,l,i,a(),t,C,Y)}function _(e){typeof e=="object"&&e!==null&&e.$$typeof===w&&e._store&&(e._store.validated=1)}var b=j,w=Symbol.for("react.transitional.element"),S=Symbol.for("react.portal"),R=Symbol.for("react.fragment"),x=Symbol.for("react.strict_mode"),P=Symbol.for("react.profiler"),O=Symbol.for("react.consumer"),G=Symbol.for("react.context"),X=Symbol.for("react.forward_ref"),B=Symbol.for("react.suspense"),H=Symbol.for("react.suspense_list"),Z=Symbol.for("react.memo"),F=Symbol.for("react.lazy"),Q=Symbol.for("react.activity"),K=Symbol.for("react.client.reference"),y=b.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,D=Object.prototype.hasOwnProperty,ee=Array.isArray,N=console.createTask?console.createTask:function(){return null};b={"react-stack-bottom-frame":function(e){return e()}};var L,M={},W=b["react-stack-bottom-frame"].bind(b,s)(),U=N(d(s)),q={};p.Fragment=R,p.jsx=function(e,r,t,n,i){var l=1e4>y.recentlyCreatedOwnerStacks++;return k(e,r,t,!1,n,i,l?Error("react-stack-top-frame"):W,l?N(d(e)):U)},p.jsxs=function(e,r,t,n,i){var l=1e4>y.recentlyCreatedOwnerStacks++;return k(e,r,t,!0,n,i,l?Error("react-stack-top-frame"):W,l?N(d(e)):U)}}()),p}var V;function oe(){return V||(V=1,process.env.NODE_ENV==="production"?g.exports=te():g.exports=ne()),g.exports}var $=oe();function ae({className:c="",position:u="right",bottom:f=20,left:d=20,width:a=50,height:s=50,borderRadius:m=50,backgroundColor:E="#fff",borderColor:A="#fff",borderWidth:h=3,cursor:k="pointer",displayAt:_=0,animationDuration:b=.5,smoothScroll:w=!0,children:S}){const[R,x]=j.useState(!1),P={position:"fixed",bottom:f,left:u==="left"?d:u==="center"?"50%":void 0,right:u==="right"?20:void 0,transform:u==="center"?"translateX(-50%)":void 0,width:a,height:s,borderRadius:`${m}%`,backgroundColor:E,borderColor:A,borderWidth:h,borderStyle:"solid",cursor:k,zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",scale:R?1:0,opacity:R?1:0,transition:`all ${b}s ease`};return j.useEffect(()=>{function O(){window.scrollY>_?x(!0):x(!1)}return window.addEventListener("scroll",O),()=>{window.removeEventListener("scroll",O)}},[_]),$.jsx("button",{className:c,style:P,onClick:()=>{window.scrollTo({top:0,behavior:w?"smooth":"auto"})},children:S?$.jsx("span",{style:{color:"#000"},children:S}):$.jsx("img",{src:"https://img.icons8.com/ios/25/collapse-arrow.png",alt:"collapse-arrow"})})}const se=j.memo(ae);module.exports=se;