UNPKG

ant-design-x-vue-next

Version:

Ant Design X for Vue — community continuation aligned with @ant-design/x

117 lines (116 loc) 3.1 kB
import { defineComponent as X, ref as v, useAttrs as E, useSlots as I, watch as R, computed as g, createVNode as y, mergeProps as T } from "vue"; import { Button as j } from "ant-design-vue"; import { b as S } from "../chunks/module-chunk.mjs"; import q from "../_util/hooks/use-x-component-config.mjs"; import "../x-provider/index.mjs"; import z from "./style/index.mjs"; import D from "../x-provider/hooks/use-x-provider-context.mjs"; const O = /* @__PURE__ */ X({ name: "AXSenderSwitch", inheritAttrs: !1, __name: "SenderSwitch", props: { prefixCls: { default: void 0 }, rootClassName: { default: "" }, checkedChildren: { type: [String, Boolean], default: void 0 }, unCheckedChildren: { type: [String, Boolean], default: void 0 }, value: { type: Boolean, default: void 0 }, defaultValue: { type: Boolean, default: !1 }, icon: { type: [String, Boolean], default: void 0 }, loading: { type: Boolean, default: !1 }, disabled: { type: Boolean, default: !1 }, classNames: { default: () => ({}) }, styles: { default: () => ({}) } }, emits: ["change", "update:value"], setup(x, { expose: k, emit: w }) { const r = v(), e = x, i = w, u = E(), l = I(), c = q("sender"), { direction: B, getPrefixCls: N } = D(), o = N("sender", e.prefixCls), s = `${o}-switch`, [b, V, _] = z(o), d = v(e.defaultValue); R(() => e.value, (t) => { t !== void 0 && (d.value = t); }, { immediate: !0 }); const a = g(() => e.value !== void 0 ? e.value : d.value), A = g(() => { var t, n; return S(o, s, u.class, e.rootClassName, (t = c.value.classNames) == null ? void 0 : t.switch, (n = e.classNames) == null ? void 0 : n.root, V.value, _, { [`${s}-checked`]: a.value, [`${s}-rtl`]: B.value === "rtl" }); }), $ = () => { if (e.disabled || e.loading) return; const t = !a.value; e.value === void 0 && (d.value = t), i("update:value", t), i("change", t); }; return k({ nativeElement: r }), () => { var f, m, p, h; const { class: t, style: n, ...P } = u; return b(y("div", T(P, { ref: r, class: A.value, style: { ...n, ...(f = c.value.styles) == null ? void 0 : f.switch, ...(m = e.styles) == null ? void 0 : m.root } }), [y(j, { disabled: e.disabled, loading: e.loading, class: S(`${s}-content`, (p = e.classNames) == null ? void 0 : p.content), style: (h = e.styles) == null ? void 0 : h.content, type: a.value ? "primary" : "default", ghost: !0, icon: e.icon, onClick: $ }, { default: () => { var C; return [a.value ? e.checkedChildren : e.unCheckedChildren, (C = l.default) == null ? void 0 : C.call(l)]; } })])); }; } }); export { O as default };