uv-ui
Version:
基于vue3的移动端组件库
2 lines (1 loc) • 2.31 kB
JavaScript
;const e=require("vue"),f=require("../icon/index.cjs"),b=require("../../hooks/useContext.cjs");require("../../hooks/useCountDown.cjs");require("./checkbox.vue_vue_type_style_index_0_lang.cjs");const m={key:0,class:"uv-check-box-left"},x={key:1,class:"uv-check-box-right"},v={name:"UvCheckbox"},S=Object.assign(v,{props:{modelValue:{type:Boolean,default:!1},shape:{type:String,default:"round"},label:{type:String,default:""},disabled:{type:Boolean,default:!1},checkedColor:{type:String},labelPosition:{type:String,default:"right"},spaceBetween:{type:Boolean,default:!1}},emits:["update:modelValue","change"],setup(c,{emit:s}){const t=c,a=e.ref(null),o=e.reactive({$el:a,label:t.label,isSelect:!1}),{props:l,updateItem:u,index:d}=b.useParent("checkbox-group",o);e.onMounted(()=>{l&&l.modelValue.find(n=>n===o.label)&&(o.isSelect=!0)});const r=e.computed(()=>[t.disabled?"uv-check-box-disabled":"",t.spaceBetween?"uv-check-box-space-between":""]),h=e.computed(()=>({border:o.isSelect?`1px solid ${t.checkedColor||(l==null?void 0:l.checkedColor)}`:"",backgroundColor:o.isSelect?`${t.checkedColor||(l==null?void 0:l.checkedColor)}`:"",width:`${(l==null?void 0:l.iconSize)||18}px`,height:`${(l==null?void 0:l.iconSize)||18}px`})),k=()=>{t.disabled||(l&&l.modelValue?u(d.value):(o.isSelect=!o.isSelect,s("update:modelValue",!t.modelValue),s("change",t.label)))};return(n,y)=>{var i;return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["uv-check-box",e.unref(r)]),ref_key:"checkboxRef",ref:a,onClick:k},[c.labelPosition==="left"?(e.openBlock(),e.createElementBlock("div",m,[e.renderSlot(n.$slots,"default",{},()=>[e.createTextVNode(e.toDisplayString(c.label),1)])])):e.createCommentVNode("",!0),e.createElementVNode("div",{class:e.normalizeClass(["uv-check-box-icon",[(((i=e.unref(l))==null?void 0:i.shape)||t.shape)==="round"?"round":"",o.isSelect?"active":""]]),style:e.normalizeStyle(e.unref(h))},[o.isSelect?(e.openBlock(),e.createBlock(e.unref(f),{key:0,name:"select",color:c.disabled?"#c8c9cc":"#fff",size:"18"},null,8,["color"])):e.createCommentVNode("",!0)],6),c.labelPosition==="right"?(e.openBlock(),e.createElementBlock("div",x,[e.renderSlot(n.$slots,"default",{},()=>[e.createTextVNode(e.toDisplayString(c.label),1)])])):e.createCommentVNode("",!0)],2)}}});module.exports=S;