UNPKG

@volverjs/ui-vue

Version:

@volverjs/ui-vue is a lightweight Vue 3 component library to accompany @volverjs/style.

2 lines (1 loc) 7.28 kB
import{inject as e,computed as a,toRef as l,toRefs as t,isRef as i,defineComponent as n,h as o,useId as r,unref as u,useSlots as s,ref as d,createElementBlock as v,openBlock as f,normalizeClass as b,withDirectives as c,renderSlot as g,createVNode as y,createElementVNode as h,vModelRadio as p,createTextVNode as m,toDisplayString as S,createSlots as L,withCtx as O,normalizeProps as $,guardReactiveProps as A}from"vue";var V=/* @__PURE__ */(e=>(e.local="local",e.session="session",e))(V||{}),k=/* @__PURE__ */(e=>(e.left="left",e.right="right",e.top="top",e.bottom="bottom",e))(k||{}),B=/* @__PURE__ */(e=>(e.before="before",e.after="after",e))(B||{}),N=/* @__PURE__ */(e=>(e.button="button",e.submit="submit",e.reset="reset",e))(N||{}),j=/* @__PURE__ */(e=>(e.nuxtLink="nuxt-link",e.routerLink="router-link",e.a="a",e.button="button",e))(j||{});const x=Symbol.for("volver"),I=Symbol.for("radioGroup"),G={valid:{type:Boolean,default:!1},validLabel:{type:[String,Array],default:void 0}},H={invalid:{type:Boolean,default:!1},invalidLabel:{type:[String,Array],default:void 0}},R={loading:{type:Boolean,default:!1},loadingLabel:{type:String,default:"Loading..."}},_={disabled:{type:Boolean,default:!1}},E={label:{type:[String,Number],default:void 0}},D={readonly:{type:Boolean,default:!1}},J={modifiers:{type:[String,Array],default:void 0}},T={hintLabel:{type:String,default:""}};B.before;const q={tabindex:{type:[String,Number],default:0}},w={id:[String,Number]};k.bottom;const P={...{...w,name:{type:String,required:!0}},...q,...G,...H,...T,..._,...D,...J,...E,...R,value:{type:[String,Number,Boolean],default:void 0},modelValue:{type:[Object,Number,Boolean,String],default:void 0}};N.button,j.button,V.local;const U=P;function z(i,n){const{id:o}=t(i),{group:r,isInGroup:u,getGroupOrLocalRef:s}=function(t){const i=e(t,void 0),n=a(()=>void 0!==i);return{group:i,isInGroup:n,getGroupOrLocalRef:function(e,t,n){const o=i?.[e];if(o)return a({get:()=>o.value,set(e){o.value=e}});const r=l(t,e);return a({get:()=>r.value,set(a){n&&n(`update:${e}`,a)}})}}}(I),d=s("modelValue",i,n),v=s("valid",i),f=s("invalid",i),b=a(()=>Boolean(i.readonly||r?.readonly.value)),c=a(()=>Boolean(i.disabled||r?.disabled.value));return{id:o,group:r,isInGroup:u,modelValue:d,valid:v,invalid:f,readonly:b,disabled:c}}function C(e,a,l){return F(e,a)}function F(e,a){if(e===a)return!0;if(e&&a&&"object"==typeof e&&"object"==typeof a){const l=Array.isArray(e),t=Array.isArray(a);let i,n,o;if(l&&t){if(n=e.length,n!==a.length)return!1;for(i=n;0!==i--;)if(!F(e[i],a[i]))return!1;return!0}if(l!==t)return!1;const r=e instanceof Date,u=a instanceof Date;if(r!==u)return!1;if(r&&u)return e.getTime()===a.getTime();const s=e instanceof RegExp,d=a instanceof RegExp;if(s!==d)return!1;if(s&&d)return e.toString()===a.toString();const v=Object.keys(e);if(n=v.length,n!==Object.keys(a).length)return!1;for(i=n;0!==i--;)if(!Object.prototype.hasOwnProperty.call(a,v[i]))return!1;for(i=n;0!==i--;)if(o=v[i],!F(e[o],a[o]))return!1;return!0}return Number.isNaN(e)&&Number.isNaN(a)}function K(e){return Array.isArray(e)?e.filter(e=>"string"==typeof e).join(" "):e}function M(l,t,i){const n=e(x,void 0),o=a(()=>{if(n&&n.defaults.value?.[l])return n.defaults.value[l]});return a(()=>{if(void 0===o.value)return i;const e=o.value,a=t,l=i;return Object.keys(a).reduce((t,i)=>{const n=l[i];if(t[i]=n,i in e){if(Array.isArray(a[i])){const l=a[i];if(l.length){l[0]===n&&(t[i]=e[i])}}if("function"==typeof a[i]){(0,a[i])()===n&&(t[i]=e[i])}if("object"==typeof a[i]){let l=a[i].default;"function"==typeof l&&(l=l()),"object"==typeof l?JSON.stringify(l)===JSON.stringify(n)&&(t[i]=e[i]):l===n&&(t[i]=e[i])}}return t},{})})}const Q=["for"],W=["id","name","disabled","value","tabindex","aria-invalid","aria-describedby","aria-errormessage"],X=/* @__PURE__ */n({name:"VvRadio",props:U,emits:["click","update:modelValue","change","blur"],setup(e,{emit:l}){const V=e,k=l,B=s(),N=M("VvRadio",U,V),{id:j,disabled:x,readonly:I,modelValue:G,valid:H,invalid:R}=z(V,k),_=function(e){return a(()=>String(e?.value||r()))}(j),E=a(()=>`${_.value}-hint`),D=a(()=>T.value?-1:V.tabindex),J=d(),T=a(()=>x.value||I.value),q=a(()=>!0===R.value||!0!==H.value&&void 0),w=a(()=>Array.isArray(G.value)?function(e,a){if(null!=e&&a&&a.length)for(const l of a)if(C(e,l))return!0;return!1}(V.value,G.value):C(V.value,G.value)),P=a(()=>!["string","number","boolean"].includes(typeof V.value)||V.value),F=a({get:()=>w.value?P.value:null,set(e){Array.isArray(G.value)?G.value=[V.value]:G.value=V.value,k("change",e)}}),{modifiers:X}=t(V),Y=function(e,l,t){return a(()=>{const a={[e]:!0},i="string"==typeof l?.value?l.value.split(" "):l?.value;return i&&Array.isArray(i)&&i.forEach(l=>{l&&(a[`${e}--${l}`]=!0)}),t&&Object.keys(t.value).forEach(l=>{a[`${e}--${l}`]=u(t.value[l])}),a})}("vv-radio",X,a(()=>({valid:H.value,invalid:R.value,disabled:x.value,readonly:I.value}))),{HintSlot:Z,hasHintLabelOrSlot:ee,hasInvalidLabelOrSlot:ae,hintSlotScope:le}=function(e,l){const t=a(()=>i(e)?e.value:e),r=a(()=>K(t.value.invalidLabel)),u=a(()=>K(t.value.validLabel)),s=a(()=>t.value.loadingLabel),d=a(()=>t.value.hintLabel),v=a(()=>Boolean(t.value.loading&&(l.loading||s.value))),f=a(()=>!v.value&&Boolean(t.value.invalid&&(l.invalid||r.value))),b=a(()=>!v.value&&!f.value&&Boolean(t.value.valid&&(l.valid||u.value))),c=a(()=>!v.value&&!f.value&&!b.value&&Boolean(l.hint||d.value)),g=a(()=>f.value||b.value||v.value||c.value),y=a(()=>({modelValue:t.value.modelValue,valid:t.value.valid,invalid:t.value.invalid,loading:t.value.loading})),h=n({name:"HintSlot",props:{tag:{type:String,default:"small"}},setup:()=>({isVisible:g,invalidLabel:r,validLabel:u,loadingLabel:s,hintLabel:d,hasInvalidLabelOrSlot:f,hasValidLabelOrSlot:b,hasLoadingLabelOrSlot:v,hasHintLabelOrSlot:c}),render(){if(this.isVisible){let e;return this.hasInvalidLabelOrSlot&&(e="alert"),this.hasValidLabelOrSlot&&(e="status"),this.hasLoadingLabelOrSlot?o(this.tag,{role:e},this.$slots.loading?.()??this.loadingLabel):this.hasInvalidLabelOrSlot?o(this.tag,{role:e},this.$slots.invalid?.()??this.$slots.invalid??this.invalidLabel):this.hasValidLabelOrSlot?o(this.tag,{role:e},this.$slots.valid?.()??this.validLabel):o(this.tag,{role:e},this.$slots.hint?.()??this.$slots.hint??this.hintLabel)}return null}});return{hasInvalidLabelOrSlot:f,hasHintLabelOrSlot:c,hasValidLabelOrSlot:b,hasLoadingLabelOrSlot:v,hintSlotScope:y,HintSlot:h}}(N,B);return(e,a)=>(f(),v("label",{class:b(u(Y)),for:u(_)},[c(h("input",{id:u(_),ref_key:"input",ref:J,"onUpdate:modelValue":a[0]||(a[0]=e=>i(F)?F.value=e:null),type:"radio",class:"vv-radio__input",name:e.name,disabled:u(T),value:u(P),tabindex:u(D),"aria-invalid":u(q),"aria-describedby":u(ee)?u(E):void 0,"aria-errormessage":u(ae)?u(E):void 0},null,8,W),[[p,u(F)]]),g(e.$slots,"default",{value:u(G)},()=>[m(S(e.label),1)]),y(u(Z),{id:u(E),class:"vv-radio__hint"},L({_:2},[e.$slots.hint?{name:"hint",fn:O(()=>[g(e.$slots,"hint",$(A(u(le))))]),key:"0"}:void 0,e.$slots.loading?{name:"loading",fn:O(()=>[g(e.$slots,"loading",$(A(u(le))))]),key:"1"}:void 0,e.$slots.valid?{name:"valid",fn:O(()=>[g(e.$slots,"valid",$(A(u(le))))]),key:"2"}:void 0,e.$slots.invalid?{name:"invalid",fn:O(()=>[g(e.$slots,"invalid",$(A(u(le))))]),key:"3"}:void 0]),1032,["id"])],10,Q))}});export{X as default};