UNPKG

@volverjs/ui-vue

Version:

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

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