primevue
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primevue) [ • 5.01 kB
JavaScript
import e from"primevue/basecomponent";import{UniqueComponentId as t,DomHandler as n}from"primevue/utils";import{resolveComponent as s,openBlock as i,createElementBlock as a,mergeProps as l,createElementVNode as o,Fragment as r,renderList as p,createBlock as m,withCtx as c,toDisplayString as d,resolveDynamicComponent as u,createCommentVNode as f}from"vue";var h={name:"Steps",extends:e,props:{id:{type:String,default:t()},model:{type:Array,default:null},readonly:{type:Boolean,default:!0},exact:{type:Boolean,default:!0}},mounted(){this.findFirstItem().tabIndex="0"},methods:{onItemClick(e,t,n){this.disabled(t)||this.readonly?e.preventDefault():(t.command&&t.command({originalEvent:e,item:t}),t.to&&n&&n(e))},onItemKeydown(e,t,n){switch(e.code){case"ArrowRight":this.navigateToNextItem(e.target),e.preventDefault();break;case"ArrowLeft":this.navigateToPrevItem(e.target),e.preventDefault();break;case"Home":this.navigateToFirstItem(e.target),e.preventDefault();break;case"End":this.navigateToLastItem(e.target),e.preventDefault();break;case"Tab":break;case"Enter":case"Space":this.onItemClick(e,t,n),e.preventDefault()}},navigateToNextItem(e){const t=this.findNextItem(e);t&&this.setFocusToMenuitem(e,t)},navigateToPrevItem(e){const t=this.findPrevItem(e);t&&this.setFocusToMenuitem(e,t)},navigateToFirstItem(e){const t=this.findFirstItem(e);t&&this.setFocusToMenuitem(e,t)},navigateToLastItem(e){const t=this.findLastItem(e);t&&this.setFocusToMenuitem(e,t)},findNextItem(e){const t=e.parentElement.nextElementSibling;return t?t.children[0]:null},findPrevItem(e){const t=e.parentElement.previousElementSibling;return t?t.children[0]:null},findFirstItem(){const e=n.findSingle(this.$refs.list,".p-steps-item");return e?e.children[0]:null},findLastItem(){const e=n.find(this.$refs.list,".p-steps-item");return e?e[e.length-1].children[0]:null},setFocusToMenuitem(e,t){e.tabIndex="-1",t.tabIndex="0",t.focus()},isActive(e){return!!e.to&&this.$router.resolve(e.to).path===this.$route.path},getItemClass(e){return["p-steps-item",e.class,{"p-highlight p-steps-current":this.isActive(e),"p-disabled":this.isItemDisabled(e)}]},linkClass(e){return["p-menuitem-link",{"router-link-active":e&&e.isActive,"router-link-active-exact":this.exact&&e&&e.isExactActive}]},isItemDisabled(e){return this.disabled(e)||this.readonly&&!this.isActive(e)},visible:e=>"function"==typeof e.visible?e.visible():!1!==e.visible,disabled:e=>"function"==typeof e.disabled?e.disabled():e.disabled,label:e=>"function"==typeof e.label?e.label():e.label},computed:{containerClass(){return["p-steps p-component",{"p-readonly":this.readonly}]}}};const v=["id"],y=["href","aria-current","onClick","onKeydown"],b=["onKeydown"];!function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var s=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===n&&s.firstChild?s.insertBefore(i,s.firstChild):s.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}("\n.p-steps {\n position: relative;\n}\n.p-steps .p-steps-list {\n padding: 0;\n margin: 0;\n list-style-type: none;\n display: flex;\n}\n.p-steps-item {\n position: relative;\n display: flex;\n justify-content: center;\n flex: 1 1 auto;\n}\n.p-steps-item .p-menuitem-link {\n display: inline-flex;\n flex-direction: column;\n align-items: center;\n overflow: hidden;\n text-decoration: none;\n}\n.p-steps.p-steps-readonly .p-steps-item {\n cursor: auto;\n}\n.p-steps-item.p-steps-current .p-menuitem-link {\n cursor: default;\n}\n.p-steps-title {\n white-space: nowrap;\n}\n.p-steps-number {\n display: flex;\n align-items: center;\n justify-content: center;\n}\n.p-steps-title {\n display: block;\n}\n"),h.render=function(e,t,n,h,I,g){const x=s("router-link");return i(),a("nav",l({id:n.id,class:g.containerClass},e.ptm("root")),[o("ol",l({ref:"list",class:"p-steps-list"},e.ptm("menu")),[(i(!0),a(r,null,p(n.model,((t,n)=>(i(),a(r,{key:t.to},[g.visible(t)?(i(),a("li",l({key:0,class:g.getItemClass(t),style:t.style},e.ptm("menuitem")),[e.$slots.item?(i(),m(u(e.$slots.item),{key:1,item:t},null,8,["item"])):(i(),a(r,{key:0},[g.isItemDisabled(t)?(i(),a("span",l({key:1,class:g.linkClass(),onKeydown:e=>g.onItemKeydown(e,t)},e.ptm("action")),[o("span",l({class:"p-steps-number"},e.ptm("step")),d(n+1),17),o("span",l({class:"p-steps-title"},e.ptm("label")),d(g.label(t)),17)],16,b)):(i(),m(x,{key:0,to:t.to,custom:""},{default:c((({navigate:s,href:i,isActive:a,isExactActive:r})=>[o("a",l({href:i,class:g.linkClass({isActive:a,isExactActive:r}),tabindex:-1,"aria-current":r?"step":void 0,onClick:e=>g.onItemClick(e,t,s),onKeydown:e=>g.onItemKeydown(e,t,s)},e.ptm("action")),[o("span",l({class:"p-steps-number"},e.ptm("step")),d(n+1),17),o("span",l({class:"p-steps-title"},e.ptm("label")),d(g.label(t)),17)],16,y)])),_:2},1032,["to"]))],64))],16)):f("",!0)],64)))),128))],16)],16,v)};export{h as default};