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.
102 lines
8.4 KiB
102 lines
8.4 KiB
import{i as A,N as se}from"./icon-switch.cssr-BCTOxvoq.js";import{c as I,a as t,b as K,d as a,e as O,u as ce,f as E,g as b,h as de}from"./light-Cua7cqmF.js";import{s as ue}from"./light-CdWU_bnm.js";import{u as he}from"./use-form-item-CNgNT5jP.js";import{u as fe}from"./use-merged-state-CzrzZJbg.js";import{p as P,d as r}from"./index-C-nsH7mf.js";import{i as U,r as v}from"./resolve-slot-Dzko3qih.js";import{N as be}from"./Loading-CByrJVhO.js";import{c as j}from"./call-f2ri57Kd.js";import{d as ve,s as H,O as ge,c as V,G as n}from"./index-bVOhw2NF.js";const me=I("switch",`
|
|
height: var(--n-height);
|
|
min-width: var(--n-width);
|
|
vertical-align: middle;
|
|
user-select: none;
|
|
-webkit-user-select: none;
|
|
display: inline-flex;
|
|
outline: none;
|
|
justify-content: center;
|
|
align-items: center;
|
|
`,[t("children-placeholder",`
|
|
height: var(--n-rail-height);
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
pointer-events: none;
|
|
visibility: hidden;
|
|
`),t("rail-placeholder",`
|
|
display: flex;
|
|
flex-wrap: none;
|
|
`),t("button-placeholder",`
|
|
width: calc(1.75 * var(--n-rail-height));
|
|
height: var(--n-rail-height);
|
|
`),I("base-loading",`
|
|
position: absolute;
|
|
top: 50%;
|
|
left: 50%;
|
|
transform: translateX(-50%) translateY(-50%);
|
|
font-size: calc(var(--n-button-width) - 4px);
|
|
color: var(--n-loading-color);
|
|
transition: color .3s var(--n-bezier);
|
|
`,[A({left:"50%",top:"50%",originalTransform:"translateX(-50%) translateY(-50%)"})]),t("checked, unchecked",`
|
|
transition: color .3s var(--n-bezier);
|
|
color: var(--n-text-color);
|
|
box-sizing: border-box;
|
|
position: absolute;
|
|
white-space: nowrap;
|
|
top: 0;
|
|
bottom: 0;
|
|
display: flex;
|
|
align-items: center;
|
|
line-height: 1;
|
|
`),t("checked",`
|
|
right: 0;
|
|
padding-right: calc(1.25 * var(--n-rail-height) - var(--n-offset));
|
|
`),t("unchecked",`
|
|
left: 0;
|
|
justify-content: flex-end;
|
|
padding-left: calc(1.25 * var(--n-rail-height) - var(--n-offset));
|
|
`),K("&:focus",[t("rail",`
|
|
box-shadow: var(--n-box-shadow-focus);
|
|
`)]),a("round",[t("rail","border-radius: calc(var(--n-rail-height) / 2);",[t("button","border-radius: calc(var(--n-button-height) / 2);")])]),O("disabled",[O("icon",[a("rubber-band",[a("pressed",[t("rail",[t("button","max-width: var(--n-button-width-pressed);")])]),t("rail",[K("&:active",[t("button","max-width: var(--n-button-width-pressed);")])]),a("active",[a("pressed",[t("rail",[t("button","left: calc(100% - var(--n-offset) - var(--n-button-width-pressed));")])]),t("rail",[K("&:active",[t("button","left: calc(100% - var(--n-offset) - var(--n-button-width-pressed));")])])])])])]),a("active",[t("rail",[t("button","left: calc(100% - var(--n-button-width) - var(--n-offset))")])]),t("rail",`
|
|
overflow: hidden;
|
|
height: var(--n-rail-height);
|
|
min-width: var(--n-rail-width);
|
|
border-radius: var(--n-rail-border-radius);
|
|
cursor: pointer;
|
|
position: relative;
|
|
transition:
|
|
opacity .3s var(--n-bezier),
|
|
background .3s var(--n-bezier),
|
|
box-shadow .3s var(--n-bezier);
|
|
background-color: var(--n-rail-color);
|
|
`,[t("button-icon",`
|
|
color: var(--n-icon-color);
|
|
transition: color .3s var(--n-bezier);
|
|
font-size: calc(var(--n-button-height) - 4px);
|
|
position: absolute;
|
|
left: 0;
|
|
right: 0;
|
|
top: 0;
|
|
bottom: 0;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
line-height: 1;
|
|
`,[A()]),t("button",`
|
|
align-items: center;
|
|
top: var(--n-offset);
|
|
left: var(--n-offset);
|
|
height: var(--n-button-height);
|
|
width: var(--n-button-width-pressed);
|
|
max-width: var(--n-button-width);
|
|
border-radius: var(--n-button-border-radius);
|
|
background-color: var(--n-button-color);
|
|
box-shadow: var(--n-button-box-shadow);
|
|
box-sizing: border-box;
|
|
cursor: inherit;
|
|
content: "";
|
|
position: absolute;
|
|
transition:
|
|
background-color .3s var(--n-bezier),
|
|
left .3s var(--n-bezier),
|
|
opacity .3s var(--n-bezier),
|
|
max-width .3s var(--n-bezier),
|
|
box-shadow .3s var(--n-bezier);
|
|
`)]),a("active",[t("rail","background-color: var(--n-rail-color-active);")]),a("loading",[t("rail",`
|
|
cursor: wait;
|
|
`)]),a("disabled",[t("rail",`
|
|
cursor: not-allowed;
|
|
opacity: .5;
|
|
`)])]),we=Object.assign(Object.assign({},E.props),{size:{type:String,default:"medium"},value:{type:[String,Number,Boolean],default:void 0},loading:Boolean,defaultValue:{type:[String,Number,Boolean],default:!1},disabled:{type:Boolean,default:void 0},round:{type:Boolean,default:!0},"onUpdate:value":[Function,Array],onUpdateValue:[Function,Array],checkedValue:{type:[String,Number,Boolean],default:!0},uncheckedValue:{type:[String,Number,Boolean],default:!1},railStyle:Function,rubberBand:{type:Boolean,default:!0},onChange:[Function,Array]});let x;const Ve=ve({name:"Switch",props:we,setup(e){x===void 0&&(typeof CSS<"u"?typeof CSS.supports<"u"?x=CSS.supports("width","max(1px)"):x=!1:x=!0);const{mergedClsPrefixRef:S,inlineThemeDisabled:w}=ce(e),z=E("Switch","-switch",me,ue,e,S),l=he(e),{mergedSizeRef:_,mergedDisabledRef:h}=l,p=H(e.defaultValue),$=ge(e,"value"),f=fe($,p),y=V(()=>f.value===e.checkedValue),g=H(!1),o=H(!1),s=V(()=>{const{railStyle:i}=e;if(i)return i({focused:o.value,checked:y.value})});function c(i){const{"onUpdate:value":C,onChange:B,onUpdateValue:R}=e,{nTriggerFormInput:F,nTriggerFormChange:T}=l;C&&j(C,i),R&&j(R,i),B&&j(B,i),p.value=i,F(),T()}function L(){const{nTriggerFormFocus:i}=l;i()}function X(){const{nTriggerFormBlur:i}=l;i()}function Y(){e.loading||h.value||(f.value!==e.checkedValue?c(e.checkedValue):c(e.uncheckedValue))}function G(){o.value=!0,L()}function q(){o.value=!1,X(),g.value=!1}function J(i){e.loading||h.value||i.key===" "&&(f.value!==e.checkedValue?c(e.checkedValue):c(e.uncheckedValue),g.value=!1)}function Q(i){e.loading||h.value||i.key===" "&&(i.preventDefault(),g.value=!0)}const M=V(()=>{const{value:i}=_,{self:{opacityDisabled:C,railColor:B,railColorActive:R,buttonBoxShadow:F,buttonColor:T,boxShadowFocus:Z,loadingColor:ee,textColor:te,iconColor:ie,[b("buttonHeight",i)]:d,[b("buttonWidth",i)]:oe,[b("buttonWidthPressed",i)]:ne,[b("railHeight",i)]:u,[b("railWidth",i)]:k,[b("railBorderRadius",i)]:ae,[b("buttonBorderRadius",i)]:re},common:{cubicBezierEaseInOut:le}}=z.value;let N,W,D;return x?(N=`calc((${u} - ${d}) / 2)`,W=`max(${u}, ${d})`,D=`max(${k}, calc(${k} + ${d} - ${u}))`):(N=P((r(u)-r(d))/2),W=P(Math.max(r(u),r(d))),D=r(u)>r(d)?k:P(r(k)+r(d)-r(u))),{"--n-bezier":le,"--n-button-border-radius":re,"--n-button-box-shadow":F,"--n-button-color":T,"--n-button-width":oe,"--n-button-width-pressed":ne,"--n-button-height":d,"--n-height":W,"--n-offset":N,"--n-opacity-disabled":C,"--n-rail-border-radius":ae,"--n-rail-color":B,"--n-rail-color-active":R,"--n-rail-height":u,"--n-rail-width":k,"--n-width":D,"--n-box-shadow-focus":Z,"--n-loading-color":ee,"--n-text-color":te,"--n-icon-color":ie}}),m=w?de("switch",V(()=>_.value[0]),M,e):void 0;return{handleClick:Y,handleBlur:q,handleFocus:G,handleKeyup:J,handleKeydown:Q,mergedRailStyle:s,pressed:g,mergedClsPrefix:S,mergedValue:f,checked:y,mergedDisabled:h,cssVars:w?void 0:M,themeClass:m==null?void 0:m.themeClass,onRender:m==null?void 0:m.onRender}},render(){const{mergedClsPrefix:e,mergedDisabled:S,checked:w,mergedRailStyle:z,onRender:l,$slots:_}=this;l==null||l();const{checked:h,unchecked:p,icon:$,"checked-icon":f,"unchecked-icon":y}=_,g=!(U($)&&U(f)&&U(y));return n("div",{role:"switch","aria-checked":w,class:[`${e}-switch`,this.themeClass,g&&`${e}-switch--icon`,w&&`${e}-switch--active`,S&&`${e}-switch--disabled`,this.round&&`${e}-switch--round`,this.loading&&`${e}-switch--loading`,this.pressed&&`${e}-switch--pressed`,this.rubberBand&&`${e}-switch--rubber-band`],tabindex:this.mergedDisabled?void 0:0,style:this.cssVars,onClick:this.handleClick,onFocus:this.handleFocus,onBlur:this.handleBlur,onKeyup:this.handleKeyup,onKeydown:this.handleKeydown},n("div",{class:`${e}-switch__rail`,"aria-hidden":"true",style:z},v(h,o=>v(p,s=>o||s?n("div",{"aria-hidden":!0,class:`${e}-switch__children-placeholder`},n("div",{class:`${e}-switch__rail-placeholder`},n("div",{class:`${e}-switch__button-placeholder`}),o),n("div",{class:`${e}-switch__rail-placeholder`},n("div",{class:`${e}-switch__button-placeholder`}),s)):null)),n("div",{class:`${e}-switch__button`},v($,o=>v(f,s=>v(y,c=>n(se,null,{default:()=>this.loading?n(be,{key:"loading",clsPrefix:e,strokeWidth:20}):this.checked&&(s||o)?n("div",{class:`${e}-switch__button-icon`,key:s?"checked-icon":"icon"},s||o):!this.checked&&(c||o)?n("div",{class:`${e}-switch__button-icon`,key:c?"unchecked-icon":"icon"},c||o):null})))),v(h,o=>o&&n("div",{key:"checked",class:`${e}-switch__checked`},o)),v(p,o=>o&&n("div",{key:"unchecked",class:`${e}-switch__unchecked`},o)))))}});export{Ve as _};
|