t-fighting-design
Version:
Fighting design can quickly build interactive interfaces in vue3 applications, which looks good.
80 lines (79 loc) • 2.61 kB
JavaScript
import { defineComponent as p, ref as v, computed as s, openBlock as n, createElementBlock as c, normalizeClass as x, unref as d, withDirectives as y, createElementVNode as i, isRef as g, vModelCheckbox as C, createCommentVNode as b, renderSlot as V, Fragment as G, createTextVNode as E, toDisplayString as N, getCurrentInstance as j, inject as F } from "vue";
import { Props as I, Emits as P } from "./index3.js";
import { checkboxGroupPropsKey as A } from "../../checkbox-group/src/index3.js";
const B = ["value"], D = {
key: 0,
class: "f-checkbox__box"
}, S = { class: "f-checkbox__text" }, $ = p({
name: "FCheckbox"
}), M = /* @__PURE__ */ p({
...$,
props: I,
emits: P,
setup(f, { emit: m }) {
const o = f, l = v(null);
(() => {
const { parent: e } = j(), t = e.type.name;
t && t === "FCheckboxGroup" && (l.value = F(A));
})();
const u = s(() => !!l.value || !1), r = s({
get() {
var e;
return u.value ? (e = l.value) == null ? void 0 : e.modelValue : o.modelValue;
},
set(e) {
var t, a;
if (u.value)
!o.disabled && !((t = l.value) != null && t.disabled) && ((a = l.value) == null || a.changeEvent(e));
else {
if (o.disabled)
return;
m("update:modelValue", e);
}
}
}), h = s(() => {
const e = r.value;
return Array.isArray(e) ? e.includes(o.label) : typeof e == "boolean" ? e : e === o.label;
}), k = s(() => {
var e, t;
return [
"f-checkbox",
{
"f-checkbox__selected": h.value,
"f-checkbox__bordered": (e = l.value) == null ? void 0 : e.border,
"f-checkbox__disabled": o.disabled || ((t = l.value) == null ? void 0 : t.disabled)
}
];
});
return (e, t) => {
var a;
return n(), c("label", {
role: "checkbox",
"aria-checked": "false",
tabindex: "0",
"aria-labelledby": "chk1-label",
class: x(d(k))
}, [
y(i("input", {
"onUpdate:modelValue": t[0] || (t[0] = (_) => g(r) ? r.value = _ : null),
type: "checkbox",
class: "f-checkbox__input",
hidden: "",
value: e.label
}, null, 8, B), [
[C, d(r)]
]),
(a = l.value) != null && a.border ? b("", !0) : (n(), c("span", D)),
i("span", S, [
V(e.$slots, "default"),
e.$slots.default ? b("", !0) : (n(), c(G, { key: 0 }, [
E(N(e.label), 1)
], 64))
])
], 2);
};
}
});
export {
M as default
};