primevue
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primevue) [ • 16.5 kB
JavaScript
import t from"primevue/button";import e from"primevue/icons/plus";import n from"primevue/ripple";import i from"primevue/tooltip";import{UniqueComponentId as o,DomHandler as r}from"primevue/utils";import s from"primevue/basecomponent";import{useStyle as a}from"primevue/usestyle";import{resolveComponent as c,resolveDirective as l,openBlock as u,createElementBlock as d,Fragment as p,createElementVNode as f,mergeProps as m,renderSlot as h,createVNode as b,normalizeClass as y,withCtx as v,createBlock as g,resolveDynamicComponent as w,renderList as I,withDirectives as x,createCommentVNode as k}from"vue";function O(t){return O="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},O(t)}function S(t,e,n){return(e=C(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function C(t){var e=P(t,"string");return"symbol"===O(e)?e:String(e)}function P(t,e){if("object"!==O(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!==O(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}var A={root:function(t){var e,n=t.instance,i=t.props;return["p-speeddial p-component p-speeddial-".concat(i.type),(e={},S(e,"p-speeddial-direction-".concat(i.direction),"circle"!==i.type),S(e,"p-speeddial-opened",n.d_visible),S(e,"p-disabled",i.disabled),e)]},button:function(t){var e=t.props;return["p-speeddial-button p-button-rounded",{"p-speeddial-rotate":e.rotateAnimation&&!e.hideIcon}]},menu:"p-speeddial-list",menuitem:function(t){return["p-speeddial-item",{"p-focus":t.instance.isItemActive(t.id)}]},action:function(t){return["p-speeddial-action",{"p-disabled":t.item.disabled}]},actionIcon:"p-speeddial-action-icon",mask:function(t){return["p-speeddial-mask",{"p-speeddial-mask-visible":t.instance.d_visible}]}},D=a("\n.p-speeddial {\n position: absolute;\n display: flex;\n}\n\n.p-speeddial-button {\n z-index: 1;\n}\n\n.p-speeddial-list {\n margin: 0;\n padding: 0;\n list-style: none;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: top 0s linear 0.2s;\n pointer-events: none;\n z-index: 2;\n}\n\n.p-speeddial-item {\n transform: scale(0);\n opacity: 0;\n transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, opacity 0.8s;\n will-change: transform;\n}\n\n.p-speeddial-action {\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 50%;\n position: relative;\n overflow: hidden;\n}\n\n.p-speeddial-circle .p-speeddial-item,\n.p-speeddial-semi-circle .p-speeddial-item,\n.p-speeddial-quarter-circle .p-speeddial-item {\n position: absolute;\n}\n\n.p-speeddial-rotate {\n transition: transform 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;\n will-change: transform;\n}\n\n.p-speeddial-mask {\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n opacity: 0;\n transition: opacity 250ms cubic-bezier(0.25, 0.8, 0.25, 1);\n}\n\n.p-speeddial-mask-visible {\n pointer-events: none;\n opacity: 1;\n transition: opacity 400ms cubic-bezier(0.25, 0.8, 0.25, 1);\n}\n\n.p-speeddial-opened .p-speeddial-list {\n pointer-events: auto;\n}\n\n.p-speeddial-opened .p-speeddial-item {\n transform: scale(1);\n opacity: 1;\n}\n\n.p-speeddial-opened .p-speeddial-rotate {\n transform: rotate(45deg);\n}\n",{name:"speeddial",manual:!0});function j(t){return j="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},j(t)}function _(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function E(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?_(Object(n),!0).forEach((function(e){L(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):_(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function L(t,e,n){return(e=K(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function K(t){var e=N(t,"string");return"symbol"===j(e)?e:String(e)}function N(t,e){if("object"!==j(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!==j(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}function T(t){return R(t)||$(t)||M(t)||B()}function B(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function M(t,e){if(t){if("string"==typeof t)return F(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?F(t,e):void 0}}function $(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function R(t){if(Array.isArray(t))return F(t)}function F(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}var U={name:"SpeedDial",extends:{name:"BaseSpeedDial",extends:s,props:{model:null,visible:{type:Boolean,default:!1},direction:{type:String,default:"up"},transitionDelay:{type:Number,default:30},type:{type:String,default:"linear"},radius:{type:Number,default:0},mask:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},hideOnClickOutside:{type:Boolean,default:!0},buttonClass:null,maskStyle:null,maskClass:null,showIcon:{type:String,default:void 0},hideIcon:{type:String,default:void 0},rotateAnimation:{type:Boolean,default:!0},tooltipOptions:null,style:null,class:null,"aria-labelledby":{type:String,default:null},"aria-label":{type:String,default:null}},css:{classes:A,inlineStyles:{root:function(t){var e=t.props;return{alignItems:"up"===e.direction||"down"===e.direction?"center":"",justifyContent:"left"===e.direction||"right"===e.direction?"center":"",flexDirection:"up"===e.direction?"column-reverse":"down"===e.direction?"column":"left"===e.direction?"row-reverse":"right"===e.direction?"row":null}},menu:function(t){var e=t.props;return{flexDirection:"up"===e.direction?"column-reverse":"down"===e.direction?"column":"left"===e.direction?"row-reverse":"right"===e.direction?"row":null}}},loadStyle:D.load},provide:function(){return{$parentInstance:this}}},emits:["click","show","hide","focus","blur"],documentClickListener:null,container:null,list:null,data:function(){return{id:this.$attrs.id,d_visible:this.visible,isItemClicked:!1,focused:!1,focusedOptionIndex:-1}},watch:{"$attrs.id":function(t){this.id=t||o()},visible:function(t){this.d_visible=t}},mounted:function(){if(this.id=this.id||o(),"linear"!==this.type){var t=r.findSingle(this.container,'[data-pc-section="button"]'),e=r.findSingle(this.list,'[data-pc-section="menuitem"]');if(t&&e){var n=Math.abs(t.offsetWidth-e.offsetWidth),i=Math.abs(t.offsetHeight-e.offsetHeight);this.list.style.setProperty("--item-diff-x","".concat(n/2,"px")),this.list.style.setProperty("--item-diff-y","".concat(i/2,"px"))}}this.hideOnClickOutside&&this.bindDocumentClickListener()},beforeMount:function(){this.unbindDocumentClickListener()},methods:{getPTOptions:function(t,e){return this.ptm(e,{context:{active:this.isItemActive(t),hidden:!this.d_visible}})},onFocus:function(t){this.focused=!0,this.$emit("focus",t)},onBlur:function(t){this.focused=!1,this.focusedOptionIndex=-1,this.$emit("blur",t)},onItemClick:function(t,e){e.command&&e.command({originalEvent:t,item:e}),this.hide(),this.isItemClicked=!0,t.preventDefault()},onClick:function(t){this.d_visible?this.hide():this.show(),this.isItemClicked=!0,this.$emit("click",t)},show:function(){this.d_visible=!0,this.$emit("show")},hide:function(){this.d_visible=!1,this.$emit("hide")},calculateTransitionDelay:function(t){return(this.d_visible?t:this.model.length-t-1)*this.transitionDelay},onTogglerKeydown:function(t){switch(t.code){case"ArrowDown":case"ArrowLeft":this.onTogglerArrowDown(t);break;case"ArrowUp":case"ArrowRight":this.onTogglerArrowUp(t);break;case"Escape":this.onEscapeKey()}},onKeyDown:function(t){switch(t.code){case"ArrowDown":this.onArrowDown(t);break;case"ArrowUp":this.onArrowUp(t);break;case"ArrowLeft":this.onArrowLeft(t);break;case"ArrowRight":this.onArrowRight(t);break;case"Enter":case"Space":this.onEnterKey(t);break;case"Escape":this.onEscapeKey(t);break;case"Home":this.onHomeKey(t);break;case"End":this.onEndKey(t)}},onTogglerArrowUp:function(t){this.focused=!0,r.focus(this.list),this.show(),this.navigatePrevItem(t),t.preventDefault()},onTogglerArrowDown:function(t){this.focused=!0,r.focus(this.list),this.show(),this.navigateNextItem(t),t.preventDefault()},onEnterKey:function(t){var e=this,n=T(r.find(this.container,'[data-pc-section="menuitem"]')).findIndex((function(t){return t.id===e.focusedOptionIndex}));this.onItemClick(t,this.model[n]),this.onBlur(t);var i=r.findSingle(this.container,"button");i&&r.focus(i)},onEscapeKey:function(){this.hide();var t=r.findSingle(this.container,"button");t&&r.focus(t)},onArrowUp:function(t){"up"===this.direction?this.navigateNextItem(t):"down"===this.direction?this.navigatePrevItem(t):this.navigateNextItem(t)},onArrowDown:function(t){"up"===this.direction?this.navigatePrevItem(t):"down"===this.direction?this.navigateNextItem(t):this.navigatePrevItem(t)},onArrowLeft:function(t){["left","up-right","down-left"].includes(this.direction)?this.navigateNextItem(t):(["right","up-left","down-right"].includes(this.direction),this.navigatePrevItem(t))},onArrowRight:function(t){["left","up-right","down-left"].includes(this.direction)?this.navigatePrevItem(t):(["right","up-left","down-right"].includes(this.direction),this.navigateNextItem(t))},onEndKey:function(t){t.preventDefault(),this.focusedOptionIndex=-1,this.navigatePrevItem(t)},onHomeKey:function(t){t.preventDefault(),this.focusedOptionIndex=-1,this.navigateNextItem(t)},navigateNextItem:function(t){var e=this.findNextOptionIndex(this.focusedOptionIndex);this.changeFocusedOptionIndex(e),t.preventDefault()},navigatePrevItem:function(t){var e=this.findPrevOptionIndex(this.focusedOptionIndex);this.changeFocusedOptionIndex(e),t.preventDefault()},changeFocusedOptionIndex:function(t){var e=T(r.find(this.container,'[data-pc-section="menuitem"]')).filter((function(t){return!r.hasClass(r.findSingle(t,"a"),"p-disabled")}));e[t]&&(this.focusedOptionIndex=e[t].getAttribute("id"))},findPrevOptionIndex:function(t){var e=T(r.find(this.container,'[data-pc-section="menuitem"]')).filter((function(t){return!r.hasClass(r.findSingle(t,"a"),"p-disabled")})),n=-1===t?e[e.length-1].id:t,i=e.findIndex((function(t){return t.getAttribute("id")===n}));return i=-1===t?e.length-1:i-1},findNextOptionIndex:function(t){var e=T(r.find(this.container,'[data-pc-section="menuitem"]')).filter((function(t){return!r.hasClass(r.findSingle(t,"a"),"p-disabled")})),n=-1===t?e[0].id:t,i=e.findIndex((function(t){return t.getAttribute("id")===n}));return i=-1===t?0:i+1},calculatePointStyle:function(t){var e=this.type;if("linear"!==e){var n=this.model.length,i=this.radius||20*n;if("circle"===e){var o=2*Math.PI/n;return{left:"calc(".concat(i*Math.cos(o*t),"px + var(--item-diff-x, 0px))"),top:"calc(".concat(i*Math.sin(o*t),"px + var(--item-diff-y, 0px))")}}if("semi-circle"===e){var r=this.direction,s=Math.PI/(n-1),a="calc(".concat(i*Math.cos(s*t),"px + var(--item-diff-x, 0px))"),c="calc(".concat(i*Math.sin(s*t),"px + var(--item-diff-y, 0px))");if("up"===r)return{left:a,bottom:c};if("down"===r)return{left:a,top:c};if("left"===r)return{right:c,top:a};if("right"===r)return{left:c,top:a}}else if("quarter-circle"===e){var l=this.direction,u=Math.PI/(2*(n-1)),d="calc(".concat(i*Math.cos(u*t),"px + var(--item-diff-x, 0px))"),p="calc(".concat(i*Math.sin(u*t),"px + var(--item-diff-y, 0px))");if("up-left"===l)return{right:d,bottom:p};if("up-right"===l)return{left:d,bottom:p};if("down-left"===l)return{right:p,top:d};if("down-right"===l)return{left:p,top:d}}}return{}},getItemStyle:function(t){var e=this.calculateTransitionDelay(t),n=this.calculatePointStyle(t);return E({transitionDelay:"".concat(e,"ms")},n)},bindDocumentClickListener:function(){var t=this;this.documentClickListener||(this.documentClickListener=function(e){t.d_visible&&t.isOutsideClicked(e)&&t.hide(),t.isItemClicked=!1},document.addEventListener("click",this.documentClickListener))},unbindDocumentClickListener:function(){this.documentClickListener&&(document.removeEventListener("click",this.documentClickListener),this.documentClickListener=null)},isOutsideClicked:function(t){return this.container&&!(this.container.isSameNode(t.target)||this.container.contains(t.target)||this.isItemClicked)},isItemVisible:function(t){return"function"==typeof t.visible?t.visible():!1!==t.visible},isItemActive:function(t){return t===this.focusedOptionId},containerRef:function(t){this.container=t},listRef:function(t){this.list=t}},computed:{containerClass:function(){return[this.cx("root"),this.class]},focusedOptionId:function(){return-1!==this.focusedOptionIndex?this.focusedOptionIndex:null}},components:{SDButton:t,PlusIcon:e},directives:{ripple:n,tooltip:i}},z=["id","aria-activedescendant"],H=["id","aria-controls"],q=["href","target","onClick","aria-label"];U.render=function(t,e,n,i,o,r){var s=c("SDButton"),a=l("ripple"),O=l("tooltip");return u(),d(p,null,[f("div",m({ref:r.containerRef,class:r.containerClass,style:[t.style,t.sx("root")]},t.ptm("root"),{"data-pc-name":"speeddial"}),[h(t.$slots,"button",{onClick:r.onClick},(function(){return[b(s,{type:"button",class:y([t.cx("button"),t.buttonClass]),onClick:e[0]||(e[0]=function(t){return r.onClick(t)}),disabled:t.disabled,onKeydown:r.onTogglerKeydown,"aria-expanded":o.d_visible,"aria-haspopup":!0,"aria-controls":o.id+"_list","aria-label":t.ariaLabel,"aria-labelledby":t.ariaLabelledby,pt:t.ptm("button"),unstyled:t.unstyled},{icon:v((function(){return[h(t.$slots,"icon",{visible:o.d_visible},(function(){return[o.d_visible&&t.hideIcon?(u(),g(w(t.hideIcon?"span":"PlusIcon"),m({key:0,class:t.cx("buttonIcon")},t.ptm("button").icon),null,16,["class"])):(u(),g(w(t.showIcon?"span":"PlusIcon"),m({key:1,class:o.d_visible&&t.hideIcon?t.hideIcon:t.showIcon},t.ptm("button").icon),null,16,["class"]))]}))]})),_:3},8,["class","disabled","onKeydown","aria-expanded","aria-controls","aria-label","aria-labelledby","pt","unstyled"])]})),f("ul",m({ref:r.listRef,id:o.id+"_list",class:t.cx("menu"),style:t.sx("menu"),role:"menu","aria-activedescendant":o.focused?r.focusedOptionId:void 0,tabindex:"-1",onFocus:e[1]||(e[1]=function(){return r.onFocus&&r.onFocus.apply(r,arguments)}),onBlur:e[2]||(e[2]=function(){return r.onBlur&&r.onBlur.apply(r,arguments)}),onKeydown:e[3]||(e[3]=function(){return r.onKeyDown&&r.onKeyDown.apply(r,arguments)})},t.ptm("menu")),[(u(!0),d(p,null,I(t.model,(function(e,n){return u(),d(p,{key:n},[r.isItemVisible(e)?(u(),d("li",m({key:0,id:"".concat(o.id,"_").concat(n),"aria-controls":"".concat(o.id,"_item"),class:t.cx("menuitem",{id:"".concat(o.id,"_").concat(n)}),style:r.getItemStyle(n),role:"menuitem"},r.getPTOptions("".concat(o.id,"_").concat(n),"menuitem")),[t.$slots.item?(u(),g(w(t.$slots.item),{key:1,item:e,onClick:function(t){return r.onItemClick(t,e)}},null,8,["item","onClick"])):x((u(),d("a",m({key:0,tabindex:-1,href:e.url||"#",role:"menuitem",class:t.cx("action",{item:e}),target:e.target,onClick:function(t){return r.onItemClick(t,e)},"aria-label":e.label},r.getPTOptions("".concat(o.id,"_").concat(n),"action")),[e.icon?(u(),d("span",m({key:0,class:[t.cx("actionIcon"),e.icon]},r.getPTOptions("".concat(o.id,"_").concat(n),"actionIcon")),null,16)):k("",!0)],16,q)),[[a],[O,{value:e.label,disabled:!t.tooltipOptions},t.tooltipOptions]])],16,H)):k("",!0)],64)})),128))],16,z)],16),t.mask?(u(),d("div",m({key:0,class:[t.cx("mask"),t.maskClass],style:t.maskStyle},t.ptm("mask")),null,16)):k("",!0)],64)};export{U as default};