You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
4.9 KiB

import{b as J,i as R,Y as k,H as w,k as I,d as K,u as X,c as u,m as S,Q as V,s as x,o,v as d,x as E,e as a,n as r,L as ee,a as v,w as b,g as T,I as c,A as N,y as ae,f as F,M as te,Z as ie,_ as ne,$ as O,h as oe}from"./normalize-8daa80b1.js";import{i as U,g as se,E as g,l as le,_ as re}from"./base-a9e1396c.js";import{i as ce}from"./validator-9be52df0.js";import{U as B,C as P,I as _,a as ue,b as de,c as ve,e as fe,u as pe,d as me,t as he}from"./el-button-4f2e1711.js";const ye=J({modelValue:{type:[Boolean,String,Number],default:!1},value:{type:[Boolean,String,Number],default:!1},disabled:{type:Boolean,default:!1},width:{type:[String,Number],default:""},inlinePrompt:{type:Boolean,default:!1},activeIcon:{type:U},inactiveIcon:{type:U},activeText:{type:String,default:""},inactiveText:{type:String,default:""},activeColor:{type:String,default:""},inactiveColor:{type:String,default:""},borderColor:{type:String,default:""},activeValue:{type:[Boolean,String,Number],default:!0},inactiveValue:{type:[Boolean,String,Number],default:!1},name:{type:String,default:""},validateEvent:{type:Boolean,default:!0},id:String,loading:{type:Boolean,default:!1},beforeChange:{type:R(Function)},size:{type:String,validator:ce},tabindex:{type:[String,Number]}}),be={[B]:s=>k(s)||w(s)||I(s),[P]:s=>k(s)||w(s)||I(s),[_]:s=>k(s)||w(s)||I(s)},ge=["onClick"],ke=["id","aria-checked","aria-disabled","name","true-value","false-value","disabled","tabindex","onKeydown"],Ce=["aria-hidden"],we=["aria-hidden"],Ie=["aria-hidden"],D="ElSwitch",Se=K({name:D}),Ve=K({...Se,props:ye,emits:be,setup(s,{expose:H,emit:f}){const t=s,L=ie(),{formItem:m}=ue(),G=de(),i=X("switch");ve({from:'"value"',replacement:'"model-value" or "v-model"',scope:D,version:"2.3.0",ref:"https://element-plus.org/en-US/component/switch.html#attributes",type:"Attribute"},u(()=>{var e;return!!((e=L.vnode.props)!=null&&e.value)}));const{inputId:Q}=fe(t,{formItemContext:m}),h=pe(u(()=>t.loading)),C=S(t.modelValue!==!1),p=S(),W=S(),Y=u(()=>[i.b(),i.m(G.value),i.is("disabled",h.value),i.is("checked",n.value)]),Z=u(()=>({width:se(t.width)}));V(()=>t.modelValue,()=>{C.value=!0}),V(()=>t.value,()=>{C.value=!1});const z=u(()=>C.value?t.modelValue:t.value),n=u(()=>z.value===t.activeValue);[t.activeValue,t.inactiveValue].includes(z.value)||(f(B,t.inactiveValue),f(P,t.inactiveValue),f(_,t.inactiveValue)),V(n,e=>{var l;p.value.checked=e,t.validateEvent&&((l=m==null?void 0:m.validate)==null||l.call(m,"change").catch(q=>me()))});const y=()=>{const e=n.value?t.inactiveValue:t.activeValue;f(B,e),f(P,e),f(_,e),ne(()=>{p.value.checked=n.value})},M=()=>{if(h.value)return;const{beforeChange:e}=t;if(!e){y();return}const l=e();[O(l),k(l)].includes(!0)||he(D,"beforeChange must return type `Promise<boolean>` or `boolean`"),O(l)?l.then(A=>{A&&y()}).catch(A=>{}):l&&y()},$=u(()=>i.cssVarBlock({...t.activeColor?{"on-color":t.activeColor}:null,...t.inactiveColor?{"off-color":t.inactiveColor}:null,...t.borderColor?{"border-color":t.borderColor}:null})),j=()=>{var e,l;(l=(e=p.value)==null?void 0:e.focus)==null||l.call(e)};return x(()=>{p.value.checked=n.value}),H({focus:j,checked:n}),(e,l)=>(o(),d("div",{class:r(a(Y)),style:F(a($)),onClick:te(M,["prevent"])},[E("input",{id:a(Q),ref_key:"input",ref:p,class:r(a(i).e("input")),type:"checkbox",role:"switch","aria-checked":a(n),"aria-disabled":a(h),name:e.name,"true-value":e.activeValue,"false-value":e.inactiveValue,disabled:a(h),tabindex:e.tabindex,onChange:y,onKeydown:ee(M,["enter"])},null,42,ke),!e.inlinePrompt&&(e.inactiveIcon||e.inactiveText)?(o(),d("span",{key:0,class:r([a(i).e("label"),a(i).em("label","left"),a(i).is("active",!a(n))])},[e.inactiveIcon?(o(),v(a(g),{key:0},{default:b(()=>[(o(),v(T(e.inactiveIcon)))]),_:1})):c("v-if",!0),!e.inactiveIcon&&e.inactiveText?(o(),d("span",{key:1,"aria-hidden":a(n)},N(e.inactiveText),9,Ce)):c("v-if",!0)],2)):c("v-if",!0),E("span",{ref_key:"core",ref:W,class:r(a(i).e("core")),style:F(a(Z))},[e.inlinePrompt?(o(),d("div",{key:0,class:r(a(i).e("inner"))},[e.activeIcon||e.inactiveIcon?(o(),v(a(g),{key:0,class:r(a(i).is("icon"))},{default:b(()=>[(o(),v(T(a(n)?e.activeIcon:e.inactiveIcon)))]),_:1},8,["class"])):e.activeText||e.inactiveText?(o(),d("span",{key:1,class:r(a(i).is("text")),"aria-hidden":!a(n)},N(a(n)?e.activeText:e.inactiveText),11,we)):c("v-if",!0)],2)):c("v-if",!0),E("div",{class:r(a(i).e("action"))},[e.loading?(o(),v(a(g),{key:0,class:r(a(i).is("loading"))},{default:b(()=>[ae(a(le))]),_:1},8,["class"])):c("v-if",!0)],2)],6),!e.inlinePrompt&&(e.activeIcon||e.activeText)?(o(),d("span",{key:1,class:r([a(i).e("label"),a(i).em("label","right"),a(i).is("active",a(n))])},[e.activeIcon?(o(),v(a(g),{key:0},{default:b(()=>[(o(),v(T(e.activeIcon)))]),_:1})):c("v-if",!0),!e.activeIcon&&e.activeText?(o(),d("span",{key:1,"aria-hidden":!a(n)},N(e.activeText),9,Ie)):c("v-if",!0)],2)):c("v-if",!0)],14,ge))}});var Ee=re(Ve,[["__file","/home/runner/work/element-plus/element-plus/packages/components/switch/src/switch.vue"]]);const _e=oe(Ee);export{_e as E};