UNPKG

yanzhen-design-vue

Version:

70 lines (69 loc) 2.48 kB
import { defineComponent, computed, mergeProps, useSlots, ref, openBlock, createBlock, unref as unref$1, isRef, createSlots, renderList, withCtx, renderSlot, normalizeProps, guardReactiveProps } from "vue"; import { Switch } from "ant-design-vue"; import { useDynamicProps, useModelValue, useProxyProps, unref } from "@yanzhen-libs/utils-vue"; import { pick } from "lodash-es"; import { switchName, switchProps, switchEmits, switchOptions, AntSwitchProps } from "./switch.mjs"; const _sfc_main = /* @__PURE__ */ defineComponent({ ...{ name: switchName }, __name: "switch", props: switchProps, emits: switchEmits, setup(__props, { expose: __expose, emit: __emit }) { const { ns } = switchOptions; const props = __props; const emit = __emit; const props1 = useDynamicProps({ update: true }); const checked = props1.includes("checked") ? useModelValue(props, "checked", emit) : useModelValue(props, null, emit); const styleRef = computed(() => { return checked.value ? { backgroundColor: props.activeColor } : {}; }); const config = computed(() => pick(props, ...Object.keys(AntSwitchProps.props))); const proxyProps = useProxyProps(config, AntSwitchProps.emits, { emit, exclude: ["checked", "value"], filter: (key) => { switch (key) { case "onUpdate:checked": case "onUpdate:value": return false; } return true; } }); const propsRef = computed(() => { return mergeProps( { style: [unref(styleRef)] }, unref(proxyProps) ); }); const slots = useSlots(); const slotKeys = Object.keys(slots); const _ref = ref(); __expose({ ref: _ref }); return (_ctx, _cache) => { return openBlock(), createBlock(unref$1(Switch), mergeProps({ ref_key: "_ref", ref: _ref, checked: unref$1(checked), "onUpdate:checked": _cache[0] || (_cache[0] = ($event) => isRef(checked) ? checked.value = $event : null), class: [unref$1(ns).b()] }, propsRef.value), createSlots({ _: 2 }, [ renderList(unref$1(slotKeys), (slot) => { return { name: slot, fn: withCtx((slotItem) => [ renderSlot(_ctx.$slots, slot, normalizeProps(guardReactiveProps(slotItem))) ]) }; }) ]), 1040, ["checked", "class"]); }; } }); export { _sfc_main as default };