UNPKG

y-design-ssr

Version:

SSR component library of YUI with Vue3

140 lines (139 loc) 3.38 kB
import { ref as m, reactive as y, inject as g, getCurrentInstance as h, watch as p, onUnmounted as v, defineComponent as V, computed as c, createVNode as s } from "vue"; const o = (e, t) => t ? typeof t == "string" ? ` ${e}--${t}` : Array.isArray(t) ? t.reduce((a, n) => a + o(e, n), "") : Object.keys(t).reduce( (a, n) => a + (t[n] ? o(e, n) : ""), "" ) : "", C = (e) => (t, a) => { let n = t, l = a; return n && typeof n != "string" && (l = n, n = ""), n = n ? `${e}__${n}` : e, `${n}${o(n, l)}`; }, $ = () => (e, t) => t ? `${o(`y-${e}`, t)}` : `y-${e}`, z = { "pull-refresh": { pulling: "下拉刷新...", loosing: "释放刷新...", loading: "数据加载中...", success: "数据已更新", failed: "数据跟新失败,请稍后再试" }, "form-item": { validateMessage: "请输入正确内容" } }; m("zh-CN"); y({ "zh-CN": z }); const b = (e) => { const t = `y-${e}`; return [t, C(t), $()]; }, x = (e) => isNaN(Number(e)) && typeof e == "string" ? e : `${e}px`, N = "y-form-item", w = () => { const e = g(N, null), t = h(); if (e && (t != null && t.proxy)) { const { setField: a } = e, { resetValidation: n, change: l, validateWithTrigger: i } = e; return p( () => t.proxy.modelValue, () => { e.instance && e.instance.exposed && (n(), l(), i("onChange")); } ), a(t), v(() => a(null)), { parent: e }; } return { parent: null }; }, [S, u] = b("switch"), B = /* @__PURE__ */ V({ name: S, props: { size: { type: [Number, String], default: null }, disabled: { type: Boolean, default: !1 }, readonly: { type: Boolean, default: !1 }, modelValue: { type: Boolean, default: !1 }, activeValue: { type: Boolean, default: !0 }, inactiveValue: { type: Boolean, default: !1 }, activeColor: { type: String, default: "" }, inactiveColor: { type: String, default: "" } }, emits: ["change", "update:modelValue"], setup(e, { emit: t }) { const { parent: a } = w(), n = c(() => e.modelValue === e.activeValue), l = () => { if (!e.disabled && !e.readonly) { const r = n.value ? e.inactiveValue : e.activeValue; t("update:modelValue", r), t("change", r); } }, i = c(() => { switch (e.size || (a == null ? void 0 : a.getProp("size")) || "middle") { case "large": return "34px"; case "middle": return "28px"; case "small": return "24px"; default: return x(e.size); } }); return () => { const { disabled: r, activeColor: d, inactiveColor: f } = e; return s("div", { class: u("", { on: n.value, disabled: r }), style: { fontSize: i.value, backgroundColor: n.value ? d : f }, "aria-checked": n.value, onClick: l, role: "switch" }, [s("div", { class: u("node", { on: n.value, disabled: r }) }, null)]); }; } }); function _(e) { const t = e; return t.install = (a) => { const { name: n } = e; n && a.component(n, e); }, t; } const I = _(B); export { I as default };