@uva-glass/component-library
Version:
React components UvA
159 lines (158 loc) • 6.82 kB
JavaScript
import { jsx as _, jsxs as A } from "react/jsx-runtime";
import { fn as w } from "../../index-DXR-TB1d.js";
import { s as g, j as V, V as j } from "../../index-DH9Vbk37.js";
import { useState as D } from "react";
import { CheckboxTree as O } from "./CheckboxTree.js";
import { Chip as I } from "../Chip/Chip.js";
let y;
const k = new Uint8Array(16);
function M() {
if (!y && (y = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !y))
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
return y(k);
}
const c = [];
for (let e = 0; e < 256; ++e)
c.push((e + 256).toString(16).slice(1));
function P(e, t = 0) {
return c[e[t + 0]] + c[e[t + 1]] + c[e[t + 2]] + c[e[t + 3]] + "-" + c[e[t + 4]] + c[e[t + 5]] + "-" + c[e[t + 6]] + c[e[t + 7]] + "-" + c[e[t + 8]] + c[e[t + 9]] + "-" + c[e[t + 10]] + c[e[t + 11]] + c[e[t + 12]] + c[e[t + 13]] + c[e[t + 14]] + c[e[t + 15]];
}
const N = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), E = {
randomUUID: N
};
function U(e, t, n) {
if (E.randomUUID && !e)
return E.randomUUID();
e = e || {};
const r = e.random || (e.rng || M)();
return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, P(r);
}
var $ = Object.defineProperty, K = (e, t) => {
for (var n in t) $(e, n, { get: t[n], enumerable: !0 });
}, B = "storybook/actions", F = `${B}/action-event`, L = { depth: 10, clearOnStoryChange: !0, limit: 50 }, C = (e, t) => {
let n = Object.getPrototypeOf(e);
return !n || t(n) ? n : C(n, t);
}, W = (e) => !!(typeof e == "object" && e && C(e, (t) => /^Synthetic(?:Base)?Event$/.test(t.constructor.name)) && typeof e.persist == "function"), Y = (e) => {
if (W(e)) {
let t = Object.create(e.constructor.prototype, Object.getOwnPropertyDescriptors(e));
t.persist();
let n = Object.getOwnPropertyDescriptor(t, "view"), r = n == null ? void 0 : n.value;
return typeof r == "object" && (r == null ? void 0 : r.constructor.name) === "Window" && Object.defineProperty(t, "view", { ...n, value: Object.create(r.constructor.prototype) }), t;
}
return e;
}, z = () => typeof crypto == "object" && typeof crypto.getRandomValues == "function" ? U() : Date.now().toString(36) + Math.random().toString(36).substring(2);
function h(e, t = {}) {
let n = { ...L, ...t }, r = function(...o) {
var b, T;
if (t.implicit) {
let f = (b = "__STORYBOOK_PREVIEW__" in g ? g.__STORYBOOK_PREVIEW__ : void 0) == null ? void 0 : b.storyRenders.find((u) => u.phase === "playing" || u.phase === "rendering");
if (f) {
let u = !((T = globalThis == null ? void 0 : globalThis.FEATURES) != null && T.disallowImplicitActionsInRenderV8), x = new V({ phase: f.phase, name: e, deprecated: u });
if (u) console.warn(x);
else throw x;
}
}
let i = j.getChannel(), a = z(), s = 5, l = o.map(Y), p = o.length > 1 ? l : l[0], d = { id: a, count: 0, data: { name: e, args: p }, options: { ...n, maxDepth: s + (n.depth || 3), allowFunction: n.allowFunction || !1 } };
i.emit(F, d);
};
return r.isAction = !0, r.implicit = t.implicit, r;
}
var H = {};
K(H, { argsEnhancers: () => X, loaders: () => Q });
var v = (e, t) => typeof t[e] > "u" && !(e in t), J = (e) => {
let { initialArgs: t, argTypes: n, id: r, parameters: { actions: o } } = e;
if (!o || o.disable || !o.argTypesRegex || !n) return {};
let i = new RegExp(o.argTypesRegex);
return Object.entries(n).filter(([a]) => !!i.test(a)).reduce((a, [s, l]) => (v(s, t) && (a[s] = h(s, { implicit: !0, id: r })), a), {});
}, G = (e) => {
let { initialArgs: t, argTypes: n, parameters: { actions: r } } = e;
return r != null && r.disable || !n ? {} : Object.entries(n).filter(([o, i]) => !!i.action).reduce((o, [i, a]) => (v(i, t) && (o[i] = h(typeof a.action == "string" ? a.action : i)), o), {});
}, X = [G, J], R = !1, q = (e) => {
let { parameters: { actions: t } } = e;
if (!(t != null && t.disable) && !R && "__STORYBOOK_TEST_ON_MOCK_CALL__" in g && typeof g.__STORYBOOK_TEST_ON_MOCK_CALL__ == "function") {
let n = g.__STORYBOOK_TEST_ON_MOCK_CALL__;
n((r, o) => {
let i = r.getMockName();
i !== "spy" && (!/^next\/.*::/.test(i) || ["next/router::useRouter()", "next/navigation::useRouter()", "next/navigation::redirect", "next/cache::", "next/headers::cookies().set", "next/headers::cookies().delete", "next/headers::headers().set", "next/headers::headers().delete"].some((a) => i.startsWith(a))) && h(i)(o);
}), R = !0;
}
}, Q = [q];
const Z = (e, t, n) => {
const r = Array.from({ length: t }, (s, l) => l + 1), o = (s) => {
const l = Math.ceil(parseInt(s) / n), p = l === n ? "" : `.${parseInt(s) % n || n}`;
return `${l}${p}`;
}, i = r.map((s) => ({
itemName: o(String(s)),
itemValue: s,
disabled: !1
}));
return r.reduce((s, l, p) => {
const d = Math.ceil(l / n);
return e.includes(String(p + 1)) && (s[d] || (s[d] = {
itemName: `Semester ${d}`,
children: []
}), s[d].children.push({
...i[p],
itemValue: String(i[p].itemValue)
})), s;
}, []);
}, ee = 7, te = 3, S = Z(
["1", "2", "3", "4", "5", "6", "7"],
ee,
te
), ne = "<CheckboxTree title={} checkboxTree={} selectedValues={} onChange={} />", me = {
title: "Organisms/CheckboxTree",
component: O,
parameters: {
inspectComponent: O,
codeString: ne
}
}, re = (e) => /* @__PURE__ */ _(O, { ...e }), oe = re.bind({});
oe.args = {
title: "Periode",
checkboxTree: S,
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
selectedValues: ["3", "4"],
onChange: w()
};
const m = 3, ie = (e) => {
const t = Math.ceil(parseInt(e) / m), n = t === m ? "" : `.${parseInt(e) % m || m}`;
return `${t}${n}`;
}, se = (e) => {
const [t, n] = e.split(".").map(Number);
return `${(t - 1) * m + (n || 1)}`;
}, ge = () => {
const [e, t] = D(["5", "4", "1"]), n = (o) => {
const i = JSON.parse(JSON.stringify(e)).filter(
(a) => a !== se(o)
);
t(() => i), h("onChange value:")(i);
}, r = (o) => {
t([...o]), h("onChange value:")(o);
};
return /* @__PURE__ */ A("div", { style: { width: "15rem" }, children: [
/* @__PURE__ */ _("div", { style: { display: "flex", flexWrap: "wrap", gap: "0.5rem", width: "100%", marginBottom: "1rem" }, children: e && e.map((o, i) => /* @__PURE__ */ _(
I,
{
label: ie(o),
onDelete: n
},
`${i}_${o}`
)) }),
/* @__PURE__ */ _(
O,
{
title: "Periode",
checkboxTree: S,
selectedValues: e,
onChange: r
}
)
] });
};
export {
oe as CheckboxTreeExample,
ge as CheckboxTreeWithChips,
me as default
};
//# sourceMappingURL=CheckboxTree.stories.js.map