@rinzai/zen 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animated-number/index.d.ts +6 -2
- package/dist/animated-number/index.d.ts.map +1 -1
- package/dist/animated-number/index.js +68 -17
- package/dist/calendar-heatmap/index.d.ts +25 -0
- package/dist/calendar-heatmap/index.d.ts.map +1 -0
- package/dist/calendar-heatmap/index.js +48 -0
- package/dist/chart/allocation.d.ts +30 -0
- package/dist/chart/allocation.d.ts.map +1 -0
- package/dist/chart/allocation.js +69 -0
- package/dist/chart/index.d.ts +1 -0
- package/dist/chart/index.d.ts.map +1 -1
- package/dist/chart/index.js +85 -83
- package/dist/code-block/index.d.ts +1 -1
- package/dist/code-block/index.d.ts.map +1 -1
- package/dist/code-block/index.js +31 -22
- package/dist/collapse/index.d.ts +3 -2
- package/dist/collapse/index.d.ts.map +1 -1
- package/dist/collapse/index.js +1 -1
- package/dist/date-picker/index.d.ts +10 -2
- package/dist/date-picker/index.d.ts.map +1 -1
- package/dist/date-picker/index.js +43 -21
- package/dist/dialog/index.d.ts +4 -2
- package/dist/dialog/index.d.ts.map +1 -1
- package/dist/dialog/index.js +69 -113
- package/dist/editable-cell/index.d.ts +2 -1
- package/dist/editable-cell/index.d.ts.map +1 -1
- package/dist/editable-cell/index.js +24 -17
- package/dist/filter-bar/index.d.ts +21 -0
- package/dist/filter-bar/index.d.ts.map +1 -0
- package/dist/filter-bar/index.js +90 -0
- package/dist/icon-picker/index.d.ts +38 -0
- package/dist/icon-picker/index.d.ts.map +1 -0
- package/dist/icon-picker/index.js +112 -0
- package/dist/icons/arrow-left.js +23 -0
- package/dist/icons/micro/arrow-trending-down.d.ts +3 -0
- package/dist/icons/micro/arrow-trending-down.d.ts.map +1 -0
- package/dist/icons/micro/arrow-trending-down.js +21 -0
- package/dist/icons/micro/arrow-trending-up.d.ts +3 -0
- package/dist/icons/micro/arrow-trending-up.d.ts.map +1 -0
- package/dist/icons/micro/arrow-trending-up.js +21 -0
- package/dist/index.d.ts +17 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/kbd/index.d.ts +4 -0
- package/dist/kbd/index.d.ts.map +1 -0
- package/dist/kbd/index.js +12 -0
- package/dist/keypad/index.d.ts +20 -0
- package/dist/keypad/index.d.ts.map +1 -0
- package/dist/keypad/index.js +42 -0
- package/dist/lib.js +92 -77
- package/dist/load-more/index.d.ts +19 -0
- package/dist/load-more/index.d.ts.map +1 -0
- package/dist/load-more/index.js +37 -0
- package/dist/menu/index.d.ts +22 -3
- package/dist/menu/index.d.ts.map +1 -1
- package/dist/menu/index.js +132 -45
- package/dist/meter/index.d.ts +3 -1
- package/dist/meter/index.d.ts.map +1 -1
- package/dist/meter/index.js +19 -14
- package/dist/money-input/index.d.ts +3 -3
- package/dist/page-transition/index.d.ts +10 -0
- package/dist/page-transition/index.d.ts.map +1 -0
- package/dist/page-transition/index.js +16 -0
- package/dist/progress-ring/index.d.ts +4 -1
- package/dist/progress-ring/index.d.ts.map +1 -1
- package/dist/progress-ring/index.js +47 -38
- package/dist/range-slider/index.d.ts +26 -0
- package/dist/range-slider/index.d.ts.map +1 -0
- package/dist/range-slider/index.js +44 -0
- package/dist/repeat-picker/index.d.ts +22 -0
- package/dist/repeat-picker/index.d.ts.map +1 -0
- package/dist/repeat-picker/index.js +115 -0
- package/dist/slider/index.d.ts +2 -0
- package/dist/slider/index.d.ts.map +1 -1
- package/dist/slider/index.js +19 -18
- package/dist/sortable/index.d.ts +33 -0
- package/dist/sortable/index.d.ts.map +1 -0
- package/dist/sortable/index.js +147 -0
- package/dist/table/index.d.ts +5 -1
- package/dist/table/index.d.ts.map +1 -1
- package/dist/table/index.js +90 -58
- package/dist/table/selection.d.ts +55 -0
- package/dist/table/selection.d.ts.map +1 -0
- package/dist/table/selection.js +83 -0
- package/dist/table/swipe.d.ts +18 -0
- package/dist/table/swipe.d.ts.map +1 -0
- package/dist/table/swipe.js +53 -0
- package/dist/tabs/index.d.ts.map +1 -1
- package/dist/tabs/index.js +101 -51
- package/dist/theme-toggle/index.js +6 -6
- package/dist/theme.css +184 -11
- package/dist/toast/index.js +25 -25
- package/dist/toggle/index.d.ts.map +1 -1
- package/dist/toggle/index.js +1 -1
- package/dist/trend/index.d.ts +19 -0
- package/dist/trend/index.d.ts.map +1 -0
- package/dist/trend/index.js +27 -0
- package/dist/utils/date.d.ts +34 -0
- package/dist/utils/date.d.ts.map +1 -1
- package/dist/utils/date.js +45 -12
- package/dist/utils/money.d.ts +3 -1
- package/dist/utils/money.d.ts.map +1 -1
- package/dist/utils/money.js +24 -1
- package/dist/utils/repeat.d.ts +17 -0
- package/dist/utils/repeat.d.ts.map +1 -0
- package/dist/utils/repeat.js +38 -0
- package/dist/utils/swipe.d.ts +29 -0
- package/dist/utils/swipe.d.ts.map +1 -0
- package/dist/utils/swipe.js +85 -0
- package/dist/utils/useAnchoredPopup.d.ts.map +1 -1
- package/dist/utils/useAnchoredPopup.js +3 -9
- package/dist/zen.css +1 -1
- package/package.json +3 -1
package/dist/table/index.js
CHANGED
|
@@ -3,54 +3,56 @@ import { cx as e } from "../utils/cx.js";
|
|
|
3
3
|
import { reducedMotion as t } from "../utils/motion.js";
|
|
4
4
|
import n from "../icons/chevron-down.js";
|
|
5
5
|
import r from "../icons/chevron-up.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { SelectionBar as i, TableSelectCell as a, TableSelectHead as o, useSelection as s } from "./selection.js";
|
|
7
|
+
import { TableSwipeAction as c, TableSwipeRow as l } from "./swipe.js";
|
|
8
|
+
import { useCallback as u, useEffect as d, useLayoutEffect as f, useMemo as p, useRef as m, useState as h } from "react";
|
|
9
|
+
import { jsx as g, jsxs as _ } from "react/jsx-runtime";
|
|
8
10
|
//#region packages/table/index.tsx
|
|
9
|
-
function
|
|
10
|
-
let
|
|
11
|
-
let e =
|
|
11
|
+
function v({ label: t, className: n, ref: r, onScroll: i, ...a }) {
|
|
12
|
+
let o = m(null), s = u(() => {
|
|
13
|
+
let e = o.current;
|
|
12
14
|
if (!e) return;
|
|
13
15
|
let t = (t, n) => n !== e.hasAttribute(t) && e.toggleAttribute(t, n);
|
|
14
16
|
t("data-under-top", e.scrollTop > 0), t("data-under-left", e.scrollLeft > 0), t("data-under-bottom", e.scrollTop + e.clientHeight < e.scrollHeight - 1);
|
|
15
17
|
}, []);
|
|
16
|
-
return
|
|
17
|
-
let e =
|
|
18
|
+
return d(() => {
|
|
19
|
+
let e = o.current;
|
|
18
20
|
if (!e) return;
|
|
19
|
-
|
|
20
|
-
let t = typeof ResizeObserver > "u" ? null : new ResizeObserver(
|
|
21
|
+
s();
|
|
22
|
+
let t = typeof ResizeObserver > "u" ? null : new ResizeObserver(s);
|
|
21
23
|
return t?.observe(e), e.firstElementChild && t?.observe(e.firstElementChild), () => t?.disconnect();
|
|
22
|
-
}, [
|
|
24
|
+
}, [s]), /* @__PURE__ */ g("div", {
|
|
23
25
|
className: e("zen__table-panel glass glow-edge isolate flex flex-col overflow-hidden rounded-xl", n),
|
|
24
|
-
children: /* @__PURE__ */
|
|
26
|
+
children: /* @__PURE__ */ g("div", {
|
|
25
27
|
ref: (e) => {
|
|
26
|
-
|
|
28
|
+
o.current = e, typeof r == "function" ? r(e) : r && (r.current = e);
|
|
27
29
|
},
|
|
28
30
|
onScroll: (e) => {
|
|
29
|
-
|
|
31
|
+
s(), i?.(e);
|
|
30
32
|
},
|
|
31
33
|
role: t ? "region" : void 0,
|
|
32
34
|
"aria-label": t,
|
|
33
35
|
tabIndex: t ? 0 : void 0,
|
|
34
|
-
className: "zen__table-container focus-visible:ring-ring/30 min-h-0 overflow-auto rounded-[inherit] outline-hidden will-change-scroll focus-visible:ring-2 focus-visible:ring-inset",
|
|
35
|
-
...
|
|
36
|
+
className: "zen__table-container focus-visible:ring-ring/30 relative min-h-0 overflow-auto rounded-[inherit] outline-hidden will-change-scroll focus-visible:ring-2 focus-visible:ring-inset",
|
|
37
|
+
...a
|
|
36
38
|
})
|
|
37
39
|
});
|
|
38
40
|
}
|
|
39
|
-
function
|
|
40
|
-
return /* @__PURE__ */
|
|
41
|
+
function y({ className: t, ...n }) {
|
|
42
|
+
return /* @__PURE__ */ g("table", {
|
|
41
43
|
className: e("zen__table w-full border-separate border-spacing-0 text-sm", t),
|
|
42
44
|
...n
|
|
43
45
|
});
|
|
44
46
|
}
|
|
45
|
-
function
|
|
46
|
-
return /* @__PURE__ */
|
|
47
|
+
function b({ className: t, ...n }) {
|
|
48
|
+
return /* @__PURE__ */ g("thead", {
|
|
47
49
|
className: e("zen__sticky-top sticky top-0 z-20", t),
|
|
48
50
|
...n
|
|
49
51
|
});
|
|
50
52
|
}
|
|
51
|
-
function
|
|
52
|
-
let r =
|
|
53
|
-
return
|
|
53
|
+
function x({ ref: e, ...n }) {
|
|
54
|
+
let r = m(null), i = m(null);
|
|
55
|
+
return C(() => {
|
|
54
56
|
let e = r.current;
|
|
55
57
|
if (!e) return;
|
|
56
58
|
let n = [...e.rows], a = i.current;
|
|
@@ -59,14 +61,19 @@ function h({ ref: e, ...n }) {
|
|
|
59
61
|
if (i.current = {
|
|
60
62
|
rows: n,
|
|
61
63
|
tops: o
|
|
62
|
-
}, !
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
}, !a || t() || e.querySelector("[data-zen-spacer]")) return;
|
|
65
|
+
let s = a.rows.filter((e) => !e.isConnected), c = (e) => e.matches(".zen__tree-row-enter, .zen__tree-row-exit");
|
|
66
|
+
if (!(n.some((e) => !a.tops.has(e) && c(e)) || s.some(c))) {
|
|
67
|
+
if (n.some((e) => a.tops.has(e))) for (let t of s) S(t, a.tops.get(t), e, n);
|
|
68
|
+
for (let e of n) {
|
|
69
|
+
let t = a.tops.get(e);
|
|
70
|
+
t === void 0 ? e.animate?.({
|
|
71
|
+
opacity: [0, 1],
|
|
72
|
+
translate: ["0 -6px", "0 0"]
|
|
73
|
+
}, E) : t !== o.get(e) && e.animate?.({ translate: [`0 ${t - o.get(e)}px`, "0 0"] }, T);
|
|
74
|
+
}
|
|
68
75
|
}
|
|
69
|
-
}), /* @__PURE__ */
|
|
76
|
+
}), /* @__PURE__ */ g("tbody", {
|
|
70
77
|
ref: (t) => {
|
|
71
78
|
if (r.current = t, typeof e == "function") return e(t);
|
|
72
79
|
e && (e.current = t);
|
|
@@ -74,42 +81,67 @@ function h({ ref: e, ...n }) {
|
|
|
74
81
|
...n
|
|
75
82
|
});
|
|
76
83
|
}
|
|
77
|
-
|
|
84
|
+
function S(e, t, n, r) {
|
|
85
|
+
let i = n.closest("table"), a = n.closest(".zen__table-container"), o = r.find((t) => t.cells.length === e.cells.length);
|
|
86
|
+
if (!i || !a || !o) return;
|
|
87
|
+
let s = a.getBoundingClientRect(), c = i.getBoundingClientRect(), l = document.createElement("table");
|
|
88
|
+
l.className = i.className, l.setAttribute("aria-hidden", "true"), Object.assign(l.style, {
|
|
89
|
+
position: "absolute",
|
|
90
|
+
top: `${c.top - s.top + a.scrollTop + t}px`,
|
|
91
|
+
left: `${c.left - s.left + a.scrollLeft}px`,
|
|
92
|
+
width: `${i.offsetWidth}px`,
|
|
93
|
+
tableLayout: "fixed",
|
|
94
|
+
pointerEvents: "none"
|
|
95
|
+
});
|
|
96
|
+
let u = document.createElement("colgroup");
|
|
97
|
+
for (let e of o.cells) u.appendChild(document.createElement("col")).style.width = `${e.offsetWidth}px`;
|
|
98
|
+
l.append(u, document.createElement("tbody")), l.tBodies[0].append(e), a.append(l);
|
|
99
|
+
let d = l.animate?.({
|
|
100
|
+
opacity: [1, 0],
|
|
101
|
+
translate: ["0 0", "-12px 0"]
|
|
102
|
+
}, w);
|
|
103
|
+
d ? d.onfinish = d.oncancel = () => l.remove() : l.remove();
|
|
104
|
+
}
|
|
105
|
+
var C = typeof window > "u" ? d : f, w = {
|
|
106
|
+
duration: 220,
|
|
107
|
+
easing: "ease-in"
|
|
108
|
+
}, T = {
|
|
78
109
|
duration: 320,
|
|
79
110
|
easing: "cubic-bezier(0.2, 0.8, 0.2, 1)"
|
|
80
|
-
},
|
|
111
|
+
}, E = {
|
|
81
112
|
duration: 260,
|
|
82
113
|
easing: "ease-out"
|
|
83
114
|
};
|
|
84
|
-
function
|
|
85
|
-
return /* @__PURE__ */
|
|
115
|
+
function D({ className: t, ...n }) {
|
|
116
|
+
return /* @__PURE__ */ g("tfoot", {
|
|
86
117
|
className: e("zen__sticky-bottom sticky bottom-0 z-20", t),
|
|
87
118
|
...n
|
|
88
119
|
});
|
|
89
120
|
}
|
|
90
|
-
function
|
|
91
|
-
return /* @__PURE__ */
|
|
92
|
-
|
|
93
|
-
|
|
121
|
+
function O({ selected: t, className: n, ...r }) {
|
|
122
|
+
return /* @__PURE__ */ g("tr", {
|
|
123
|
+
"data-selected": t || void 0,
|
|
124
|
+
className: e("group", n),
|
|
125
|
+
...r
|
|
94
126
|
});
|
|
95
127
|
}
|
|
96
|
-
function
|
|
97
|
-
return /* @__PURE__ */
|
|
128
|
+
function k({ numeric: t, sticky: i, sortDirection: a, onSort: o, scope: s = "col", className: c, children: l, ...u }) {
|
|
129
|
+
return /* @__PURE__ */ g("th", {
|
|
98
130
|
scope: s,
|
|
99
131
|
"aria-sort": a === "asc" ? "ascending" : a === "desc" ? "descending" : void 0,
|
|
100
132
|
className: e("border-tint/[0.07] text-muted-foreground border-b px-3 py-2.5 align-middle text-xs leading-5 font-medium tracking-wider whitespace-nowrap uppercase", i === "left" && "zen__sticky-left sticky left-0 z-10", t ? "text-right" : "text-left", c),
|
|
101
|
-
...
|
|
102
|
-
children: o ? /* @__PURE__ */
|
|
133
|
+
...u,
|
|
134
|
+
children: o ? /* @__PURE__ */ _("button", {
|
|
103
135
|
type: "button",
|
|
104
136
|
onClick: o,
|
|
105
137
|
className: e("hover:text-foreground touch-target inline-flex cursor-pointer items-center gap-1 align-middle leading-5 tracking-wider uppercase", t && "flex-row-reverse"),
|
|
106
|
-
children: [l, /* @__PURE__ */
|
|
138
|
+
children: [l, /* @__PURE__ */ g("span", {
|
|
107
139
|
"aria-hidden": !0,
|
|
108
140
|
className: "inline-flex w-3",
|
|
109
|
-
children: a === "asc" ? /* @__PURE__ */
|
|
141
|
+
children: a === "asc" ? /* @__PURE__ */ g(r, {
|
|
110
142
|
className: "size-3",
|
|
111
143
|
strokeWidth: 2.5
|
|
112
|
-
}) : a === "desc" ? /* @__PURE__ */
|
|
144
|
+
}) : a === "desc" ? /* @__PURE__ */ g(n, {
|
|
113
145
|
className: "size-3",
|
|
114
146
|
strokeWidth: 2.5
|
|
115
147
|
}) : null
|
|
@@ -117,23 +149,23 @@ function x({ numeric: t, sticky: i, sortDirection: a, onSort: o, scope: s = "col
|
|
|
117
149
|
}) : l
|
|
118
150
|
});
|
|
119
151
|
}
|
|
120
|
-
function
|
|
121
|
-
return /* @__PURE__ */
|
|
122
|
-
className: e("border-tint/[0.045] border-b px-3 py-2.5 transition-colors duration-150", "group-hover:[background-image:linear-gradient(oklch(var(--tint)/0.035),oklch(var(--tint)/0.035))]", n === "left" && "zen__sticky-left sticky left-0 z-10 shadow-[inset_-1px_0_0_oklch(var(--tint)/0.06)]", t && "text-right tabular-nums", r),
|
|
152
|
+
function A({ numeric: t, sticky: n, className: r, ...i }) {
|
|
153
|
+
return /* @__PURE__ */ g("td", {
|
|
154
|
+
className: e("border-tint/[0.045] border-b px-3 py-2.5 transition-colors duration-150", "group-hover:[background-image:linear-gradient(oklch(var(--tint)/0.035),oklch(var(--tint)/0.035))]", "group-data-selected:[background-image:linear-gradient(oklch(var(--primary)/0.09),oklch(var(--primary)/0.09))]", n === "left" && "zen__sticky-left sticky left-0 z-10 shadow-[inset_-1px_0_0_oklch(var(--tint)/0.06)]", t && "text-right tabular-nums", r),
|
|
123
155
|
...i
|
|
124
156
|
});
|
|
125
157
|
}
|
|
126
|
-
function
|
|
127
|
-
return /* @__PURE__ */
|
|
158
|
+
function j({ numeric: t, sticky: n, className: r, ...i }) {
|
|
159
|
+
return /* @__PURE__ */ g("td", {
|
|
128
160
|
className: e("border-tint/[0.07] h-9 border-t px-3 font-medium whitespace-nowrap", n === "left" && "zen__sticky-left sticky left-0 z-10 shadow-[inset_-1px_0_0_oklch(var(--tint)/0.06)]", t && "text-right tabular-nums", r),
|
|
129
161
|
...i
|
|
130
162
|
});
|
|
131
163
|
}
|
|
132
|
-
function
|
|
133
|
-
return e <= 0 ? null : /* @__PURE__ */
|
|
164
|
+
function M({ height: e, colSpan: t }) {
|
|
165
|
+
return e <= 0 ? null : /* @__PURE__ */ g("tr", {
|
|
134
166
|
"aria-hidden": !0,
|
|
135
167
|
"data-zen-spacer": !0,
|
|
136
|
-
children: /* @__PURE__ */
|
|
168
|
+
children: /* @__PURE__ */ g("td", {
|
|
137
169
|
colSpan: t,
|
|
138
170
|
style: {
|
|
139
171
|
height: e,
|
|
@@ -143,17 +175,17 @@ function w({ height: e, colSpan: t }) {
|
|
|
143
175
|
})
|
|
144
176
|
});
|
|
145
177
|
}
|
|
146
|
-
function
|
|
147
|
-
return /* @__PURE__ */
|
|
178
|
+
function N({ colSpan: e, children: t = "Nothing here yet." }) {
|
|
179
|
+
return /* @__PURE__ */ g("tr", { children: /* @__PURE__ */ g("td", {
|
|
148
180
|
colSpan: e,
|
|
149
181
|
className: "text-muted-foreground px-3 py-8 text-center",
|
|
150
182
|
children: t
|
|
151
183
|
}) });
|
|
152
184
|
}
|
|
153
|
-
function
|
|
154
|
-
let [r, i] =
|
|
185
|
+
function P(e, t, n) {
|
|
186
|
+
let [r, i] = h(n ?? null);
|
|
155
187
|
return {
|
|
156
|
-
rows:
|
|
188
|
+
rows: p(() => {
|
|
157
189
|
if (!r) return e;
|
|
158
190
|
let n = t[r.key], i = [...e].sort(n);
|
|
159
191
|
return r.direction === "desc" ? i.reverse() : i;
|
|
@@ -177,4 +209,4 @@ function E(e, t, n) {
|
|
|
177
209
|
};
|
|
178
210
|
}
|
|
179
211
|
//#endregion
|
|
180
|
-
export {
|
|
212
|
+
export { i as SelectionBar, x as TableBody, A as TableCell, v as TableContainer, N as TableEmpty, D as TableFooter, j as TableFooterCell, k as TableHead, b as TableHeader, O as TableRow, a as TableSelectCell, o as TableSelectHead, M as TableSpacerRow, c as TableSwipeAction, l as TableSwipeRow, y as default, s as useSelection, P as useSort };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ComponentProps, ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Which rows are selected, by key: give it the keys in the order shown.
|
|
4
|
+
* Shift-click selects (or clears) every row between the last one clicked
|
|
5
|
+
* and this one. Keys no longer shown drop out of the selection.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useSelection<K>(keys: readonly K[]): {
|
|
8
|
+
selected: Set<K>;
|
|
9
|
+
clear: () => void;
|
|
10
|
+
/** For a row's TableSelectCell. */
|
|
11
|
+
rowProps: (key: K) => {
|
|
12
|
+
checked: boolean;
|
|
13
|
+
onSelect: (on: boolean, range: boolean) => void;
|
|
14
|
+
};
|
|
15
|
+
/** For the header's TableSelectHead. */
|
|
16
|
+
allProps: () => {
|
|
17
|
+
checked: boolean;
|
|
18
|
+
indeterminate: boolean;
|
|
19
|
+
onSelect: (on: boolean) => void;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
/** A row's checkbox cell; spread `rowProps(key)` from useSelection into it. */
|
|
23
|
+
export declare function TableSelectCell({ checked, onSelect, label, className, ...rest }: TableSelectCellProps): import('react').JSX.Element;
|
|
24
|
+
/** The header's checkbox, for every row at once; spread `allProps()` from useSelection into it. */
|
|
25
|
+
export declare function TableSelectHead({ checked, indeterminate, onSelect, label, className, ...rest }: TableSelectHeadProps): import('react').JSX.Element;
|
|
26
|
+
/**
|
|
27
|
+
* What to do with the selected rows: their count, your actions, and a × to
|
|
28
|
+
* clear the selection. Floats at the bottom of the screen while any are
|
|
29
|
+
* selected (move it with className).
|
|
30
|
+
*/
|
|
31
|
+
export declare function SelectionBar({ count, onClear, label, clearLabel, className, children, }: SelectionBarProps): import('react').JSX.Element | null;
|
|
32
|
+
export interface TableSelectCellProps extends Omit<ComponentProps<'td'>, 'onSelect'> {
|
|
33
|
+
checked: boolean;
|
|
34
|
+
/** With `range` when shift was held. */
|
|
35
|
+
onSelect: (on: boolean, range: boolean) => void;
|
|
36
|
+
/** The checkbox's name, e.g. "Select Rent". */
|
|
37
|
+
label: string;
|
|
38
|
+
}
|
|
39
|
+
export interface TableSelectHeadProps extends Omit<ComponentProps<'th'>, 'onSelect'> {
|
|
40
|
+
checked: boolean;
|
|
41
|
+
indeterminate: boolean;
|
|
42
|
+
onSelect: (on: boolean) => void;
|
|
43
|
+
label?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface SelectionBarProps {
|
|
46
|
+
count: number;
|
|
47
|
+
onClear: () => void;
|
|
48
|
+
/** The count as text (default "3 selected"). */
|
|
49
|
+
label?: (count: number) => string;
|
|
50
|
+
clearLabel?: string;
|
|
51
|
+
className?: string;
|
|
52
|
+
/** The actions, e.g. buttons to delete or re-tag them. */
|
|
53
|
+
children?: ReactNode;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=selection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection.d.ts","sourceRoot":"","sources":["../../packages/table/selection.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAc,SAAS,EAAoB,MAAM,OAAO,CAAC;AAEhF;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE;;;IAoB1C,mCAAmC;oBACnB,CAAC;;uBAEE,OAAO,SAAS,OAAO;;IAO1C,wCAAwC;;;;uBAIrB,OAAO;;EAGjC;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,EAAE,oBAAoB,+BAYrG;AAED,mGAAmG;AACnG,wBAAgB,eAAe,CAAC,EAC5B,OAAO,EACP,aAAa,EACb,QAAQ,EACR,KAAoB,EACpB,SAAS,EACT,GAAG,IAAI,EACV,EAAE,oBAAoB,+BAYtB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,EACzB,KAAK,EACL,OAAO,EACP,KAA8B,EAC9B,UAA8B,EAC9B,SAAS,EACT,QAAQ,GACX,EAAE,iBAAiB,sCAyBnB;AAED,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;IAChF,OAAO,EAAE,OAAO,CAAC;IACjB,wCAAwC;IACxC,QAAQ,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAChD,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;IAChF,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,CAAC,EAAE,EAAE,OAAO,KAAK,IAAI,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,gDAAgD;IAChD,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,SAAS,CAAC;CACxB"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx as e } from "../utils/cx.js";
|
|
3
|
+
import t from "../icons/micro/x-mark.js";
|
|
4
|
+
import n from "../checkbox/index.js";
|
|
5
|
+
import { useRef as r, useState as i } from "react";
|
|
6
|
+
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
7
|
+
//#region packages/table/selection.tsx
|
|
8
|
+
function s(e) {
|
|
9
|
+
let [t, n] = i(() => /* @__PURE__ */ new Set()), a = r(null), o = new Set(e), s = new Set([...t].filter((e) => o.has(e))), c = e.length > 0 && s.size === e.length, l = (e, t) => n((n) => {
|
|
10
|
+
let r = new Set([...n].filter((e) => o.has(e)));
|
|
11
|
+
for (let n of e) t ? r.add(n) : r.delete(n);
|
|
12
|
+
return r;
|
|
13
|
+
});
|
|
14
|
+
return {
|
|
15
|
+
selected: s,
|
|
16
|
+
clear: () => n(/* @__PURE__ */ new Set()),
|
|
17
|
+
rowProps: (t) => ({
|
|
18
|
+
checked: s.has(t),
|
|
19
|
+
onSelect: (n, r) => {
|
|
20
|
+
let i = r && a.current !== null ? e.indexOf(a.current) : -1, o = e.indexOf(t);
|
|
21
|
+
l(i === -1 ? [t] : e.slice(Math.min(i, o), Math.max(i, o) + 1), n), a.current = t;
|
|
22
|
+
}
|
|
23
|
+
}),
|
|
24
|
+
allProps: () => ({
|
|
25
|
+
checked: c,
|
|
26
|
+
indeterminate: s.size > 0 && !c,
|
|
27
|
+
onSelect: (t) => l(e, t)
|
|
28
|
+
})
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function c({ checked: t, onSelect: r, label: i, className: o, ...s }) {
|
|
32
|
+
return /* @__PURE__ */ a("td", {
|
|
33
|
+
className: e("border-tint/[0.045] w-10 border-b py-2.5 pr-0 pl-3", o),
|
|
34
|
+
...s,
|
|
35
|
+
children: /* @__PURE__ */ a(n, {
|
|
36
|
+
"aria-label": i,
|
|
37
|
+
checked: t,
|
|
38
|
+
onClick: (e) => r(e.currentTarget.checked, e.shiftKey),
|
|
39
|
+
onChange: () => {},
|
|
40
|
+
className: "touch-target grid"
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function l({ checked: t, indeterminate: r, onSelect: i, label: o = "Select all", className: s, ...c }) {
|
|
45
|
+
return /* @__PURE__ */ a("th", {
|
|
46
|
+
className: e("w-10 py-2.5 pr-0 pl-3", s),
|
|
47
|
+
...c,
|
|
48
|
+
children: /* @__PURE__ */ a(n, {
|
|
49
|
+
"aria-label": o,
|
|
50
|
+
checked: t,
|
|
51
|
+
indeterminate: r,
|
|
52
|
+
onChange: (e) => i(!r && e),
|
|
53
|
+
className: "touch-target grid"
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function u({ count: n, onClear: r, label: i = (e) => `${e} selected`, clearLabel: s = "Clear selection", className: c, children: l }) {
|
|
58
|
+
return n === 0 ? null : /* @__PURE__ */ o("div", {
|
|
59
|
+
role: "toolbar",
|
|
60
|
+
"aria-label": "Selection",
|
|
61
|
+
className: e("zen__selection-bar glass glass-blur glow-edge fixed inset-x-0 bottom-6 z-40 mx-auto flex w-fit max-w-[calc(100vw-2rem)] items-center gap-2 rounded-2xl py-2 pr-2 pl-4 shadow-[0_12px_40px_-12px_oklch(0_0_0/0.6)]", c),
|
|
62
|
+
children: [
|
|
63
|
+
/* @__PURE__ */ a("span", {
|
|
64
|
+
className: "text-sm font-medium whitespace-nowrap tabular-nums",
|
|
65
|
+
"aria-live": "polite",
|
|
66
|
+
children: i(n)
|
|
67
|
+
}),
|
|
68
|
+
/* @__PURE__ */ a("span", {
|
|
69
|
+
className: "flex items-center gap-1",
|
|
70
|
+
children: l
|
|
71
|
+
}),
|
|
72
|
+
/* @__PURE__ */ a("button", {
|
|
73
|
+
type: "button",
|
|
74
|
+
"aria-label": s,
|
|
75
|
+
onClick: r,
|
|
76
|
+
className: "text-muted-foreground hover:text-foreground hover:bg-tint/10 focus-visible:ring-ring/50 touch-target grid size-8 cursor-pointer place-items-center rounded-lg outline-hidden focus-visible:ring-2",
|
|
77
|
+
children: /* @__PURE__ */ a(t, { className: "size-4" })
|
|
78
|
+
})
|
|
79
|
+
]
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
export { u as SelectionBar, c as TableSelectCell, l as TableSelectHead, s as useSelection };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ComponentProps, ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A row whose actions sit behind it at its end: swipe it left to reveal them
|
|
4
|
+
* (right, in right-to-left layouts), back (or tap the row) to put them away. They also come out when focused, so the
|
|
5
|
+
* keyboard reaches them. Use it in a TableContainer.
|
|
6
|
+
*/
|
|
7
|
+
export declare function TableSwipeRow({ actions, ref, className, children, onClickCapture, onBlur, ...rest }: TableSwipeRowProps): import('react').JSX.Element;
|
|
8
|
+
/** One of a swipe row's actions: fills the row's height, flush with its end. */
|
|
9
|
+
export declare function TableSwipeAction({ tone, className, ...rest }: TableSwipeActionProps): import('react').JSX.Element;
|
|
10
|
+
export interface TableSwipeActionProps extends ComponentProps<'button'> {
|
|
11
|
+
tone?: 'default' | 'destructive';
|
|
12
|
+
}
|
|
13
|
+
export interface TableSwipeRowProps extends ComponentProps<'tr'> {
|
|
14
|
+
/** What's behind the row: TableSwipeActions, e.g. Edit and Delete. */
|
|
15
|
+
actions: ReactNode;
|
|
16
|
+
selected?: boolean;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=swipe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swipe.d.ts","sourceRoot":"","sources":["../../packages/table/swipe.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAoB,MAAM,OAAO,CAAC;AAIpE;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,EAC1B,OAAO,EACP,GAAG,EACH,SAAS,EACT,QAAQ,EACR,cAAc,EACd,MAAM,EACN,GAAG,IAAI,EACV,EAAE,kBAAkB,+BA2DpB;AAED,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,EAAE,IAAgB,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,EAAE,qBAAqB,+BAc/F;AAED,MAAM,WAAW,qBAAsB,SAAQ,cAAc,CAAC,QAAQ,CAAC;IACnE,IAAI,CAAC,EAAE,SAAS,GAAG,aAAa,CAAC;CACpC;AAED,MAAM,WAAW,kBAAmB,SAAQ,cAAc,CAAC,IAAI,CAAC;IAC5D,sEAAsE;IACtE,OAAO,EAAE,SAAS,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx as e } from "../utils/cx.js";
|
|
3
|
+
import { useSwipe as t } from "../utils/swipe.js";
|
|
4
|
+
import { TableRow as n } from "./index.js";
|
|
5
|
+
import { useRef as r, useState as i } from "react";
|
|
6
|
+
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
7
|
+
//#region packages/table/swipe.tsx
|
|
8
|
+
function s({ actions: s, ref: c, className: l, children: u, onClickCapture: d, onBlur: f, ...p }) {
|
|
9
|
+
let m = r(null), h = r(null), [g, _] = i(!1), v = () => h.current?.offsetWidth ?? 0, y = (e) => m.current?.style.setProperty("--zen-row-swipe", `${Math.max(0, e)}px`), b = (e) => {
|
|
10
|
+
y(e ? v() : 0), _(e);
|
|
11
|
+
}, x = (e) => e > v() ? v() + (e - v()) / 4 : e;
|
|
12
|
+
return t(m, {
|
|
13
|
+
axis: "inline",
|
|
14
|
+
sign: g ? 1 : -1
|
|
15
|
+
}, {
|
|
16
|
+
move: (e) => y(x(g ? v() - e : e)),
|
|
17
|
+
release: (e, t) => b(g !== (e > v() / 2 || t > .5)),
|
|
18
|
+
cancel: () => b(g),
|
|
19
|
+
threshold: () => v() / 2
|
|
20
|
+
}), /* @__PURE__ */ o(n, {
|
|
21
|
+
ref: (e) => {
|
|
22
|
+
m.current = e, typeof c == "function" ? c(e) : c && (c.current = e);
|
|
23
|
+
},
|
|
24
|
+
"data-open": g || void 0,
|
|
25
|
+
className: e("zen__swipe-row relative", l),
|
|
26
|
+
onClickCapture: (e) => {
|
|
27
|
+
d?.(e), g && !h.current?.contains(e.target) && (e.preventDefault(), e.stopPropagation(), b(!1));
|
|
28
|
+
},
|
|
29
|
+
onBlur: (e) => {
|
|
30
|
+
f?.(e), g && !e.currentTarget.contains(e.relatedTarget) && b(!1);
|
|
31
|
+
},
|
|
32
|
+
...p,
|
|
33
|
+
children: [u, /* @__PURE__ */ a("td", {
|
|
34
|
+
className: "zen__swipe-actions border-tint/[0.045] absolute inset-y-0 start-full flex w-(--zen-row-swipe,0px) justify-end overflow-hidden border-b p-0",
|
|
35
|
+
children: /* @__PURE__ */ a("div", {
|
|
36
|
+
ref: h,
|
|
37
|
+
onFocus: () => !g && b(!0),
|
|
38
|
+
onClick: () => b(!1),
|
|
39
|
+
className: "flex shrink-0 items-stretch",
|
|
40
|
+
children: s
|
|
41
|
+
})
|
|
42
|
+
})]
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function c({ tone: t = "default", className: n, ...r }) {
|
|
46
|
+
return /* @__PURE__ */ a("button", {
|
|
47
|
+
type: "button",
|
|
48
|
+
className: e("focus-visible:ring-ring/60 cursor-pointer px-4 text-sm font-medium whitespace-nowrap outline-hidden transition-colors focus-visible:ring-2 focus-visible:ring-inset", t === "destructive" ? "bg-destructive/90 text-destructive-foreground hover:bg-destructive" : "bg-tint/[0.09] hover:bg-tint/[0.14]", n),
|
|
49
|
+
...r
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { c as TableSwipeAction, s as TableSwipeRow };
|
package/dist/tabs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/tabs/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/tabs/index.tsx"],"names":[],"mappings":"AAKA,OAAO,EACH,cAAc,EASjB,MAAM,OAAO,CAAC;AAsBf,6GAA6G;AAC7G,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,EAAE,KAAK,EAAE,YAAiB,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,EAAE,SAAS,+BAuBtG;AAID;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,EAAE,OAAqB,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,EAAE,YAAY,+BAiC5F;AAiCD,wBAAgB,GAAG,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,QAAQ,+BA0BnE;AAED,wBAAgB,QAAQ,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,EAAE,aAAa,sCA6BpE;AA4DD,MAAM,WAAW,SAAU,SAAQ,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC;IAC1E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3C;AAED,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,OAAO,CAAC;AAEnD,MAAM,WAAW,YAAa,SAAQ,cAAc,CAAC,KAAK,CAAC;IACvD,OAAO,CAAC,EAAE,cAAc,CAAC;CAC5B;AAED,MAAM,WAAW,QAAS,SAAQ,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACrE,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAc,SAAQ,cAAc,CAAC,KAAK,CAAC;IACxD,KAAK,EAAE,MAAM,CAAC;CACjB"}
|