@volverjs/ui-vue
Version:
@volverjs/ui-vue is a lightweight Vue 3 component library to accompany @volverjs/style.
2 lines (1 loc) • 5.88 kB
JavaScript
import{inject as e,computed as t,useId as o,unref as l,watch as a,ref as i,defineComponent as s,mergeDefaults as r,toRefs as n,createBlock as u,createCommentVNode as v,openBlock as c,mergeProps as f,createElementBlock as d,normalizeProps as p,guardReactiveProps as m,renderSlot as h,createTextVNode as b,toDisplayString as y,withModifiers as $,createElementVNode as g}from"vue";import{iconLoaded as w,Icon as S,addIcon as k}from"@iconify/vue";var x=/* @__PURE__ */(e=>(e.local="local",e.session="session",e))(x||{}),I=/* @__PURE__ */(e=>(e.left="left",e.right="right",e.top="top",e.bottom="bottom",e))(I||{}),_=/* @__PURE__ */(e=>(e.before="before",e.after="after",e))(_||{}),C=/* @__PURE__ */(e=>(e.button="button",e.submit="submit",e.reset="reset",e))(C||{}),L=/* @__PURE__ */(e=>(e.nuxtLink="nuxt-link",e.routerLink="router-link",e.a="a",e.button="button",e))(L||{}),F=/* @__PURE__ */(e=>(e.alert="alert",e.alertdialog="alertdialog",e))(F||{});const T=Symbol.for("volver"),B=Symbol.for("alertGroup"),M={prefix:"normal"},O={icon:{type:[String,Object],default:void 0},iconPosition:{type:String,default:_.before,validation:e=>Object.values(_).includes(e)}},P={id:[String,Number]};function A(e,o,a){return t(()=>{const t={[e]:!0},i="string"==typeof o?.value?o.value.split(" "):o?.value;return i&&Array.isArray(i)&&i.forEach(o=>{o&&(t[`${e}--${o}`]=!0)}),a&&Object.keys(a.value).forEach(o=>{t[`${e}--${o}`]=l(a.value[o])}),t})}I.bottom,C.button,L.button,x.local;const j={...P,...O,modifiers:{type:[String,Array],default:void 0},dismissable:{type:Boolean,default:!1},autoClose:{type:Number,default:0},closeLabel:{type:String,default:"Close"},title:{type:String,default:void 0},content:{type:String,default:void 0},footer:{type:String,default:void 0},role:{type:String,default:F.alert}};function E(l,s){const{bus:r}=e(B,{}),n=(u=t(()=>l.id),t(()=>String(u?.value||o())));var u;const v=t(()=>`${n.value}-title`);let c;const f=()=>{c&&clearTimeout(c),s("close",n.value),r?.emit("close",n.value)};a(()=>l.autoClose,e=>{e>0?c=setTimeout(f,e):c&&clearTimeout(c)},{immediate:!0});const d=i(!1),p=()=>{d.value=!0,c&&clearTimeout(c)},m=()=>{d.value=!1,l.autoClose>0&&(c=setTimeout(f,l.autoClose))},{hasIcon:h}=function(e,o){const l=t(()=>"string"==typeof e?.value?{name:e?.value}:e?.value),a=t(()=>o?.value===_.before?l.value:void 0),i=t(()=>o?.value===_.after?l.value:void 0),s=t(()=>o?.value===I.left?l.value:void 0),r=t(()=>o?.value===I.right?l.value:void 0),n=t(()=>o?.value===I.top?l.value:void 0),u=t(()=>o?.value===I.bottom?l.value:void 0);return{hasIcon:l,hasIconLeft:s,hasIconRight:r,hasIconTop:n,hasIconBottom:u,hasIconBefore:a,hasIconAfter:i}}(t(()=>l.icon)),b=A("vv-alert",t(()=>l.modifiers),t(()=>({dismissable:l.autoClose>0||l.dismissable,"auto-close":l.autoClose>0,hover:d.value}))),y=t(()=>({"--alert-duration":`${l.autoClose}ms`}));return{close:f,hasIcon:h,hasTitleId:v,hasProps:t(()=>({onMouseover:p,onMouseleave:m,class:b.value,style:y.value,role:l.role,"aria-labelledby":v.value}))}}const V=/* @__PURE__ */s({name:"VvIcon",props:/* @__PURE__ */r({name:{},color:{},width:{},height:{},provider:{},prefix:{},src:{},horizontalFlip:{type:Boolean},verticalFlip:{type:Boolean},flip:{},mode:{},inline:{type:Boolean},rotate:{},onLoad:{type:Function},svg:{},modifiers:{}},M),setup(o){const a=o,s=t(()=>"string"==typeof a.rotate?Number.parseFloat(a.rotate):a.rotate),r=i(!0),d=e(T,void 0),{modifiers:p}=n(a),m=A("vv-icon",p),h=t(()=>a.provider||d?.iconsProvider),b=t(()=>{const e=a.name??"",t=`@${h.value}:${a.prefix}:${e}`;if(w(t))return t;const o=d?.iconsCollections.find(t=>{const o=`@${h.value}:${t.prefix}:${e}`;return w(o)});return o?`@${h.value}:${o.prefix}:${e}`:e});function y(e){const t=function(e){let t;if("undefined"==typeof window){const{JSDOM:e}=require("jsdom");t=(new e).window}return(t?new t.DOMParser:new window.DOMParser).parseFromString(e,"text/html").querySelector("svg")}(e),o=t?.innerHTML.trim()||"";t&&o&&k(`@${h.value}:${a.prefix}:${a.name}`,{body:o,height:t.viewBox.baseVal.height,width:t.viewBox.baseVal.width})}return d&&a.src&&!w(`@${h.value}:${a.prefix}:${a.name}`)&&(r.value=!1,d.fetchIcon(a.src).then(e=>{e&&(y(e),r.value=!0)}).catch(e=>{throw new Error(`Error during fetch icon: ${e?.message}`)})),a.svg&&y(a.svg),(e,t)=>l(r)?(c(),u(l(S),f({key:0,class:l(m)},{inline:o.inline,width:o.width,height:o.height,horizontalFlip:o.horizontalFlip,verticalFlip:o.verticalFlip,flip:o.flip,rotate:l(s),color:o.color,icon:l(b)},{onLoad:o.onLoad}),null,16,["class","onLoad"])):v("v-if",!0)}}),z={key:0,class:"vv-alert__header"},D=["id"],N=["aria-label"],q={key:1,class:"vv-alert__content"},G={key:2,class:"vv-alert__footer"},H=/* @__PURE__ */s({name:"VvAlert",props:j,emits:["close"],setup(e,{expose:t,emit:o}){const a=e,i=o,{hasProps:s,hasTitleId:r,hasIcon:n,close:w}=E(a,i);return t({close:w}),(e,t)=>(c(),d("div",p(m(l(s))),[e.$slots.header||e.$slots.title||e.$slots.close||e.$slots["title::before"]||e.$slots["title::after"]||e.title||l(n)||e.dismissable||e.autoClose?(c(),d("div",z,[l(n)?(c(),u(V,f({key:0},l(n),{class:"vv-alert__icon"}),null,16)):v("v-if",!0),h(e.$slots,"header",{},()=>[h(e.$slots,"title::before"),e.$slots.title||e.title?(c(),d("strong",{key:0,id:l(r),class:"vv-alert__title"},[h(e.$slots,"title",{},()=>[b(y(e.title),1)])],8,D)):v("v-if",!0),h(e.$slots,"title::after")]),h(e.$slots,"close",p(m({close:l(w)})),()=>[e.dismissable||e.autoClose?(c(),d("button",{key:0,class:"vv-alert__close",type:"button","aria-label":e.closeLabel,onClick:t[0]||(t[0]=$((...e)=>l(w)&&l(w)(...e),["stop"]))},[...t[1]||(t[1]=[g("div",{class:"vv-alert__close-mask"},null,-1)])],8,N)):v("v-if",!0)])])):v("v-if",!0),e.$slots.default||e.content?(c(),d("div",q,[h(e.$slots,"default",{},()=>[b(y(e.content),1)])])):v("v-if",!0),e.$slots.footer||e.footer?(c(),d("div",G,[h(e.$slots,"footer",{},()=>[b(y(e.footer),1)])])):v("v-if",!0)],16))}});export{H as default};