@middag-io/react 0.45.0 → 0.45.3
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 +4 -3
- package/docs/public/schemas/ai-contract-manifest.json +1820 -0
- package/docs/public/schemas/blocks.json +445 -0
- package/docs/public/schemas/components.json +166 -0
- package/docs/public/schemas/connectors.json +97 -0
- package/docs/public/schemas/fragment.json +2329 -0
- package/docs/public/schemas/manifest.json +119 -0
- package/docs/public/schemas/navigation.json +72 -0
- package/docs/public/schemas/page-contract.json +2329 -0
- package/docs/public/schemas/shared-props.json +118 -0
- package/docs/public/schemas/theme-defaults.json +253 -0
- package/docs/public/schemas/theme.json +401 -0
- package/package.json +109 -3
- package/src/assets/lottie/calendar/schedule-1.json +1 -0
- package/src/assets/lottie/calendar/schedule-2.json +1 -0
- package/src/assets/lottie/celebration/confetti-1.json +1 -0
- package/src/assets/lottie/celebration/confetti-2.json +1 -0
- package/src/assets/lottie/celebration/confetti-3.json +1 -0
- package/src/assets/lottie/cloud/cloud-1.json +1 -0
- package/src/assets/lottie/cloud/cloud-2.json +1 -0
- package/src/assets/lottie/connection/network-1.json +1 -0
- package/src/assets/lottie/connection/network-2.json +1 -0
- package/src/assets/lottie/connection/network-3.json +1 -0
- package/src/assets/lottie/dashboard/analytics-1.json +1 -0
- package/src/assets/lottie/dashboard/analytics-2.json +1 -0
- package/src/assets/lottie/dashboard/analytics-3.json +1 -0
- package/src/assets/lottie/email/mail-1.json +1 -0
- package/src/assets/lottie/email/mail-2.json +1 -0
- package/src/assets/lottie/email/mail-3.json +1 -0
- package/src/assets/lottie/empty-state/empty-1.json +1 -0
- package/src/assets/lottie/empty-state/empty-2.json +1 -0
- package/src/assets/lottie/empty-state/empty-3.json +1 -0
- package/src/assets/lottie/error/warning-1.json +1 -0
- package/src/assets/lottie/error/warning-2.json +1 -0
- package/src/assets/lottie/error/warning-3.json +1 -0
- package/src/assets/lottie/index.ts +49 -0
- package/src/assets/lottie/loading/spinner-1.json +1 -0
- package/src/assets/lottie/loading/spinner-2.json +1 -0
- package/src/assets/lottie/loading/spinner-3.json +1 -0
- package/src/assets/lottie/maintenance/construction-1.json +1 -0
- package/src/assets/lottie/maintenance/construction-2.json +1 -0
- package/src/assets/lottie/maintenance/construction-3.json +1 -0
- package/src/assets/lottie/not-found/404-1.json +1 -0
- package/src/assets/lottie/not-found/404-2.json +1 -0
- package/src/assets/lottie/not-found/404-3.json +1 -0
- package/src/assets/lottie/notification/bell-1.json +1 -0
- package/src/assets/lottie/notification/bell-2.json +1 -0
- package/src/assets/lottie/notification/bell-3.json +1 -0
- package/src/assets/lottie/onboarding/welcome-1.json +1 -0
- package/src/assets/lottie/onboarding/welcome-2.json +1 -0
- package/src/assets/lottie/onboarding/welcome-3.json +1 -0
- package/src/assets/lottie/payment/wallet-1.json +1 -0
- package/src/assets/lottie/payment/wallet-2.json +1 -0
- package/src/assets/lottie/payment/wallet-3.json +1 -0
- package/src/assets/lottie/search/search-1.json +1 -0
- package/src/assets/lottie/search/search-2.json +1 -0
- package/src/assets/lottie/search/search-3.json +1 -0
- package/src/assets/lottie/security/lock-1.json +1 -0
- package/src/assets/lottie/security/lock-2.json +1 -0
- package/src/assets/lottie/security/lock-3.json +1 -0
- package/src/assets/lottie/settings/gear-1.json +1 -0
- package/src/assets/lottie/settings/gear-2.json +1 -0
- package/src/assets/lottie/settings/gear-3.json +1 -0
- package/src/assets/lottie/success/check-1.json +1 -0
- package/src/assets/lottie/success/check-2.json +1 -0
- package/src/assets/lottie/success/check-3.json +1 -0
- package/src/assets/lottie/upload/upload-1.json +1 -0
- package/src/assets/lottie/upload/upload-2.json +1 -0
- package/src/assets/lottie/upload/upload-3.json +1 -0
- package/src/assets/lottie/user/profile-1.json +1 -0
- package/src/assets/lottie/user/profile-2.json +1 -0
- package/src/assets/lottie/user/profile-3.json +1 -0
- package/src/base/blocks/ActionGridBlock.tsx +151 -0
- package/src/base/blocks/ActivityTimelineBlock.tsx +180 -0
- package/src/base/blocks/CardGridBlock.tsx +384 -0
- package/src/base/blocks/ChartBlock.tsx +81 -0
- package/src/base/blocks/DenseTableBlock.tsx +403 -0
- package/src/base/blocks/DetailPanelBlock.tsx +189 -0
- package/src/base/blocks/EmptyStateBlock.tsx +46 -0
- package/src/base/blocks/FormPanelBlock.lazy.tsx +38 -0
- package/src/base/blocks/FormPanelBlock.tsx +480 -0
- package/src/base/blocks/LinkListBlock.tsx +94 -0
- package/src/base/blocks/MarkdownPanelBlock.tsx +60 -0
- package/src/base/blocks/MetricCardBlock.tsx +128 -0
- package/src/base/blocks/StatusStripBlock.tsx +43 -0
- package/src/base/blocks/TabsBlock.tsx +94 -0
- package/src/base/form/FormField.tsx +607 -0
- package/src/base/form/fields/CheckboxField.tsx +56 -0
- package/src/base/form/fields/ColorField.tsx +76 -0
- package/src/base/form/fields/CurrencyField.tsx +126 -0
- package/src/base/form/fields/DateField.tsx +168 -0
- package/src/base/form/fields/DateRangeField.tsx +66 -0
- package/src/base/form/fields/DocumentField.tsx +222 -0
- package/src/base/form/fields/EntityPickerField.tsx +244 -0
- package/src/base/form/fields/FileUploadField.tsx +253 -0
- package/src/base/form/fields/MultiSelectField.tsx +286 -0
- package/src/base/form/fields/NativeSelectField.tsx +67 -0
- package/src/base/form/fields/NumberField.tsx +67 -0
- package/src/base/form/fields/OtpField.tsx +88 -0
- package/src/base/form/fields/PasswordField.tsx +69 -0
- package/src/base/form/fields/PhoneField.tsx +64 -0
- package/src/base/form/fields/RadioField.tsx +66 -0
- package/src/base/form/fields/RatingField.tsx +52 -0
- package/src/base/form/fields/SelectField.tsx +76 -0
- package/src/base/form/fields/SliderField.tsx +77 -0
- package/src/base/form/fields/SlugField.tsx +114 -0
- package/src/base/form/fields/StaticField.tsx +25 -0
- package/src/base/form/fields/SwitchField.tsx +56 -0
- package/src/base/form/fields/TagsField.tsx +128 -0
- package/src/base/form/fields/TextField.tsx +55 -0
- package/src/base/form/fields/TextareaField.tsx +55 -0
- package/src/base/form/fields/document-validation.ts +126 -0
- package/src/base/form/fields/field-registry.ts +53 -0
- package/src/base/form/fields/register-default-fields.ts +86 -0
- package/src/base/form/form-schema-builder.ts +192 -0
- package/src/base/form/form-utils.ts +71 -0
- package/src/base/hooks/useIsDark.ts +50 -0
- package/src/base/hooks/useLazyTabs.ts +98 -0
- package/src/base/hooks/usePolling.ts +43 -0
- package/src/base/hooks/useRemember.ts +58 -0
- package/src/base/hooks/useToast.ts +27 -0
- package/src/base/layout/BlockRegion.tsx +39 -0
- package/src/base/layout/DashboardLayout.tsx +110 -0
- package/src/base/layout/SidebarLayout.tsx +38 -0
- package/src/base/layout/StackLayout.tsx +32 -0
- package/src/base/layout/WizardLayout.tsx +49 -0
- package/src/base/partials/ActionBar/index.tsx +115 -0
- package/src/base/partials/ConfirmationDialog/index.tsx +128 -0
- package/src/base/partials/DataTable/cell-registry.ts +50 -0
- package/src/base/partials/DataTable/cell-renderers.tsx +372 -0
- package/src/base/partials/DataTable/index.tsx +1282 -0
- package/src/base/partials/DataTable/register-default-cells.ts +37 -0
- package/src/base/partials/DataTable/sanitize-html.ts +45 -0
- package/src/base/partials/DataTable/types.ts +229 -0
- package/src/base/partials/DetailSection/index.tsx +316 -0
- package/src/base/partials/EmptyPlaceholder/index.tsx +162 -0
- package/src/base/partials/EntityItem/index.tsx +154 -0
- package/src/base/partials/FilterBar/index.tsx +256 -0
- package/src/base/partials/FormSection/index.tsx +87 -0
- package/src/base/partials/LogViewer/JsonBlock.tsx +39 -0
- package/src/base/partials/LogViewer/LogEntry.tsx +68 -0
- package/src/base/partials/LogViewer/LogViewerToolbar.tsx +71 -0
- package/src/base/partials/LogViewer/index.tsx +110 -0
- package/src/base/partials/LogViewer/types.ts +28 -0
- package/src/base/partials/MarkdownContent/index.tsx +307 -0
- package/src/base/partials/MenuBar/index.tsx +80 -0
- package/src/base/partials/QuickRecordSheet/index.tsx +59 -0
- package/src/base/partials/ResizableSidebar/index.tsx +70 -0
- package/src/base/partials/StatRow/index.tsx +28 -0
- package/src/base/partials/StatusBar/index.tsx +126 -0
- package/src/base/partials/StatusIndicator/index.tsx +61 -0
- package/src/base/partials/StepIndicator/index.tsx +63 -0
- package/src/base/partials/TableOfContents/index.tsx +78 -0
- package/src/base/partials/TimelineList/index.tsx +273 -0
- package/src/base/partials/ToggleGroupControl/index.tsx +100 -0
- package/src/base/partials/TreeView/index.tsx +75 -0
- package/src/base/partials/index.ts +23 -0
- package/src/base/shell/AuthShell.tsx +54 -0
- package/src/base/shell/BasicShell.tsx +286 -0
- package/src/base/shell/ImmersiveShell.tsx +85 -0
- package/src/base/shell/partials/EditablePanelContext.tsx +82 -0
- package/src/base/shell/partials/EditablePanelProvider.tsx +122 -0
- package/src/base/shell/partials/InlineEditablePanel.tsx +239 -0
- package/src/base/shell/partials/InspectorContext.tsx +173 -0
- package/src/base/shell/partials/InspectorPanel.tsx +65 -0
- package/src/base/shell/partials/NavErrorBoundary.tsx +82 -0
- package/src/base/shell/partials/OverlayScreen.tsx +67 -0
- package/src/base/shell/partials/PageActionButton.tsx +203 -0
- package/src/base/theme/appearance.ts +133 -0
- package/src/base/theme/host-layout-detector.ts +119 -0
- package/src/base/theme/host-theme-detector.ts +146 -0
- package/src/base/theme/sidebar-safelist.txt +20 -0
- package/src/base/theme/tailwind-theme.css +136 -0
- package/src/base/theme/theme-bridge.css +164 -0
- package/src/base/theme/theme-context.tsx +142 -0
- package/src/base/theme/themes/classic.css +174 -0
- package/src/base/theme/tokens.css +290 -0
- package/src/base/theme/useHostTheme.ts +95 -0
- package/src/base/utils/clipboard.ts +39 -0
- package/src/base/utils/conditions.ts +27 -0
- package/src/base/utils/icon-registry.ts +78 -0
- package/src/base/utils/icons.ts +31 -0
- package/src/base/utils/interpolate.ts +9 -0
- package/src/base/utils/register-default-icons.ts +163 -0
- package/src/base/utils/storage.ts +65 -0
- package/src/base/utils/time.ts +139 -0
- package/src/contracts/block-data/actions.ts +73 -0
- package/src/contracts/block-data/data-display.ts +343 -0
- package/src/contracts/block-data/form.ts +164 -0
- package/src/contracts/block-data/index.ts +15 -0
- package/src/contracts/block-data/interactive.ts +34 -0
- package/src/contracts/block-data/shared.ts +44 -0
- package/src/contracts/connectors.ts +60 -0
- package/src/contracts/generated/contract-schema.ts +1237 -0
- package/src/contracts/generated/contract-types.ts +675 -0
- package/src/contracts/generated/index.ts +15 -0
- package/src/contracts/navigation.ts +59 -0
- package/src/contracts/page-contract-schema.ts +40 -0
- package/src/contracts/page-contract.ts +79 -0
- package/src/contracts/shared-props.ts +92 -0
- package/src/engine/ContractPage.tsx +178 -0
- package/src/engine/EntityRoutes.tsx +72 -0
- package/src/engine/HostSlot.tsx +126 -0
- package/src/engine/LazyBlock.tsx +92 -0
- package/src/engine/bootstrap.tsx +20 -0
- package/src/engine/providers/auth.tsx +87 -0
- package/src/engine/providers/error-reporter.tsx +89 -0
- package/src/engine/providers/flash.tsx +44 -0
- package/src/engine/providers/index.ts +18 -0
- package/src/engine/providers/inertia-error-reporter.tsx +61 -0
- package/src/engine/providers/progress.tsx +56 -0
- package/src/engine/providers/scope.tsx +51 -0
- package/src/engine/register-defaults.ts +88 -0
- package/src/engine/registries.ts +96 -0
- package/src/i18n/I18nProvider.tsx +53 -0
- package/src/i18n/MANIFEST.md +101 -0
- package/src/i18n/host-resolver.ts +18 -0
- package/src/i18n/instance.ts +69 -0
- package/src/i18n/locales/en/ui.json +277 -0
- package/src/i18n/locales/en/validators.json +13 -0
- package/src/i18n/locales/pt-BR/ui.json +277 -0
- package/src/i18n/locales/pt-BR/validators.json +13 -0
- package/src/i18n/register-strings.ts +10 -0
- package/src/i18n/render-label.ts +33 -0
- package/src/i18n/resolve-field-error.ts +29 -0
- package/src/i18n/useHostString.ts +50 -0
- package/src/i18n/useTranslation.ts +83 -0
- package/src/lib/actions/resolve-action-target.ts +151 -0
- package/src/lib/hooks/use-copy-to-clipboard.ts +37 -0
- package/src/lib/hooks/use-file-upload.ts +406 -0
- package/src/lib/hooks/use-mobile.ts +21 -0
- package/src/lib/host-pending.ts +76 -0
- package/src/lib/portal-container.ts +16 -0
- package/src/lib/test-ids.ts +40 -0
- package/src/lib/utils.ts +6 -0
- package/src/primitives/reui/MANIFEST.md +97 -0
- package/src/primitives/reui/accordion.tsx +64 -0
- package/src/primitives/reui/alert-dialog.tsx +196 -0
- package/src/primitives/reui/alert.tsx +92 -0
- package/src/primitives/reui/aspect-ratio.tsx +9 -0
- package/src/primitives/reui/autocomplete.tsx +343 -0
- package/src/primitives/reui/avatar.tsx +109 -0
- package/src/primitives/reui/badge.tsx +94 -0
- package/src/primitives/reui/breadcrumb.tsx +109 -0
- package/src/primitives/reui/button-group.tsx +83 -0
- package/src/primitives/reui/button.tsx +64 -0
- package/src/primitives/reui/calendar.tsx +220 -0
- package/src/primitives/reui/card.tsx +92 -0
- package/src/primitives/reui/carousel.tsx +239 -0
- package/src/primitives/reui/chart.tsx +388 -0
- package/src/primitives/reui/checkbox.tsx +30 -0
- package/src/primitives/reui/collapsible.tsx +31 -0
- package/src/primitives/reui/combobox.tsx +308 -0
- package/src/primitives/reui/command.tsx +182 -0
- package/src/primitives/reui/context-menu.tsx +250 -0
- package/src/primitives/reui/data-grid/data-grid-column-filter.tsx +172 -0
- package/src/primitives/reui/data-grid/data-grid-column-header.tsx +420 -0
- package/src/primitives/reui/data-grid/data-grid-column-visibility.tsx +51 -0
- package/src/primitives/reui/data-grid/data-grid-pagination.tsx +235 -0
- package/src/primitives/reui/data-grid/data-grid-scroll-area.tsx +427 -0
- package/src/primitives/reui/data-grid/data-grid-table-dnd-rows.tsx +308 -0
- package/src/primitives/reui/data-grid/data-grid-table-dnd.tsx +318 -0
- package/src/primitives/reui/data-grid/data-grid-table-virtual.tsx +491 -0
- package/src/primitives/reui/data-grid/data-grid-table.tsx +1430 -0
- package/src/primitives/reui/data-grid/data-grid.tsx +269 -0
- package/src/primitives/reui/data-grid-pagination.tsx +235 -0
- package/src/primitives/reui/date-selector.tsx +1353 -0
- package/src/primitives/reui/dialog.tsx +158 -0
- package/src/primitives/reui/drawer.tsx +133 -0
- package/src/primitives/reui/dropdown-menu.tsx +257 -0
- package/src/primitives/reui/empty.tsx +104 -0
- package/src/primitives/reui/field.tsx +246 -0
- package/src/primitives/reui/filters.tsx +1891 -0
- package/src/primitives/reui/frame.tsx +170 -0
- package/src/primitives/reui/hover-card.tsx +42 -0
- package/src/primitives/reui/icon-placeholder.tsx +39 -0
- package/src/primitives/reui/index.ts +98 -0
- package/src/primitives/reui/input-group.tsx +170 -0
- package/src/primitives/reui/input-otp.tsx +75 -0
- package/src/primitives/reui/input.tsx +21 -0
- package/src/primitives/reui/item.tsx +193 -0
- package/src/primitives/reui/kanban.tsx +743 -0
- package/src/primitives/reui/kbd.tsx +28 -0
- package/src/primitives/reui/label.tsx +22 -0
- package/src/primitives/reui/menubar.tsx +274 -0
- package/src/primitives/reui/native-select.tsx +62 -0
- package/src/primitives/reui/navigation-menu.tsx +168 -0
- package/src/primitives/reui/number-field.tsx +250 -0
- package/src/primitives/reui/pagination.tsx +127 -0
- package/src/primitives/reui/phone-input.tsx +231 -0
- package/src/primitives/reui/popover.tsx +87 -0
- package/src/primitives/reui/progress.tsx +31 -0
- package/src/primitives/reui/radio-group.tsx +43 -0
- package/src/primitives/reui/rating.tsx +177 -0
- package/src/primitives/reui/resizable.tsx +51 -0
- package/src/primitives/reui/scroll-area.tsx +58 -0
- package/src/primitives/reui/scrollspy.tsx +240 -0
- package/src/primitives/reui/select.tsx +188 -0
- package/src/primitives/reui/separator.tsx +28 -0
- package/src/primitives/reui/sheet.tsx +141 -0
- package/src/primitives/reui/sidebar.tsx +732 -0
- package/src/primitives/reui/skeleton.tsx +13 -0
- package/src/primitives/reui/slider.tsx +61 -0
- package/src/primitives/reui/sonner.tsx +47 -0
- package/src/primitives/reui/sortable.tsx +414 -0
- package/src/primitives/reui/spinner.tsx +16 -0
- package/src/primitives/reui/stepper.tsx +484 -0
- package/src/primitives/reui/svgs/claudeAiIcon.tsx +12 -0
- package/src/primitives/reui/svgs/gemini.tsx +171 -0
- package/src/primitives/reui/svgs/openai.tsx +9 -0
- package/src/primitives/reui/svgs/openaiDark.tsx +12 -0
- package/src/primitives/reui/switch.tsx +33 -0
- package/src/primitives/reui/table.tsx +114 -0
- package/src/primitives/reui/tabs.tsx +91 -0
- package/src/primitives/reui/textarea.tsx +18 -0
- package/src/primitives/reui/timeline.tsx +219 -0
- package/src/primitives/reui/toggle-group.tsx +83 -0
- package/src/primitives/reui/toggle.tsx +45 -0
- package/src/primitives/reui/tooltip.tsx +55 -0
- package/src/primitives/reui/tree.tsx +247 -0
- package/src/theme.css +71 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { HTMLAttributes, memo, ReactNode, useMemo } from "react";
|
|
4
|
+
import {
|
|
5
|
+
getColumnHeaderLabel,
|
|
6
|
+
useDataGrid,
|
|
7
|
+
} from "@/primitives/reui/data-grid/data-grid";
|
|
8
|
+
import { Column } from "@tanstack/react-table";
|
|
9
|
+
|
|
10
|
+
import { cn } from "@/lib/utils";
|
|
11
|
+
import { Button } from "@/primitives/reui/button";
|
|
12
|
+
import {
|
|
13
|
+
DropdownMenu,
|
|
14
|
+
DropdownMenuCheckboxItem,
|
|
15
|
+
DropdownMenuContent,
|
|
16
|
+
DropdownMenuGroup,
|
|
17
|
+
DropdownMenuItem,
|
|
18
|
+
DropdownMenuLabel,
|
|
19
|
+
DropdownMenuSeparator,
|
|
20
|
+
DropdownMenuSub,
|
|
21
|
+
DropdownMenuSubContent,
|
|
22
|
+
DropdownMenuSubTrigger,
|
|
23
|
+
DropdownMenuTrigger,
|
|
24
|
+
} from "@/primitives/reui/dropdown-menu";
|
|
25
|
+
import { HugeiconsIcon } from "@hugeicons/react";
|
|
26
|
+
import {
|
|
27
|
+
ArrowDown02Icon,
|
|
28
|
+
ArrowUp02Icon,
|
|
29
|
+
UnfoldMoreIcon,
|
|
30
|
+
Tick02Icon,
|
|
31
|
+
ArrowLeft03Icon,
|
|
32
|
+
ArrowRight03Icon,
|
|
33
|
+
ArrowLeft02Icon,
|
|
34
|
+
ArrowRight02Icon,
|
|
35
|
+
SlidersHorizontalIcon,
|
|
36
|
+
PinOffIcon,
|
|
37
|
+
} from "@hugeicons/core-free-icons";
|
|
38
|
+
|
|
39
|
+
interface DataGridColumnHeaderProps<
|
|
40
|
+
TData,
|
|
41
|
+
TValue,
|
|
42
|
+
> extends HTMLAttributes<HTMLDivElement> {
|
|
43
|
+
column: Column<TData, TValue>;
|
|
44
|
+
/** When omitted, uses `column.columnDef.meta.headerTitle`, then a string `columnDef.header`, then `column.id`. */
|
|
45
|
+
title?: string;
|
|
46
|
+
icon?: ReactNode;
|
|
47
|
+
pinnable?: boolean;
|
|
48
|
+
filter?: ReactNode;
|
|
49
|
+
visibility?: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function DataGridColumnHeaderInner<TData, TValue>({
|
|
53
|
+
column,
|
|
54
|
+
title,
|
|
55
|
+
icon,
|
|
56
|
+
className,
|
|
57
|
+
filter,
|
|
58
|
+
visibility = false,
|
|
59
|
+
}: DataGridColumnHeaderProps<TData, TValue>) {
|
|
60
|
+
const { isLoading, table, props, recordCount } = useDataGrid();
|
|
61
|
+
const resolvedTitle = title ?? getColumnHeaderLabel(column);
|
|
62
|
+
|
|
63
|
+
const columnOrder = table.getState().columnOrder;
|
|
64
|
+
const columnVisibilityKey = JSON.stringify(table.getState().columnVisibility);
|
|
65
|
+
const isSorted = column.getIsSorted();
|
|
66
|
+
const isPinned = column.getIsPinned();
|
|
67
|
+
const canSort = column.getCanSort();
|
|
68
|
+
const canPin = column.getCanPin();
|
|
69
|
+
const canResize = column.getCanResize();
|
|
70
|
+
|
|
71
|
+
const columnIndex = columnOrder.indexOf(column.id);
|
|
72
|
+
const canMoveLeft = columnIndex > 0;
|
|
73
|
+
const canMoveRight = columnIndex < columnOrder.length - 1;
|
|
74
|
+
|
|
75
|
+
const handleSort = () => {
|
|
76
|
+
if (isSorted === "asc") {
|
|
77
|
+
column.toggleSorting(true);
|
|
78
|
+
} else if (isSorted === "desc") {
|
|
79
|
+
column.clearSorting();
|
|
80
|
+
} else {
|
|
81
|
+
column.toggleSorting(false);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const headerLabelClassName = cn(
|
|
86
|
+
"text-secondary-foreground/80 inline-flex h-full items-center gap-1.5 font-normal [&_svg]:opacity-60 text-[0.8125rem] leading-[calc(1.125/0.8125)] [&_svg]:size-3.5",
|
|
87
|
+
className,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const headerButtonClassName = cn(
|
|
91
|
+
"text-secondary-foreground/80 hover:bg-secondary data-[state=open]:bg-secondary hover:text-foreground data-[state=open]:text-foreground -ms-2 px-2 font-normal h-7 rounded-4xl",
|
|
92
|
+
className,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const sortIcon =
|
|
96
|
+
canSort &&
|
|
97
|
+
(isSorted === "desc" ? (
|
|
98
|
+
<HugeiconsIcon
|
|
99
|
+
icon={ArrowDown02Icon}
|
|
100
|
+
strokeWidth={2}
|
|
101
|
+
className="size-3.25"
|
|
102
|
+
/>
|
|
103
|
+
) : isSorted === "asc" ? (
|
|
104
|
+
<HugeiconsIcon
|
|
105
|
+
icon={ArrowUp02Icon}
|
|
106
|
+
strokeWidth={2}
|
|
107
|
+
className="size-3.25"
|
|
108
|
+
/>
|
|
109
|
+
) : (
|
|
110
|
+
<HugeiconsIcon
|
|
111
|
+
icon={UnfoldMoreIcon}
|
|
112
|
+
strokeWidth={2}
|
|
113
|
+
className="mt-px size-3.25"
|
|
114
|
+
/>
|
|
115
|
+
));
|
|
116
|
+
|
|
117
|
+
const hasControls =
|
|
118
|
+
props.tableLayout?.columnsMovable ||
|
|
119
|
+
(props.tableLayout?.columnsVisibility && visibility) ||
|
|
120
|
+
(props.tableLayout?.columnsPinnable && canPin) ||
|
|
121
|
+
filter;
|
|
122
|
+
|
|
123
|
+
const menuItems = useMemo(() => {
|
|
124
|
+
const items: ReactNode[] = [];
|
|
125
|
+
let hasPreviousSection = false;
|
|
126
|
+
|
|
127
|
+
// Filter section
|
|
128
|
+
if (filter) {
|
|
129
|
+
items.push(
|
|
130
|
+
<DropdownMenuGroup key="group-filter">
|
|
131
|
+
<DropdownMenuLabel key="filter">{filter}</DropdownMenuLabel>
|
|
132
|
+
</DropdownMenuGroup>,
|
|
133
|
+
);
|
|
134
|
+
hasPreviousSection = true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Sort section
|
|
138
|
+
if (canSort) {
|
|
139
|
+
if (hasPreviousSection) {
|
|
140
|
+
items.push(<DropdownMenuSeparator key="sep-sort" />);
|
|
141
|
+
}
|
|
142
|
+
items.push(
|
|
143
|
+
<DropdownMenuItem
|
|
144
|
+
key="sort-asc"
|
|
145
|
+
onClick={() => {
|
|
146
|
+
if (isSorted === "asc") {
|
|
147
|
+
column.clearSorting();
|
|
148
|
+
} else {
|
|
149
|
+
column.toggleSorting(false);
|
|
150
|
+
}
|
|
151
|
+
}}
|
|
152
|
+
disabled={!canSort}
|
|
153
|
+
>
|
|
154
|
+
<HugeiconsIcon
|
|
155
|
+
icon={ArrowUp02Icon}
|
|
156
|
+
strokeWidth={2}
|
|
157
|
+
className="size-3.5!"
|
|
158
|
+
/>
|
|
159
|
+
<span className="grow">Asc</span>
|
|
160
|
+
{isSorted === "asc" && (
|
|
161
|
+
<HugeiconsIcon
|
|
162
|
+
icon={Tick02Icon}
|
|
163
|
+
strokeWidth={2}
|
|
164
|
+
className="text-primary size-4 opacity-100!"
|
|
165
|
+
/>
|
|
166
|
+
)}
|
|
167
|
+
</DropdownMenuItem>,
|
|
168
|
+
<DropdownMenuItem
|
|
169
|
+
key="sort-desc"
|
|
170
|
+
onClick={() => {
|
|
171
|
+
if (isSorted === "desc") {
|
|
172
|
+
column.clearSorting();
|
|
173
|
+
} else {
|
|
174
|
+
column.toggleSorting(true);
|
|
175
|
+
}
|
|
176
|
+
}}
|
|
177
|
+
disabled={!canSort}
|
|
178
|
+
>
|
|
179
|
+
<HugeiconsIcon
|
|
180
|
+
icon={ArrowDown02Icon}
|
|
181
|
+
strokeWidth={2}
|
|
182
|
+
className="size-3.5!"
|
|
183
|
+
/>
|
|
184
|
+
<span className="grow">Desc</span>
|
|
185
|
+
{isSorted === "desc" && (
|
|
186
|
+
<HugeiconsIcon
|
|
187
|
+
icon={Tick02Icon}
|
|
188
|
+
strokeWidth={2}
|
|
189
|
+
className="text-primary size-4 opacity-100!"
|
|
190
|
+
/>
|
|
191
|
+
)}
|
|
192
|
+
</DropdownMenuItem>,
|
|
193
|
+
);
|
|
194
|
+
hasPreviousSection = true;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Pin section
|
|
198
|
+
if (props.tableLayout?.columnsPinnable && canPin) {
|
|
199
|
+
if (hasPreviousSection) {
|
|
200
|
+
items.push(<DropdownMenuSeparator key="sep-pin" />);
|
|
201
|
+
}
|
|
202
|
+
items.push(
|
|
203
|
+
<DropdownMenuItem
|
|
204
|
+
key="pin-left"
|
|
205
|
+
onClick={() => column.pin(isPinned === "left" ? false : "left")}
|
|
206
|
+
>
|
|
207
|
+
<HugeiconsIcon
|
|
208
|
+
icon={ArrowLeft03Icon}
|
|
209
|
+
strokeWidth={2}
|
|
210
|
+
className="size-3.5!"
|
|
211
|
+
aria-hidden="true"
|
|
212
|
+
/>
|
|
213
|
+
<span className="grow">Pin to left</span>
|
|
214
|
+
{isPinned === "left" && (
|
|
215
|
+
<HugeiconsIcon
|
|
216
|
+
icon={Tick02Icon}
|
|
217
|
+
strokeWidth={2}
|
|
218
|
+
className="text-primary size-4 opacity-100!"
|
|
219
|
+
/>
|
|
220
|
+
)}
|
|
221
|
+
</DropdownMenuItem>,
|
|
222
|
+
<DropdownMenuItem
|
|
223
|
+
key="pin-right"
|
|
224
|
+
onClick={() => column.pin(isPinned === "right" ? false : "right")}
|
|
225
|
+
>
|
|
226
|
+
<HugeiconsIcon
|
|
227
|
+
icon={ArrowRight03Icon}
|
|
228
|
+
strokeWidth={2}
|
|
229
|
+
className="size-3.5!"
|
|
230
|
+
aria-hidden="true"
|
|
231
|
+
/>
|
|
232
|
+
<span className="grow">Pin to right</span>
|
|
233
|
+
{isPinned === "right" && (
|
|
234
|
+
<HugeiconsIcon
|
|
235
|
+
icon={Tick02Icon}
|
|
236
|
+
strokeWidth={2}
|
|
237
|
+
className="text-primary size-4 opacity-100!"
|
|
238
|
+
/>
|
|
239
|
+
)}
|
|
240
|
+
</DropdownMenuItem>,
|
|
241
|
+
);
|
|
242
|
+
hasPreviousSection = true;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Move section
|
|
246
|
+
if (props.tableLayout?.columnsMovable) {
|
|
247
|
+
if (hasPreviousSection) {
|
|
248
|
+
items.push(<DropdownMenuSeparator key="sep-move" />);
|
|
249
|
+
}
|
|
250
|
+
items.push(
|
|
251
|
+
<DropdownMenuItem
|
|
252
|
+
key="move-left"
|
|
253
|
+
onClick={() => {
|
|
254
|
+
if (columnIndex > 0) {
|
|
255
|
+
const newOrder = [...columnOrder];
|
|
256
|
+
const [movedColumn] = newOrder.splice(columnIndex, 1);
|
|
257
|
+
newOrder.splice(columnIndex - 1, 0, movedColumn);
|
|
258
|
+
table.setColumnOrder(newOrder);
|
|
259
|
+
}
|
|
260
|
+
}}
|
|
261
|
+
disabled={!canMoveLeft || isPinned !== false}
|
|
262
|
+
>
|
|
263
|
+
<HugeiconsIcon
|
|
264
|
+
icon={ArrowLeft02Icon}
|
|
265
|
+
strokeWidth={2}
|
|
266
|
+
className="size-3.5!"
|
|
267
|
+
aria-hidden="true"
|
|
268
|
+
/>
|
|
269
|
+
<span>Move to Left</span>
|
|
270
|
+
</DropdownMenuItem>,
|
|
271
|
+
<DropdownMenuItem
|
|
272
|
+
key="move-right"
|
|
273
|
+
onClick={() => {
|
|
274
|
+
if (columnIndex < columnOrder.length - 1) {
|
|
275
|
+
const newOrder = [...columnOrder];
|
|
276
|
+
const [movedColumn] = newOrder.splice(columnIndex, 1);
|
|
277
|
+
newOrder.splice(columnIndex + 1, 0, movedColumn);
|
|
278
|
+
table.setColumnOrder(newOrder);
|
|
279
|
+
}
|
|
280
|
+
}}
|
|
281
|
+
disabled={!canMoveRight || isPinned !== false}
|
|
282
|
+
>
|
|
283
|
+
<HugeiconsIcon
|
|
284
|
+
icon={ArrowRight02Icon}
|
|
285
|
+
strokeWidth={2}
|
|
286
|
+
className="size-3.5!"
|
|
287
|
+
aria-hidden="true"
|
|
288
|
+
/>
|
|
289
|
+
<span>Move to Right</span>
|
|
290
|
+
</DropdownMenuItem>,
|
|
291
|
+
);
|
|
292
|
+
hasPreviousSection = true;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Visibility section
|
|
296
|
+
if (props.tableLayout?.columnsVisibility && visibility) {
|
|
297
|
+
if (hasPreviousSection) {
|
|
298
|
+
items.push(<DropdownMenuSeparator key="sep-visibility" />);
|
|
299
|
+
}
|
|
300
|
+
items.push(
|
|
301
|
+
<DropdownMenuSub key="visibility">
|
|
302
|
+
<DropdownMenuSubTrigger>
|
|
303
|
+
<HugeiconsIcon
|
|
304
|
+
icon={SlidersHorizontalIcon}
|
|
305
|
+
strokeWidth={2}
|
|
306
|
+
className="size-3.5!"
|
|
307
|
+
/>
|
|
308
|
+
<span>Columns</span>
|
|
309
|
+
</DropdownMenuSubTrigger>
|
|
310
|
+
<DropdownMenuSubContent>
|
|
311
|
+
{table
|
|
312
|
+
.getAllColumns()
|
|
313
|
+
.filter((col) => col.getCanHide())
|
|
314
|
+
.map((col) => (
|
|
315
|
+
<DropdownMenuCheckboxItem
|
|
316
|
+
key={col.id}
|
|
317
|
+
checked={col.getIsVisible()}
|
|
318
|
+
onSelect={(event) => event.preventDefault()}
|
|
319
|
+
onCheckedChange={(value) => col.toggleVisibility(!!value)}
|
|
320
|
+
className="capitalize"
|
|
321
|
+
>
|
|
322
|
+
{getColumnHeaderLabel(col)}
|
|
323
|
+
</DropdownMenuCheckboxItem>
|
|
324
|
+
))}
|
|
325
|
+
</DropdownMenuSubContent>
|
|
326
|
+
</DropdownMenuSub>,
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return items;
|
|
331
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
332
|
+
}, [
|
|
333
|
+
filter,
|
|
334
|
+
canSort,
|
|
335
|
+
isSorted,
|
|
336
|
+
column,
|
|
337
|
+
props.tableLayout?.columnsPinnable,
|
|
338
|
+
props.tableLayout?.columnsMovable,
|
|
339
|
+
props.tableLayout?.columnsVisibility,
|
|
340
|
+
canPin,
|
|
341
|
+
isPinned,
|
|
342
|
+
canMoveLeft,
|
|
343
|
+
canMoveRight,
|
|
344
|
+
visibility,
|
|
345
|
+
table,
|
|
346
|
+
columnIndex,
|
|
347
|
+
columnOrder,
|
|
348
|
+
columnVisibilityKey, // Needed to update checkbox states when visibility changes
|
|
349
|
+
]);
|
|
350
|
+
|
|
351
|
+
if (hasControls) {
|
|
352
|
+
return (
|
|
353
|
+
<div className="flex h-full items-center justify-between gap-1.5">
|
|
354
|
+
<DropdownMenu>
|
|
355
|
+
<DropdownMenuTrigger asChild>
|
|
356
|
+
<Button
|
|
357
|
+
variant="ghost"
|
|
358
|
+
className={headerButtonClassName}
|
|
359
|
+
disabled={isLoading || recordCount === 0}
|
|
360
|
+
>
|
|
361
|
+
{icon && icon}
|
|
362
|
+
{resolvedTitle}
|
|
363
|
+
{sortIcon}
|
|
364
|
+
</Button>
|
|
365
|
+
</DropdownMenuTrigger>
|
|
366
|
+
<DropdownMenuContent className="w-40" align="start">
|
|
367
|
+
{menuItems}
|
|
368
|
+
</DropdownMenuContent>
|
|
369
|
+
</DropdownMenu>
|
|
370
|
+
{props.tableLayout?.columnsPinnable && canPin && isPinned && (
|
|
371
|
+
<Button
|
|
372
|
+
size="icon-sm"
|
|
373
|
+
variant="ghost"
|
|
374
|
+
className="-me-1 size-7 rounded-md"
|
|
375
|
+
onClick={() => column.pin(false)}
|
|
376
|
+
aria-label={`Unpin ${resolvedTitle} column`}
|
|
377
|
+
title={`Unpin ${resolvedTitle} column`}
|
|
378
|
+
>
|
|
379
|
+
<HugeiconsIcon
|
|
380
|
+
icon={PinOffIcon}
|
|
381
|
+
strokeWidth={2}
|
|
382
|
+
className="size-3.5! opacity-50!"
|
|
383
|
+
aria-hidden="true"
|
|
384
|
+
/>
|
|
385
|
+
</Button>
|
|
386
|
+
)}
|
|
387
|
+
</div>
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
if (canSort || (props.tableLayout?.columnsResizable && canResize)) {
|
|
392
|
+
return (
|
|
393
|
+
<div className="flex h-full items-center">
|
|
394
|
+
<Button
|
|
395
|
+
variant="ghost"
|
|
396
|
+
className={headerButtonClassName}
|
|
397
|
+
disabled={isLoading || recordCount === 0}
|
|
398
|
+
onClick={handleSort}
|
|
399
|
+
>
|
|
400
|
+
{icon && icon}
|
|
401
|
+
{resolvedTitle}
|
|
402
|
+
{sortIcon}
|
|
403
|
+
</Button>
|
|
404
|
+
</div>
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return (
|
|
409
|
+
<div className={headerLabelClassName}>
|
|
410
|
+
{icon && icon}
|
|
411
|
+
{resolvedTitle}
|
|
412
|
+
</div>
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
const DataGridColumnHeader = memo(
|
|
417
|
+
DataGridColumnHeaderInner,
|
|
418
|
+
) as typeof DataGridColumnHeaderInner;
|
|
419
|
+
|
|
420
|
+
export { DataGridColumnHeader, type DataGridColumnHeaderProps };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ReactElement } from "react";
|
|
2
|
+
import { getColumnHeaderLabel } from "@/primitives/reui/data-grid/data-grid";
|
|
3
|
+
import { Table } from "@tanstack/react-table";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
DropdownMenu,
|
|
7
|
+
DropdownMenuCheckboxItem,
|
|
8
|
+
DropdownMenuContent,
|
|
9
|
+
DropdownMenuGroup,
|
|
10
|
+
DropdownMenuLabel,
|
|
11
|
+
DropdownMenuTrigger,
|
|
12
|
+
} from "@/primitives/reui/dropdown-menu";
|
|
13
|
+
|
|
14
|
+
function DataGridColumnVisibility<TData>({
|
|
15
|
+
table,
|
|
16
|
+
trigger,
|
|
17
|
+
}: {
|
|
18
|
+
table: Table<TData>;
|
|
19
|
+
trigger: ReactElement<Record<string, unknown>>;
|
|
20
|
+
}) {
|
|
21
|
+
return (
|
|
22
|
+
<DropdownMenu>
|
|
23
|
+
<DropdownMenuTrigger asChild>{trigger}</DropdownMenuTrigger>
|
|
24
|
+
<DropdownMenuContent align="end" className="min-w-[150px]">
|
|
25
|
+
<DropdownMenuGroup>
|
|
26
|
+
<DropdownMenuLabel className="font-medium">
|
|
27
|
+
Toggle Columns
|
|
28
|
+
</DropdownMenuLabel>
|
|
29
|
+
{table
|
|
30
|
+
.getAllColumns()
|
|
31
|
+
.filter((column) => column.getCanHide())
|
|
32
|
+
.map((column) => {
|
|
33
|
+
return (
|
|
34
|
+
<DropdownMenuCheckboxItem
|
|
35
|
+
key={column.id}
|
|
36
|
+
className="capitalize"
|
|
37
|
+
checked={column.getIsVisible()}
|
|
38
|
+
onSelect={(event) => event.preventDefault()}
|
|
39
|
+
onCheckedChange={(value) => column.toggleVisibility(!!value)}
|
|
40
|
+
>
|
|
41
|
+
{getColumnHeaderLabel(column)}
|
|
42
|
+
</DropdownMenuCheckboxItem>
|
|
43
|
+
);
|
|
44
|
+
})}
|
|
45
|
+
</DropdownMenuGroup>
|
|
46
|
+
</DropdownMenuContent>
|
|
47
|
+
</DropdownMenu>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { DataGridColumnVisibility };
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, { ReactNode } from "react";
|
|
4
|
+
import { useDataGrid } from "@/primitives/reui/data-grid/data-grid";
|
|
5
|
+
|
|
6
|
+
import { cn } from "@/lib/utils";
|
|
7
|
+
import { Button } from "@/primitives/reui/button";
|
|
8
|
+
import {
|
|
9
|
+
Select,
|
|
10
|
+
SelectContent,
|
|
11
|
+
SelectItem,
|
|
12
|
+
SelectTrigger,
|
|
13
|
+
SelectValue,
|
|
14
|
+
} from "@/primitives/reui/select";
|
|
15
|
+
import { Skeleton } from "@/primitives/reui/skeleton";
|
|
16
|
+
import { HugeiconsIcon } from "@hugeicons/react";
|
|
17
|
+
import { ArrowLeft01Icon, ArrowRight01Icon } from "@hugeicons/core-free-icons";
|
|
18
|
+
|
|
19
|
+
interface DataGridPaginationProps {
|
|
20
|
+
sizes?: number[];
|
|
21
|
+
sizesInfo?: string;
|
|
22
|
+
sizesLabel?: string;
|
|
23
|
+
sizesDescription?: string;
|
|
24
|
+
sizesSkeleton?: ReactNode;
|
|
25
|
+
more?: boolean;
|
|
26
|
+
moreLimit?: number;
|
|
27
|
+
info?: string;
|
|
28
|
+
infoSkeleton?: ReactNode;
|
|
29
|
+
className?: string;
|
|
30
|
+
rowsPerPageLabel?: string;
|
|
31
|
+
previousPageLabel?: string;
|
|
32
|
+
nextPageLabel?: string;
|
|
33
|
+
ellipsisText?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function DataGridPagination(props: DataGridPaginationProps): React.JSX.Element {
|
|
37
|
+
const { table, recordCount, isLoading } = useDataGrid();
|
|
38
|
+
|
|
39
|
+
const defaultProps: Partial<DataGridPaginationProps> = {
|
|
40
|
+
sizes: [5, 10, 25, 50, 100],
|
|
41
|
+
sizesLabel: "Show",
|
|
42
|
+
sizesDescription: "per page",
|
|
43
|
+
sizesSkeleton: <Skeleton className="h-8 w-44" />,
|
|
44
|
+
moreLimit: 5,
|
|
45
|
+
more: false,
|
|
46
|
+
info: "{from} - {to} of {count}",
|
|
47
|
+
infoSkeleton: <Skeleton className="h-8 w-60" />,
|
|
48
|
+
rowsPerPageLabel: "Rows per page",
|
|
49
|
+
previousPageLabel: "Go to previous page",
|
|
50
|
+
nextPageLabel: "Go to next page",
|
|
51
|
+
ellipsisText: "...",
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const mergedProps: DataGridPaginationProps = { ...defaultProps, ...props };
|
|
55
|
+
|
|
56
|
+
const btnBaseClasses = "size-7 p-0 text-sm";
|
|
57
|
+
const btnArrowClasses = btnBaseClasses + " rtl:transform rtl:rotate-180";
|
|
58
|
+
const pageIndex = table.getState().pagination.pageIndex;
|
|
59
|
+
const pageSize = table.getState().pagination.pageSize;
|
|
60
|
+
const from = pageIndex * pageSize + 1;
|
|
61
|
+
const to = Math.min((pageIndex + 1) * pageSize, recordCount);
|
|
62
|
+
const pageCount = table.getPageCount();
|
|
63
|
+
|
|
64
|
+
// Replace placeholders in paginationInfo
|
|
65
|
+
const paginationInfo = mergedProps?.info
|
|
66
|
+
? mergedProps.info
|
|
67
|
+
.replace("{from}", from.toString())
|
|
68
|
+
.replace("{to}", to.toString())
|
|
69
|
+
.replace("{count}", recordCount.toString())
|
|
70
|
+
: `${from} - ${to} of ${recordCount}`;
|
|
71
|
+
|
|
72
|
+
// Pagination limit logic
|
|
73
|
+
const paginationMoreLimit = mergedProps?.moreLimit || 5;
|
|
74
|
+
|
|
75
|
+
// Determine the start and end of the pagination group
|
|
76
|
+
const currentGroupStart =
|
|
77
|
+
Math.floor(pageIndex / paginationMoreLimit) * paginationMoreLimit;
|
|
78
|
+
const currentGroupEnd = Math.min(
|
|
79
|
+
currentGroupStart + paginationMoreLimit,
|
|
80
|
+
pageCount,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
// Render page buttons based on the current group
|
|
84
|
+
const renderPageButtons = () => {
|
|
85
|
+
const buttons = [];
|
|
86
|
+
for (let i = currentGroupStart; i < currentGroupEnd; i++) {
|
|
87
|
+
buttons.push(
|
|
88
|
+
<Button
|
|
89
|
+
key={i}
|
|
90
|
+
size="icon-sm"
|
|
91
|
+
variant="ghost"
|
|
92
|
+
className={cn(btnBaseClasses, "text-muted-foreground", {
|
|
93
|
+
"bg-accent text-accent-foreground": pageIndex === i,
|
|
94
|
+
})}
|
|
95
|
+
onClick={() => {
|
|
96
|
+
if (pageIndex !== i) {
|
|
97
|
+
table.setPageIndex(i);
|
|
98
|
+
}
|
|
99
|
+
}}
|
|
100
|
+
>
|
|
101
|
+
{i + 1}
|
|
102
|
+
</Button>,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
return buttons;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// Render a "previous" ellipsis button if there are previous pages to show
|
|
109
|
+
const renderEllipsisPrevButton = () => {
|
|
110
|
+
if (currentGroupStart > 0) {
|
|
111
|
+
return (
|
|
112
|
+
<Button
|
|
113
|
+
size="icon-sm"
|
|
114
|
+
className={btnBaseClasses}
|
|
115
|
+
variant="ghost"
|
|
116
|
+
onClick={() => table.setPageIndex(currentGroupStart - 1)}
|
|
117
|
+
>
|
|
118
|
+
{mergedProps.ellipsisText}
|
|
119
|
+
</Button>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// Render a "next" ellipsis button if there are more pages to show after the current group
|
|
126
|
+
const renderEllipsisNextButton = () => {
|
|
127
|
+
if (currentGroupEnd < pageCount) {
|
|
128
|
+
return (
|
|
129
|
+
<Button
|
|
130
|
+
className={btnBaseClasses}
|
|
131
|
+
variant="ghost"
|
|
132
|
+
size="icon-sm"
|
|
133
|
+
onClick={() => table.setPageIndex(currentGroupEnd)}
|
|
134
|
+
>
|
|
135
|
+
{mergedProps.ellipsisText}
|
|
136
|
+
</Button>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<div
|
|
144
|
+
data-slot="data-grid-pagination"
|
|
145
|
+
className={cn(
|
|
146
|
+
"flex grow flex-col flex-wrap items-center justify-between gap-2.5 py-2.5 sm:flex-row sm:py-0",
|
|
147
|
+
mergedProps?.className,
|
|
148
|
+
)}
|
|
149
|
+
>
|
|
150
|
+
<div className="order-2 flex flex-wrap items-center space-x-2.5 pb-2.5 sm:order-1 sm:pb-0">
|
|
151
|
+
{isLoading ? (
|
|
152
|
+
mergedProps?.sizesSkeleton
|
|
153
|
+
) : (
|
|
154
|
+
<>
|
|
155
|
+
<div className="text-muted-foreground text-sm">
|
|
156
|
+
{mergedProps.rowsPerPageLabel}
|
|
157
|
+
</div>
|
|
158
|
+
<Select
|
|
159
|
+
value={`${pageSize}`}
|
|
160
|
+
onValueChange={(value) => {
|
|
161
|
+
const newPageSize = Number(value);
|
|
162
|
+
table.setPageSize(newPageSize);
|
|
163
|
+
}}
|
|
164
|
+
>
|
|
165
|
+
<SelectTrigger className="w-14" size="sm">
|
|
166
|
+
<SelectValue />
|
|
167
|
+
</SelectTrigger>
|
|
168
|
+
<SelectContent side="top" className="min-w-18">
|
|
169
|
+
{mergedProps?.sizes?.map((size: number) => (
|
|
170
|
+
<SelectItem key={size} value={`${size}`}>
|
|
171
|
+
{size}
|
|
172
|
+
</SelectItem>
|
|
173
|
+
))}
|
|
174
|
+
</SelectContent>
|
|
175
|
+
</Select>
|
|
176
|
+
</>
|
|
177
|
+
)}
|
|
178
|
+
</div>
|
|
179
|
+
<div className="order-1 flex flex-col items-center justify-center gap-2.5 pt-2.5 sm:order-2 sm:flex-row sm:justify-end sm:pt-0">
|
|
180
|
+
{isLoading ? (
|
|
181
|
+
mergedProps?.infoSkeleton
|
|
182
|
+
) : (
|
|
183
|
+
<>
|
|
184
|
+
<div className="text-muted-foreground text-sm order-2 text-nowrap sm:order-1">
|
|
185
|
+
{paginationInfo}
|
|
186
|
+
</div>
|
|
187
|
+
{pageCount > 1 && (
|
|
188
|
+
<div className="order-1 flex items-center space-x-1 sm:order-2">
|
|
189
|
+
<Button
|
|
190
|
+
size="icon-sm"
|
|
191
|
+
variant="ghost"
|
|
192
|
+
className={btnArrowClasses}
|
|
193
|
+
onClick={() => table.previousPage()}
|
|
194
|
+
disabled={!table.getCanPreviousPage()}
|
|
195
|
+
>
|
|
196
|
+
<span className="sr-only">
|
|
197
|
+
{mergedProps.previousPageLabel}
|
|
198
|
+
</span>
|
|
199
|
+
<HugeiconsIcon
|
|
200
|
+
icon={ArrowLeft01Icon}
|
|
201
|
+
strokeWidth={2}
|
|
202
|
+
className="size-4"
|
|
203
|
+
/>
|
|
204
|
+
</Button>
|
|
205
|
+
|
|
206
|
+
{renderEllipsisPrevButton()}
|
|
207
|
+
|
|
208
|
+
{renderPageButtons()}
|
|
209
|
+
|
|
210
|
+
{renderEllipsisNextButton()}
|
|
211
|
+
|
|
212
|
+
<Button
|
|
213
|
+
size="icon-sm"
|
|
214
|
+
variant="ghost"
|
|
215
|
+
className={btnArrowClasses}
|
|
216
|
+
onClick={() => table.nextPage()}
|
|
217
|
+
disabled={!table.getCanNextPage()}
|
|
218
|
+
>
|
|
219
|
+
<span className="sr-only">{mergedProps.nextPageLabel}</span>
|
|
220
|
+
<HugeiconsIcon
|
|
221
|
+
icon={ArrowRight01Icon}
|
|
222
|
+
strokeWidth={2}
|
|
223
|
+
className="size-4"
|
|
224
|
+
/>
|
|
225
|
+
</Button>
|
|
226
|
+
</div>
|
|
227
|
+
)}
|
|
228
|
+
</>
|
|
229
|
+
)}
|
|
230
|
+
</div>
|
|
231
|
+
</div>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export { DataGridPagination, type DataGridPaginationProps };
|