@ztwoint/z-ui 0.1.107 → 0.1.108

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.
@@ -0,0 +1,4 @@
1
+ export * from './z2-table';
2
+ export * from './z2-table-context';
3
+ export * from './z2-table-pagination';
4
+ export * from './z2-column-header';
@@ -0,0 +1,186 @@
1
+ import { jsx as t, jsxs as r, Fragment as b } from "react/jsx-runtime";
2
+ import "react";
3
+ import { cn as R } from "../../lib/utils.js";
4
+ import { Button as V } from "../button/button.js";
5
+ import { useZ2Table as j } from "./z2-table-context.js";
6
+ import { Z2DropdownMenu as U, Z2DropdownMenuTrigger as B, Z2DropdownMenuContent as F, Z2DropdownMenuLabel as H, Z2DropdownMenuSeparator as f, Z2DropdownMenuItem as g, Z2DropdownMenuSub as _, Z2DropdownMenuSubTrigger as $, Z2DropdownMenuPortal as q, Z2DropdownMenuSubContent as E, Z2DropdownMenuCheckboxItem as G } from "../dropdown-menu/z2-dropdown-menu.js";
7
+ import { ArrowUp as I, Check as C, ArrowDown as L, ArrowLeftToLine as J, ArrowRightToLine as K, ArrowLeft as Q, ArrowRight as W, Settings2 as X, ChevronsUpDown as Y, PinOff as ee } from "lucide-react";
8
+ function le({
9
+ column: e,
10
+ title: p = "",
11
+ icon: m,
12
+ className: k,
13
+ filter: d,
14
+ visibility: h = !1
15
+ }) {
16
+ var M, z, y, P;
17
+ const { isLoading: Z, table: u, props: o, recordCount: v } = j(), S = (a) => {
18
+ const s = [...u.getState().columnOrder], n = s.indexOf(e.id);
19
+ if (a === "left" && n > 0) {
20
+ const i = [...s], [c] = i.splice(n, 1);
21
+ i.splice(n - 1, 0, c), u.setColumnOrder(i);
22
+ }
23
+ if (a === "right" && n < s.length - 1) {
24
+ const i = [...s], [c] = i.splice(n, 1);
25
+ i.splice(n + 1, 0, c), u.setColumnOrder(i);
26
+ }
27
+ }, N = (a) => {
28
+ const s = u.getState().columnOrder, n = s.indexOf(e.id);
29
+ return a === "left" ? n > 0 : n < s.length - 1;
30
+ }, O = () => /* @__PURE__ */ r(
31
+ "div",
32
+ {
33
+ className: R(
34
+ "inline-flex h-full items-center gap-1.5 [&_svg]:size-3.5 [&_svg]:opacity-60",
35
+ k
36
+ ),
37
+ children: [
38
+ m && m,
39
+ p
40
+ ]
41
+ }
42
+ ), D = () => /* @__PURE__ */ r(
43
+ "button",
44
+ {
45
+ className: "p-0 h-fit w-full flex justify-between cursor-pointer",
46
+ disabled: Z || v === 0,
47
+ onClick: () => {
48
+ const a = e.getIsSorted();
49
+ a === "asc" ? e.toggleSorting(!0) : a === "desc" ? e.clearSorting() : e.toggleSorting(!1);
50
+ },
51
+ children: [
52
+ m && /* @__PURE__ */ t("span", { className: "size-3.5", children: m }),
53
+ p && /* @__PURE__ */ t("span", { className: "grow text-left", children: p }),
54
+ e.getCanSort() && /* @__PURE__ */ t("span", { className: "size-3.5", children: e.getIsSorted() === "desc" ? /* @__PURE__ */ t(L, { className: "size-[0.7rem]! mt-px ml-auto" }) : e.getIsSorted() === "asc" ? /* @__PURE__ */ t(I, { className: "size-[0.7rem]! mt-px ml-auto" }) : /* @__PURE__ */ t(Y, { className: "size-[0.7rem]! mt-px ml-auto" }) })
55
+ ]
56
+ }
57
+ ), T = () => /* @__PURE__ */ t(
58
+ V,
59
+ {
60
+ size: "small",
61
+ variant: "ghost",
62
+ className: "-me-1 size-7 rounded-md",
63
+ onClick: () => e.pin(!1),
64
+ "aria-label": `Unpin ${p} column`,
65
+ title: `Unpin ${p} column`,
66
+ children: /* @__PURE__ */ t(ee, { className: "size-3.5! opacity-50!", "aria-hidden": "true" })
67
+ }
68
+ ), A = () => {
69
+ var a, s, n, i, c;
70
+ return /* @__PURE__ */ r("div", { className: "flex items-center h-full gap-1.5 justify-between", children: [
71
+ /* @__PURE__ */ r(U, { children: [
72
+ /* @__PURE__ */ t(B, { asChild: !0, children: D() }),
73
+ /* @__PURE__ */ r(F, { className: "w-40", align: "start", children: [
74
+ d && /* @__PURE__ */ t(H, { children: d }),
75
+ d && (e.getCanSort() || e.getCanPin() || h) && /* @__PURE__ */ t(f, {}),
76
+ e.getCanSort() && /* @__PURE__ */ r(b, { children: [
77
+ /* @__PURE__ */ r(
78
+ g,
79
+ {
80
+ onClick: () => {
81
+ e.getIsSorted() === "asc" ? e.clearSorting() : e.toggleSorting(!1);
82
+ },
83
+ disabled: !e.getCanSort(),
84
+ children: [
85
+ /* @__PURE__ */ t(I, { className: "size-3.5!" }),
86
+ /* @__PURE__ */ t("span", { className: "grow", children: "Asc" }),
87
+ e.getIsSorted() === "asc" && /* @__PURE__ */ t(C, { className: "size-4 opacity-100! text-primary" })
88
+ ]
89
+ }
90
+ ),
91
+ /* @__PURE__ */ r(
92
+ g,
93
+ {
94
+ onClick: () => {
95
+ e.getIsSorted() === "desc" ? e.clearSorting() : e.toggleSorting(!0);
96
+ },
97
+ disabled: !e.getCanSort(),
98
+ children: [
99
+ /* @__PURE__ */ t(L, { className: "size-3.5!" }),
100
+ /* @__PURE__ */ t("span", { className: "grow", children: "Desc" }),
101
+ e.getIsSorted() === "desc" && /* @__PURE__ */ t(C, { className: "size-4 opacity-100! text-primary" })
102
+ ]
103
+ }
104
+ )
105
+ ] }),
106
+ (d || e.getCanSort()) && (e.getCanSort() || e.getCanPin() || h) && /* @__PURE__ */ t(f, {}),
107
+ ((a = o.tableLayout) == null ? void 0 : a.columnsPinnable) && e.getCanPin() && /* @__PURE__ */ r(b, { children: [
108
+ /* @__PURE__ */ r(
109
+ g,
110
+ {
111
+ onClick: () => e.pin(e.getIsPinned() === "left" ? !1 : "left"),
112
+ children: [
113
+ /* @__PURE__ */ t(J, { className: "size-3.5!", "aria-hidden": "true" }),
114
+ /* @__PURE__ */ t("span", { className: "grow", children: "Pin to left" }),
115
+ e.getIsPinned() === "left" && /* @__PURE__ */ t(C, { className: "size-4 opacity-100! text-primary" })
116
+ ]
117
+ }
118
+ ),
119
+ /* @__PURE__ */ r(
120
+ g,
121
+ {
122
+ onClick: () => e.pin(e.getIsPinned() === "right" ? !1 : "right"),
123
+ children: [
124
+ /* @__PURE__ */ t(K, { className: "size-3.5!", "aria-hidden": "true" }),
125
+ /* @__PURE__ */ t("span", { className: "grow", children: "Pin to right" }),
126
+ e.getIsPinned() === "right" && /* @__PURE__ */ t(C, { className: "size-4 opacity-100! text-primary" })
127
+ ]
128
+ }
129
+ )
130
+ ] }),
131
+ ((s = o.tableLayout) == null ? void 0 : s.columnsMovable) && /* @__PURE__ */ r(b, { children: [
132
+ /* @__PURE__ */ t(f, {}),
133
+ /* @__PURE__ */ r(
134
+ g,
135
+ {
136
+ onClick: () => S("left"),
137
+ disabled: !N("left") || e.getIsPinned() !== !1,
138
+ children: [
139
+ /* @__PURE__ */ t(Q, { className: "size-3.5!", "aria-hidden": "true" }),
140
+ /* @__PURE__ */ t("span", { children: "Move to Left" })
141
+ ]
142
+ }
143
+ ),
144
+ /* @__PURE__ */ r(
145
+ g,
146
+ {
147
+ onClick: () => S("right"),
148
+ disabled: !N("right") || e.getIsPinned() !== !1,
149
+ children: [
150
+ /* @__PURE__ */ t(W, { className: "size-3.5!", "aria-hidden": "true" }),
151
+ /* @__PURE__ */ t("span", { children: "Move to Right" })
152
+ ]
153
+ }
154
+ )
155
+ ] }),
156
+ ((n = o.tableLayout) == null ? void 0 : n.columnsVisibility) && h && (e.getCanSort() || e.getCanPin() || d) && /* @__PURE__ */ t(f, {}),
157
+ ((i = o.tableLayout) == null ? void 0 : i.columnsVisibility) && h && /* @__PURE__ */ r(_, { children: [
158
+ /* @__PURE__ */ r($, { children: [
159
+ /* @__PURE__ */ t(X, { className: "size-3.5!" }),
160
+ /* @__PURE__ */ t("span", { children: "Columns" })
161
+ ] }),
162
+ /* @__PURE__ */ t(q, { children: /* @__PURE__ */ t(E, { children: u.getAllColumns().filter((l) => typeof l.accessorFn < "u" && l.getCanHide()).map((l) => {
163
+ var x;
164
+ return /* @__PURE__ */ t(
165
+ G,
166
+ {
167
+ checked: l.getIsVisible(),
168
+ onSelect: (w) => w.preventDefault(),
169
+ onCheckedChange: (w) => l.toggleVisibility(!!w),
170
+ className: "capitalize",
171
+ children: ((x = l.columnDef.meta) == null ? void 0 : x.headerTitle) || l.id
172
+ },
173
+ l.id
174
+ );
175
+ }) }) })
176
+ ] })
177
+ ] })
178
+ ] }),
179
+ ((c = o.tableLayout) == null ? void 0 : c.columnsPinnable) && e.getCanPin() && e.getIsPinned() && T()
180
+ ] });
181
+ };
182
+ return (M = o.tableLayout) != null && M.columnsMovable || (z = o.tableLayout) != null && z.columnsVisibility && h || (y = o.tableLayout) != null && y.columnsPinnable && e.getCanPin() || d ? A() : e.getCanSort() || (P = o.tableLayout) != null && P.columnsResizable && e.getCanResize() ? /* @__PURE__ */ t("div", { className: "flex items-start h-full", children: D() }) : O();
183
+ }
184
+ export {
185
+ le as Z2TableColumnHeader
186
+ };
@@ -0,0 +1,98 @@
1
+ import { jsx as t } from "react/jsx-runtime";
2
+ import { createContext as d, useContext as n } from "react";
3
+ import { cn as i } from "../../lib/utils.js";
4
+ const l = d(void 0);
5
+ function m() {
6
+ const a = n(l);
7
+ if (!a)
8
+ throw new Error("useZ2Table must be used within a Z2TableProvider");
9
+ return a;
10
+ }
11
+ function u({
12
+ children: a,
13
+ table: o,
14
+ ...e
15
+ }) {
16
+ return /* @__PURE__ */ t(
17
+ l.Provider,
18
+ {
19
+ value: {
20
+ props: e,
21
+ table: o,
22
+ recordCount: e.recordCount,
23
+ isLoading: e.isLoading || !1
24
+ },
25
+ children: a
26
+ }
27
+ );
28
+ }
29
+ function g({ children: a, table: o, ...e }) {
30
+ const r = {
31
+ loadingMode: "skeleton",
32
+ tableLayout: {
33
+ dense: !1,
34
+ cellBorder: !1,
35
+ rowBorder: !0,
36
+ rowRounded: !1,
37
+ stripped: !1,
38
+ headerSticky: !1,
39
+ headerBackground: !0,
40
+ headerBorder: !0,
41
+ width: "fixed",
42
+ columnsVisibility: !1,
43
+ columnsResizable: !1,
44
+ columnsPinnable: !1,
45
+ columnsMovable: !1,
46
+ columnsDraggable: !1,
47
+ rowsDraggable: !1
48
+ },
49
+ tableClassNames: {
50
+ base: "",
51
+ header: "",
52
+ headerRow: "",
53
+ headerSticky: "sticky top-0 bg-background-neutral-medium",
54
+ body: "",
55
+ bodyRow: "",
56
+ footer: "",
57
+ edgeCell: ""
58
+ }
59
+ }, s = {
60
+ ...r,
61
+ ...e,
62
+ tableLayout: {
63
+ ...r.tableLayout,
64
+ ...e.tableLayout || {}
65
+ },
66
+ tableClassNames: {
67
+ ...r.tableClassNames,
68
+ ...e.tableClassNames || {}
69
+ }
70
+ };
71
+ if (!o)
72
+ throw new Error('Z2Table requires a "table" prop');
73
+ return /* @__PURE__ */ t(u, { table: o, ...s, children: a });
74
+ }
75
+ function w({
76
+ children: a,
77
+ className: o,
78
+ border: e = !0
79
+ }) {
80
+ return /* @__PURE__ */ t(
81
+ "div",
82
+ {
83
+ "data-slot": "data-grid",
84
+ className: i(
85
+ "grid w-full",
86
+ e && "border border-stroke-solid-light rounded-xl overflow-hidden",
87
+ o
88
+ ),
89
+ children: a
90
+ }
91
+ );
92
+ }
93
+ export {
94
+ w as Z2TableContainer,
95
+ u as Z2TableProvider,
96
+ g as Z2TableRoot,
97
+ m as useZ2Table
98
+ };
@@ -0,0 +1,124 @@
1
+ import { jsx as t, jsxs as l, Fragment as v } from "react/jsx-runtime";
2
+ import { ChevronLeftIcon as P, ChevronRightIcon as I } from "lucide-react";
3
+ import { useZ2Table as L } from "./z2-table-context.js";
4
+ import { Z2Skeleton as S } from "../skeleton/skeleton.js";
5
+ import { Button as r } from "../button/button.js";
6
+ import "react";
7
+ import { cn as Z } from "../../lib/utils.js";
8
+ import { Z2Select as y, Z2SelectTrigger as T, Z2SelectValue as $, Z2SelectContent as j, Z2SelectItem as B } from "../select/z2-select.js";
9
+ function H(N) {
10
+ var b;
11
+ const { table: n, recordCount: m, isLoading: u } = L(), e = { ...{
12
+ sizes: [5, 10, 25, 50, 100],
13
+ sizesLabel: "Show",
14
+ sizesDescription: "per page",
15
+ sizesSkeleton: /* @__PURE__ */ t(S, { className: "h-8 w-44" }),
16
+ moreLimit: 5,
17
+ more: !1,
18
+ info: "{from} - {to} of {count}",
19
+ infoSkeleton: /* @__PURE__ */ t(S, { className: "h-8 w-60" }),
20
+ rowsPerPageLabel: "Rows per page",
21
+ previousPageLabel: "Go to previous page",
22
+ nextPageLabel: "Go to next page",
23
+ ellipsisText: "..."
24
+ }, ...N }, g = " rtl:transform rtl:rotate-180", o = n.getState().pagination.pageIndex, i = n.getState().pagination.pageSize, x = o * i + 1, h = Math.min((o + 1) * i, m), p = n.getPageCount(), w = e != null && e.info ? e.info.replace("{from}", x.toString()).replace("{to}", h.toString()).replace("{count}", m.toString()) : `${x} - ${h} of ${m}`, f = (e == null ? void 0 : e.moreLimit) || 5, c = Math.floor(o / f) * f, d = Math.min(c + f, p), z = () => {
25
+ const s = [];
26
+ for (let a = c; a < d; a++)
27
+ s.push(
28
+ /* @__PURE__ */ t(
29
+ r,
30
+ {
31
+ size: "small",
32
+ variant: "stroke",
33
+ disabled: o === a,
34
+ onClick: () => {
35
+ o !== a && n.setPageIndex(a);
36
+ },
37
+ leftIcon: a + 1
38
+ },
39
+ a
40
+ )
41
+ );
42
+ return s;
43
+ }, k = () => c > 0 ? /* @__PURE__ */ t(
44
+ r,
45
+ {
46
+ size: "small",
47
+ variant: "stroke",
48
+ onClick: () => n.setPageIndex(c - 1),
49
+ label: e.ellipsisText
50
+ }
51
+ ) : null, C = () => d < p ? /* @__PURE__ */ t(
52
+ r,
53
+ {
54
+ variant: "stroke",
55
+ size: "small",
56
+ onClick: () => n.setPageIndex(d),
57
+ label: e.ellipsisText
58
+ }
59
+ ) : null;
60
+ return /* @__PURE__ */ l(
61
+ "div",
62
+ {
63
+ "data-slot": "data-grid-pagination",
64
+ className: Z(
65
+ "flex flex-wrap flex-col sm:flex-row justify-between items-center gap-2.5 py-2.5 sm:py-0 grow",
66
+ e == null ? void 0 : e.className
67
+ ),
68
+ children: [
69
+ /* @__PURE__ */ t("div", { className: "flex flex-wrap items-center space-x-2.5 pb-2.5 sm:pb-0 order-2 sm:order-1", children: u ? e == null ? void 0 : e.sizesSkeleton : /* @__PURE__ */ l(v, { children: [
70
+ /* @__PURE__ */ t("div", { className: "text-sm text-muted-foreground", children: e.rowsPerPageLabel }),
71
+ /* @__PURE__ */ l(
72
+ y,
73
+ {
74
+ value: `${i}`,
75
+ onValueChange: (s) => {
76
+ const a = Number(s);
77
+ n.setPageSize(a);
78
+ },
79
+ children: [
80
+ /* @__PURE__ */ t(T, { className: "w-fit", size: "sm", children: /* @__PURE__ */ t($, { placeholder: `${i}` }) }),
81
+ /* @__PURE__ */ t(j, { side: "top", className: "min-w-[50px]", children: (b = e == null ? void 0 : e.sizes) == null ? void 0 : b.map((s) => /* @__PURE__ */ t(B, { value: `${s}`, children: s }, s)) })
82
+ ]
83
+ }
84
+ )
85
+ ] }) }),
86
+ /* @__PURE__ */ t("div", { className: "flex flex-col sm:flex-row justify-center sm:justify-end items-center gap-2.5 pt-2.5 sm:pt-0 order-1 sm:order-2", children: u ? e == null ? void 0 : e.infoSkeleton : /* @__PURE__ */ l(v, { children: [
87
+ /* @__PURE__ */ t("div", { className: "text-sm text-muted-foreground text-nowrap order-2 sm:order-1", children: w }),
88
+ p > 1 && /* @__PURE__ */ l("div", { className: "flex items-center space-x-1 order-1 sm:order-2", children: [
89
+ /* @__PURE__ */ t(
90
+ r,
91
+ {
92
+ size: "small",
93
+ variant: "stroke",
94
+ className: g,
95
+ onClick: () => n.previousPage(),
96
+ disabled: !n.getCanPreviousPage(),
97
+ leftIcon: /* @__PURE__ */ t(P, { className: "size-full" }),
98
+ children: /* @__PURE__ */ t("span", { className: "sr-only", children: e.previousPageLabel })
99
+ }
100
+ ),
101
+ k(),
102
+ z(),
103
+ C(),
104
+ /* @__PURE__ */ t(
105
+ r,
106
+ {
107
+ size: "small",
108
+ variant: "stroke",
109
+ className: g,
110
+ onClick: () => n.nextPage(),
111
+ disabled: !n.getCanNextPage(),
112
+ leftIcon: /* @__PURE__ */ t(I, { className: "size-full" }),
113
+ children: /* @__PURE__ */ t("span", { className: "sr-only", children: e.nextPageLabel })
114
+ }
115
+ )
116
+ ] })
117
+ ] }) })
118
+ ]
119
+ }
120
+ );
121
+ }
122
+ export {
123
+ H as Z2TablePagination
124
+ };
@@ -39,7 +39,7 @@ declare function Z2TableBodyRow<TData>({ children, row, dndRef, dndStyle, }: {
39
39
  }): import("react/jsx-runtime").JSX.Element;
40
40
  declare function Z2TableBodyRowExpandded<TData>({ row }: {
41
41
  row: Row<TData>;
42
- }): import("react/jsx-runtime").JSX.Element;
42
+ }): import("react/jsx-runtime").JSX.Element | null;
43
43
  declare function Z2TableBodyRowCell<TData>({ children, cell, dndRef, dndStyle, }: {
44
44
  children: ReactNode;
45
45
  cell: Cell<TData, unknown>;