@trackany-device/components 1.0.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/package.json +185 -0
- package/src/assets/logo.png +0 -0
- package/src/assets/map/arrows/map-arrow-blue.png +0 -0
- package/src/assets/map/arrows/map-arrow-green.png +0 -0
- package/src/assets/map/arrows/map-arrow-purple.png +0 -0
- package/src/assets/map/arrows/map-arrow-red.png +0 -0
- package/src/assets/map/flags/flag-blue.png +0 -0
- package/src/assets/map/flags/flag-green.png +0 -0
- package/src/assets/map/flags/flag-red.png +0 -0
- package/src/assets/map/flags/flag-yellow.png +0 -0
- package/src/assets/map/pins/map-pin-blue.png +0 -0
- package/src/assets/map/pins/map-pin-green.png +0 -0
- package/src/assets/map/pins/map-pin-purple.png +0 -0
- package/src/assets/map/pins/map-pin-red.png +0 -0
- package/src/components/Card.tsx +9 -0
- package/src/components/alert-error.tsx +24 -0
- package/src/components/app-content.tsx +22 -0
- package/src/components/app-header.tsx +153 -0
- package/src/components/app-logo-icon.tsx +13 -0
- package/src/components/app-logo.tsx +21 -0
- package/src/components/app-shell.tsx +19 -0
- package/src/components/app-sidebar-header.tsx +68 -0
- package/src/components/app-sidebar.tsx +106 -0
- package/src/components/appearance-tabs.tsx +46 -0
- package/src/components/breadcrumbs.tsx +50 -0
- package/src/components/cms/blurred-image.tsx +111 -0
- package/src/components/cms/section-bg.tsx +473 -0
- package/src/components/cms/section-button.tsx +127 -0
- package/src/components/cms/sections/banner-5050-section.tsx +135 -0
- package/src/components/cms/sections/blogs-listing-section.tsx +270 -0
- package/src/components/cms/sections/cards-grid-section.tsx +185 -0
- package/src/components/cms/sections/contact-form-section.tsx +157 -0
- package/src/components/cms/sections/cta-section.tsx +101 -0
- package/src/components/cms/sections/featured-blog-slider-section.tsx +256 -0
- package/src/components/cms/sections/featured-products-grid-section.tsx +173 -0
- package/src/components/cms/sections/featured-solutions-grid-section.tsx +183 -0
- package/src/components/cms/sections/hero-section.tsx +180 -0
- package/src/components/cms/sections/solutions-with-filter-section.tsx +234 -0
- package/src/components/cms/sections/text-section.tsx +77 -0
- package/src/components/cutout-image.tsx +228 -0
- package/src/components/devices/devices-mini-map.tsx +275 -0
- package/src/components/docs/docs-shell.tsx +280 -0
- package/src/components/fleet-hero-animated.tsx +383 -0
- package/src/components/input-error.tsx +17 -0
- package/src/components/keenicons/assets/duotone/Read Me.txt +7 -0
- package/src/components/keenicons/assets/duotone/demo-files/demo.css +160 -0
- package/src/components/keenicons/assets/duotone/demo-files/demo.js +32 -0
- package/src/components/keenicons/assets/duotone/demo.html +12424 -0
- package/src/components/keenicons/assets/duotone/fonts/keenicons-duotone.svg +1109 -0
- package/src/components/keenicons/assets/duotone/fonts/keenicons-duotone.ttf +0 -0
- package/src/components/keenicons/assets/duotone/fonts/keenicons-duotone.woff +0 -0
- package/src/components/keenicons/assets/duotone/selection.json +17313 -0
- package/src/components/keenicons/assets/duotone/style.css +4931 -0
- package/src/components/keenicons/assets/filled/Read Me.txt +7 -0
- package/src/components/keenicons/assets/filled/demo-files/demo.css +160 -0
- package/src/components/keenicons/assets/filled/demo-files/demo.js +32 -0
- package/src/components/keenicons/assets/filled/demo.html +12370 -0
- package/src/components/keenicons/assets/filled/fonts/keenicons-filled.svg +1082 -0
- package/src/components/keenicons/assets/filled/fonts/keenicons-filled.ttf +0 -0
- package/src/components/keenicons/assets/filled/fonts/keenicons-filled.woff +0 -0
- package/src/components/keenicons/assets/filled/selection.json +17096 -0
- package/src/components/keenicons/assets/filled/style.css +4769 -0
- package/src/components/keenicons/assets/outline/Read Me.txt +7 -0
- package/src/components/keenicons/assets/outline/demo-files/demo.css +160 -0
- package/src/components/keenicons/assets/outline/demo-files/demo.js +32 -0
- package/src/components/keenicons/assets/outline/demo.html +11356 -0
- package/src/components/keenicons/assets/outline/fonts/keenicons-outline.svg +575 -0
- package/src/components/keenicons/assets/outline/fonts/keenicons-outline.ttf +0 -0
- package/src/components/keenicons/assets/outline/fonts/keenicons-outline.woff +0 -0
- package/src/components/keenicons/assets/outline/selection.json +13054 -0
- package/src/components/keenicons/assets/outline/style.css +1721 -0
- package/src/components/keenicons/assets/solid/Read Me.txt +7 -0
- package/src/components/keenicons/assets/solid/demo-files/demo.css +160 -0
- package/src/components/keenicons/assets/solid/demo-files/demo.js +32 -0
- package/src/components/keenicons/assets/solid/demo.html +11356 -0
- package/src/components/keenicons/assets/solid/fonts/keenicons-solid.svg +575 -0
- package/src/components/keenicons/assets/solid/fonts/keenicons-solid.ttf +0 -0
- package/src/components/keenicons/assets/solid/fonts/keenicons-solid.woff +0 -0
- package/src/components/keenicons/assets/solid/selection.json +13048 -0
- package/src/components/keenicons/assets/solid/style.css +1721 -0
- package/src/components/keenicons/assets/styles.css +4 -0
- package/src/components/keenicons/index.ts +2 -0
- package/src/components/keenicons/keenicons.tsx +16 -0
- package/src/components/keenicons/types.ts +7 -0
- package/src/components/nav-footer.tsx +49 -0
- package/src/components/nav-main.tsx +53 -0
- package/src/components/nav-user.tsx +59 -0
- package/src/components/notification-bell.tsx +190 -0
- package/src/components/products/product-card.tsx +159 -0
- package/src/components/text-link.tsx +23 -0
- package/src/components/ui/accordion-menu.tsx +322 -0
- package/src/components/ui/accordion.tsx +133 -0
- package/src/components/ui/alert-dialog.tsx +82 -0
- package/src/components/ui/alert.tsx +63 -0
- package/src/components/ui/avatar-group.tsx +129 -0
- package/src/components/ui/avatar.tsx +67 -0
- package/src/components/ui/badge.tsx +230 -0
- package/src/components/ui/breadcrumb.tsx +88 -0
- package/src/components/ui/button.tsx +412 -0
- package/src/components/ui/calendar.tsx +56 -0
- package/src/components/ui/card.tsx +147 -0
- package/src/components/ui/chart.tsx +290 -0
- package/src/components/ui/checkbox.tsx +47 -0
- package/src/components/ui/code.tsx +45 -0
- package/src/components/ui/collapsible.tsx +31 -0
- package/src/components/ui/command-palette.tsx +189 -0
- package/src/components/ui/command.tsx +138 -0
- package/src/components/ui/cookie-banner.tsx +220 -0
- package/src/components/ui/copy-button.tsx +60 -0
- package/src/components/ui/data-grid-column-filter.tsx +124 -0
- package/src/components/ui/data-grid-column-header.tsx +284 -0
- package/src/components/ui/data-grid-column-visibility.tsx +38 -0
- package/src/components/ui/data-grid-pagination.tsx +206 -0
- package/src/components/ui/data-grid-table-dnd-rows.tsx +147 -0
- package/src/components/ui/data-grid-table-dnd.tsx +175 -0
- package/src/components/ui/data-grid-table.tsx +500 -0
- package/src/components/ui/data-grid.tsx +193 -0
- package/src/components/ui/data-list.tsx +76 -0
- package/src/components/ui/datefield.tsx +91 -0
- package/src/components/ui/dialog.tsx +139 -0
- package/src/components/ui/divider.tsx +41 -0
- package/src/components/ui/drawer.tsx +59 -0
- package/src/components/ui/dropdown-menu.tsx +224 -0
- package/src/components/ui/empty-state.tsx +54 -0
- package/src/components/ui/file-upload.tsx +152 -0
- package/src/components/ui/form.tsx +88 -0
- package/src/components/ui/icon.tsx +14 -0
- package/src/components/ui/input-otp.tsx +71 -0
- package/src/components/ui/input.tsx +155 -0
- package/src/components/ui/kbd.tsx +26 -0
- package/src/components/ui/label.tsx +31 -0
- package/src/components/ui/navigation-menu.tsx +168 -0
- package/src/components/ui/pagination.tsx +37 -0
- package/src/components/ui/placeholder-pattern.tsx +21 -0
- package/src/components/ui/popover.tsx +50 -0
- package/src/components/ui/progress.tsx +65 -0
- package/src/components/ui/radio-group.tsx +73 -0
- package/src/components/ui/resizable.tsx +39 -0
- package/src/components/ui/scroll-area.tsx +50 -0
- package/src/components/ui/select.tsx +234 -0
- package/src/components/ui/separator.tsx +24 -0
- package/src/components/ui/sheet.tsx +147 -0
- package/src/components/ui/sidebar.tsx +721 -0
- package/src/components/ui/skeleton.tsx +15 -0
- package/src/components/ui/slider.tsx +35 -0
- package/src/components/ui/sonner.tsx +28 -0
- package/src/components/ui/sortable.tsx +724 -0
- package/src/components/ui/spinner.tsx +17 -0
- package/src/components/ui/stat-card.tsx +82 -0
- package/src/components/ui/stepper.tsx +410 -0
- package/src/components/ui/switch.tsx +68 -0
- package/src/components/ui/table.tsx +42 -0
- package/src/components/ui/tabs.tsx +196 -0
- package/src/components/ui/timeline.tsx +90 -0
- package/src/components/ui/toggle-group.tsx +73 -0
- package/src/components/ui/toggle.tsx +45 -0
- package/src/components/ui/tooltip.tsx +55 -0
- package/src/components/user-info.tsx +33 -0
- package/src/components/user-menu-content.tsx +53 -0
- package/src/components/web/SiteFooter.tsx +154 -0
- package/src/components/web/SiteHeader.tsx +159 -0
- package/src/components/workflows/workflow-canvas.tsx +321 -0
- package/src/controls/Blockquote.tsx +25 -0
- package/src/controls/Button.tsx +101 -0
- package/src/controls/Checkbox.tsx +29 -0
- package/src/controls/DateField.tsx +37 -0
- package/src/controls/FormField.tsx +20 -0
- package/src/controls/Heading.tsx +28 -0
- package/src/controls/Input.tsx +21 -0
- package/src/controls/Label.tsx +18 -0
- package/src/controls/Paragraph.tsx +39 -0
- package/src/controls/PasswordInput.tsx +40 -0
- package/src/controls/RadioGroup.tsx +70 -0
- package/src/controls/Select.tsx +24 -0
- package/src/controls/Slider.tsx +33 -0
- package/src/controls/Switch.tsx +31 -0
- package/src/controls/Textarea.tsx +22 -0
- package/src/elements/ConfirmPasswordForm.tsx +43 -0
- package/src/elements/DeviceStatusBadge.tsx +38 -0
- package/src/elements/DriverCard.tsx +67 -0
- package/src/elements/ForgotPasswordForm.tsx +64 -0
- package/src/elements/IncidentCard.tsx +67 -0
- package/src/elements/LoginForm.tsx +100 -0
- package/src/elements/OtpForm.tsx +71 -0
- package/src/elements/RegisterForm.tsx +150 -0
- package/src/elements/ResetPasswordForm.tsx +72 -0
- package/src/elements/SmsChallengeForm.tsx +104 -0
- package/src/elements/VehicleCard.tsx +73 -0
- package/src/elements/VerifyEmailForm.tsx +39 -0
- package/src/hooks/use-appearance.tsx +117 -0
- package/src/hooks/use-applied-theme.ts +98 -0
- package/src/hooks/use-clipboard.ts +34 -0
- package/src/hooks/use-current-url.ts +83 -0
- package/src/hooks/use-dark-mode.ts +48 -0
- package/src/hooks/use-flash-toast.ts +29 -0
- package/src/hooks/use-initials.tsx +24 -0
- package/src/hooks/use-mobile-navigation.ts +12 -0
- package/src/hooks/use-mobile.tsx +38 -0
- package/src/index.ts +408 -0
- package/src/layouts/AppLayout.tsx +60 -0
- package/src/layouts/AuthLayout.tsx +32 -0
- package/src/layouts/SettingsLayout.tsx +21 -0
- package/src/layouts/app/AIChatLayout.tsx +73 -0
- package/src/layouts/app/AsideSidebarLayout.tsx +3 -0
- package/src/layouts/app/CalendarSidebarLayout.tsx +69 -0
- package/src/layouts/app/CommunitiesNavbarLayout.tsx +3 -0
- package/src/layouts/app/DualNavbarSidebarLayout.tsx +3 -0
- package/src/layouts/app/FocusSidebarLayout.tsx +75 -0
- package/src/layouts/app/MailLayout.tsx +69 -0
- package/src/layouts/app/MegaMenuHeaderLayout.tsx +3 -0
- package/src/layouts/app/MegaMenuLayout.tsx +81 -0
- package/src/layouts/app/MegaMenuNavbarLayout.tsx +88 -0
- package/src/layouts/app/MegaMenuSearchNavbarLayout.tsx +3 -0
- package/src/layouts/app/NavbarCollapsibleLayout.tsx +88 -0
- package/src/layouts/app/NavbarCollapsibleLinksLayout.tsx +3 -0
- package/src/layouts/app/NavbarMinimalLayout.tsx +3 -0
- package/src/layouts/app/NavbarMinimalSidebarLayout.tsx +3 -0
- package/src/layouts/app/NavbarSidebarDashboardLayout.tsx +3 -0
- package/src/layouts/app/NavbarSidebarLayout.tsx +92 -0
- package/src/layouts/app/NavbarSimpleSidebarLayout.tsx +3 -0
- package/src/layouts/app/NavbarTitledSidebarLayout.tsx +3 -0
- package/src/layouts/app/PanelSidebarLayout.tsx +3 -0
- package/src/layouts/app/SearchNavbarSidebarLayout.tsx +3 -0
- package/src/layouts/app/SidebarBreadcrumbLayout.tsx +3 -0
- package/src/layouts/app/SidebarCleanLayout.tsx +3 -0
- package/src/layouts/app/SidebarCommunitiesLayout.tsx +3 -0
- package/src/layouts/app/SidebarContentLayout.tsx +3 -0
- package/src/layouts/app/SidebarDualMenuLayout.tsx +104 -0
- package/src/layouts/app/SidebarFixedLayout.tsx +166 -0
- package/src/layouts/app/SidebarFooterNavbarLayout.tsx +3 -0
- package/src/layouts/app/SidebarHeaderMenuLayout.tsx +3 -0
- package/src/layouts/app/SidebarMegaMenuLayout.tsx +4 -0
- package/src/layouts/app/SidebarMinimalLayout.tsx +70 -0
- package/src/layouts/app/SidebarMobileSearchLayout.tsx +3 -0
- package/src/layouts/app/SidebarMultiPanelLayout.tsx +3 -0
- package/src/layouts/app/SidebarPrimarySecondaryLayout.tsx +3 -0
- package/src/layouts/app/SidebarSearchHeaderLayout.tsx +103 -0
- package/src/layouts/app/SidebarSearchToolbarLayout.tsx +3 -0
- package/src/layouts/app/SidebarTabsDualLayout.tsx +3 -0
- package/src/layouts/app/SidebarTabsLayout.tsx +98 -0
- package/src/layouts/app/SidebarTreeLayout.tsx +3 -0
- package/src/layouts/app/SplitNavbarLayout.tsx +3 -0
- package/src/layouts/app/SplitSidebarDashboardLayout.tsx +3 -0
- package/src/layouts/app/SplitSidebarLayout.tsx +99 -0
- package/src/layouts/app/TopNavLayout.tsx +105 -0
- package/src/layouts/app/TopNavLinksLayout.tsx +3 -0
- package/src/layouts/app/WorkspaceBreadcrumbLayout.tsx +3 -0
- package/src/layouts/app/WorkspaceCommunitiesLayout.tsx +3 -0
- package/src/layouts/app/WorkspaceNavbarLayout.tsx +3 -0
- package/src/layouts/app/WorkspaceSidebarLayout.tsx +98 -0
- package/src/layouts/app/WorkspaceSidebarTitleLayout.tsx +3 -0
- package/src/layouts/app/app-header-layout.tsx +45 -0
- package/src/layouts/app/app-sidebar-layout.tsx +56 -0
- package/src/layouts/app/layout-context.tsx +44 -0
- package/src/layouts/app/layout-types.ts +47 -0
- package/src/layouts/app/partials/Footer.tsx +35 -0
- package/src/layouts/app/partials/HeaderTopbar.tsx +96 -0
- package/src/layouts/app/partials/Navbar.tsx +85 -0
- package/src/layouts/app/partials/Toolbar.tsx +47 -0
- package/src/layouts/app-layout.tsx +29 -0
- package/src/layouts/auth/AuthBrandedLayout.tsx +58 -0
- package/src/layouts/auth/AuthCardLayout.tsx +31 -0
- package/src/layouts/auth/AuthCenteredLayout.tsx +41 -0
- package/src/layouts/auth/AuthClassicLayout.tsx +41 -0
- package/src/layouts/auth/AuthSimpleLayout.tsx +33 -0
- package/src/layouts/auth/AuthSplitLayout.tsx +89 -0
- package/src/layouts/web-app-layout.tsx +162 -0
- package/src/layouts/web-layout.tsx +23 -0
- package/src/lib/datetime.ts +188 -0
- package/src/lib/google-maps-loader.ts +99 -0
- package/src/lib/location.ts +127 -0
- package/src/lib/lucide-icon-map.ts +132 -0
- package/src/lib/map-markers.ts +124 -0
- package/src/lib/map-styles.ts +351 -0
- package/src/lib/utils.ts +11 -0
- package/src/platform/adapters/default.tsx +156 -0
- package/src/platform/adapters/inertia.tsx +88 -0
- package/src/platform/adapters/nextjs.ts +86 -0
- package/src/platform/context.tsx +106 -0
- package/src/platform/index.ts +27 -0
- package/src/platform/types.ts +105 -0
- package/src/styles/layouts/sidebar-fixed.css +161 -0
- package/src/styles/themes.css +583 -0
- package/src/types/assets.d.ts +5 -0
- package/src/types/auth.ts +25 -0
- package/src/types/global.d.ts +13 -0
- package/src/types/index.ts +9 -0
- package/src/types/navigation.ts +15 -0
- package/src/types/ui.ts +32 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { CSSProperties, Fragment, useId } from 'react';
|
|
3
|
+
import { Button } from '../../controls/Button';
|
|
4
|
+
import { useDataGrid } from './data-grid';
|
|
5
|
+
import {
|
|
6
|
+
DataGridTableBase,
|
|
7
|
+
DataGridTableBody,
|
|
8
|
+
DataGridTableBodyRow,
|
|
9
|
+
DataGridTableBodyRowCell,
|
|
10
|
+
DataGridTableBodyRowExpandded,
|
|
11
|
+
DataGridTableBodyRowSkeleton,
|
|
12
|
+
DataGridTableBodyRowSkeletonCell,
|
|
13
|
+
DataGridTableEmpty,
|
|
14
|
+
DataGridTableHead,
|
|
15
|
+
DataGridTableHeadRow,
|
|
16
|
+
DataGridTableHeadRowCell,
|
|
17
|
+
DataGridTableHeadRowCellResize,
|
|
18
|
+
DataGridTableRowSpacer,
|
|
19
|
+
} from './data-grid-table';
|
|
20
|
+
import {
|
|
21
|
+
closestCenter,
|
|
22
|
+
DndContext,
|
|
23
|
+
KeyboardSensor,
|
|
24
|
+
MouseSensor,
|
|
25
|
+
TouchSensor,
|
|
26
|
+
useSensor,
|
|
27
|
+
useSensors,
|
|
28
|
+
type DragEndEvent,
|
|
29
|
+
} from '@dnd-kit/core';
|
|
30
|
+
import { restrictToParentElement } from '@dnd-kit/modifiers';
|
|
31
|
+
import { horizontalListSortingStrategy, SortableContext, useSortable } from '@dnd-kit/sortable';
|
|
32
|
+
import { CSS } from '@dnd-kit/utilities';
|
|
33
|
+
import { Cell, flexRender, Header, HeaderGroup, Row } from '@tanstack/react-table';
|
|
34
|
+
import { GripVertical } from 'lucide-react';
|
|
35
|
+
|
|
36
|
+
function DataGridTableDndHeader<TData>({ header }: { header: Header<TData, unknown> }) {
|
|
37
|
+
const { props } = useDataGrid();
|
|
38
|
+
const { column } = header;
|
|
39
|
+
|
|
40
|
+
const { attributes, isDragging, listeners, setNodeRef, transform, transition } = useSortable({
|
|
41
|
+
id: header.column.id,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const style: CSSProperties = {
|
|
45
|
+
opacity: isDragging ? 0.8 : 1,
|
|
46
|
+
position: 'relative',
|
|
47
|
+
transform: CSS.Translate.toString(transform),
|
|
48
|
+
transition,
|
|
49
|
+
whiteSpace: 'nowrap',
|
|
50
|
+
width: header.column.getSize(),
|
|
51
|
+
zIndex: isDragging ? 1 : 0,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<DataGridTableHeadRowCell header={header} dndStyle={style} dndRef={setNodeRef}>
|
|
56
|
+
<div className="flex items-center justify-start gap-0.5">
|
|
57
|
+
<Button
|
|
58
|
+
size="sm"
|
|
59
|
+
variant="ghost"
|
|
60
|
+
className="-ms-2 size-6"
|
|
61
|
+
{...attributes}
|
|
62
|
+
{...listeners}
|
|
63
|
+
aria-label="Drag to reorder"
|
|
64
|
+
>
|
|
65
|
+
<GripVertical className="opacity-50" aria-hidden="true" />
|
|
66
|
+
</Button>
|
|
67
|
+
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
|
|
68
|
+
{props.tableLayout?.columnsResizable && column.getCanResize() && (
|
|
69
|
+
<DataGridTableHeadRowCellResize header={header} />
|
|
70
|
+
)}
|
|
71
|
+
</div>
|
|
72
|
+
</DataGridTableHeadRowCell>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function DataGridTableDndCell<TData>({ cell }: { cell: Cell<TData, unknown> }) {
|
|
77
|
+
const { isDragging, setNodeRef, transform, transition } = useSortable({
|
|
78
|
+
id: cell.column.id,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const style: CSSProperties = {
|
|
82
|
+
opacity: isDragging ? 0.8 : 1,
|
|
83
|
+
position: 'relative',
|
|
84
|
+
transform: CSS.Translate.toString(transform),
|
|
85
|
+
transition,
|
|
86
|
+
width: cell.column.getSize(),
|
|
87
|
+
zIndex: isDragging ? 1 : 0,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<DataGridTableBodyRowCell cell={cell} dndStyle={style} dndRef={setNodeRef}>
|
|
92
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
93
|
+
</DataGridTableBodyRowCell>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function DataGridTableDnd<TData>({ handleDragEnd }: { handleDragEnd: (event: DragEndEvent) => void }) {
|
|
98
|
+
const { table, isLoading, props } = useDataGrid();
|
|
99
|
+
const pagination = table.getState().pagination;
|
|
100
|
+
|
|
101
|
+
const sensors = useSensors(useSensor(MouseSensor, {}), useSensor(TouchSensor, {}), useSensor(KeyboardSensor, {}));
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<DndContext
|
|
105
|
+
id={useId()}
|
|
106
|
+
collisionDetection={closestCenter}
|
|
107
|
+
modifiers={[restrictToParentElement]}
|
|
108
|
+
onDragEnd={handleDragEnd}
|
|
109
|
+
sensors={sensors}
|
|
110
|
+
>
|
|
111
|
+
<div className="relative">
|
|
112
|
+
<DataGridTableBase>
|
|
113
|
+
<DataGridTableHead>
|
|
114
|
+
{table.getHeaderGroups().map((headerGroup: HeaderGroup<TData>, index) => {
|
|
115
|
+
console.log('table.getState().columnOrder:', table.getState().columnOrder);
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<DataGridTableHeadRow headerGroup={headerGroup} key={index}>
|
|
119
|
+
<SortableContext items={table.getState().columnOrder} strategy={horizontalListSortingStrategy}>
|
|
120
|
+
{headerGroup.headers.map((header, index) => (
|
|
121
|
+
<DataGridTableDndHeader header={header} key={index} />
|
|
122
|
+
))}
|
|
123
|
+
</SortableContext>
|
|
124
|
+
</DataGridTableHeadRow>
|
|
125
|
+
);
|
|
126
|
+
})}
|
|
127
|
+
</DataGridTableHead>
|
|
128
|
+
|
|
129
|
+
{(props.tableLayout?.stripped || !props.tableLayout?.rowBorder) && <DataGridTableRowSpacer />}
|
|
130
|
+
|
|
131
|
+
<DataGridTableBody>
|
|
132
|
+
{props.loadingMode === 'skeleton' && isLoading && pagination?.pageSize ? (
|
|
133
|
+
Array.from({ length: pagination.pageSize }).map((_, rowIndex) => (
|
|
134
|
+
<DataGridTableBodyRowSkeleton key={rowIndex}>
|
|
135
|
+
{table.getVisibleFlatColumns().map((column, colIndex) => {
|
|
136
|
+
return (
|
|
137
|
+
<DataGridTableBodyRowSkeletonCell column={column} key={colIndex}>
|
|
138
|
+
{column.columnDef.meta?.skeleton}
|
|
139
|
+
</DataGridTableBodyRowSkeletonCell>
|
|
140
|
+
);
|
|
141
|
+
})}
|
|
142
|
+
</DataGridTableBodyRowSkeleton>
|
|
143
|
+
))
|
|
144
|
+
) : table.getRowModel().rows.length ? (
|
|
145
|
+
table.getRowModel().rows.map((row: Row<TData>, index) => {
|
|
146
|
+
return (
|
|
147
|
+
<Fragment key={row.id}>
|
|
148
|
+
<DataGridTableBodyRow row={row} key={index}>
|
|
149
|
+
{row.getVisibleCells().map((cell: Cell<TData, unknown>) => {
|
|
150
|
+
return (
|
|
151
|
+
<SortableContext
|
|
152
|
+
key={cell.id}
|
|
153
|
+
items={table.getState().columnOrder}
|
|
154
|
+
strategy={horizontalListSortingStrategy}
|
|
155
|
+
>
|
|
156
|
+
<DataGridTableDndCell cell={cell} />
|
|
157
|
+
</SortableContext>
|
|
158
|
+
);
|
|
159
|
+
})}
|
|
160
|
+
</DataGridTableBodyRow>
|
|
161
|
+
{row.getIsExpanded() && <DataGridTableBodyRowExpandded row={row} />}
|
|
162
|
+
</Fragment>
|
|
163
|
+
);
|
|
164
|
+
})
|
|
165
|
+
) : (
|
|
166
|
+
<DataGridTableEmpty />
|
|
167
|
+
)}
|
|
168
|
+
</DataGridTableBody>
|
|
169
|
+
</DataGridTableBase>
|
|
170
|
+
</div>
|
|
171
|
+
</DndContext>
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export { DataGridTableDnd };
|
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { CSSProperties, Fragment, ReactNode } from 'react';
|
|
4
|
+
import { Checkbox } from './checkbox';
|
|
5
|
+
import { useDataGrid } from './data-grid';
|
|
6
|
+
import { Cell, Column, flexRender, Header, HeaderGroup, Row } from '@tanstack/react-table';
|
|
7
|
+
import { cva } from 'class-variance-authority';
|
|
8
|
+
import { cn } from '../../lib/utils';
|
|
9
|
+
|
|
10
|
+
const headerCellSpacingVariants = cva('', {
|
|
11
|
+
variants: {
|
|
12
|
+
size: {
|
|
13
|
+
dense: 'px-2.5 h-8',
|
|
14
|
+
default: 'px-4',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
defaultVariants: {
|
|
18
|
+
size: 'default',
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const bodyCellSpacingVariants = cva('', {
|
|
23
|
+
variants: {
|
|
24
|
+
size: {
|
|
25
|
+
dense: 'px-2.5 py-2',
|
|
26
|
+
default: 'px-4 py-3',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
defaultVariants: {
|
|
30
|
+
size: 'default',
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
function getPinningStyles<TData>(column: Column<TData>): CSSProperties {
|
|
35
|
+
const isPinned = column.getIsPinned();
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
left: isPinned === 'left' ? `${column.getStart('left')}px` : undefined,
|
|
39
|
+
right: isPinned === 'right' ? `${column.getAfter('right')}px` : undefined,
|
|
40
|
+
position: isPinned ? 'sticky' : 'relative',
|
|
41
|
+
width: column.getSize(),
|
|
42
|
+
zIndex: isPinned ? 1 : 0,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function DataGridTableBase({ children }: { children: ReactNode }) {
|
|
47
|
+
const { props } = useDataGrid();
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<table
|
|
51
|
+
data-slot="data-grid-table"
|
|
52
|
+
className={cn(
|
|
53
|
+
'w-full align-middle caption-bottom text-left rtl:text-right text-foreground font-normal text-sm',
|
|
54
|
+
!props.tableLayout?.columnsDraggable && 'border-separate border-spacing-0',
|
|
55
|
+
props.tableLayout?.width === 'fixed' ? 'table-fixed' : 'table-auto',
|
|
56
|
+
props.tableClassNames?.base,
|
|
57
|
+
)}
|
|
58
|
+
>
|
|
59
|
+
{children}
|
|
60
|
+
</table>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function DataGridTableHead({ children }: { children: ReactNode }) {
|
|
65
|
+
const { props } = useDataGrid();
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<thead
|
|
69
|
+
className={cn(
|
|
70
|
+
props.tableClassNames?.header,
|
|
71
|
+
props.tableLayout?.headerSticky && props.tableClassNames?.headerSticky,
|
|
72
|
+
)}
|
|
73
|
+
>
|
|
74
|
+
{children}
|
|
75
|
+
</thead>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function DataGridTableHeadRow<TData>({
|
|
80
|
+
children,
|
|
81
|
+
headerGroup,
|
|
82
|
+
}: {
|
|
83
|
+
children: ReactNode;
|
|
84
|
+
headerGroup: HeaderGroup<TData>;
|
|
85
|
+
}) {
|
|
86
|
+
const { props } = useDataGrid();
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<tr
|
|
90
|
+
key={headerGroup.id}
|
|
91
|
+
className={cn(
|
|
92
|
+
'bg-muted/40',
|
|
93
|
+
props.tableLayout?.headerBorder && '[&>th]:border-b',
|
|
94
|
+
props.tableLayout?.cellBorder && '[&_>:last-child]:border-e-0',
|
|
95
|
+
props.tableLayout?.stripped && 'bg-transparent',
|
|
96
|
+
props.tableLayout?.headerBackground === false && 'bg-transparent',
|
|
97
|
+
props.tableClassNames?.headerRow,
|
|
98
|
+
)}
|
|
99
|
+
>
|
|
100
|
+
{children}
|
|
101
|
+
</tr>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function DataGridTableHeadRowCell<TData>({
|
|
106
|
+
children,
|
|
107
|
+
header,
|
|
108
|
+
dndRef,
|
|
109
|
+
dndStyle,
|
|
110
|
+
}: {
|
|
111
|
+
children: ReactNode;
|
|
112
|
+
header: Header<TData, unknown>;
|
|
113
|
+
dndRef?: React.Ref<HTMLTableCellElement>;
|
|
114
|
+
dndStyle?: CSSProperties;
|
|
115
|
+
}) {
|
|
116
|
+
const { props } = useDataGrid();
|
|
117
|
+
|
|
118
|
+
const { column } = header;
|
|
119
|
+
const isPinned = column.getIsPinned();
|
|
120
|
+
const isLastLeftPinned = isPinned === 'left' && column.getIsLastColumn('left');
|
|
121
|
+
const isFirstRightPinned = isPinned === 'right' && column.getIsFirstColumn('right');
|
|
122
|
+
const headerCellSpacing = headerCellSpacingVariants({
|
|
123
|
+
size: props.tableLayout?.dense ? 'dense' : 'default',
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<th
|
|
128
|
+
key={header.id}
|
|
129
|
+
ref={dndRef}
|
|
130
|
+
style={{
|
|
131
|
+
...(props.tableLayout?.width === 'fixed' && {
|
|
132
|
+
width: `${header.getSize()}px`,
|
|
133
|
+
}),
|
|
134
|
+
...(props.tableLayout?.columnsPinnable && column.getCanPin() && getPinningStyles(column)),
|
|
135
|
+
...(dndStyle ? dndStyle : null),
|
|
136
|
+
}}
|
|
137
|
+
data-pinned={isPinned || undefined}
|
|
138
|
+
data-last-col={isLastLeftPinned ? 'left' : isFirstRightPinned ? 'right' : undefined}
|
|
139
|
+
className={cn(
|
|
140
|
+
'relative h-10 text-left rtl:text-right align-middle font-normal text-accent-foreground [&:has([role=checkbox])]:pe-0',
|
|
141
|
+
headerCellSpacing,
|
|
142
|
+
props.tableLayout?.cellBorder && 'border-e',
|
|
143
|
+
props.tableLayout?.columnsResizable && column.getCanResize() && 'truncate',
|
|
144
|
+
props.tableLayout?.columnsPinnable &&
|
|
145
|
+
column.getCanPin() &&
|
|
146
|
+
'[&:not([data-pinned]):has(+[data-pinned])_div.cursor-col-resize:last-child]:opacity-0 [&[data-last-col=left]_div.cursor-col-resize:last-child]:opacity-0 [&[data-pinned=left][data-last-col=left]]:border-e! [&[data-pinned=right]:last-child_div.cursor-col-resize:last-child]:opacity-0 [&[data-pinned=right][data-last-col=right]]:border-s! [&[data-pinned][data-last-col]]:border-border data-pinned:bg-muted/90 data-pinned:backdrop-blur-xs',
|
|
147
|
+
header.column.columnDef.meta?.headerClassName,
|
|
148
|
+
column.getIndex() === 0 || column.getIndex() === header.headerGroup.headers.length - 1
|
|
149
|
+
? props.tableClassNames?.edgeCell
|
|
150
|
+
: '',
|
|
151
|
+
)}
|
|
152
|
+
>
|
|
153
|
+
{children}
|
|
154
|
+
</th>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function DataGridTableHeadRowCellResize<TData>({ header }: { header: Header<TData, unknown> }) {
|
|
159
|
+
const { column } = header;
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<div
|
|
163
|
+
{...{
|
|
164
|
+
onDoubleClick: () => column.resetSize(),
|
|
165
|
+
onMouseDown: header.getResizeHandler(),
|
|
166
|
+
onTouchStart: header.getResizeHandler(),
|
|
167
|
+
className:
|
|
168
|
+
'absolute top-0 h-full w-4 cursor-col-resize user-select-none touch-none -end-2 z-10 flex justify-center before:absolute before:w-px before:inset-y-0 before:bg-border before:-translate-x-px',
|
|
169
|
+
}}
|
|
170
|
+
/>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function DataGridTableRowSpacer() {
|
|
175
|
+
return <tbody aria-hidden="true" className="h-2"></tbody>;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function DataGridTableBody({ children }: { children: ReactNode }) {
|
|
179
|
+
const { props } = useDataGrid();
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<tbody
|
|
183
|
+
className={cn(
|
|
184
|
+
'[&_tr:last-child]:border-0',
|
|
185
|
+
props.tableLayout?.rowRounded && '[&_td:first-child]:rounded-s-lg [&_td:last-child]:rounded-e-lg',
|
|
186
|
+
props.tableClassNames?.body,
|
|
187
|
+
)}
|
|
188
|
+
>
|
|
189
|
+
{children}
|
|
190
|
+
</tbody>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function DataGridTableBodyRowSkeleton({ children }: { children: ReactNode }) {
|
|
195
|
+
const { table, props } = useDataGrid();
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
<tr
|
|
199
|
+
className={cn(
|
|
200
|
+
'hover:bg-muted/40 data-[state=selected]:bg-muted/50',
|
|
201
|
+
props.onRowClick && 'cursor-pointer',
|
|
202
|
+
!props.tableLayout?.stripped &&
|
|
203
|
+
props.tableLayout?.rowBorder &&
|
|
204
|
+
'border-b border-border [&:not(:last-child)>td]:border-b',
|
|
205
|
+
props.tableLayout?.cellBorder && '[&_>:last-child]:border-e-0',
|
|
206
|
+
props.tableLayout?.stripped && 'odd:bg-muted/90 hover:bg-transparent odd:hover:bg-muted',
|
|
207
|
+
table.options.enableRowSelection && '[&_>:first-child]:relative',
|
|
208
|
+
props.tableClassNames?.bodyRow,
|
|
209
|
+
)}
|
|
210
|
+
>
|
|
211
|
+
{children}
|
|
212
|
+
</tr>
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function DataGridTableBodyRowSkeletonCell<TData>({ children, column }: { children: ReactNode; column: Column<TData> }) {
|
|
217
|
+
const { props, table } = useDataGrid();
|
|
218
|
+
const bodyCellSpacing = bodyCellSpacingVariants({
|
|
219
|
+
size: props.tableLayout?.dense ? 'dense' : 'default',
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
return (
|
|
223
|
+
<td
|
|
224
|
+
className={cn(
|
|
225
|
+
'align-middle',
|
|
226
|
+
bodyCellSpacing,
|
|
227
|
+
props.tableLayout?.cellBorder && 'border-e',
|
|
228
|
+
props.tableLayout?.columnsResizable && column.getCanResize() && 'truncate',
|
|
229
|
+
column.columnDef.meta?.cellClassName,
|
|
230
|
+
props.tableLayout?.columnsPinnable &&
|
|
231
|
+
column.getCanPin() &&
|
|
232
|
+
'[&[data-pinned=left][data-last-col=left]]:border-e! [&[data-pinned=right][data-last-col=right]]:border-s! [&[data-pinned][data-last-col]]:border-border data-pinned:bg-background/90 data-pinned:backdrop-blur-xs"',
|
|
233
|
+
column.getIndex() === 0 || column.getIndex() === table.getVisibleFlatColumns().length - 1
|
|
234
|
+
? props.tableClassNames?.edgeCell
|
|
235
|
+
: '',
|
|
236
|
+
)}
|
|
237
|
+
>
|
|
238
|
+
{children}
|
|
239
|
+
</td>
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function DataGridTableBodyRow<TData>({
|
|
244
|
+
children,
|
|
245
|
+
row,
|
|
246
|
+
dndRef,
|
|
247
|
+
dndStyle,
|
|
248
|
+
}: {
|
|
249
|
+
children: ReactNode;
|
|
250
|
+
row: Row<TData>;
|
|
251
|
+
dndRef?: React.Ref<HTMLTableRowElement>;
|
|
252
|
+
dndStyle?: CSSProperties;
|
|
253
|
+
}) {
|
|
254
|
+
const { props, table } = useDataGrid();
|
|
255
|
+
|
|
256
|
+
return (
|
|
257
|
+
<tr
|
|
258
|
+
ref={dndRef}
|
|
259
|
+
style={{ ...(dndStyle ? dndStyle : null) }}
|
|
260
|
+
data-state={table.options.enableRowSelection && row.getIsSelected() ? 'selected' : undefined}
|
|
261
|
+
onClick={() => props.onRowClick && props.onRowClick(row.original)}
|
|
262
|
+
className={cn(
|
|
263
|
+
'hover:bg-muted/40 data-[state=selected]:bg-muted/50',
|
|
264
|
+
props.onRowClick && 'cursor-pointer',
|
|
265
|
+
!props.tableLayout?.stripped &&
|
|
266
|
+
props.tableLayout?.rowBorder &&
|
|
267
|
+
'border-b border-border [&:not(:last-child)>td]:border-b',
|
|
268
|
+
props.tableLayout?.cellBorder && '[&_>:last-child]:border-e-0',
|
|
269
|
+
props.tableLayout?.stripped && 'odd:bg-muted/90 hover:bg-transparent odd:hover:bg-muted',
|
|
270
|
+
table.options.enableRowSelection && '[&_>:first-child]:relative',
|
|
271
|
+
props.tableClassNames?.bodyRow,
|
|
272
|
+
)}
|
|
273
|
+
>
|
|
274
|
+
{children}
|
|
275
|
+
</tr>
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function DataGridTableBodyRowExpandded<TData>({ row }: { row: Row<TData> }) {
|
|
280
|
+
const { props, table } = useDataGrid();
|
|
281
|
+
|
|
282
|
+
return (
|
|
283
|
+
<tr className={cn(props.tableLayout?.rowBorder && '[&:not(:last-child)>td]:border-b')}>
|
|
284
|
+
<td colSpan={row.getVisibleCells().length}>
|
|
285
|
+
{table
|
|
286
|
+
.getAllColumns()
|
|
287
|
+
.find((column) => column.columnDef.meta?.expandedContent)
|
|
288
|
+
?.columnDef.meta?.expandedContent?.(row.original)}
|
|
289
|
+
</td>
|
|
290
|
+
</tr>
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function DataGridTableBodyRowCell<TData>({
|
|
295
|
+
children,
|
|
296
|
+
cell,
|
|
297
|
+
dndRef,
|
|
298
|
+
dndStyle,
|
|
299
|
+
}: {
|
|
300
|
+
children: ReactNode;
|
|
301
|
+
cell: Cell<TData, unknown>;
|
|
302
|
+
dndRef?: React.Ref<HTMLTableCellElement>;
|
|
303
|
+
dndStyle?: CSSProperties;
|
|
304
|
+
}) {
|
|
305
|
+
const { props } = useDataGrid();
|
|
306
|
+
|
|
307
|
+
const { column, row } = cell;
|
|
308
|
+
const isPinned = column.getIsPinned();
|
|
309
|
+
const isLastLeftPinned = isPinned === 'left' && column.getIsLastColumn('left');
|
|
310
|
+
const isFirstRightPinned = isPinned === 'right' && column.getIsFirstColumn('right');
|
|
311
|
+
const bodyCellSpacing = bodyCellSpacingVariants({
|
|
312
|
+
size: props.tableLayout?.dense ? 'dense' : 'default',
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
return (
|
|
316
|
+
<td
|
|
317
|
+
key={cell.id}
|
|
318
|
+
ref={dndRef}
|
|
319
|
+
{...(props.tableLayout?.columnsDraggable && !isPinned ? { cell } : {})}
|
|
320
|
+
style={{
|
|
321
|
+
...(props.tableLayout?.columnsPinnable && column.getCanPin() && getPinningStyles(column)),
|
|
322
|
+
...(dndStyle ? dndStyle : null),
|
|
323
|
+
}}
|
|
324
|
+
data-pinned={isPinned || undefined}
|
|
325
|
+
data-last-col={isLastLeftPinned ? 'left' : isFirstRightPinned ? 'right' : undefined}
|
|
326
|
+
className={cn(
|
|
327
|
+
'align-middle',
|
|
328
|
+
bodyCellSpacing,
|
|
329
|
+
props.tableLayout?.cellBorder && 'border-e',
|
|
330
|
+
props.tableLayout?.columnsResizable && column.getCanResize() && 'truncate',
|
|
331
|
+
cell.column.columnDef.meta?.cellClassName,
|
|
332
|
+
props.tableLayout?.columnsPinnable &&
|
|
333
|
+
column.getCanPin() &&
|
|
334
|
+
'[&[data-pinned=left][data-last-col=left]]:border-e! [&[data-pinned=right][data-last-col=right]]:border-s! [&[data-pinned][data-last-col]]:border-border data-pinned:bg-background/90 data-pinned:backdrop-blur-xs"',
|
|
335
|
+
column.getIndex() === 0 || column.getIndex() === row.getVisibleCells().length - 1
|
|
336
|
+
? props.tableClassNames?.edgeCell
|
|
337
|
+
: '',
|
|
338
|
+
)}
|
|
339
|
+
>
|
|
340
|
+
{children}
|
|
341
|
+
</td>
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function DataGridTableEmpty() {
|
|
346
|
+
const { table, props } = useDataGrid();
|
|
347
|
+
const totalColumns = table.getAllColumns().length;
|
|
348
|
+
|
|
349
|
+
return (
|
|
350
|
+
<tr>
|
|
351
|
+
<td colSpan={totalColumns} className="text-center text-muted-foreground py-6">
|
|
352
|
+
{props.emptyMessage || 'No data available'}
|
|
353
|
+
</td>
|
|
354
|
+
</tr>
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function DataGridTableLoader() {
|
|
359
|
+
const { props } = useDataGrid();
|
|
360
|
+
|
|
361
|
+
return (
|
|
362
|
+
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2">
|
|
363
|
+
<div className="text-muted-foreground bg-card flex items-center gap-2 px-4 py-2 font-medium leading-none text-sm border shadow-xs rounded-md">
|
|
364
|
+
<svg
|
|
365
|
+
className="animate-spin -ml-1 h-5 w-5 text-muted-foreground"
|
|
366
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
367
|
+
fill="none"
|
|
368
|
+
viewBox="0 0 24 24"
|
|
369
|
+
>
|
|
370
|
+
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="3"></circle>
|
|
371
|
+
<path
|
|
372
|
+
className="opacity-75"
|
|
373
|
+
fill="currentColor"
|
|
374
|
+
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
|
375
|
+
></path>
|
|
376
|
+
</svg>
|
|
377
|
+
{props.loadingMessage || 'Loading...'}
|
|
378
|
+
</div>
|
|
379
|
+
</div>
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function DataGridTableRowSelect<TData>({ row, size }: { row: Row<TData>; size?: 'sm' | 'md' | 'lg' }) {
|
|
384
|
+
return (
|
|
385
|
+
<>
|
|
386
|
+
<div
|
|
387
|
+
className={cn('hidden absolute top-0 bottom-0 start-0 w-[2px] bg-primary', row.getIsSelected() && 'block')}
|
|
388
|
+
></div>
|
|
389
|
+
<Checkbox
|
|
390
|
+
checked={row.getIsSelected()}
|
|
391
|
+
onCheckedChange={(value) => row.toggleSelected(!!value)}
|
|
392
|
+
aria-label="Select row"
|
|
393
|
+
size={size ?? 'sm'}
|
|
394
|
+
className="align-[inherit]"
|
|
395
|
+
/>
|
|
396
|
+
</>
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function DataGridTableRowSelectAll({ size }: { size?: 'sm' | 'md' | 'lg' }) {
|
|
401
|
+
const { table, recordCount, isLoading } = useDataGrid();
|
|
402
|
+
|
|
403
|
+
return (
|
|
404
|
+
<Checkbox
|
|
405
|
+
checked={table.getIsAllPageRowsSelected() || (table.getIsSomePageRowsSelected() && 'indeterminate')}
|
|
406
|
+
disabled={isLoading || recordCount === 0}
|
|
407
|
+
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
|
|
408
|
+
aria-label="Select all"
|
|
409
|
+
size={size}
|
|
410
|
+
className="align-[inherit]"
|
|
411
|
+
/>
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function DataGridTable<TData>() {
|
|
416
|
+
const { table, isLoading, props } = useDataGrid();
|
|
417
|
+
const pagination = table.getState().pagination;
|
|
418
|
+
|
|
419
|
+
return (
|
|
420
|
+
<DataGridTableBase>
|
|
421
|
+
<DataGridTableHead>
|
|
422
|
+
{table.getHeaderGroups().map((headerGroup: HeaderGroup<TData>, index) => {
|
|
423
|
+
return (
|
|
424
|
+
<DataGridTableHeadRow headerGroup={headerGroup} key={index}>
|
|
425
|
+
{headerGroup.headers.map((header, index) => {
|
|
426
|
+
const { column } = header;
|
|
427
|
+
|
|
428
|
+
return (
|
|
429
|
+
<DataGridTableHeadRowCell header={header} key={index}>
|
|
430
|
+
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
|
|
431
|
+
{props.tableLayout?.columnsResizable && column.getCanResize() && (
|
|
432
|
+
<DataGridTableHeadRowCellResize header={header} />
|
|
433
|
+
)}
|
|
434
|
+
</DataGridTableHeadRowCell>
|
|
435
|
+
);
|
|
436
|
+
})}
|
|
437
|
+
</DataGridTableHeadRow>
|
|
438
|
+
);
|
|
439
|
+
})}
|
|
440
|
+
</DataGridTableHead>
|
|
441
|
+
|
|
442
|
+
{(props.tableLayout?.stripped || !props.tableLayout?.rowBorder) && <DataGridTableRowSpacer />}
|
|
443
|
+
|
|
444
|
+
<DataGridTableBody>
|
|
445
|
+
{props.loadingMode === 'skeleton' && isLoading && pagination?.pageSize ? (
|
|
446
|
+
Array.from({ length: pagination.pageSize }).map((_, rowIndex) => (
|
|
447
|
+
<DataGridTableBodyRowSkeleton key={rowIndex}>
|
|
448
|
+
{table.getVisibleFlatColumns().map((column, colIndex) => {
|
|
449
|
+
return (
|
|
450
|
+
<DataGridTableBodyRowSkeletonCell column={column} key={colIndex}>
|
|
451
|
+
{column.columnDef.meta?.skeleton}
|
|
452
|
+
</DataGridTableBodyRowSkeletonCell>
|
|
453
|
+
);
|
|
454
|
+
})}
|
|
455
|
+
</DataGridTableBodyRowSkeleton>
|
|
456
|
+
))
|
|
457
|
+
) : table.getRowModel().rows.length ? (
|
|
458
|
+
table.getRowModel().rows.map((row: Row<TData>, index) => {
|
|
459
|
+
return (
|
|
460
|
+
<Fragment key={row.id}>
|
|
461
|
+
<DataGridTableBodyRow row={row} key={index}>
|
|
462
|
+
{row.getVisibleCells().map((cell: Cell<TData, unknown>, colIndex) => {
|
|
463
|
+
return (
|
|
464
|
+
<DataGridTableBodyRowCell cell={cell} key={colIndex}>
|
|
465
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
466
|
+
</DataGridTableBodyRowCell>
|
|
467
|
+
);
|
|
468
|
+
})}
|
|
469
|
+
</DataGridTableBodyRow>
|
|
470
|
+
{row.getIsExpanded() && <DataGridTableBodyRowExpandded row={row} />}
|
|
471
|
+
</Fragment>
|
|
472
|
+
);
|
|
473
|
+
})
|
|
474
|
+
) : (
|
|
475
|
+
<DataGridTableEmpty />
|
|
476
|
+
)}
|
|
477
|
+
</DataGridTableBody>
|
|
478
|
+
</DataGridTableBase>
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export {
|
|
483
|
+
DataGridTable,
|
|
484
|
+
DataGridTableBase,
|
|
485
|
+
DataGridTableBody,
|
|
486
|
+
DataGridTableBodyRow,
|
|
487
|
+
DataGridTableBodyRowCell,
|
|
488
|
+
DataGridTableBodyRowExpandded,
|
|
489
|
+
DataGridTableBodyRowSkeleton,
|
|
490
|
+
DataGridTableBodyRowSkeletonCell,
|
|
491
|
+
DataGridTableEmpty,
|
|
492
|
+
DataGridTableHead,
|
|
493
|
+
DataGridTableHeadRow,
|
|
494
|
+
DataGridTableHeadRowCell,
|
|
495
|
+
DataGridTableHeadRowCellResize,
|
|
496
|
+
DataGridTableLoader,
|
|
497
|
+
DataGridTableRowSelect,
|
|
498
|
+
DataGridTableRowSelectAll,
|
|
499
|
+
DataGridTableRowSpacer,
|
|
500
|
+
};
|