UNPKG

@vuesax-alpha/nightly

Version:
117 lines (114 loc) 4.35 kB
import { defineComponent, computed, openBlock, createElementBlock, normalizeClass, normalizeStyle, unref, createElementVNode, renderSlot, createBlock, createCommentVNode } from 'vue'; import '../../../hooks/index.mjs'; import { IconLoading } from '../../icon/index.mjs'; import '../../../utils/index.mjs'; import { switchProps, switchEmits } from './switch.mjs'; import { useSwitch } from './use-switch.mjs'; import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs'; import { useNamespace } from '../../../hooks/use-namespace/index.mjs'; import { useColor } from '../../../hooks/use-common-props/index.mjs'; import { useVuesaxBaseComponent } from '../../../hooks/use-base-component/index.mjs'; import { getVsColor } from '../../../utils/color.mjs'; const _hoisted_1 = ["checked", "disabled", "readonly"]; const __default__ = defineComponent({ name: "VsSwitch", inheritAttrs: false }); const _sfc_main = defineComponent({ ...__default__, props: switchProps, emits: switchEmits, setup(__props, { expose: __expose, emit }) { const props = __props; const ns = useNamespace("switch"); const color = useColor("primary"); const { isLoading, checked, isDisabled, handleChange, switchValue } = useSwitch( props, emit ); const vsBaseClasses = useVuesaxBaseComponent(color); const switchKls = computed(() => [ vsBaseClasses, ns.b(), ns.is("loading", isLoading.value), ns.is(props.shape), ns.is("indeterminate", props.indeterminate), ns.is("icon", props.icon), ns.is("disabled", isDisabled.value) ]); const switchStyles = computed(() => [ ns.cssVar({ color: getVsColor(color.value) }) ]); __expose({ checked }); return (_ctx, _cache) => { return openBlock(), createElementBlock( "div", { type: "checkbox", class: normalizeClass(switchKls.value), style: normalizeStyle(switchStyles.value), onClick: _cache[1] || (_cache[1] = (...args) => unref(switchValue) && unref(switchValue)(...args)) }, [ createElementVNode("input", { type: "checkbox", checked: unref(checked), disabled: unref(isDisabled), readonly: unref(isDisabled), class: normalizeClass(unref(ns).e("input")), onChange: _cache[0] || (_cache[0] = (...args) => unref(handleChange) && unref(handleChange)(...args)) }, null, 42, _hoisted_1), createElementVNode( "div", { class: normalizeClass(unref(ns).e("circle")) }, [ renderSlot(_ctx.$slots, "circle"), unref(isLoading) ? (openBlock(), createBlock(unref(IconLoading), { key: 0 })) : createCommentVNode("v-if", true) ], 2 ), _ctx.$slots.on || _ctx.$slots.default ? (openBlock(), createElementBlock( "div", { key: 0, class: normalizeClass([unref(ns).e("text"), unref(ns).is("on")]) }, [ _ctx.$slots.on ? renderSlot(_ctx.$slots, "on", { key: 0 }) : _ctx.$slots.default ? renderSlot(_ctx.$slots, "default", { key: 1 }) : createCommentVNode("v-if", true) ], 2 )) : createCommentVNode("v-if", true), _ctx.$slots.off || _ctx.$slots.default ? (openBlock(), createElementBlock( "div", { key: 1, class: normalizeClass([unref(ns).e("text"), unref(ns).is("off")]) }, [ _ctx.$slots.off ? renderSlot(_ctx.$slots, "off", { key: 0 }) : _ctx.$slots.default ? renderSlot(_ctx.$slots, "default", { key: 1 }) : createCommentVNode("v-if", true) ], 2 )) : createCommentVNode("v-if", true), createElementVNode( "div", { class: normalizeClass(unref(ns).e("background")) }, null, 2 ) ], 6 ); }; } }); var Switch = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "/home/runner/work/vuesax-alpha/vuesax-alpha/packages/components/switch/src/switch.vue"]]); export { Switch as default }; //# sourceMappingURL=switch2.mjs.map