UNPKG

primereact

Version:

PrimeReact is an open source UI library for React 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 Prime

2 lines (1 loc) 6.92 kB
import*as e from"react";import{Button as t}from"primereact/button";import{useEventListener as n,useMountEffect as r,useUpdateEffect as i}from"primereact/hooks";import{Ripple as l}from"primereact/ripple";import{DomHandler as a,ObjectUtils as o,classNames as c,IconUtils as s}from"primereact/utils";function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u.apply(this,arguments)}function p(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function f(e){if(Array.isArray(e))return e}function d(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,i,l=[],a=!0,o=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(l.push(r.value),!t||l.length!==t);a=!0);}catch(e){o=!0,i=e}finally{try{a||null==n.return||n.return()}finally{if(o)throw i}}return l}}function m(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function b(e,t){if(e){if("string"==typeof e)return m(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?m(e,t):void 0}}function h(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function y(e,t){return f(e)||d(e,t)||b(e,t)||h()}function v(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function g(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?v(Object(n),!0).forEach((function(t){p(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):v(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var O=e.memo(e.forwardRef((function(f,d){var m,b=y(e.useState(!1),2),h=b[0],v=b[1],w=e.useRef(!1),S=e.useRef(null),C=e.useRef(null),k=f.onVisibleChange?f.visible:h,I=y(n({type:"click",listener:function(e){!w.current&&D(e)&&P(),w.current=!1},when:h}),2),x=I[0],N=I[1],j=function(){f.onVisibleChange?f.onVisibleChange(!0):v(!0),f.onShow&&f.onShow()},P=function(){f.onVisibleChange?f.onVisibleChange(!1):v(!1),f.onHide&&f.onHide()},E=function(e){k?P():j(),f.onClick&&f.onClick(e),w.current=!0},M=function(e,t){t.command&&t.command({originalEvent:e,item:t}),P(),w.current=!0,e.preventDefault()},D=function(e){return S.current&&!(S.current.isSameNode(e.target)||S.current.contains(e.target))},A=function(e){return(k?e:f.model.length-e-1)*f.transitionDelay},H=function(e){var t=f.type;if("linear"!==t){var n=f.model.length,r=f.radius||20*n;if("circle"===t){var i=2*Math.PI/n;return{left:"calc(".concat(r*Math.cos(i*e),"px + var(--item-diff-x, 0px))"),top:"calc(".concat(r*Math.sin(i*e),"px + var(--item-diff-y, 0px))")}}if("semi-circle"===t){var l=f.direction,a=Math.PI/(n-1),o="calc(".concat(r*Math.cos(a*e),"px + var(--item-diff-x, 0px))"),c="calc(".concat(r*Math.sin(a*e),"px + var(--item-diff-y, 0px))");if("up"===l)return{left:o,bottom:c};if("down"===l)return{left:o,top:c};if("left"===l)return{right:c,top:o};if("right"===l)return{left:c,top:o}}else if("quarter-circle"===t){var s=f.direction,u=Math.PI/(2*(n-1)),p="calc(".concat(r*Math.cos(u*e),"px + var(--item-diff-x, 0px))"),d="calc(".concat(r*Math.sin(u*e),"px + var(--item-diff-y, 0px))");if("up-left"===s)return{right:p,bottom:d};if("up-right"===s)return{left:p,bottom:d};if("down-left"===s)return{right:d,top:p};if("down-right"===s)return{left:d,top:p}}}return{}},V=function(e){var t=A(e),n=H(e);return g({transitionDelay:"".concat(t,"ms")},n)};r((function(){if("linear"!==f.type){var e=a.findSingle(S.current,".p-speeddial-button"),t=a.findSingle(C.current,".p-speeddial-item");if(e&&t){var n=Math.abs(e.offsetWidth-t.offsetWidth),r=Math.abs(e.offsetHeight-t.offsetHeight);C.current.style.setProperty("--item-diff-x","".concat(n/2,"px")),C.current.style.setProperty("--item-diff-y","".concat(r/2,"px"))}}})),i((function(){return h&&f.hideOnClickOutside&&x(),function(){f.hideOnClickOutside&&N()}}),[h]),e.useImperativeHandle(d,(function(){return{props:f,show:j,hide:P,getElement:function(){return S.current}}}));var T,J=function(t,n){if(!1===t.visible)return null;var r=V(n),i=t.icon,a=t.label,u=t.template,p=t.url,d=t.target,m=c("p-speeddial-action",{"p-disabled":t.disabled}),b=c("p-speeddial-action-icon",i),h=s.getJSXIcon(i,{className:"p-speeddial-action-icon"},{props:f}),y=e.createElement("a",{href:p||"#",role:"menuitem",className:m,target:d,"data-pr-tooltip":a,onClick:function(e){return M(e,t)}},h,e.createElement(l,null));u&&(y=o.getJSXElement(u,t,{onClick:function(e){return M(e,t)},className:m,iconClassName:b,element:y,props:f,visible:k}));return e.createElement("li",{key:n,className:"p-speeddial-item",style:r,role:"none"},y)},R=o.findDiffKeys(f,O.defaultProps),X=c("p-speeddial p-component p-speeddial-".concat(f.type),(p(m={},"p-speeddial-direction-".concat(f.direction),"circle"!==f.type),p(m,"p-speeddial-opened",k),p(m,"p-disabled",f.disabled),m),f.className),W=function(){var n,r=!k&&!!f.showIcon||!f.hideIcon,i=k&&!!f.hideIcon,l=c("p-speeddial-button p-button-rounded",{"p-speeddial-rotate":f.rotateAnimation&&!f.hideIcon},f.buttonClassName),a=c((p(n={},"".concat(f.showIcon),!k&&!!f.showIcon||!f.hideIcon),p(n,"".concat(f.hideIcon),k&&!!f.hideIcon),n)),u=s.getJSXIcon(r?f.showIcon:i?f.hideIcon:null,void 0,{props:f}),d=e.createElement(t,{type:"button",style:f.buttonStyle,className:l,icon:u,onClick:E,disabled:f.disabled,"aria-label":f["aria-label"]});return f.buttonTemplate?o.getJSXElement(f.buttonTemplate,{onClick:E,className:l,iconClassName:a,element:d,props:f,visible:k}):d}(),_=(T=f.model?f.model.map(J):null,e.createElement("ul",{ref:C,className:"p-speeddial-list",role:"menu"},T)),q=function(){if(f.mask){var t=c("p-speeddial-mask",{"p-speeddial-mask-visible":k},f.maskClassName);return e.createElement("div",{className:t,style:f.maskStyle})}return null}();return e.createElement(e.Fragment,null,e.createElement("div",u({ref:S,id:f.id,className:X,style:f.style},R),W,_),q)})));O.displayName="SpeedDial",O.defaultProps={__TYPE:"SpeedDial",id:null,model:null,visible:!1,style:null,className:null,direction:"up",transitionDelay:30,type:"linear",radius:0,mask:!1,disabled:!1,hideOnClickOutside:!0,buttonStyle:null,buttonClassName:null,buttonTemplate:null,"aria-label":null,maskStyle:null,maskClassName:null,showIcon:"pi pi-plus",hideIcon:null,rotateAnimation:!0,onVisibleChange:null,onClick:null,onShow:null,onHide:null};export{O as SpeedDial};