@middag-io/react 0.45.0 → 0.45.2
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/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,269 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { createContext, ReactNode, useContext, useMemo } from "react";
|
|
4
|
+
import {
|
|
5
|
+
Column,
|
|
6
|
+
ColumnFiltersState,
|
|
7
|
+
RowData,
|
|
8
|
+
SortingState,
|
|
9
|
+
Table,
|
|
10
|
+
} from "@tanstack/react-table";
|
|
11
|
+
|
|
12
|
+
import { cn } from "@/lib/utils";
|
|
13
|
+
|
|
14
|
+
declare module "@tanstack/react-table" {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
+
interface ColumnMeta<TData extends RowData, TValue> {
|
|
17
|
+
headerTitle?: string;
|
|
18
|
+
headerClassName?: string;
|
|
19
|
+
cellClassName?: string;
|
|
20
|
+
skeleton?: ReactNode;
|
|
21
|
+
expandedContent?: (row: TData) => ReactNode;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Label for headers / column visibility: `meta.headerTitle`, string `columnDef.header`, or `column.id`. */
|
|
26
|
+
export function getColumnHeaderLabel<TData, TValue>(
|
|
27
|
+
column: Column<TData, TValue>,
|
|
28
|
+
): string {
|
|
29
|
+
const meta = column.columnDef.meta as { headerTitle?: string } | undefined;
|
|
30
|
+
if (typeof meta?.headerTitle === "string") return meta.headerTitle;
|
|
31
|
+
const defHeader = column.columnDef.header;
|
|
32
|
+
if (typeof defHeader === "string") return defHeader;
|
|
33
|
+
return String(column.id);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type DataGridApiFetchParams = {
|
|
37
|
+
pageIndex: number;
|
|
38
|
+
pageSize: number;
|
|
39
|
+
sorting?: SortingState;
|
|
40
|
+
filters?: ColumnFiltersState;
|
|
41
|
+
searchQuery?: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type DataGridApiResponse<T> = {
|
|
45
|
+
data: T[];
|
|
46
|
+
empty: boolean;
|
|
47
|
+
pagination: {
|
|
48
|
+
total: number;
|
|
49
|
+
page: number;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export interface DataGridContextProps<TData extends object> {
|
|
54
|
+
props: DataGridProps<TData>;
|
|
55
|
+
table: Table<TData>;
|
|
56
|
+
recordCount: number;
|
|
57
|
+
isLoading: boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type DataGridRequestParams = {
|
|
61
|
+
pageIndex: number;
|
|
62
|
+
pageSize: number;
|
|
63
|
+
sorting?: SortingState;
|
|
64
|
+
columnFilters?: ColumnFiltersState;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export interface DataGridProps<TData extends object> {
|
|
68
|
+
className?: string;
|
|
69
|
+
table?: Table<TData>;
|
|
70
|
+
recordCount: number;
|
|
71
|
+
children?: ReactNode;
|
|
72
|
+
onRowClick?: (row: TData) => void;
|
|
73
|
+
isLoading?: boolean;
|
|
74
|
+
loadingMode?: "skeleton" | "spinner";
|
|
75
|
+
loadingMessage?: ReactNode | string;
|
|
76
|
+
fetchingMoreMessage?: ReactNode | string;
|
|
77
|
+
allRowsLoadedMessage?: ReactNode | string;
|
|
78
|
+
emptyMessage?: ReactNode | string;
|
|
79
|
+
tableLayout?: {
|
|
80
|
+
dense?: boolean;
|
|
81
|
+
cellBorder?: boolean;
|
|
82
|
+
rowBorder?: boolean;
|
|
83
|
+
rowRounded?: boolean;
|
|
84
|
+
stripped?: boolean;
|
|
85
|
+
headerBackground?: boolean;
|
|
86
|
+
headerBorder?: boolean;
|
|
87
|
+
headerSticky?: boolean;
|
|
88
|
+
width?: "auto" | "fixed";
|
|
89
|
+
columnsVisibility?: boolean;
|
|
90
|
+
columnsResizable?: boolean;
|
|
91
|
+
columnsResizeMode?: "onChange" | "onEnd";
|
|
92
|
+
columnsPinnable?: boolean;
|
|
93
|
+
columnsMovable?: boolean;
|
|
94
|
+
columnsDraggable?: boolean;
|
|
95
|
+
rowsDraggable?: boolean;
|
|
96
|
+
rowsPinnable?: boolean;
|
|
97
|
+
};
|
|
98
|
+
tableClassNames?: {
|
|
99
|
+
base?: string;
|
|
100
|
+
header?: string;
|
|
101
|
+
headerRow?: string;
|
|
102
|
+
headerSticky?: string;
|
|
103
|
+
body?: string;
|
|
104
|
+
bodyRow?: string;
|
|
105
|
+
footer?: string;
|
|
106
|
+
edgeCell?: string;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const DataGridContext = createContext<
|
|
111
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
112
|
+
DataGridContextProps<any> | undefined
|
|
113
|
+
>(undefined);
|
|
114
|
+
|
|
115
|
+
function useDataGrid() {
|
|
116
|
+
const context = useContext(DataGridContext);
|
|
117
|
+
if (!context) {
|
|
118
|
+
throw new Error("useDataGrid must be used within a DataGridProvider");
|
|
119
|
+
}
|
|
120
|
+
return context;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function DataGridProvider<TData extends object>({
|
|
124
|
+
children,
|
|
125
|
+
table,
|
|
126
|
+
...props
|
|
127
|
+
}: DataGridProps<TData> & { table: Table<TData> }) {
|
|
128
|
+
const tableState = table.getState();
|
|
129
|
+
const resolvedColumnsResizeMode =
|
|
130
|
+
props.tableLayout?.columnsResizeMode ?? "onEnd";
|
|
131
|
+
|
|
132
|
+
// Keep resize mode aligned with the DataGrid contract every render so
|
|
133
|
+
// consumer-level useReactTable options cannot flip it back between drags.
|
|
134
|
+
if (props.tableLayout?.columnsResizable) {
|
|
135
|
+
table.options.columnResizeMode = resolvedColumnsResizeMode;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Memoize context value so consumers don't re-render during column resize.
|
|
139
|
+
// Column sizing state is intentionally excluded from deps -- CSS variables
|
|
140
|
+
// on the <table> element handle width updates without React re-renders.
|
|
141
|
+
const value = useMemo(
|
|
142
|
+
() => ({
|
|
143
|
+
props,
|
|
144
|
+
table,
|
|
145
|
+
recordCount: props.recordCount,
|
|
146
|
+
isLoading: props.isLoading || false,
|
|
147
|
+
}),
|
|
148
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
149
|
+
[
|
|
150
|
+
table,
|
|
151
|
+
props.recordCount,
|
|
152
|
+
props.isLoading,
|
|
153
|
+
props.loadingMode,
|
|
154
|
+
props.loadingMessage,
|
|
155
|
+
props.fetchingMoreMessage,
|
|
156
|
+
props.allRowsLoadedMessage,
|
|
157
|
+
props.emptyMessage,
|
|
158
|
+
props.onRowClick,
|
|
159
|
+
props.className,
|
|
160
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
161
|
+
JSON.stringify(props.tableLayout),
|
|
162
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
163
|
+
JSON.stringify(props.tableClassNames),
|
|
164
|
+
tableState.sorting,
|
|
165
|
+
tableState.pagination,
|
|
166
|
+
tableState.columnFilters,
|
|
167
|
+
tableState.rowSelection,
|
|
168
|
+
tableState.expanded,
|
|
169
|
+
tableState.columnVisibility,
|
|
170
|
+
tableState.columnOrder,
|
|
171
|
+
tableState.columnPinning,
|
|
172
|
+
tableState.globalFilter,
|
|
173
|
+
],
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<DataGridContext.Provider value={value}>
|
|
178
|
+
{children}
|
|
179
|
+
</DataGridContext.Provider>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function DataGrid<TData extends object>({
|
|
184
|
+
children,
|
|
185
|
+
table,
|
|
186
|
+
...props
|
|
187
|
+
}: DataGridProps<TData>) {
|
|
188
|
+
const defaultProps: Partial<DataGridProps<TData>> = {
|
|
189
|
+
loadingMode: "skeleton",
|
|
190
|
+
tableLayout: {
|
|
191
|
+
dense: false,
|
|
192
|
+
cellBorder: false,
|
|
193
|
+
rowBorder: true,
|
|
194
|
+
rowRounded: false,
|
|
195
|
+
stripped: false,
|
|
196
|
+
headerSticky: false,
|
|
197
|
+
headerBackground: true,
|
|
198
|
+
headerBorder: true,
|
|
199
|
+
width: "fixed",
|
|
200
|
+
columnsVisibility: false,
|
|
201
|
+
columnsResizable: false,
|
|
202
|
+
columnsResizeMode: "onEnd",
|
|
203
|
+
columnsPinnable: false,
|
|
204
|
+
columnsMovable: false,
|
|
205
|
+
columnsDraggable: false,
|
|
206
|
+
rowsDraggable: false,
|
|
207
|
+
rowsPinnable: false,
|
|
208
|
+
},
|
|
209
|
+
tableClassNames: {
|
|
210
|
+
base: "",
|
|
211
|
+
header: "",
|
|
212
|
+
headerRow: "",
|
|
213
|
+
headerSticky: "sticky top-0 z-15 bg-background/90 backdrop-blur-xs",
|
|
214
|
+
body: "",
|
|
215
|
+
bodyRow: "",
|
|
216
|
+
footer: "",
|
|
217
|
+
edgeCell: "",
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const mergedProps: DataGridProps<TData> = {
|
|
222
|
+
...defaultProps,
|
|
223
|
+
...props,
|
|
224
|
+
tableLayout: {
|
|
225
|
+
...defaultProps.tableLayout,
|
|
226
|
+
...(props.tableLayout || {}),
|
|
227
|
+
},
|
|
228
|
+
tableClassNames: {
|
|
229
|
+
...defaultProps.tableClassNames,
|
|
230
|
+
...(props.tableClassNames || {}),
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// Ensure table is provided
|
|
235
|
+
if (!table) {
|
|
236
|
+
throw new Error('DataGrid requires a "table" prop');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return (
|
|
240
|
+
<DataGridProvider table={table} {...mergedProps}>
|
|
241
|
+
{children}
|
|
242
|
+
</DataGridProvider>
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function DataGridContainer({
|
|
247
|
+
children,
|
|
248
|
+
className,
|
|
249
|
+
border = true,
|
|
250
|
+
}: {
|
|
251
|
+
children: ReactNode;
|
|
252
|
+
className?: string;
|
|
253
|
+
border?: boolean;
|
|
254
|
+
}) {
|
|
255
|
+
return (
|
|
256
|
+
<div
|
|
257
|
+
data-slot="data-grid"
|
|
258
|
+
className={cn(
|
|
259
|
+
"w-full overflow-hidden",
|
|
260
|
+
border && "border-border rounded-2xl border",
|
|
261
|
+
className,
|
|
262
|
+
)}
|
|
263
|
+
>
|
|
264
|
+
{children}
|
|
265
|
+
</div>
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export { useDataGrid, DataGridProvider, DataGrid, DataGridContainer };
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { 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) {
|
|
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 order-2 text-sm 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 };
|