@giddaa-housing/ui 0.1.0 → 1.1.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/README.md +18 -6
- package/css/base.css +37 -0
- package/css/components.css +135 -0
- package/css/generated/shared.css +1 -0
- package/css/giddaa.css +402 -0
- package/css/preset.css +77 -0
- package/css/styles.css +2 -0
- package/css/theme.css +255 -0
- package/dist/accordion.d.ts +9 -10
- package/dist/accordion.js +41 -117
- package/dist/activity-timeline.d.ts +29 -0
- package/dist/activity-timeline.js +97 -0
- package/dist/alert.d.ts +8 -9
- package/dist/alert.js +53 -141
- package/dist/auth-layout.d.ts +23 -0
- package/dist/auth-layout.js +153 -0
- package/dist/avatar.d.ts +6 -6
- package/dist/avatar.js +40 -142
- package/dist/badge.d.ts +12 -13
- package/dist/badge.js +66 -114
- package/dist/bar-chart.d.ts +136 -114
- package/dist/bar-chart.js +244 -297
- package/dist/breadcrumb.d.ts +5 -5
- package/dist/breadcrumb.js +56 -148
- package/dist/bullet-chart.d.ts +33 -33
- package/dist/bullet-chart.js +123 -183
- package/dist/button-BZIeyUw6.d.ts +17 -0
- package/dist/button-group.d.ts +13 -16
- package/dist/button-group.js +38 -163
- package/dist/button.d.ts +2 -19
- package/dist/button.js +90 -142
- package/dist/calendar.d.ts +6 -6
- package/dist/calendar.js +134 -288
- package/dist/card.d.ts +14 -16
- package/dist/card.js +58 -174
- package/dist/carousel.d.ts +34 -35
- package/dist/carousel.js +319 -378
- package/dist/chart.d.ts +58 -59
- package/dist/chart.js +350 -466
- package/dist/checkbox.d.ts +10 -12
- package/dist/checkbox.js +84 -84
- package/dist/cn-BI_4DMBf.js +23 -0
- package/dist/collapsible.d.ts +7 -8
- package/dist/collapsible.js +23 -77
- package/dist/combobox.d.ts +10 -10
- package/dist/combobox.js +220 -696
- package/dist/cta.d.ts +64 -0
- package/dist/cta.js +192 -0
- package/dist/currency-selector.d.ts +41 -0
- package/dist/currency-selector.js +114 -0
- package/dist/data-table.d.ts +164 -0
- package/dist/data-table.js +673 -0
- package/dist/date-picker.d.ts +27 -20
- package/dist/date-picker.js +122 -520
- package/dist/details-card.d.ts +19 -0
- package/dist/details-card.js +118 -0
- package/dist/dialog.d.ts +13 -14
- package/dist/dialog.js +117 -320
- package/dist/dropdown-menu.d.ts +14 -14
- package/dist/dropdown-menu.js +170 -365
- package/dist/dropzone.d.ts +55 -55
- package/dist/dropzone.js +328 -467
- package/dist/editorial-card.d.ts +27 -0
- package/dist/editorial-card.js +144 -0
- package/dist/empty-state.d.ts +8 -9
- package/dist/empty-state.js +48 -135
- package/dist/field.d.ts +23 -25
- package/dist/field.js +111 -327
- package/dist/filter.d.ts +118 -0
- package/dist/filter.js +775 -0
- package/dist/footer.d.ts +40 -0
- package/dist/footer.js +227 -0
- package/dist/funnel-chart.d.ts +38 -41
- package/dist/funnel-chart.js +168 -563
- package/dist/gallery-indicator.d.ts +17 -0
- package/dist/gallery-indicator.js +75 -0
- package/dist/heatmap-chart.d.ts +95 -0
- package/dist/heatmap-chart.js +197 -0
- package/dist/infotip.d.ts +10 -0
- package/dist/infotip.js +40 -0
- package/dist/input-CfoEJ8A6.d.ts +12 -0
- package/dist/input-group.d.ts +16 -19
- package/dist/input-group.js +92 -372
- package/dist/input-size-context-C-SFx9sx.d.ts +10 -0
- package/dist/input-size-context.d.ts +2 -11
- package/dist/input-size-context.js +14 -20
- package/dist/input.d.ts +2 -13
- package/dist/input.js +23 -79
- package/dist/item.d.ts +7 -8
- package/dist/item.js +22 -89
- package/dist/kpi-card.d.ts +18 -20
- package/dist/kpi-card.js +84 -232
- package/dist/label.d.ts +6 -6
- package/dist/label.js +39 -66
- package/dist/line-chart.d.ts +88 -89
- package/dist/line-chart.js +143 -262
- package/dist/logo.d.ts +4 -4
- package/dist/logo.js +87 -141
- package/dist/map-indicator.d.ts +13 -0
- package/dist/map-indicator.js +83 -0
- package/dist/match.d.ts +15 -0
- package/dist/match.js +68 -0
- package/dist/media-gallery-hero.d.ts +58 -0
- package/dist/media-gallery-hero.js +201 -0
- package/dist/media-player.d.ts +60 -0
- package/dist/media-player.js +919 -0
- package/dist/multi-step-form.d.ts +56 -0
- package/dist/multi-step-form.js +342 -0
- package/dist/number-input.d.ts +34 -34
- package/dist/number-input.js +62 -413
- package/dist/page-header.d.ts +10 -11
- package/dist/page-header.js +34 -107
- package/dist/pagination.d.ts +17 -20
- package/dist/pagination.js +132 -341
- package/dist/password-input.d.ts +5 -12
- package/dist/password-input.js +32 -354
- package/dist/phone-input.d.ts +19 -19
- package/dist/phone-input.js +232 -561
- package/dist/photo-gallery.d.ts +20 -20
- package/dist/photo-gallery.js +314 -746
- package/dist/picker-lzgmsNfG.js +32 -0
- package/dist/pie-chart.d.ts +60 -60
- package/dist/pie-chart.js +141 -184
- package/dist/popover.d.ts +9 -9
- package/dist/popover.js +60 -156
- package/dist/price-tag.d.ts +34 -0
- package/dist/price-tag.js +118 -0
- package/dist/progress.d.ts +18 -16
- package/dist/progress.js +156 -300
- package/dist/property-listing-card.d.ts +29 -0
- package/dist/property-listing-card.js +117 -0
- package/dist/radar-chart.d.ts +108 -0
- package/dist/radar-chart.js +172 -0
- package/dist/radio-group.d.ts +11 -13
- package/dist/radio-group.js +47 -96
- package/dist/review-block.d.ts +18 -0
- package/dist/review-block.js +154 -0
- package/dist/rich-text-editor.d.ts +30 -14
- package/dist/rich-text-editor.js +594 -979
- package/dist/scatter-chart.d.ts +140 -0
- package/dist/scatter-chart.js +248 -0
- package/dist/search-input.d.ts +8 -15
- package/dist/search-input.js +58 -408
- package/dist/select.d.ts +8 -8
- package/dist/select.js +131 -291
- package/dist/separator.d.ts +8 -9
- package/dist/separator.js +31 -70
- package/dist/sheet.d.ts +11 -11
- package/dist/sheet.js +84 -262
- package/dist/sidebar.d.ts +32 -37
- package/dist/sidebar.js +380 -1055
- package/dist/size-context-D4mYvcg8.d.ts +10 -0
- package/dist/size-context.d.ts +2 -11
- package/dist/size-context.js +14 -18
- package/dist/skeleton.d.ts +4 -5
- package/dist/skeleton.js +9 -45
- package/dist/slider.d.ts +27 -0
- package/dist/slider.js +81 -0
- package/dist/sparkline.d.ts +43 -46
- package/dist/sparkline.js +223 -561
- package/dist/stepper.d.ts +23 -24
- package/dist/stepper.js +149 -276
- package/dist/styles.css +9995 -2
- package/dist/switch.d.ts +10 -12
- package/dist/switch.js +49 -106
- package/dist/table-card.d.ts +35 -0
- package/dist/table-card.js +125 -0
- package/dist/table.d.ts +18 -14
- package/dist/table.js +114 -182
- package/dist/tabs.d.ts +23 -15
- package/dist/tabs.js +62 -149
- package/dist/tag.d.ts +22 -23
- package/dist/tag.js +104 -156
- package/dist/testimonial-block.d.ts +33 -0
- package/dist/testimonial-block.js +208 -0
- package/dist/textarea-IS_D8pXf.d.ts +11 -0
- package/dist/textarea.d.ts +2 -12
- package/dist/textarea.js +20 -74
- package/dist/time-picker.d.ts +11 -11
- package/dist/time-picker.js +247 -464
- package/dist/toast.d.ts +16 -18
- package/dist/toast.js +154 -310
- package/dist/tooltip.d.ts +9 -10
- package/dist/tooltip.js +33 -91
- package/dist/tree-map.d.ts +54 -57
- package/dist/tree-map.js +231 -646
- package/dist/use-uncontrolled-CLfM1XbB.js +21 -0
- package/dist/waterfall-chart.d.ts +126 -0
- package/dist/waterfall-chart.js +480 -0
- package/package.json +123 -34
- package/dist/accordion.js.map +0 -1
- package/dist/alert.js.map +0 -1
- package/dist/avatar.js.map +0 -1
- package/dist/badge.js.map +0 -1
- package/dist/bar-chart.js.map +0 -1
- package/dist/base.css +0 -32
- package/dist/breadcrumb.js.map +0 -1
- package/dist/bullet-chart.js.map +0 -1
- package/dist/button-group.js.map +0 -1
- package/dist/button.js.map +0 -1
- package/dist/calendar.js.map +0 -1
- package/dist/card.js.map +0 -1
- package/dist/carousel.js.map +0 -1
- package/dist/chart.js.map +0 -1
- package/dist/checkbox.js.map +0 -1
- package/dist/collapsible.js.map +0 -1
- package/dist/combobox.js.map +0 -1
- package/dist/date-picker.js.map +0 -1
- package/dist/dialog.js.map +0 -1
- package/dist/dropdown-menu.js.map +0 -1
- package/dist/dropzone.js.map +0 -1
- package/dist/empty-state.js.map +0 -1
- package/dist/field.js.map +0 -1
- package/dist/files/red-hat-display-latin-300-italic.woff +0 -0
- package/dist/files/red-hat-display-latin-300-italic.woff2 +0 -0
- package/dist/files/red-hat-display-latin-300-normal.woff +0 -0
- package/dist/files/red-hat-display-latin-300-normal.woff2 +0 -0
- package/dist/files/red-hat-display-latin-400-italic.woff +0 -0
- package/dist/files/red-hat-display-latin-400-italic.woff2 +0 -0
- package/dist/files/red-hat-display-latin-400-normal.woff +0 -0
- package/dist/files/red-hat-display-latin-400-normal.woff2 +0 -0
- package/dist/files/red-hat-display-latin-500-italic.woff +0 -0
- package/dist/files/red-hat-display-latin-500-italic.woff2 +0 -0
- package/dist/files/red-hat-display-latin-500-normal.woff +0 -0
- package/dist/files/red-hat-display-latin-500-normal.woff2 +0 -0
- package/dist/files/red-hat-display-latin-600-italic.woff +0 -0
- package/dist/files/red-hat-display-latin-600-italic.woff2 +0 -0
- package/dist/files/red-hat-display-latin-600-normal.woff +0 -0
- package/dist/files/red-hat-display-latin-600-normal.woff2 +0 -0
- package/dist/files/red-hat-display-latin-700-italic.woff +0 -0
- package/dist/files/red-hat-display-latin-700-italic.woff2 +0 -0
- package/dist/files/red-hat-display-latin-700-normal.woff +0 -0
- package/dist/files/red-hat-display-latin-700-normal.woff2 +0 -0
- package/dist/files/red-hat-display-latin-800-italic.woff +0 -0
- package/dist/files/red-hat-display-latin-800-italic.woff2 +0 -0
- package/dist/files/red-hat-display-latin-800-normal.woff +0 -0
- package/dist/files/red-hat-display-latin-800-normal.woff2 +0 -0
- package/dist/files/red-hat-display-latin-900-italic.woff +0 -0
- package/dist/files/red-hat-display-latin-900-italic.woff2 +0 -0
- package/dist/files/red-hat-display-latin-900-normal.woff +0 -0
- package/dist/files/red-hat-display-latin-900-normal.woff2 +0 -0
- package/dist/files/red-hat-display-latin-ext-300-italic.woff +0 -0
- package/dist/files/red-hat-display-latin-ext-300-italic.woff2 +0 -0
- package/dist/files/red-hat-display-latin-ext-300-normal.woff +0 -0
- package/dist/files/red-hat-display-latin-ext-300-normal.woff2 +0 -0
- package/dist/files/red-hat-display-latin-ext-400-italic.woff +0 -0
- package/dist/files/red-hat-display-latin-ext-400-italic.woff2 +0 -0
- package/dist/files/red-hat-display-latin-ext-400-normal.woff +0 -0
- package/dist/files/red-hat-display-latin-ext-400-normal.woff2 +0 -0
- package/dist/files/red-hat-display-latin-ext-500-italic.woff +0 -0
- package/dist/files/red-hat-display-latin-ext-500-italic.woff2 +0 -0
- package/dist/files/red-hat-display-latin-ext-500-normal.woff +0 -0
- package/dist/files/red-hat-display-latin-ext-500-normal.woff2 +0 -0
- package/dist/files/red-hat-display-latin-ext-600-italic.woff +0 -0
- package/dist/files/red-hat-display-latin-ext-600-italic.woff2 +0 -0
- package/dist/files/red-hat-display-latin-ext-600-normal.woff +0 -0
- package/dist/files/red-hat-display-latin-ext-600-normal.woff2 +0 -0
- package/dist/files/red-hat-display-latin-ext-700-italic.woff +0 -0
- package/dist/files/red-hat-display-latin-ext-700-italic.woff2 +0 -0
- package/dist/files/red-hat-display-latin-ext-700-normal.woff +0 -0
- package/dist/files/red-hat-display-latin-ext-700-normal.woff2 +0 -0
- package/dist/files/red-hat-display-latin-ext-800-italic.woff +0 -0
- package/dist/files/red-hat-display-latin-ext-800-italic.woff2 +0 -0
- package/dist/files/red-hat-display-latin-ext-800-normal.woff +0 -0
- package/dist/files/red-hat-display-latin-ext-800-normal.woff2 +0 -0
- package/dist/files/red-hat-display-latin-ext-900-italic.woff +0 -0
- package/dist/files/red-hat-display-latin-ext-900-italic.woff2 +0 -0
- package/dist/files/red-hat-display-latin-ext-900-normal.woff +0 -0
- package/dist/files/red-hat-display-latin-ext-900-normal.woff2 +0 -0
- package/dist/funnel-chart.js.map +0 -1
- package/dist/index.d.ts +0 -87
- package/dist/index.js +0 -10448
- package/dist/index.js.map +0 -1
- package/dist/input-group.js.map +0 -1
- package/dist/input-size-context.js.map +0 -1
- package/dist/input.js.map +0 -1
- package/dist/item.js.map +0 -1
- package/dist/kpi-card.js.map +0 -1
- package/dist/label.js.map +0 -1
- package/dist/line-chart.js.map +0 -1
- package/dist/logo.js.map +0 -1
- package/dist/number-input.js.map +0 -1
- package/dist/page-header.js.map +0 -1
- package/dist/pagination.js.map +0 -1
- package/dist/password-input.js.map +0 -1
- package/dist/phone-input.js.map +0 -1
- package/dist/photo-gallery.js.map +0 -1
- package/dist/pie-chart.js.map +0 -1
- package/dist/popover.js.map +0 -1
- package/dist/progress.js.map +0 -1
- package/dist/radio-group.js.map +0 -1
- package/dist/red-hat-display.css +0 -2
- package/dist/rich-text-editor.js.map +0 -1
- package/dist/search-input.js.map +0 -1
- package/dist/select.js.map +0 -1
- package/dist/separator.js.map +0 -1
- package/dist/sheet.js.map +0 -1
- package/dist/sidebar.js.map +0 -1
- package/dist/size-context.js.map +0 -1
- package/dist/skeleton.js.map +0 -1
- package/dist/sparkline.js.map +0 -1
- package/dist/stepper.js.map +0 -1
- package/dist/switch.js.map +0 -1
- package/dist/tab-list.d.ts +0 -38
- package/dist/tab-list.js +0 -394
- package/dist/tab-list.js.map +0 -1
- package/dist/table.js.map +0 -1
- package/dist/tabs.js.map +0 -1
- package/dist/tag.js.map +0 -1
- package/dist/textarea.js.map +0 -1
- package/dist/theme/giddaa.css +0 -2
- package/dist/time-picker.js.map +0 -1
- package/dist/toast.js.map +0 -1
- package/dist/tooltip.js.map +0 -1
- package/dist/tree-map.js.map +0 -1
|
@@ -0,0 +1,673 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { t as cn } from "./cn-BI_4DMBf.js";
|
|
3
|
+
import { Button } from "./button.js";
|
|
4
|
+
import { Input } from "./input.js";
|
|
5
|
+
import { Checkbox } from "./checkbox.js";
|
|
6
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./select.js";
|
|
7
|
+
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from "./empty-state.js";
|
|
8
|
+
import { Filter, FilterApplyButton, FilterContent, FilterResetButton, FilterTrigger } from "./filter.js";
|
|
9
|
+
import { Pagination, PaginationButton, PaginationContent, PaginationEllipsis, PaginationItem } from "./pagination.js";
|
|
10
|
+
import { Popover, PopoverBody, PopoverContent, PopoverFooter, PopoverHeader, PopoverTitle, PopoverTrigger } from "./popover.js";
|
|
11
|
+
import { Skeleton } from "./skeleton.js";
|
|
12
|
+
import { Table as Table$1, TableBody, TableCell, TableHead, TableHeader, TableRow } from "./table.js";
|
|
13
|
+
import { TableCard, TableCardAction } from "./table-card.js";
|
|
14
|
+
import { ChevronDown, ChevronLeft, ChevronRight, ChevronUp, ChevronsUpDown, PinIcon, SearchX, SlidersHorizontal } from "lucide-react";
|
|
15
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
16
|
+
import * as React from "react";
|
|
17
|
+
import { flexRender, getCoreRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
|
|
18
|
+
//#region src/data-table.tsx
|
|
19
|
+
const DataTableContext = React.createContext(null);
|
|
20
|
+
const ROW_SELECT_COLUMN_ID = "row-select";
|
|
21
|
+
const ACTIONS_COLUMN_ID = "actions";
|
|
22
|
+
const DEFAULT_SKELETON_ROW_COUNT = 5;
|
|
23
|
+
const DEFAULT_PAGE_SIZE_OPTIONS = [
|
|
24
|
+
10,
|
|
25
|
+
25,
|
|
26
|
+
50,
|
|
27
|
+
100,
|
|
28
|
+
200,
|
|
29
|
+
500
|
|
30
|
+
];
|
|
31
|
+
function useOptionalDataTableContext() {
|
|
32
|
+
return React.useContext(DataTableContext);
|
|
33
|
+
}
|
|
34
|
+
function useDataTableContext() {
|
|
35
|
+
const context = useOptionalDataTableContext();
|
|
36
|
+
if (!context) throw new Error("DataTable components must be rendered inside <DataTableRoot>.");
|
|
37
|
+
return context;
|
|
38
|
+
}
|
|
39
|
+
function getCommonPinningStyles(column) {
|
|
40
|
+
const isPinned = column.getIsPinned();
|
|
41
|
+
return {
|
|
42
|
+
left: isPinned === "left" ? `${column.getStart("left")}px` : void 0,
|
|
43
|
+
right: isPinned === "right" ? `${column.getAfter("right")}px` : void 0,
|
|
44
|
+
position: isPinned ? "sticky" : "relative",
|
|
45
|
+
width: column.getSize(),
|
|
46
|
+
zIndex: isPinned ? 1 : 0
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function getPinnedSide(column) {
|
|
50
|
+
const isPinned = column.getIsPinned();
|
|
51
|
+
if (isPinned === "left" && column.getIsLastColumn("left")) return "left";
|
|
52
|
+
if (isPinned === "right" && column.getIsFirstColumn("right")) return "right";
|
|
53
|
+
}
|
|
54
|
+
function getDefaultColumnPinning(columns) {
|
|
55
|
+
const left = [];
|
|
56
|
+
const right = [];
|
|
57
|
+
for (const column of columns) {
|
|
58
|
+
if (!column.id || !column.meta?.isPinned) continue;
|
|
59
|
+
if (column.meta.pinPosition === "right") right.push(column.id);
|
|
60
|
+
else left.push(column.id);
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
left,
|
|
64
|
+
right
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function renderTableCellSkeleton(skeletonType = "default") {
|
|
68
|
+
if (skeletonType === "image-description") return /* @__PURE__ */ jsxs("div", {
|
|
69
|
+
className: "flex items-center gap-3",
|
|
70
|
+
children: [/* @__PURE__ */ jsx(Skeleton, { className: "size-10 shrink-0 rounded-full" }), /* @__PURE__ */ jsxs("div", {
|
|
71
|
+
className: "min-w-0 flex-1 space-y-2",
|
|
72
|
+
children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-3.5 w-32 max-w-full rounded" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-3 w-48 max-w-full rounded" })]
|
|
73
|
+
})]
|
|
74
|
+
});
|
|
75
|
+
return /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-full rounded" });
|
|
76
|
+
}
|
|
77
|
+
function useDataTable({ columns, data, enableRowSelection = false, initialState, getSortedRowModel: getSortedRowModelOption, ...options }) {
|
|
78
|
+
const resolvedColumns = React.useMemo(() => {
|
|
79
|
+
if (!enableRowSelection) return columns;
|
|
80
|
+
return [{
|
|
81
|
+
id: ROW_SELECT_COLUMN_ID,
|
|
82
|
+
meta: {
|
|
83
|
+
isPinned: true,
|
|
84
|
+
pinPosition: "left"
|
|
85
|
+
},
|
|
86
|
+
header: ({ table }) => /* @__PURE__ */ jsx(Checkbox, {
|
|
87
|
+
"aria-label": "Select all rows",
|
|
88
|
+
checked: table.getIsAllPageRowsSelected(),
|
|
89
|
+
onCheckedChange: (value) => table.toggleAllPageRowsSelected(!!value),
|
|
90
|
+
size: "sm"
|
|
91
|
+
}),
|
|
92
|
+
cell: ({ row }) => /* @__PURE__ */ jsx(Checkbox, {
|
|
93
|
+
"aria-label": "Select row",
|
|
94
|
+
checked: row.getIsSelected(),
|
|
95
|
+
onCheckedChange: (value) => row.toggleSelected(!!value),
|
|
96
|
+
size: "sm"
|
|
97
|
+
}),
|
|
98
|
+
enableHiding: false,
|
|
99
|
+
enablePinning: false,
|
|
100
|
+
enableSorting: false,
|
|
101
|
+
size: 56
|
|
102
|
+
}, ...columns];
|
|
103
|
+
}, [columns, enableRowSelection]);
|
|
104
|
+
const defaultColumnPinning = React.useMemo(() => getDefaultColumnPinning(resolvedColumns), [resolvedColumns]);
|
|
105
|
+
return useReactTable({
|
|
106
|
+
...options,
|
|
107
|
+
columns: resolvedColumns,
|
|
108
|
+
data,
|
|
109
|
+
enableRowSelection,
|
|
110
|
+
getCoreRowModel: getCoreRowModel(),
|
|
111
|
+
getSortedRowModel: getSortedRowModelOption ?? getSortedRowModel(),
|
|
112
|
+
initialState: {
|
|
113
|
+
...initialState,
|
|
114
|
+
columnPinning: {
|
|
115
|
+
...defaultColumnPinning,
|
|
116
|
+
...initialState?.columnPinning
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function DataTableRoot({ children, className, isLoading, onRowClick, table, ...props }) {
|
|
122
|
+
const contextValue = {
|
|
123
|
+
isLoading,
|
|
124
|
+
onRowClick,
|
|
125
|
+
table
|
|
126
|
+
};
|
|
127
|
+
return /* @__PURE__ */ jsx(DataTableContext.Provider, {
|
|
128
|
+
value: contextValue,
|
|
129
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
130
|
+
"data-slot": "data-table-root",
|
|
131
|
+
className: cn("flex w-full min-w-0 flex-col gap-4", className),
|
|
132
|
+
...props,
|
|
133
|
+
children
|
|
134
|
+
})
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function DataTableToolbar({ className, ...props }) {
|
|
138
|
+
return /* @__PURE__ */ jsx("div", {
|
|
139
|
+
"data-slot": "data-table-toolbar",
|
|
140
|
+
className: cn("flex flex-col justify-between gap-4 md:flex-row md:items-center", className),
|
|
141
|
+
...props
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
function DataTableFilter({ applyButtonProps, children, closeOnApply = true, closeOnReset = true, contentProps, defaultJoin, defaultOpen = false, defaultValue, fields, footer, onApply, onOpenChange, open, popoverBodyProps, popoverContentProps, popoverFooterProps, popoverHeaderProps, resetButtonProps, title = "Filter", trigger, triggerButtonProps, triggerCountClassName, triggerHideCountWhenZero, triggerLabel = "Filters" }) {
|
|
145
|
+
const [internalOpen, setInternalOpen] = React.useState(defaultOpen);
|
|
146
|
+
const isOpenControlled = open !== void 0;
|
|
147
|
+
const resolvedOpen = open ?? internalOpen;
|
|
148
|
+
const { onApplySuccess, ...resolvedApplyButtonProps } = applyButtonProps ?? {};
|
|
149
|
+
const { onReset, ...resolvedResetButtonProps } = resetButtonProps ?? {};
|
|
150
|
+
const { className: triggerButtonClassName, ...resolvedTriggerButtonProps } = triggerButtonProps ?? {};
|
|
151
|
+
const { className: popoverContentClassName, ...resolvedPopoverContentProps } = popoverContentProps ?? {};
|
|
152
|
+
const { className: popoverHeaderClassName, ...resolvedPopoverHeaderProps } = popoverHeaderProps ?? {};
|
|
153
|
+
const { className: popoverBodyClassName, ...resolvedPopoverBodyProps } = popoverBodyProps ?? {};
|
|
154
|
+
const { className: popoverFooterClassName, ...resolvedPopoverFooterProps } = popoverFooterProps ?? {};
|
|
155
|
+
const handleOpenChange = (nextOpen) => {
|
|
156
|
+
if (!isOpenControlled) setInternalOpen(nextOpen);
|
|
157
|
+
onOpenChange?.(nextOpen);
|
|
158
|
+
};
|
|
159
|
+
return /* @__PURE__ */ jsx(Filter, {
|
|
160
|
+
defaultJoin,
|
|
161
|
+
defaultValue,
|
|
162
|
+
fields,
|
|
163
|
+
onApply,
|
|
164
|
+
children: /* @__PURE__ */ jsxs(Popover, {
|
|
165
|
+
open: resolvedOpen,
|
|
166
|
+
onOpenChange: handleOpenChange,
|
|
167
|
+
children: [/* @__PURE__ */ jsx(FilterTrigger, {
|
|
168
|
+
countClassName: triggerCountClassName,
|
|
169
|
+
hideCountWhenZero: triggerHideCountWhenZero,
|
|
170
|
+
children: /* @__PURE__ */ jsx(PopoverTrigger, { render: trigger ?? /* @__PURE__ */ jsxs(Button, {
|
|
171
|
+
className: cn("group", triggerButtonClassName),
|
|
172
|
+
size: "sm",
|
|
173
|
+
variant: "tertiary-outline",
|
|
174
|
+
...resolvedTriggerButtonProps,
|
|
175
|
+
children: [
|
|
176
|
+
/* @__PURE__ */ jsx(SlidersHorizontal, { className: "shrink-0" }),
|
|
177
|
+
triggerLabel,
|
|
178
|
+
/* @__PURE__ */ jsx(ChevronDown, { className: "transition-transform group-data-popup-open:rotate-180" })
|
|
179
|
+
]
|
|
180
|
+
}) })
|
|
181
|
+
}), /* @__PURE__ */ jsxs(PopoverContent, {
|
|
182
|
+
align: "end",
|
|
183
|
+
sideOffset: 12,
|
|
184
|
+
size: "sm",
|
|
185
|
+
...resolvedPopoverContentProps,
|
|
186
|
+
className: cn("w-140 max-w-[calc(100vw-2rem)]", popoverContentClassName),
|
|
187
|
+
children: [
|
|
188
|
+
title ? /* @__PURE__ */ jsx(PopoverHeader, {
|
|
189
|
+
border: true,
|
|
190
|
+
...resolvedPopoverHeaderProps,
|
|
191
|
+
className: cn("items-center", popoverHeaderClassName),
|
|
192
|
+
children: /* @__PURE__ */ jsx(PopoverTitle, { children: title })
|
|
193
|
+
}) : null,
|
|
194
|
+
/* @__PURE__ */ jsx(PopoverBody, {
|
|
195
|
+
...resolvedPopoverBodyProps,
|
|
196
|
+
className: popoverBodyClassName,
|
|
197
|
+
children: children ?? /* @__PURE__ */ jsx(FilterContent, { ...contentProps })
|
|
198
|
+
}),
|
|
199
|
+
footer !== null ? /* @__PURE__ */ jsx(PopoverFooter, {
|
|
200
|
+
...resolvedPopoverFooterProps,
|
|
201
|
+
className: popoverFooterClassName,
|
|
202
|
+
children: footer !== void 0 ? footer : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(FilterResetButton, {
|
|
203
|
+
...resolvedResetButtonProps,
|
|
204
|
+
onReset: () => {
|
|
205
|
+
if (closeOnReset) handleOpenChange(false);
|
|
206
|
+
onReset?.();
|
|
207
|
+
}
|
|
208
|
+
}), /* @__PURE__ */ jsx(FilterApplyButton, {
|
|
209
|
+
...resolvedApplyButtonProps,
|
|
210
|
+
onApplySuccess: () => {
|
|
211
|
+
if (closeOnApply) handleOpenChange(false);
|
|
212
|
+
onApplySuccess?.();
|
|
213
|
+
}
|
|
214
|
+
})] })
|
|
215
|
+
}) : null
|
|
216
|
+
]
|
|
217
|
+
})]
|
|
218
|
+
})
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
function DataTable({ containerClassName, emptyState, interactiveColumnIds = [ACTIONS_COLUMN_ID, ROW_SELECT_COLUMN_ID], isLoading: isLoadingProp, loadingRowCount = DEFAULT_SKELETON_ROW_COUNT, onRowClick: onRowClickProp, table: tableProp, ...props }) {
|
|
222
|
+
const context = useOptionalDataTableContext();
|
|
223
|
+
const table = tableProp ?? context?.table;
|
|
224
|
+
const isLoading = isLoadingProp ?? context?.isLoading;
|
|
225
|
+
const onRowClick = onRowClickProp ?? context?.onRowClick;
|
|
226
|
+
if (!table) throw new Error("DataTable requires a table prop or DataTableRoot context.");
|
|
227
|
+
const rows = table.getRowModel().rows;
|
|
228
|
+
const isEmpty = !isLoading && rows.length === 0;
|
|
229
|
+
const skeletonRows = Array.from({ length: loadingRowCount }, (_, index) => index);
|
|
230
|
+
if (isEmpty && emptyState) return emptyState;
|
|
231
|
+
return /* @__PURE__ */ jsxs(Table$1, {
|
|
232
|
+
containerClassName: cn("max-h-[68vh] overflow-y-auto", containerClassName),
|
|
233
|
+
style: { width: table.getTotalSize() },
|
|
234
|
+
...props,
|
|
235
|
+
children: [/* @__PURE__ */ jsx(TableHeader, {
|
|
236
|
+
sticky: true,
|
|
237
|
+
children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx(TableRow, { children: headerGroup.headers.map((header) => {
|
|
238
|
+
const isPinned = header.column.getIsPinned();
|
|
239
|
+
const pinnedSide = getPinnedSide(header.column);
|
|
240
|
+
return /* @__PURE__ */ jsx(TableHead, {
|
|
241
|
+
colSpan: header.colSpan,
|
|
242
|
+
pinnedSide,
|
|
243
|
+
style: getCommonPinningStyles(header.column),
|
|
244
|
+
children: header.isPlaceholder ? null : /* @__PURE__ */ jsxs("div", {
|
|
245
|
+
className: "flex items-center gap-2",
|
|
246
|
+
children: [
|
|
247
|
+
flexRender(header.column.columnDef.header, header.getContext()),
|
|
248
|
+
header.column.getCanSort() ? /* @__PURE__ */ jsx("button", {
|
|
249
|
+
"aria-label": `Toggle sorting for ${header.column.id}`,
|
|
250
|
+
type: "button",
|
|
251
|
+
className: "shrink-0 cursor-pointer border-none bg-transparent p-0 outline-none",
|
|
252
|
+
onClick: header.column.getToggleSortingHandler(),
|
|
253
|
+
children: header.column.getIsSorted() === "asc" ? /* @__PURE__ */ jsx(ChevronUp, { className: "size-3.5 text-fg-primary" }) : header.column.getIsSorted() === "desc" ? /* @__PURE__ */ jsx(ChevronDown, { className: "size-3.5 text-fg-primary" }) : /* @__PURE__ */ jsx(ChevronsUpDown, { className: "size-3.5" })
|
|
254
|
+
}) : null,
|
|
255
|
+
header.column.getCanPin() ? /* @__PURE__ */ jsx("button", {
|
|
256
|
+
"aria-label": isPinned ? `Unpin ${header.column.id}` : `Pin ${header.column.id} to the left`,
|
|
257
|
+
type: "button",
|
|
258
|
+
className: "shrink-0 cursor-pointer border-none bg-transparent p-0 outline-none",
|
|
259
|
+
onClick: () => isPinned ? header.column.pin(false) : header.column.pin("left"),
|
|
260
|
+
children: /* @__PURE__ */ jsx(PinIcon, { className: cn("size-3.5", isPinned && "text-fg-brand") })
|
|
261
|
+
}) : null,
|
|
262
|
+
header.column.getCanResize() ? /* @__PURE__ */ jsx("button", {
|
|
263
|
+
"aria-label": "Resize column",
|
|
264
|
+
type: "button",
|
|
265
|
+
onDoubleClick: () => header.column.resetSize(),
|
|
266
|
+
onMouseDown: header.getResizeHandler(),
|
|
267
|
+
onTouchStart: header.getResizeHandler(),
|
|
268
|
+
className: cn("ml-auto h-6 w-0.5 cursor-col-resize rounded-[1px] border-0 bg-line p-0 outline-none", header.column.getIsResizing() && "w-1 bg-line-focus")
|
|
269
|
+
}) : null
|
|
270
|
+
]
|
|
271
|
+
})
|
|
272
|
+
}, header.id);
|
|
273
|
+
}) }, headerGroup.id))
|
|
274
|
+
}), /* @__PURE__ */ jsx(TableBody, { children: isLoading ? skeletonRows.map((rowKey) => /* @__PURE__ */ jsx(TableRow, { children: table.getVisibleLeafColumns().map((column) => {
|
|
275
|
+
return /* @__PURE__ */ jsx(TableCell, {
|
|
276
|
+
pinned: !!column.getIsPinned(),
|
|
277
|
+
pinnedSide: getPinnedSide(column),
|
|
278
|
+
style: getCommonPinningStyles(column),
|
|
279
|
+
children: column.id === ROW_SELECT_COLUMN_ID ? /* @__PURE__ */ jsx(Skeleton, { className: "size-4 rounded-sm" }) : renderTableCellSkeleton(column.columnDef.meta?.skeletonType)
|
|
280
|
+
}, `${rowKey}-${column.id}`);
|
|
281
|
+
}) }, rowKey)) : rows.map((row) => /* @__PURE__ */ jsx(TableRow, {
|
|
282
|
+
"data-state": row.getIsSelected() ? "selected" : void 0,
|
|
283
|
+
onClick: () => onRowClick?.(row),
|
|
284
|
+
children: row.getVisibleCells().map((cell) => {
|
|
285
|
+
const isInteractiveColumn = interactiveColumnIds.includes(cell.column.id);
|
|
286
|
+
return /* @__PURE__ */ jsx(TableCell, {
|
|
287
|
+
pinned: !!cell.column.getIsPinned(),
|
|
288
|
+
pinnedSide: getPinnedSide(cell.column),
|
|
289
|
+
style: getCommonPinningStyles(cell.column),
|
|
290
|
+
className: cn(onRowClick && "cursor-pointer", cell.column.id === ACTIONS_COLUMN_ID && "text-center"),
|
|
291
|
+
onClick: isInteractiveColumn ? (event) => event.stopPropagation() : void 0,
|
|
292
|
+
children: flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
293
|
+
}, cell.id);
|
|
294
|
+
})
|
|
295
|
+
}, row.id)) })]
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
function DataTableCardGrid({ actionsColumnId = ACTIONS_COLUMN_ID, badgeColumnId, className, detailColumnIds, emptyState, isLoading: isLoadingProp, loadingCardCount = DEFAULT_SKELETON_ROW_COUNT, onCardClick, renderActions, renderCard, subtitleColumnId, table: tableProp, titleColumnId, ...props }) {
|
|
299
|
+
const context = useOptionalDataTableContext();
|
|
300
|
+
const table = tableProp ?? context?.table;
|
|
301
|
+
const isLoading = isLoadingProp ?? context?.isLoading;
|
|
302
|
+
const handleCardClick = onCardClick ?? context?.onRowClick;
|
|
303
|
+
if (!table) throw new Error("DataTableCardGrid requires a table prop or DataTableRoot context.");
|
|
304
|
+
const rows = table.getRowModel().rows;
|
|
305
|
+
const isEmpty = !isLoading && rows.length === 0;
|
|
306
|
+
const resolvedTitleColumnId = titleColumnId ?? getColumnIdByCardMeta(table, "useAsCardTitle");
|
|
307
|
+
const resolvedSubtitleColumnId = subtitleColumnId ?? getColumnIdByCardMeta(table, "useAsCardSubtitle");
|
|
308
|
+
const resolvedBadgeColumnId = badgeColumnId ?? getColumnIdByCardMeta(table, "useAsCardBadge");
|
|
309
|
+
const resolvedDetailColumnIds = getDataTableCardDetailColumnIds({
|
|
310
|
+
actionsColumnId,
|
|
311
|
+
badgeColumnId: resolvedBadgeColumnId,
|
|
312
|
+
detailColumnIds,
|
|
313
|
+
subtitleColumnId: resolvedSubtitleColumnId,
|
|
314
|
+
table,
|
|
315
|
+
titleColumnId: resolvedTitleColumnId
|
|
316
|
+
});
|
|
317
|
+
const skeletonCards = Array.from({ length: loadingCardCount }, (_, index) => index);
|
|
318
|
+
if (isEmpty && emptyState) return emptyState;
|
|
319
|
+
return /* @__PURE__ */ jsx("div", {
|
|
320
|
+
"data-slot": "data-table-card-grid",
|
|
321
|
+
className: cn("grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3", className),
|
|
322
|
+
...props,
|
|
323
|
+
children: isLoading ? skeletonCards.map((cardKey) => /* @__PURE__ */ jsxs(TableCard, {
|
|
324
|
+
"aria-hidden": true,
|
|
325
|
+
children: [
|
|
326
|
+
/* @__PURE__ */ jsxs("div", {
|
|
327
|
+
className: "flex min-w-0 items-start justify-between gap-4",
|
|
328
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
329
|
+
className: "min-w-0 flex-1 space-y-2",
|
|
330
|
+
children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-5 w-4/5 rounded" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-2/5 rounded" })]
|
|
331
|
+
}), /* @__PURE__ */ jsx(Skeleton, { className: "size-8 rounded-full" })]
|
|
332
|
+
}),
|
|
333
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-8 w-24 rounded-full" }),
|
|
334
|
+
/* @__PURE__ */ jsx("div", {
|
|
335
|
+
className: "space-y-3",
|
|
336
|
+
children: range(1, 4).map((detailKey) => /* @__PURE__ */ jsxs("div", {
|
|
337
|
+
className: "flex items-center justify-between gap-4 border-line-subtle border-t pt-3 first:border-t-0 first:pt-0",
|
|
338
|
+
children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-20 rounded" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-28 rounded" })]
|
|
339
|
+
}, detailKey))
|
|
340
|
+
})
|
|
341
|
+
]
|
|
342
|
+
}, cardKey)) : rows.map((row) => {
|
|
343
|
+
const actions = renderActions?.(row) ?? renderRowCellByColumnId(row, actionsColumnId);
|
|
344
|
+
const action = renderDataTableCardAction(row, handleCardClick);
|
|
345
|
+
const selection = renderDataTableCardSelection(row);
|
|
346
|
+
if (renderCard) return /* @__PURE__ */ jsx(React.Fragment, { children: renderCard(row, {
|
|
347
|
+
action,
|
|
348
|
+
actions,
|
|
349
|
+
row,
|
|
350
|
+
selection,
|
|
351
|
+
table
|
|
352
|
+
}) }, row.id);
|
|
353
|
+
const details = resolvedDetailColumnIds.map((columnId) => ({
|
|
354
|
+
label: getDataTableCardColumnLabel(table, columnId),
|
|
355
|
+
value: renderRowCellByColumnId(row, columnId)
|
|
356
|
+
}));
|
|
357
|
+
return /* @__PURE__ */ jsx(TableCard, {
|
|
358
|
+
action,
|
|
359
|
+
actions,
|
|
360
|
+
badge: resolvedBadgeColumnId ? renderRowCellByColumnId(row, resolvedBadgeColumnId) : null,
|
|
361
|
+
details,
|
|
362
|
+
selection,
|
|
363
|
+
selected: row.getIsSelected(),
|
|
364
|
+
subtitle: resolvedSubtitleColumnId ? renderRowCellByColumnId(row, resolvedSubtitleColumnId) : null,
|
|
365
|
+
title: resolvedTitleColumnId ? renderRowCellByColumnId(row, resolvedTitleColumnId) : row.id
|
|
366
|
+
}, row.id);
|
|
367
|
+
})
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
function renderDataTableCardAction(row, onCardClick) {
|
|
371
|
+
if (!onCardClick) return null;
|
|
372
|
+
return /* @__PURE__ */ jsx(TableCardAction, {
|
|
373
|
+
"aria-label": `Open row ${row.id}`,
|
|
374
|
+
onClick: () => onCardClick(row)
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
function renderDataTableCardSelection(row) {
|
|
378
|
+
if (!row.getCanSelect()) return null;
|
|
379
|
+
return /* @__PURE__ */ jsx(Checkbox, {
|
|
380
|
+
"aria-label": "Select row",
|
|
381
|
+
checked: row.getIsSelected(),
|
|
382
|
+
onCheckedChange: (value) => row.toggleSelected(!!value),
|
|
383
|
+
size: "sm"
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
function getColumnIdByCardMeta(table, metaKey) {
|
|
387
|
+
return table.getAllLeafColumns().find((column) => column.columnDef.meta?.[metaKey])?.id;
|
|
388
|
+
}
|
|
389
|
+
function getDataTableCardDetailColumnIds({ actionsColumnId, badgeColumnId, detailColumnIds, subtitleColumnId, table, titleColumnId }) {
|
|
390
|
+
if (detailColumnIds) return detailColumnIds;
|
|
391
|
+
const reservedColumnIds = /* @__PURE__ */ new Set([
|
|
392
|
+
ACTIONS_COLUMN_ID,
|
|
393
|
+
ROW_SELECT_COLUMN_ID,
|
|
394
|
+
actionsColumnId,
|
|
395
|
+
badgeColumnId,
|
|
396
|
+
subtitleColumnId,
|
|
397
|
+
titleColumnId
|
|
398
|
+
]);
|
|
399
|
+
return table.getVisibleLeafColumns().filter((column) => !reservedColumnIds.has(column.id) && !column.columnDef.meta?.hideInCard).map((column) => column.id);
|
|
400
|
+
}
|
|
401
|
+
function getDataTableCardColumnLabel(table, columnId) {
|
|
402
|
+
const column = table.getAllLeafColumns().find((item) => item.id === columnId);
|
|
403
|
+
const header = column?.columnDef.header;
|
|
404
|
+
if (column?.columnDef.meta?.cardLabel) return column.columnDef.meta.cardLabel;
|
|
405
|
+
if (typeof header === "string") return header;
|
|
406
|
+
return column?.id ?? columnId;
|
|
407
|
+
}
|
|
408
|
+
function renderRowCellByColumnId(row, columnId) {
|
|
409
|
+
if (!columnId) return null;
|
|
410
|
+
const cell = row.getAllCells().find((item) => item.column.id === columnId);
|
|
411
|
+
if (!cell) return null;
|
|
412
|
+
return flexRender(cell.column.columnDef.cell, cell.getContext());
|
|
413
|
+
}
|
|
414
|
+
function DataTableBulkActions({ children, className, style, table: tableProp, ...props }) {
|
|
415
|
+
const context = useOptionalDataTableContext();
|
|
416
|
+
const table = tableProp ?? context?.table;
|
|
417
|
+
const barRef = React.useRef(null);
|
|
418
|
+
const [fixedStyle, setFixedStyle] = React.useState(null);
|
|
419
|
+
const [spacerHeight, setSpacerHeight] = React.useState(0);
|
|
420
|
+
if (!table) throw new Error("DataTableBulkActions requires a table prop or DataTable context.");
|
|
421
|
+
const selectedRows = table.getSelectedRowModel().rows;
|
|
422
|
+
React.useLayoutEffect(() => {
|
|
423
|
+
if (selectedRows.length === 0) {
|
|
424
|
+
setFixedStyle(null);
|
|
425
|
+
setSpacerHeight(0);
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
const bar = barRef.current;
|
|
429
|
+
const container = bar?.parentElement;
|
|
430
|
+
if (!bar || !container) return;
|
|
431
|
+
const updatePosition = () => {
|
|
432
|
+
const containerRect = container.getBoundingClientRect();
|
|
433
|
+
const left = Math.max(containerRect.left, 16);
|
|
434
|
+
const right = Math.max(window.innerWidth - containerRect.right, 16);
|
|
435
|
+
const height = bar.offsetHeight;
|
|
436
|
+
setFixedStyle((currentStyle) => currentStyle?.left === left && currentStyle.right === right ? currentStyle : {
|
|
437
|
+
left,
|
|
438
|
+
right
|
|
439
|
+
});
|
|
440
|
+
setSpacerHeight((currentHeight) => currentHeight === height ? currentHeight : height);
|
|
441
|
+
};
|
|
442
|
+
updatePosition();
|
|
443
|
+
const resizeObserver = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(updatePosition);
|
|
444
|
+
resizeObserver?.observe(container);
|
|
445
|
+
resizeObserver?.observe(bar);
|
|
446
|
+
window.addEventListener("resize", updatePosition);
|
|
447
|
+
window.addEventListener("scroll", updatePosition, true);
|
|
448
|
+
return () => {
|
|
449
|
+
resizeObserver?.disconnect();
|
|
450
|
+
window.removeEventListener("resize", updatePosition);
|
|
451
|
+
window.removeEventListener("scroll", updatePosition, true);
|
|
452
|
+
};
|
|
453
|
+
}, [selectedRows.length]);
|
|
454
|
+
if (selectedRows.length === 0) return null;
|
|
455
|
+
const content = typeof children === "function" ? children({
|
|
456
|
+
data: selectedRows.map((row) => row.original),
|
|
457
|
+
rows: selectedRows,
|
|
458
|
+
table
|
|
459
|
+
}) : children;
|
|
460
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
461
|
+
ref: barRef,
|
|
462
|
+
"data-slot": "data-table-bulk-actions",
|
|
463
|
+
className: cn("fixed bottom-4 z-50 flex items-center gap-4 rounded-xl border border-line bg-surface-overlay px-4 py-3 shadow-(--shadow-3)", !fixedStyle && "invisible", className),
|
|
464
|
+
style: {
|
|
465
|
+
...fixedStyle,
|
|
466
|
+
...style
|
|
467
|
+
},
|
|
468
|
+
...props,
|
|
469
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
470
|
+
className: "text-gdt-sm font-medium text-fg-secondary",
|
|
471
|
+
children: [selectedRows.length, " selected"]
|
|
472
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
473
|
+
className: "flex items-center gap-2",
|
|
474
|
+
children: content
|
|
475
|
+
})]
|
|
476
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
477
|
+
"aria-hidden": "true",
|
|
478
|
+
style: { height: spacerHeight }
|
|
479
|
+
})] });
|
|
480
|
+
}
|
|
481
|
+
function DataTablePagination({ className, controlAppearance = "icon", getSummaryLabel = ({ end, start, totalEntries }) => `Showing ${start} to ${end} of ${totalEntries} entries`, jumpToPageLabel = "Jump to page", nextLabel = "Next", onPageChange, page, pageCount: pageCountProp, pageSize: pageSizeProp, previousLabel = "Previous", showControls = true, showJumpToPage = true, showPreviousNext = true, showSummary = true, siblingCount = 1, table: tableProp, totalEntries: totalEntriesProp, ...props }) {
|
|
482
|
+
const context = useOptionalDataTableContext();
|
|
483
|
+
const table = tableProp ?? context?.table;
|
|
484
|
+
const tablePageSize = table?.getState().pagination.pageSize;
|
|
485
|
+
const pageSize = pageSizeProp ?? tablePageSize;
|
|
486
|
+
const totalEntries = totalEntriesProp ?? table?.getRowCount();
|
|
487
|
+
const derivedPageCount = totalEntries !== void 0 && pageSize ? Math.ceil(totalEntries / pageSize) : void 0;
|
|
488
|
+
if (!(page !== void 0 && (pageCountProp !== void 0 || derivedPageCount !== void 0)) && !table) throw new Error("DataTablePagination requires either a table (prop or DataTable context) or controlled `page` with `pageCount` or `totalEntries` + `pageSize`.");
|
|
489
|
+
const pageCount = pageCountProp ?? derivedPageCount ?? table?.getPageCount() ?? 0;
|
|
490
|
+
const currentPage = page ?? (table ? table.getState().pagination.pageIndex + 1 : 1);
|
|
491
|
+
if (!Number.isFinite(pageCount) || pageCount <= 1) return null;
|
|
492
|
+
const goToPage = (nextPage) => {
|
|
493
|
+
const clampedPage = Math.min(Math.max(nextPage, 1), pageCount);
|
|
494
|
+
if (clampedPage === currentPage) return;
|
|
495
|
+
if (onPageChange) onPageChange(clampedPage);
|
|
496
|
+
else table?.setPageIndex(clampedPage - 1);
|
|
497
|
+
};
|
|
498
|
+
const canPreviousPage = currentPage > 1;
|
|
499
|
+
const canNextPage = currentPage < pageCount;
|
|
500
|
+
const pages = getPaginationItems(currentPage, pageCount, siblingCount);
|
|
501
|
+
const startEntry = totalEntries !== void 0 && pageSize ? totalEntries === 0 ? 0 : (currentPage - 1) * pageSize + 1 : void 0;
|
|
502
|
+
const endEntry = totalEntries !== void 0 && pageSize ? Math.min(currentPage * pageSize, totalEntries) : void 0;
|
|
503
|
+
const summary = showSummary && totalEntries !== void 0 && pageSize !== void 0 && startEntry !== void 0 && endEntry !== void 0 ? getSummaryLabel({
|
|
504
|
+
end: endEntry,
|
|
505
|
+
page: currentPage,
|
|
506
|
+
pageSize,
|
|
507
|
+
start: startEntry,
|
|
508
|
+
totalEntries
|
|
509
|
+
}) : null;
|
|
510
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
511
|
+
"data-slot": "data-table-pagination",
|
|
512
|
+
className: cn("flex w-full flex-col gap-4 text-gdt-sm text-fg-primary md:flex-row md:items-center md:justify-between", className),
|
|
513
|
+
children: [summary ? /* @__PURE__ */ jsx("p", {
|
|
514
|
+
"data-slot": "data-table-pagination-summary",
|
|
515
|
+
className: "text-fg-primary",
|
|
516
|
+
children: summary
|
|
517
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
518
|
+
"aria-hidden": true,
|
|
519
|
+
className: "hidden md:block"
|
|
520
|
+
}), /* @__PURE__ */ jsx(Pagination, {
|
|
521
|
+
className: "mx-0 w-auto justify-start md:justify-end",
|
|
522
|
+
...props,
|
|
523
|
+
children: /* @__PURE__ */ jsxs(PaginationContent, { children: [
|
|
524
|
+
showControls && showPreviousNext ? /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsxs(PaginationButton, {
|
|
525
|
+
"aria-label": "Go to previous page",
|
|
526
|
+
appearance: controlAppearance,
|
|
527
|
+
disabled: !canPreviousPage,
|
|
528
|
+
onClick: () => goToPage(currentPage - 1),
|
|
529
|
+
page: Math.max(1, currentPage - 1),
|
|
530
|
+
children: [/* @__PURE__ */ jsx(ChevronLeft, { className: "cn-rtl-flip" }), controlAppearance === "control" ? previousLabel : null]
|
|
531
|
+
}) }) : null,
|
|
532
|
+
showControls ? pages.map((paginationPage, index) => paginationPage === "ellipsis" ? /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationEllipsis, {}) }, `ellipsis-${index.toString()}`) : /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationButton, {
|
|
533
|
+
isActive: paginationPage === currentPage,
|
|
534
|
+
onClick: () => goToPage(paginationPage),
|
|
535
|
+
page: paginationPage,
|
|
536
|
+
children: paginationPage
|
|
537
|
+
}) }, paginationPage)) : null,
|
|
538
|
+
showControls && showPreviousNext ? /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsxs(PaginationButton, {
|
|
539
|
+
"aria-label": "Go to next page",
|
|
540
|
+
appearance: controlAppearance,
|
|
541
|
+
disabled: !canNextPage,
|
|
542
|
+
onClick: () => goToPage(currentPage + 1),
|
|
543
|
+
page: Math.min(pageCount, currentPage + 1),
|
|
544
|
+
children: [controlAppearance === "control" ? nextLabel : null, /* @__PURE__ */ jsx(ChevronRight, { className: "cn-rtl-flip" })]
|
|
545
|
+
}) }) : null,
|
|
546
|
+
showJumpToPage ? /* @__PURE__ */ jsx(DataTablePaginationJumpToPage, {
|
|
547
|
+
currentPage,
|
|
548
|
+
label: jumpToPageLabel,
|
|
549
|
+
onSubmit: goToPage,
|
|
550
|
+
totalPages: pageCount
|
|
551
|
+
}) : null
|
|
552
|
+
] })
|
|
553
|
+
})]
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
function DataTablePaginationJumpToPage({ currentPage, label, onSubmit, totalPages }) {
|
|
557
|
+
const inputId = React.useId();
|
|
558
|
+
const [value, setValue] = React.useState(currentPage.toString());
|
|
559
|
+
React.useEffect(() => {
|
|
560
|
+
setValue(currentPage.toString());
|
|
561
|
+
}, [currentPage]);
|
|
562
|
+
const commitValue = (nextValue) => {
|
|
563
|
+
if (nextValue.trim() === "") {
|
|
564
|
+
setValue(currentPage.toString());
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
const parsedPage = Number.parseInt(nextValue, 10);
|
|
568
|
+
if (!Number.isFinite(parsedPage)) {
|
|
569
|
+
setValue(currentPage.toString());
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
const clampedPage = clampPage(parsedPage, totalPages);
|
|
573
|
+
setValue(clampedPage.toString());
|
|
574
|
+
onSubmit(clampedPage);
|
|
575
|
+
};
|
|
576
|
+
return /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsxs("label", {
|
|
577
|
+
htmlFor: inputId,
|
|
578
|
+
className: "ml-2 flex items-center gap-3 text-gdt-sm font-normal text-fg-secondary",
|
|
579
|
+
children: [/* @__PURE__ */ jsx("span", { children: label }), /* @__PURE__ */ jsx(Input, {
|
|
580
|
+
id: inputId,
|
|
581
|
+
type: "number",
|
|
582
|
+
inputMode: "numeric",
|
|
583
|
+
min: 1,
|
|
584
|
+
max: totalPages,
|
|
585
|
+
size: "sm",
|
|
586
|
+
value,
|
|
587
|
+
className: "w-16 rounded-md text-center text-fg-primary [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none",
|
|
588
|
+
"aria-label": typeof label === "string" ? label : "Jump to page",
|
|
589
|
+
onChange: (event) => {
|
|
590
|
+
setValue(event.target.value);
|
|
591
|
+
},
|
|
592
|
+
onBlur: (event) => {
|
|
593
|
+
commitValue(event.target.value);
|
|
594
|
+
},
|
|
595
|
+
onKeyDown: (event) => {
|
|
596
|
+
if (event.key === "Enter") {
|
|
597
|
+
event.preventDefault();
|
|
598
|
+
commitValue(event.currentTarget.value);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
})]
|
|
602
|
+
}) });
|
|
603
|
+
}
|
|
604
|
+
function clampPage(page, totalPages) {
|
|
605
|
+
return Math.min(Math.max(page, 1), totalPages);
|
|
606
|
+
}
|
|
607
|
+
function getPaginationItems(currentPage, pageCount, siblingCount) {
|
|
608
|
+
const boundaryCount = 1;
|
|
609
|
+
const startPages = range(1, Math.min(boundaryCount, pageCount));
|
|
610
|
+
const endPages = range(Math.max(pageCount - boundaryCount + 1, 2), pageCount);
|
|
611
|
+
const siblingsStart = Math.max(Math.min(currentPage - siblingCount, pageCount - boundaryCount - siblingCount * 2 - 1), 3);
|
|
612
|
+
const siblingsEnd = Math.min(Math.max(currentPage + siblingCount, boundaryCount + siblingCount * 2 + 2), endPages.length > 0 ? endPages[0] - 2 : pageCount - 1);
|
|
613
|
+
const items = [...startPages];
|
|
614
|
+
if (siblingsStart > 3) items.push("ellipsis");
|
|
615
|
+
else if (2 < pageCount - boundaryCount) items.push(2);
|
|
616
|
+
items.push(...range(siblingsStart, siblingsEnd));
|
|
617
|
+
if (siblingsEnd < pageCount - boundaryCount - 1) items.push("ellipsis");
|
|
618
|
+
else if (pageCount - boundaryCount > boundaryCount) items.push(pageCount - boundaryCount);
|
|
619
|
+
items.push(...endPages);
|
|
620
|
+
return items;
|
|
621
|
+
}
|
|
622
|
+
function range(start, end) {
|
|
623
|
+
const length = end - start + 1;
|
|
624
|
+
if (length <= 0) return [];
|
|
625
|
+
return Array.from({ length }, (_, index) => start + index);
|
|
626
|
+
}
|
|
627
|
+
function DataTablePageSizeSelect({ className, label = (pageSize) => `Showing ${pageSize} entries`, onPageSizeChange, pageSize: pageSizeProp, pageSizeOptions = DEFAULT_PAGE_SIZE_OPTIONS, table: tableProp }) {
|
|
628
|
+
const context = useOptionalDataTableContext();
|
|
629
|
+
const table = tableProp ?? context?.table;
|
|
630
|
+
if (!(pageSizeProp !== void 0) && !table) throw new Error("DataTablePageSizeSelect requires either a table (prop or DataTable context) or the controlled `pageSize` prop.");
|
|
631
|
+
const pageSize = pageSizeProp ?? table?.getState().pagination.pageSize ?? DEFAULT_PAGE_SIZE_OPTIONS[0];
|
|
632
|
+
const handleValueChange = (value) => {
|
|
633
|
+
if (value === null) return;
|
|
634
|
+
const nextPageSize = Number(value);
|
|
635
|
+
if (onPageSizeChange) onPageSizeChange(nextPageSize);
|
|
636
|
+
else table?.setPageSize(nextPageSize);
|
|
637
|
+
};
|
|
638
|
+
return /* @__PURE__ */ jsxs(Select, {
|
|
639
|
+
value: pageSize.toString(),
|
|
640
|
+
onValueChange: handleValueChange,
|
|
641
|
+
size: "sm",
|
|
642
|
+
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
643
|
+
unstyled: true,
|
|
644
|
+
render: /* @__PURE__ */ jsx(Button, {
|
|
645
|
+
variant: "tertiary-outline",
|
|
646
|
+
className
|
|
647
|
+
}),
|
|
648
|
+
children: /* @__PURE__ */ jsx(SelectValue, { children: () => label(pageSize) })
|
|
649
|
+
}), /* @__PURE__ */ jsx(SelectContent, {
|
|
650
|
+
side: "top",
|
|
651
|
+
children: pageSizeOptions.map((option) => /* @__PURE__ */ jsx(SelectItem, {
|
|
652
|
+
value: option.toString(),
|
|
653
|
+
children: option
|
|
654
|
+
}, option))
|
|
655
|
+
})]
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
function DataTableEmptyState({ action, className, description = "Try adjusting your search or filters to find what you need.", title = "No results found", ...props }) {
|
|
659
|
+
return /* @__PURE__ */ jsxs(Empty, {
|
|
660
|
+
className: cn("min-h-60 rounded-[20px] border border-line bg-canvas", className),
|
|
661
|
+
...props,
|
|
662
|
+
children: [/* @__PURE__ */ jsxs(EmptyHeader, { children: [
|
|
663
|
+
/* @__PURE__ */ jsx(EmptyMedia, {
|
|
664
|
+
variant: "icon",
|
|
665
|
+
children: /* @__PURE__ */ jsx(SearchX, {})
|
|
666
|
+
}),
|
|
667
|
+
/* @__PURE__ */ jsx(EmptyTitle, { children: title }),
|
|
668
|
+
description ? /* @__PURE__ */ jsx(EmptyDescription, { children: description }) : null
|
|
669
|
+
] }), action ? /* @__PURE__ */ jsx(EmptyContent, { children: action }) : null]
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
//#endregion
|
|
673
|
+
export { DataTable, DataTableBulkActions, DataTableCardGrid, DataTableEmptyState, DataTableFilter, DataTablePageSizeSelect, DataTablePagination, DataTableRoot, DataTableToolbar, useDataTable, useDataTableContext };
|