UNPKG

dm-vue3-ui

Version:

This Components Library will help get you started developing in Vue 3.

2 lines (1 loc) 2.17 kB
"use strict";const e=require("vue"),l=require("@vueuse/core"),o=require("../utils/index"),t=require("../utils/theme"),a={class:"label"},r=e.defineComponent({name:"dm-switch",__name:"index",props:{modelValue:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},loading:{type:Boolean,default:!1},size:{default:"medium"},checkedText:{default:""},unCheckedText:{default:""},colorOn:{default:""},colorOff:{default:"#00000040"},sliderColor:{default:"#fff"},loadingParams:{default:()=>({type:"solid",style:"2px",styleColor:"#ccc",borderTopColor:"#4caf50"})}},emits:["update:modelValue"],setup(r,{emit:d}){const n=o.store("platformConfig")||{},s=(null==n?void 0:n.themeColor)||"default";t.themeManager.initializeTheme();const c=t.themeManager.applyThemeByType(s),u=r,i=d,m=l.useVModel(u,"modelValue",i),f=e.computed((()=>`switch-${u.size}`)),p=e.computed((()=>{const e=u.colorOn||(null==c?void 0:c.primaryColor)||"#7857fc";return{backgroundColor:m.value?e:u.colorOff}})),y=e.computed((()=>({backgroundColor:u.sliderColor}))),C=e.computed((()=>({border:`${u.loadingParams.style} ${u.loadingParams.type} ${u.loadingParams.styleColor}`,borderTopColor:`${u.loadingParams.borderTopColor}`}))),h=()=>{u.disabled||u.loading||(m.value=!m.value)};return(l,o)=>(e.openBlock(),e.createElementBlock("button",{class:e.normalizeClass(["dm-switch",f.value,{"switch-on":e.unref(m)},{"switch-off":!e.unref(m)},{"switch-disabled":l.disabled}]),style:e.normalizeStyle(p.value),onClick:h},[e.createElementVNode("div",{class:"slider",style:e.normalizeStyle(y.value)},null,4),e.createElementVNode("span",a,[e.unref(m)&&(l.checkedText||l.$slots.checkedText)?e.renderSlot(l.$slots,"checkedText",{key:0},(()=>[e.createTextVNode(e.toDisplayString(l.checkedText),1)])):e.createCommentVNode("",!0),e.unref(m)||!l.unCheckedText&&!l.$slots.unCheckedText?e.createCommentVNode("",!0):e.renderSlot(l.$slots,"unCheckedText",{key:1},(()=>[e.createTextVNode(e.toDisplayString(l.unCheckedText),1)])),e.renderSlot(l.$slots,"default")]),l.loading?(e.openBlock(),e.createElementBlock("div",{key:0,class:"loading",style:e.normalizeStyle(C.value)},null,4)):e.createCommentVNode("",!0)],6))}});module.exports=r;