banhaten 0.3.0 → 0.5.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/CHANGELOG.md +139 -73
- package/CONTRIBUTING.md +46 -44
- package/README.md +192 -190
- package/SECURITY.md +15 -15
- package/banhaten.config.example.json +11 -11
- package/docs/design-spacing.md +13 -0
- package/docs/design-system/README.md +22 -20
- package/docs/design-system/adoption-quality-remediation.md +87 -87
- package/docs/design-system/agent-usage.md +13 -13
- package/docs/design-system/appearance-presets.md +189 -189
- package/docs/design-system/appearances/default.md +94 -94
- package/docs/design-system/appearances/rounded.md +95 -95
- package/docs/design-system/appearances/sharp.md +95 -95
- package/docs/design-system/component-docs-pattern.md +81 -81
- package/docs/design-system/component-implementation-ownership-audit.md +245 -244
- package/docs/design-system/component-quality-audit-2026-08-20.md +225 -223
- package/docs/design-system/component-showcase-consistency-report.md +219 -219
- package/docs/design-system/component-token-consistency-audit.md +173 -173
- package/docs/design-system/components/README.md +90 -76
- package/docs/design-system/components/accordion.md +53 -53
- package/docs/design-system/components/activity-feed.md +94 -94
- package/docs/design-system/components/activity-heatmap.md +57 -57
- package/docs/design-system/components/agent-input.md +85 -0
- package/docs/design-system/components/alert-dialog.md +72 -72
- package/docs/design-system/components/alert.md +98 -98
- package/docs/design-system/components/approval-card.md +134 -0
- package/docs/design-system/components/aspect-ratio.md +45 -45
- package/docs/design-system/components/attribute.md +89 -89
- package/docs/design-system/components/autocomplete.md +75 -75
- package/docs/design-system/components/avatar.md +54 -54
- package/docs/design-system/components/badge.md +54 -54
- package/docs/design-system/components/banner.md +87 -87
- package/docs/design-system/components/breadcrumbs.md +177 -176
- package/docs/design-system/components/button-group.md +98 -98
- package/docs/design-system/components/button.md +83 -80
- package/docs/design-system/components/card.md +88 -88
- package/docs/design-system/components/carousel.md +46 -46
- package/docs/design-system/components/catalog-components.md +47 -47
- package/docs/design-system/components/chart.md +95 -24
- package/docs/design-system/components/checkbox.md +54 -54
- package/docs/design-system/components/collapsible.md +67 -53
- package/docs/design-system/components/command.md +62 -62
- package/docs/design-system/components/context-menu.md +46 -46
- package/docs/design-system/components/date-picker.md +81 -79
- package/docs/design-system/components/divider.md +102 -102
- package/docs/design-system/components/empty-state.md +56 -56
- package/docs/design-system/components/field.md +70 -70
- package/docs/design-system/components/file-upload.md +187 -187
- package/docs/design-system/components/hover-card.md +48 -48
- package/docs/design-system/components/icons.md +48 -48
- package/docs/design-system/components/inline-citations.md +93 -0
- package/docs/design-system/components/input-group.md +58 -58
- package/docs/design-system/components/input-otp.md +56 -56
- package/docs/design-system/components/input.md +117 -61
- package/docs/design-system/components/item.md +59 -57
- package/docs/design-system/components/kbd.md +54 -49
- package/docs/design-system/components/label.md +49 -49
- package/docs/design-system/components/menu.md +71 -61
- package/docs/design-system/components/menubar.md +47 -47
- package/docs/design-system/components/modal.md +105 -105
- package/docs/design-system/components/native-select.md +54 -54
- package/docs/design-system/components/navigation-menu.md +50 -50
- package/docs/design-system/components/onboarding-step-list-item.md +82 -82
- package/docs/design-system/components/page-header.md +93 -86
- package/docs/design-system/components/pagination.md +57 -57
- package/docs/design-system/components/popover.md +60 -60
- package/docs/design-system/components/progress-slider.md +50 -50
- package/docs/design-system/components/progress.md +76 -76
- package/docs/design-system/components/radio-card.md +51 -51
- package/docs/design-system/components/radio-group.md +57 -57
- package/docs/design-system/components/resizable.md +44 -44
- package/docs/design-system/components/rolling-count.md +61 -0
- package/docs/design-system/components/scroll-area.md +51 -51
- package/docs/design-system/components/segmented-control.md +54 -54
- package/docs/design-system/components/select.md +68 -62
- package/docs/design-system/components/sheet.md +67 -67
- package/docs/design-system/components/shimmer-text.md +67 -0
- package/docs/design-system/components/sidebar.md +127 -76
- package/docs/design-system/components/skeleton.md +75 -75
- package/docs/design-system/components/slideout.md +65 -65
- package/docs/design-system/components/slider.md +63 -63
- package/docs/design-system/components/social-button.md +50 -50
- package/docs/design-system/components/spinner.md +62 -62
- package/docs/design-system/components/steps.md +65 -65
- package/docs/design-system/components/streaming-text.md +82 -0
- package/docs/design-system/components/table.md +419 -414
- package/docs/design-system/components/tabs.md +59 -55
- package/docs/design-system/components/tag.md +80 -80
- package/docs/design-system/components/task-list.md +95 -0
- package/docs/design-system/components/textarea.md +50 -50
- package/docs/design-system/components/thinking-reasoning.md +72 -0
- package/docs/design-system/components/thinking-state.md +67 -0
- package/docs/design-system/components/timeline.md +83 -83
- package/docs/design-system/components/toast.md +58 -58
- package/docs/design-system/components/toggle.md +81 -81
- package/docs/design-system/components/toolbar.md +92 -87
- package/docs/design-system/components/tooltip.md +94 -92
- package/docs/design-system/components/typography.md +18 -18
- package/docs/design-system/density-and-elevation.md +65 -61
- package/docs/design-system/design-system-test-missing-items.md +368 -368
- package/docs/design-system/direction-and-localization.md +23 -23
- package/docs/design-system/form-recipes.md +73 -73
- package/docs/design-system/gap-promotion-policy.md +21 -21
- package/docs/design-system/icons.md +74 -69
- package/docs/design-system/installation.md +70 -68
- package/docs/design-system/launch-comparison-shadcn.md +98 -98
- package/docs/design-system/registry-and-cli.md +64 -64
- package/docs/design-system/release-policy.md +30 -30
- package/docs/design-system/roadmap.md +14 -14
- package/docs/design-system/support-matrix.md +23 -23
- package/docs/design-system/tabs.md +54 -53
- package/docs/design-system/template-gap-audit.md +32 -0
- package/docs/design-system/templates.md +59 -0
- package/docs/design-system/token-governance.md +72 -60
- package/package.json +98 -98
- package/registry/component-contract.json +40 -40
- package/registry/components/accordion.tsx +155 -155
- package/registry/components/agent-input-parts.tsx +552 -0
- package/registry/components/agent-input-state.ts +156 -0
- package/registry/components/agent-input.css +307 -0
- package/registry/components/agent-input.tsx +382 -0
- package/registry/components/alert-dialog.tsx +297 -297
- package/registry/components/alert.tsx +293 -293
- package/registry/components/approval-card.css +409 -0
- package/registry/components/approval-card.tsx +401 -0
- package/registry/components/approval-frame.tsx +108 -0
- package/registry/components/approval-questions.tsx +559 -0
- package/registry/components/aspect-ratio.tsx +30 -30
- package/registry/components/attribute.tsx +454 -448
- package/registry/components/autocomplete.tsx +598 -651
- package/registry/components/avatar.tsx +385 -381
- package/registry/components/badge.tsx +629 -629
- package/registry/components/button-group.tsx +565 -565
- package/registry/components/button.tsx +127 -123
- package/registry/components/card.tsx +638 -638
- package/registry/components/carousel.tsx +296 -296
- package/registry/components/chart-block-data.ts +177 -0
- package/registry/components/chart-block.css +171 -0
- package/registry/components/chart-block.tsx +260 -0
- package/registry/components/chart-interactions.ts +123 -0
- package/registry/components/chart-options.cartesian.ts +162 -0
- package/registry/components/chart-options.paint.ts +99 -0
- package/registry/components/chart-options.parts.ts +72 -0
- package/registry/components/chart-options.radial.ts +109 -0
- package/registry/components/chart-options.ts +44 -0
- package/registry/components/chart-options.types.ts +67 -0
- package/registry/components/chart.tsx +203 -203
- package/registry/components/checkbox.tsx +247 -247
- package/registry/components/collapsible.tsx +109 -69
- package/registry/components/command.tsx +208 -208
- package/registry/components/context-menu.tsx +236 -236
- package/registry/components/data-chart.tsx +40 -0
- package/registry/components/date-picker.tsx +1289 -1277
- package/registry/components/echart-theme.ts +246 -0
- package/registry/components/echart.css +49 -0
- package/registry/components/echart.tsx +178 -0
- package/registry/components/expanded/ActivityFeed.tsx +227 -227
- package/registry/components/expanded/ActivityHeatmap.tsx +64 -64
- package/registry/components/expanded/Banner.tsx +179 -179
- package/registry/components/expanded/Breadcrumbs.tsx +131 -131
- package/registry/components/expanded/CatalogComponentsShowcase.tsx +205 -205
- package/registry/components/expanded/CatalogDivider.tsx +49 -49
- package/registry/components/expanded/EmptyState.tsx +155 -155
- package/registry/components/expanded/FileUpload.tsx +543 -543
- package/registry/components/expanded/OnboardingStepListItem.tsx +60 -59
- package/registry/components/expanded/PageHeader.tsx +179 -166
- package/registry/components/expanded/Slideout.tsx +108 -108
- package/registry/components/expanded/Steps.tsx +402 -402
- package/registry/components/expanded/Table.tsx +1092 -1071
- package/registry/components/expanded/Timeline.tsx +203 -203
- package/registry/components/expanded/activityFeed.css +248 -248
- package/registry/components/expanded/activityHeatmap.css +66 -66
- package/registry/components/expanded/banner.css +260 -255
- package/registry/components/expanded/breadcrumbs.css +140 -140
- package/registry/components/expanded/catalogComponentsShowcase.css +87 -87
- package/registry/components/expanded/divider.css +75 -75
- package/registry/components/expanded/emptyState.css +111 -111
- package/registry/components/expanded/fileUpload.css +457 -457
- package/registry/components/expanded/onboardingStepListItem.css +135 -126
- package/registry/components/expanded/pageHeader.css +248 -290
- package/registry/components/expanded/slideout.css +276 -276
- package/registry/components/expanded/steps.css +356 -356
- package/registry/components/expanded/table.css +606 -603
- package/registry/components/expanded/timeline.css +286 -286
- package/registry/components/field.tsx +283 -283
- package/registry/components/hover-card.tsx +48 -48
- package/registry/components/inline-citations.css +126 -0
- package/registry/components/inline-citations.tsx +292 -0
- package/registry/components/input-content.ts +107 -107
- package/registry/components/input-group.tsx +130 -130
- package/registry/components/input-otp.tsx +584 -584
- package/registry/components/input.tsx +990 -972
- package/registry/components/item.tsx +189 -189
- package/registry/components/kbd.tsx +246 -151
- package/registry/components/label.tsx +78 -78
- package/registry/components/menu.tsx +978 -986
- package/registry/components/menubar.tsx +226 -226
- package/registry/components/modal.tsx +872 -872
- package/registry/components/native-select.tsx +205 -205
- package/registry/components/navigation-menu.tsx +171 -171
- package/registry/components/pagination.css +36 -36
- package/registry/components/pagination.tsx +560 -555
- package/registry/components/popover.tsx +338 -338
- package/registry/components/progress-slider.tsx +216 -216
- package/registry/components/radio-card.tsx +676 -677
- package/registry/components/radio-group.tsx +570 -570
- package/registry/components/resizable.tsx +108 -108
- package/registry/components/rolling-count.css +37 -0
- package/registry/components/rolling-count.tsx +110 -0
- package/registry/components/scroll-area.tsx +91 -91
- package/registry/components/segmented-control.tsx +87 -87
- package/registry/components/select-content.tsx +218 -218
- package/registry/components/select.tsx +937 -932
- package/registry/components/sheet.tsx +305 -305
- package/registry/components/shimmer-text.css +69 -0
- package/registry/components/shimmer-text.tsx +43 -0
- package/registry/components/sidebar.tsx +1433 -358
- package/registry/components/skeleton.css +54 -54
- package/registry/components/skeleton.tsx +482 -482
- package/registry/components/slider.tsx +380 -380
- package/registry/components/social-button.tsx +387 -387
- package/registry/components/spinner.tsx +78 -78
- package/registry/components/streaming-text.css +45 -0
- package/registry/components/streaming-text.tsx +165 -0
- package/registry/components/table-elements.tsx +128 -128
- package/registry/components/tabs.css +222 -218
- package/registry/components/tabs.tsx +241 -241
- package/registry/components/tag.tsx +423 -423
- package/registry/components/task-list.css +328 -0
- package/registry/components/task-list.tsx +429 -0
- package/registry/components/textarea.tsx +610 -610
- package/registry/components/thinking-reasoning.css +178 -0
- package/registry/components/thinking-reasoning.tsx +253 -0
- package/registry/components/thinking-state.css +8 -0
- package/registry/components/thinking-state.tsx +46 -0
- package/registry/components/toast.tsx +136 -136
- package/registry/components/toggle.tsx +256 -256
- package/registry/components/toolbar.tsx +539 -539
- package/registry/components/tooltip.tsx +433 -431
- package/registry/examples/agent-input-demo.tsx +90 -0
- package/registry/examples/alert-demo.tsx +34 -34
- package/registry/examples/alert-dialog-demo.tsx +42 -42
- package/registry/examples/approval-card-demo.tsx +83 -0
- package/registry/examples/aspect-ratio-demo.tsx +11 -11
- package/registry/examples/attribute-demo.tsx +65 -65
- package/registry/examples/autocomplete-demo.tsx +109 -109
- package/registry/examples/avatar-demo.tsx +132 -132
- package/registry/examples/badge-demo.tsx +69 -69
- package/registry/examples/button-demo.tsx +86 -83
- package/registry/examples/button-group-demo.tsx +63 -63
- package/registry/examples/card-demo.tsx +86 -86
- package/registry/examples/carousel-demo.tsx +43 -43
- package/registry/examples/chart-block-demo.tsx +5 -0
- package/registry/examples/chart-demo.tsx +18 -33
- package/registry/examples/checkbox-demo.tsx +62 -62
- package/registry/examples/collapsible-demo.tsx +16 -16
- package/registry/examples/collection-filter-bar-demo.tsx +135 -135
- package/registry/examples/command-demo.tsx +42 -42
- package/registry/examples/command-palette-demo.tsx +235 -236
- package/registry/examples/context-menu-demo.tsx +29 -29
- package/registry/examples/control-density-contract-demo.tsx +65 -61
- package/registry/examples/date-picker-demo.tsx +127 -127
- package/registry/examples/divider-demo.tsx +17 -17
- package/registry/examples/expanded/activity-heatmap-demo.tsx +29 -29
- package/registry/examples/expanded/banner-demo.tsx +48 -48
- package/registry/examples/expanded/breadcrumbs-demo.tsx +59 -59
- package/registry/examples/expanded/empty-state-demo.tsx +39 -39
- package/registry/examples/expanded/file-upload-demo.tsx +60 -60
- package/registry/examples/expanded/onboarding-step-demo.tsx +11 -11
- package/registry/examples/expanded/slideout-demo.tsx +15 -15
- package/registry/examples/expanded/steps-demo.tsx +29 -29
- package/registry/examples/expanded/tabs-demo.tsx +13 -13
- package/registry/examples/expanded/timeline-demo.tsx +18 -18
- package/registry/examples/field-demo.tsx +51 -51
- package/registry/examples/hover-card-demo.tsx +23 -23
- package/registry/examples/inline-citations-demo.tsx +31 -0
- package/registry/examples/input-actions-demo.tsx +36 -0
- package/registry/examples/input-demo.tsx +87 -87
- package/registry/examples/input-group-demo.tsx +16 -16
- package/registry/examples/input-otp-demo.tsx +72 -72
- package/registry/examples/item-demo.tsx +46 -46
- package/registry/examples/kbd-demo.tsx +12 -11
- package/registry/examples/label-demo.tsx +20 -20
- package/registry/examples/menu-demo.tsx +122 -122
- package/registry/examples/menubar-demo.tsx +34 -34
- package/registry/examples/modal-demo.tsx +74 -74
- package/registry/examples/native-select-demo.tsx +16 -16
- package/registry/examples/navigation-menu-demo.tsx +29 -29
- package/registry/examples/pagination-demo.tsx +20 -20
- package/registry/examples/popover-demo.tsx +547 -546
- package/registry/examples/progress-demo.tsx +37 -37
- package/registry/examples/progress-slider-demo.tsx +29 -29
- package/registry/examples/radio-card-demo.tsx +51 -51
- package/registry/examples/radio-group-demo.tsx +62 -62
- package/registry/examples/resizable-demo.tsx +22 -22
- package/registry/examples/results-toolbar-demo.tsx +44 -44
- package/registry/examples/rolling-count-demo.tsx +39 -0
- package/registry/examples/scroll-area-demo.tsx +15 -15
- package/registry/examples/segmented-control-demo.tsx +39 -39
- package/registry/examples/select-demo.tsx +87 -87
- package/registry/examples/sheet-demo.tsx +47 -47
- package/registry/examples/shimmer-text-demo.tsx +20 -0
- package/registry/examples/sidebar-demo.tsx +101 -57
- package/registry/examples/slider-demo.tsx +31 -31
- package/registry/examples/social-button-demo.tsx +61 -61
- package/registry/examples/spinner-demo.tsx +59 -59
- package/registry/examples/streaming-text-demo.tsx +28 -0
- package/registry/examples/tabs-demo.tsx +13 -13
- package/registry/examples/tag-demo.tsx +29 -29
- package/registry/examples/task-list-demo.tsx +74 -0
- package/registry/examples/textarea-demo.tsx +79 -79
- package/registry/examples/thinking-reasoning-demo.tsx +74 -0
- package/registry/examples/thinking-state-demo.tsx +13 -0
- package/registry/examples/toast-demo.tsx +35 -35
- package/registry/examples/toggle-demo.tsx +59 -59
- package/registry/examples/tooltip-demo.tsx +115 -115
- package/registry/guidance/USAGE.md +27 -27
- package/registry/guidance/charts.LICENSE.txt +24 -0
- package/registry/hooks/use-controllable-state.ts +33 -0
- package/registry/hooks/use-direction.ts +207 -207
- package/registry/hooks/use-listbox-navigation.ts +73 -0
- package/registry/hooks/use-motion-end.ts +55 -0
- package/registry/hooks/use-reduced-motion.ts +28 -0
- package/registry/index.json +1634 -184
- package/registry/styles/globals.css +1462 -1570
- package/registry.json +364 -10
- package/schema/config.schema.json +51 -51
- package/schema/registry.schema.json +194 -190
- package/schema/tokens.schema.json +167 -163
- package/src/cli/command-line.js +194 -194
- package/src/cli/config-editors.js +9 -9
- package/src/cli/doctor.js +399 -399
- package/src/cli/file-transaction.js +302 -295
- package/src/cli/global-css.js +153 -153
- package/src/cli/index.js +1002 -1009
- package/src/cli/install-plan.js +592 -592
- package/src/cli/install-receipt.js +171 -171
- package/src/cli/jsonc.js +203 -203
- package/src/cli/package-install-state.js +254 -254
- package/src/cli/package-manager.js +238 -238
- package/src/cli/package-plan.js +185 -185
- package/src/cli/package-version.js +97 -97
- package/src/cli/registry-query.js +207 -207
- package/src/cli/reporting.js +55 -55
- package/src/cli/schema-validation.js +19 -19
- package/src/cli/source-scanner.js +686 -686
- package/src/cli/vite-config.js +478 -478
- package/tokens/banhaten.tokens.json +458 -224
|
@@ -1,1071 +1,1092 @@
|
|
|
1
|
-
import { useMemo, useState, type CSSProperties, type ReactNode } from "react";
|
|
2
|
-
import {
|
|
3
|
-
ArrowUpDownIcon,
|
|
4
|
-
EditIcon as LucideEditIcon,
|
|
5
|
-
EllipsisIcon,
|
|
6
|
-
EyeIcon,
|
|
7
|
-
FileIcon as LucideFileIcon,
|
|
8
|
-
StarIcon,
|
|
9
|
-
Trash2Icon,
|
|
10
|
-
} from "lucide-react";
|
|
11
|
-
import { Pagination, type PaginationPage, type PaginationProps } from "@/components/ui/pagination";
|
|
12
|
-
import { Spinner } from "@/components/ui/spinner";
|
|
13
|
-
import { Avatar as AvatarPrimitive, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
|
14
|
-
import { Badge } from "@/components/ui/badge";
|
|
15
|
-
import { Button } from "@/components/ui/button";
|
|
16
|
-
import { Checkbox } from "@/components/ui/checkbox";
|
|
17
|
-
import { Progress as ProgressPrimitive } from "@/components/ui/progress";
|
|
18
|
-
import { Tag } from "@/components/ui/tag";
|
|
19
|
-
import { Toggle } from "@/components/ui/toggle";
|
|
20
|
-
import {
|
|
21
|
-
Toolbar,
|
|
22
|
-
ToolbarBadge,
|
|
23
|
-
ToolbarButton,
|
|
24
|
-
ToolbarSearch,
|
|
25
|
-
ToolbarSection,
|
|
26
|
-
ToolbarText,
|
|
27
|
-
type ToolbarButtonProps,
|
|
28
|
-
} from "@/components/ui/toolbar";
|
|
29
|
-
import "./table.css";
|
|
30
|
-
|
|
31
|
-
export type TableDirection = "ltr" | "rtl";
|
|
32
|
-
export type TableSize = "sm" | "lg";
|
|
33
|
-
export type TableRowState = "default" | "selected" | "disabled";
|
|
34
|
-
export type TableSortDirection = "asc" | "desc";
|
|
35
|
-
export type TableSortValue = string | number | boolean | Date | null | undefined;
|
|
36
|
-
export type TableSortState = {
|
|
37
|
-
columnId: string;
|
|
38
|
-
direction: TableSortDirection;
|
|
39
|
-
} | null;
|
|
40
|
-
|
|
41
|
-
export type TableRowBase = {
|
|
42
|
-
id: string;
|
|
43
|
-
state?: TableRowState;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export type TableColumn<Row extends TableRowBase> = {
|
|
47
|
-
align?: "start" | "center" | "end";
|
|
48
|
-
header?: string;
|
|
49
|
-
id: string;
|
|
50
|
-
item?: TableItemFactory<Row>;
|
|
51
|
-
kind?: "data" | "selection" | "actions";
|
|
52
|
-
minWidth?: number;
|
|
53
|
-
renderCell?: (row: Row) => ReactNode;
|
|
54
|
-
searchValue?: (row: Row) => string;
|
|
55
|
-
sortable?: boolean;
|
|
56
|
-
sortValue?: (row: Row) => TableSortValue;
|
|
57
|
-
width?: number | "fill";
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export type TableItemFactory<Row extends TableRowBase> = (row: Row) => TableItem;
|
|
61
|
-
|
|
62
|
-
export type BadgeItem = {
|
|
63
|
-
dot?: boolean;
|
|
64
|
-
label: string;
|
|
65
|
-
tone?: "blue" | "fuchsia" | "amber" | "neutral" | "success" | "warning" | "danger";
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export type AvatarItem = {
|
|
69
|
-
alt: string;
|
|
70
|
-
src?: string;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export type TableAction = {
|
|
74
|
-
disabled?: boolean;
|
|
75
|
-
icon: "view" | "edit" | "delete" | "more";
|
|
76
|
-
label: string;
|
|
77
|
-
onAction?: () => void;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export type TableItem =
|
|
81
|
-
| { type: "checkbox"; ariaLabel?: string; checked: boolean; disabled?: boolean; indeterminate?: boolean; onCheckedChange?: (checked: boolean) => void }
|
|
82
|
-
| { type: "text"; tone?: "default" | "subtle"; value: string; weight?: "regular" | "medium" }
|
|
83
|
-
| { type: "avatarText"; caption?: string; name: string; src?: string; status?: "top" | "bottom" }
|
|
84
|
-
| { type: "rating"; max?: 5; value: number }
|
|
85
|
-
| { type: "progress"; label?: string; tone?: "success" | "brand"; value: number }
|
|
86
|
-
| { type: "toggle"; ariaLabel?: string; checked: boolean; disabled?: boolean; onCheckedChange?: (checked: boolean) => void }
|
|
87
|
-
| { type: "badges"; items: BadgeItem[]; maxVisible?: number }
|
|
88
|
-
| { type: "onlyAvatar"; alt: string; src?: string }
|
|
89
|
-
| { type: "avatarStack"; addLabel?: string; avatars: AvatarItem[]; canAdd?: boolean; count?: number; onAdd?: () => void }
|
|
90
|
-
| { type: "tags"; items: string[]; maxVisible?: number }
|
|
91
|
-
| { type: "file"; label?: string }
|
|
92
|
-
| { type: "brandLogoText"; label: string; logoSrc?: string }
|
|
93
|
-
| { type: "payment"; brand: string; label?: string }
|
|
94
|
-
| { type: "image"; label: string; src: string }
|
|
95
|
-
| { type: "action"; icon: TableAction["icon"]; label: string; onAction?: () => void }
|
|
96
|
-
| { type: "actionGroup"; actions: TableAction[] };
|
|
97
|
-
|
|
98
|
-
export type TableProps<Row extends TableRowBase> = {
|
|
99
|
-
columns: TableColumn<Row>[];
|
|
100
|
-
dir?: TableDirection;
|
|
101
|
-
onSelectedRowIdsChange?: (rowIds: string[]) => void;
|
|
102
|
-
onSortChange?: (sort: TableSortState) => void;
|
|
103
|
-
rows: Row[];
|
|
104
|
-
selectedRowIds?: string[];
|
|
105
|
-
size?: TableSize;
|
|
106
|
-
sort?: TableSortState;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export type DataTableAction = {
|
|
110
|
-
ariaLabel?: string;
|
|
111
|
-
disabled?: boolean;
|
|
112
|
-
label: string;
|
|
113
|
-
onAction?: () => void;
|
|
114
|
-
variant?: ToolbarButtonProps["variant"];
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export type DataTableFilter<Row extends TableRowBase> = {
|
|
118
|
-
active?: boolean;
|
|
119
|
-
id: string;
|
|
120
|
-
label: string;
|
|
121
|
-
onAction?: () => void;
|
|
122
|
-
predicate?: (row: Row) => boolean;
|
|
123
|
-
value?: string;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
export type DataTableSearch<Row extends TableRowBase> =
|
|
127
|
-
| boolean
|
|
128
|
-
| {
|
|
129
|
-
defaultValue?: string;
|
|
130
|
-
disabled?: boolean;
|
|
131
|
-
getRowText?: (row: Row) => string;
|
|
132
|
-
label?: string;
|
|
133
|
-
onValueChange?: (value: string) => void;
|
|
134
|
-
placeholder?: string;
|
|
135
|
-
value?: string;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export type DataTablePagination = {
|
|
139
|
-
ariaLabel?: string;
|
|
140
|
-
defaultPage?: number;
|
|
141
|
-
manual?: boolean;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
<
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
<
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
{
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
function
|
|
551
|
-
return (
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
}:
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
if (
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
return
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
return
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
function
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
case "
|
|
835
|
-
return <
|
|
836
|
-
case "
|
|
837
|
-
return <
|
|
838
|
-
case "
|
|
839
|
-
return
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
{item.
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
}
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
>
|
|
938
|
-
|
|
939
|
-
</
|
|
940
|
-
)
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
const
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
);
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1
|
+
import { useMemo, useState, type CSSProperties, type ReactNode } from "react";
|
|
2
|
+
import {
|
|
3
|
+
ArrowUpDownIcon,
|
|
4
|
+
EditIcon as LucideEditIcon,
|
|
5
|
+
EllipsisIcon,
|
|
6
|
+
EyeIcon,
|
|
7
|
+
FileIcon as LucideFileIcon,
|
|
8
|
+
StarIcon,
|
|
9
|
+
Trash2Icon,
|
|
10
|
+
} from "lucide-react";
|
|
11
|
+
import { Pagination, type PaginationPage, type PaginationProps } from "@/components/ui/pagination";
|
|
12
|
+
import { Spinner } from "@/components/ui/spinner";
|
|
13
|
+
import { Avatar as AvatarPrimitive, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
|
14
|
+
import { Badge } from "@/components/ui/badge";
|
|
15
|
+
import { Button } from "@/components/ui/button";
|
|
16
|
+
import { Checkbox } from "@/components/ui/checkbox";
|
|
17
|
+
import { Progress as ProgressPrimitive } from "@/components/ui/progress";
|
|
18
|
+
import { Tag } from "@/components/ui/tag";
|
|
19
|
+
import { Toggle } from "@/components/ui/toggle";
|
|
20
|
+
import {
|
|
21
|
+
Toolbar,
|
|
22
|
+
ToolbarBadge,
|
|
23
|
+
ToolbarButton,
|
|
24
|
+
ToolbarSearch,
|
|
25
|
+
ToolbarSection,
|
|
26
|
+
ToolbarText,
|
|
27
|
+
type ToolbarButtonProps,
|
|
28
|
+
} from "@/components/ui/toolbar";
|
|
29
|
+
import "./table.css";
|
|
30
|
+
|
|
31
|
+
export type TableDirection = "ltr" | "rtl";
|
|
32
|
+
export type TableSize = "sm" | "lg";
|
|
33
|
+
export type TableRowState = "default" | "selected" | "disabled";
|
|
34
|
+
export type TableSortDirection = "asc" | "desc";
|
|
35
|
+
export type TableSortValue = string | number | boolean | Date | null | undefined;
|
|
36
|
+
export type TableSortState = {
|
|
37
|
+
columnId: string;
|
|
38
|
+
direction: TableSortDirection;
|
|
39
|
+
} | null;
|
|
40
|
+
|
|
41
|
+
export type TableRowBase = {
|
|
42
|
+
id: string;
|
|
43
|
+
state?: TableRowState;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type TableColumn<Row extends TableRowBase> = {
|
|
47
|
+
align?: "start" | "center" | "end";
|
|
48
|
+
header?: string;
|
|
49
|
+
id: string;
|
|
50
|
+
item?: TableItemFactory<Row>;
|
|
51
|
+
kind?: "data" | "selection" | "actions";
|
|
52
|
+
minWidth?: number;
|
|
53
|
+
renderCell?: (row: Row) => ReactNode;
|
|
54
|
+
searchValue?: (row: Row) => string;
|
|
55
|
+
sortable?: boolean;
|
|
56
|
+
sortValue?: (row: Row) => TableSortValue;
|
|
57
|
+
width?: number | "fill";
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type TableItemFactory<Row extends TableRowBase> = (row: Row) => TableItem;
|
|
61
|
+
|
|
62
|
+
export type BadgeItem = {
|
|
63
|
+
dot?: boolean;
|
|
64
|
+
label: string;
|
|
65
|
+
tone?: "blue" | "fuchsia" | "amber" | "neutral" | "success" | "warning" | "danger";
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type AvatarItem = {
|
|
69
|
+
alt: string;
|
|
70
|
+
src?: string;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export type TableAction = {
|
|
74
|
+
disabled?: boolean;
|
|
75
|
+
icon: "view" | "edit" | "delete" | "more";
|
|
76
|
+
label: string;
|
|
77
|
+
onAction?: () => void;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export type TableItem =
|
|
81
|
+
| { type: "checkbox"; ariaLabel?: string; checked: boolean; disabled?: boolean; indeterminate?: boolean; onCheckedChange?: (checked: boolean) => void }
|
|
82
|
+
| { type: "text"; tone?: "default" | "subtle"; value: string; weight?: "regular" | "medium" }
|
|
83
|
+
| { type: "avatarText"; caption?: string; name: string; src?: string; status?: "top" | "bottom" }
|
|
84
|
+
| { type: "rating"; max?: 5; value: number }
|
|
85
|
+
| { type: "progress"; label?: string; tone?: "success" | "brand"; value: number }
|
|
86
|
+
| { type: "toggle"; ariaLabel?: string; checked: boolean; disabled?: boolean; onCheckedChange?: (checked: boolean) => void }
|
|
87
|
+
| { type: "badges"; items: BadgeItem[]; maxVisible?: number }
|
|
88
|
+
| { type: "onlyAvatar"; alt: string; src?: string }
|
|
89
|
+
| { type: "avatarStack"; addLabel?: string; avatars: AvatarItem[]; canAdd?: boolean; count?: number; onAdd?: () => void }
|
|
90
|
+
| { type: "tags"; items: string[]; maxVisible?: number }
|
|
91
|
+
| { type: "file"; label?: string }
|
|
92
|
+
| { type: "brandLogoText"; label: string; logoSrc?: string }
|
|
93
|
+
| { type: "payment"; brand: string; label?: string }
|
|
94
|
+
| { type: "image"; label: string; src: string }
|
|
95
|
+
| { type: "action"; icon: TableAction["icon"]; label: string; onAction?: () => void }
|
|
96
|
+
| { type: "actionGroup"; actions: TableAction[] };
|
|
97
|
+
|
|
98
|
+
export type TableProps<Row extends TableRowBase> = {
|
|
99
|
+
columns: TableColumn<Row>[];
|
|
100
|
+
dir?: TableDirection;
|
|
101
|
+
onSelectedRowIdsChange?: (rowIds: string[]) => void;
|
|
102
|
+
onSortChange?: (sort: TableSortState) => void;
|
|
103
|
+
rows: Row[];
|
|
104
|
+
selectedRowIds?: string[];
|
|
105
|
+
size?: TableSize;
|
|
106
|
+
sort?: TableSortState;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export type DataTableAction = {
|
|
110
|
+
ariaLabel?: string;
|
|
111
|
+
disabled?: boolean;
|
|
112
|
+
label: string;
|
|
113
|
+
onAction?: () => void;
|
|
114
|
+
variant?: ToolbarButtonProps["variant"];
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export type DataTableFilter<Row extends TableRowBase> = {
|
|
118
|
+
active?: boolean;
|
|
119
|
+
id: string;
|
|
120
|
+
label: string;
|
|
121
|
+
onAction?: () => void;
|
|
122
|
+
predicate?: (row: Row) => boolean;
|
|
123
|
+
value?: string;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export type DataTableSearch<Row extends TableRowBase> =
|
|
127
|
+
| boolean
|
|
128
|
+
| {
|
|
129
|
+
defaultValue?: string;
|
|
130
|
+
disabled?: boolean;
|
|
131
|
+
getRowText?: (row: Row) => string;
|
|
132
|
+
label?: string;
|
|
133
|
+
onValueChange?: (value: string) => void;
|
|
134
|
+
placeholder?: string;
|
|
135
|
+
value?: string;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export type DataTablePagination = {
|
|
139
|
+
ariaLabel?: string;
|
|
140
|
+
defaultPage?: number;
|
|
141
|
+
manual?: boolean;
|
|
142
|
+
messages?: PaginationProps["messages"];
|
|
143
|
+
onPageChange?: (page: number) => void;
|
|
144
|
+
page?: number;
|
|
145
|
+
pageSize?: number;
|
|
146
|
+
pages?: PaginationPage[];
|
|
147
|
+
showCaption?: boolean;
|
|
148
|
+
totalRows?: number;
|
|
149
|
+
type?: PaginationProps["type"];
|
|
150
|
+
variant?: PaginationProps["variant"];
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export type DataTableState = {
|
|
154
|
+
action?: DataTableAction;
|
|
155
|
+
description?: ReactNode;
|
|
156
|
+
title?: ReactNode;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export type DataTableLabels = {
|
|
160
|
+
emptyDescription: ReactNode;
|
|
161
|
+
emptyTitle: ReactNode;
|
|
162
|
+
errorDescription: ReactNode;
|
|
163
|
+
errorTitle: ReactNode;
|
|
164
|
+
loadingDescription: ReactNode;
|
|
165
|
+
loadingTitle: ReactNode;
|
|
166
|
+
resultsSummary: (summary: { from: number; to: number; total: number }) => ReactNode;
|
|
167
|
+
searchPlaceholder: string;
|
|
168
|
+
selectedCount: (count: number) => ReactNode;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export type DataTableProps<Row extends TableRowBase> = Omit<TableProps<Row>, "onSortChange" | "rows" | "sort"> & {
|
|
172
|
+
actions?: DataTableAction[];
|
|
173
|
+
bulkActions?: DataTableAction[];
|
|
174
|
+
className?: string;
|
|
175
|
+
defaultSort?: TableSortState;
|
|
176
|
+
description?: ReactNode;
|
|
177
|
+
emptyState?: DataTableState;
|
|
178
|
+
error?: boolean | string | DataTableState;
|
|
179
|
+
filters?: DataTableFilter<Row>[];
|
|
180
|
+
getRowSearchText?: (row: Row) => string;
|
|
181
|
+
labels?: Partial<DataTableLabels>;
|
|
182
|
+
loading?: boolean;
|
|
183
|
+
onSortChange?: (sort: TableSortState) => void;
|
|
184
|
+
pagination?: false | DataTablePagination;
|
|
185
|
+
rows: Row[];
|
|
186
|
+
search?: DataTableSearch<Row>;
|
|
187
|
+
sort?: TableSortState;
|
|
188
|
+
title?: ReactNode;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
function cx(...classes: Array<string | false | undefined>) {
|
|
192
|
+
return classes.filter(Boolean).join(" ");
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function Table<Row extends TableRowBase>({
|
|
196
|
+
columns,
|
|
197
|
+
dir,
|
|
198
|
+
onSelectedRowIdsChange,
|
|
199
|
+
onSortChange,
|
|
200
|
+
rows,
|
|
201
|
+
selectedRowIds = [],
|
|
202
|
+
size = "sm",
|
|
203
|
+
sort = null,
|
|
204
|
+
}: TableProps<Row>) {
|
|
205
|
+
const selectableRows = rows.filter((row) => row.state !== "disabled");
|
|
206
|
+
const allSelected = selectableRows.length > 0 && selectableRows.every((row) => selectedRowIds.includes(row.id));
|
|
207
|
+
const someSelected = selectableRows.some((row) => selectedRowIds.includes(row.id)) && !allSelected;
|
|
208
|
+
|
|
209
|
+
function toggleAll(checked: boolean) {
|
|
210
|
+
onSelectedRowIdsChange?.(checked ? selectableRows.map((row) => row.id) : []);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function toggleRow(row: Row, checked: boolean) {
|
|
214
|
+
if (row.state === "disabled") return;
|
|
215
|
+
const next = checked
|
|
216
|
+
? Array.from(new Set([...selectedRowIds, row.id]))
|
|
217
|
+
: selectedRowIds.filter((rowId) => rowId !== row.id);
|
|
218
|
+
onSelectedRowIdsChange?.(next);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return (
|
|
222
|
+
<div
|
|
223
|
+
aria-label="Scrollable table"
|
|
224
|
+
className={`ds-table-wrap ds-table-wrap--${size}`}
|
|
225
|
+
dir={dir}
|
|
226
|
+
tabIndex={0}
|
|
227
|
+
>
|
|
228
|
+
<table className="ds-table">
|
|
229
|
+
<thead>
|
|
230
|
+
<tr>
|
|
231
|
+
{columns.map((column) => (
|
|
232
|
+
<th
|
|
233
|
+
aria-sort={column.sortable ? getAriaSort(sort, column.id) : undefined}
|
|
234
|
+
className={columnClass(column)}
|
|
235
|
+
key={column.id}
|
|
236
|
+
style={columnStyle(column)}
|
|
237
|
+
scope="col"
|
|
238
|
+
>
|
|
239
|
+
{column.kind === "selection" ? (
|
|
240
|
+
<SelectionCheckbox
|
|
241
|
+
checked={allSelected}
|
|
242
|
+
indeterminate={someSelected}
|
|
243
|
+
label="Select all rows"
|
|
244
|
+
onChange={toggleAll}
|
|
245
|
+
/>
|
|
246
|
+
) : column.header ? (
|
|
247
|
+
column.sortable ? (
|
|
248
|
+
onSortChange ? (
|
|
249
|
+
<Button
|
|
250
|
+
aria-label={`Sort by ${column.header}`}
|
|
251
|
+
className={cx(
|
|
252
|
+
"ds-table__sort",
|
|
253
|
+
sort?.columnId === column.id && `ds-table__sort--${sort.direction}`,
|
|
254
|
+
)}
|
|
255
|
+
onClick={() => onSortChange(getNextSort(sort, column.id))}
|
|
256
|
+
size="xs"
|
|
257
|
+
type="button"
|
|
258
|
+
variant="ghost"
|
|
259
|
+
>
|
|
260
|
+
<span>{column.header}</span>
|
|
261
|
+
<SortIcon direction={sort?.columnId === column.id ? sort.direction : undefined} />
|
|
262
|
+
</Button>
|
|
263
|
+
) : (
|
|
264
|
+
<span className="ds-table__sort ds-table__sort--static">
|
|
265
|
+
<span>{column.header}</span>
|
|
266
|
+
<SortIcon />
|
|
267
|
+
</span>
|
|
268
|
+
)
|
|
269
|
+
) : (
|
|
270
|
+
column.header
|
|
271
|
+
)
|
|
272
|
+
) : (
|
|
273
|
+
<span className="sr-only">
|
|
274
|
+
{column.kind === "actions" ? "Actions" : column.id}
|
|
275
|
+
</span>
|
|
276
|
+
)}
|
|
277
|
+
</th>
|
|
278
|
+
))}
|
|
279
|
+
</tr>
|
|
280
|
+
</thead>
|
|
281
|
+
<tbody>
|
|
282
|
+
{rows.map((row) => {
|
|
283
|
+
const selected = selectedRowIds.includes(row.id);
|
|
284
|
+
const state = row.state === "disabled" ? "disabled" : selected ? "selected" : row.state ?? "default";
|
|
285
|
+
|
|
286
|
+
return (
|
|
287
|
+
<tr aria-selected={selected || undefined} className={`ds-table__row ds-table__row--${state}`} key={row.id}>
|
|
288
|
+
{columns.map((column) => (
|
|
289
|
+
<td className={columnClass(column)} key={column.id} style={columnStyle(column)}>
|
|
290
|
+
{column.kind === "selection" ? (
|
|
291
|
+
<SelectionCheckbox
|
|
292
|
+
checked={selected}
|
|
293
|
+
disabled={row.state === "disabled"}
|
|
294
|
+
label={`Select row ${row.id}`}
|
|
295
|
+
onChange={(checked) => toggleRow(row, checked)}
|
|
296
|
+
/>
|
|
297
|
+
) : (
|
|
298
|
+
renderTableCell(column, row, size)
|
|
299
|
+
)}
|
|
300
|
+
</td>
|
|
301
|
+
))}
|
|
302
|
+
</tr>
|
|
303
|
+
);
|
|
304
|
+
})}
|
|
305
|
+
</tbody>
|
|
306
|
+
</table>
|
|
307
|
+
</div>
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function renderTableCell<Row extends TableRowBase>(
|
|
312
|
+
column: TableColumn<Row>,
|
|
313
|
+
row: Row,
|
|
314
|
+
size: TableSize,
|
|
315
|
+
) {
|
|
316
|
+
if (column.renderCell) return column.renderCell(row);
|
|
317
|
+
if (column.item) return renderTableItem(column.item(row), size);
|
|
318
|
+
if ((column.kind ?? "data") !== "data") return null;
|
|
319
|
+
if (!Object.prototype.hasOwnProperty.call(row, column.id)) return null;
|
|
320
|
+
|
|
321
|
+
const value: unknown = Reflect.get(row, column.id);
|
|
322
|
+
if (typeof value !== "string" && typeof value !== "number") return null;
|
|
323
|
+
|
|
324
|
+
return renderTableItem({ type: "text", value: String(value) }, size);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const defaultDataTablePagination: DataTablePagination = {};
|
|
328
|
+
|
|
329
|
+
const defaultDataTableLabels: DataTableLabels = {
|
|
330
|
+
emptyDescription: "Try adjusting the search or filters.",
|
|
331
|
+
emptyTitle: "No rows found",
|
|
332
|
+
errorDescription: "Refresh the table or try again later.",
|
|
333
|
+
errorTitle: "Table unavailable",
|
|
334
|
+
loadingDescription: "Please wait while the table updates.",
|
|
335
|
+
loadingTitle: "Loading rows",
|
|
336
|
+
resultsSummary: ({ from, to, total }) => (total === 0 ? "Showing 0 rows" : `Showing ${from} to ${to} of ${total} rows`),
|
|
337
|
+
searchPlaceholder: "Search rows...",
|
|
338
|
+
selectedCount: (count) => `${count} selected`,
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
export function DataTable<Row extends TableRowBase>({
|
|
342
|
+
actions = [],
|
|
343
|
+
bulkActions = [],
|
|
344
|
+
className,
|
|
345
|
+
columns,
|
|
346
|
+
defaultSort = null,
|
|
347
|
+
description,
|
|
348
|
+
dir,
|
|
349
|
+
emptyState,
|
|
350
|
+
error = false,
|
|
351
|
+
filters = [],
|
|
352
|
+
getRowSearchText,
|
|
353
|
+
labels: labelOverrides,
|
|
354
|
+
loading = false,
|
|
355
|
+
onSelectedRowIdsChange,
|
|
356
|
+
onSortChange,
|
|
357
|
+
pagination = defaultDataTablePagination,
|
|
358
|
+
rows,
|
|
359
|
+
search = true,
|
|
360
|
+
selectedRowIds = [],
|
|
361
|
+
size = "sm",
|
|
362
|
+
sort,
|
|
363
|
+
title,
|
|
364
|
+
}: DataTableProps<Row>) {
|
|
365
|
+
const labels: DataTableLabels = { ...defaultDataTableLabels, ...labelOverrides };
|
|
366
|
+
const searchConfig = search === true ? {} : search && typeof search === "object" ? search : null;
|
|
367
|
+
const paginationConfig = pagination === false ? null : pagination;
|
|
368
|
+
const [uncontrolledSearch, setUncontrolledSearch] = useState(() => searchConfig?.defaultValue ?? "");
|
|
369
|
+
const [uncontrolledSort, setUncontrolledSort] = useState<TableSortState>(() => sort ?? defaultSort);
|
|
370
|
+
const [uncontrolledPage, setUncontrolledPage] = useState(() => paginationConfig?.page ?? paginationConfig?.defaultPage ?? 1);
|
|
371
|
+
const selectedSort = sort !== undefined ? sort : uncontrolledSort;
|
|
372
|
+
const searchValue = searchConfig?.value ?? uncontrolledSearch;
|
|
373
|
+
const normalizedSearchValue = searchValue.trim().toLowerCase();
|
|
374
|
+
|
|
375
|
+
const processedRows = useMemo(() => {
|
|
376
|
+
let nextRows = rows;
|
|
377
|
+
|
|
378
|
+
if (normalizedSearchValue) {
|
|
379
|
+
nextRows = nextRows.filter((row) =>
|
|
380
|
+
getDataTableSearchText({
|
|
381
|
+
columns,
|
|
382
|
+
getRowSearchText: getRowSearchText ?? searchConfig?.getRowText,
|
|
383
|
+
row,
|
|
384
|
+
})
|
|
385
|
+
.toLowerCase()
|
|
386
|
+
.includes(normalizedSearchValue),
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
for (const filter of filters) {
|
|
391
|
+
if (filter.active && filter.predicate) {
|
|
392
|
+
nextRows = nextRows.filter(filter.predicate);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return sortDataTableRows(nextRows, columns, selectedSort);
|
|
397
|
+
}, [columns, filters, getRowSearchText, normalizedSearchValue, rows, searchConfig?.getRowText, selectedSort]);
|
|
398
|
+
|
|
399
|
+
const pageSize = Math.max(1, paginationConfig?.pageSize ?? 10);
|
|
400
|
+
const totalRows = paginationConfig?.totalRows ?? processedRows.length;
|
|
401
|
+
const pageCount = Math.max(1, Math.ceil(Math.max(totalRows, 0) / pageSize));
|
|
402
|
+
const currentPage = paginationConfig ? clampNumber(paginationConfig.page ?? uncontrolledPage, 1, pageCount) : 1;
|
|
403
|
+
const startIndex = (currentPage - 1) * pageSize;
|
|
404
|
+
const displayedRows = paginationConfig?.manual ? processedRows : paginationConfig ? processedRows.slice(startIndex, startIndex + pageSize) : processedRows;
|
|
405
|
+
const visibleFrom = totalRows === 0 ? 0 : startIndex + 1;
|
|
406
|
+
const visibleTo = paginationConfig?.manual ? Math.min(currentPage * pageSize, totalRows) : Math.min(startIndex + displayedRows.length, totalRows);
|
|
407
|
+
const resultsSummary = paginationConfig
|
|
408
|
+
? labels.resultsSummary({ from: visibleFrom, to: visibleTo, total: totalRows })
|
|
409
|
+
: null;
|
|
410
|
+
const hasHeader = Boolean(title || description || actions.length > 0);
|
|
411
|
+
const hasToolbar = Boolean(searchConfig || filters.length > 0 || selectedRowIds.length > 0 || bulkActions.length > 0);
|
|
412
|
+
const activeBulkActions = selectedRowIds.length > 0 ? bulkActions : [];
|
|
413
|
+
const state = getDataTableState({
|
|
414
|
+
emptyState,
|
|
415
|
+
error,
|
|
416
|
+
labels,
|
|
417
|
+
loading,
|
|
418
|
+
rowCount: processedRows.length,
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
function setDataTablePage(nextPage: number) {
|
|
422
|
+
if (!paginationConfig) return;
|
|
423
|
+
|
|
424
|
+
const safePage = clampNumber(nextPage, 1, pageCount);
|
|
425
|
+
if (paginationConfig.page === undefined) {
|
|
426
|
+
setUncontrolledPage(safePage);
|
|
427
|
+
}
|
|
428
|
+
paginationConfig.onPageChange?.(safePage);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function resetPagination() {
|
|
432
|
+
setDataTablePage(1);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function handleSearchChange(value: string) {
|
|
436
|
+
if (searchConfig?.value === undefined) {
|
|
437
|
+
setUncontrolledSearch(value);
|
|
438
|
+
}
|
|
439
|
+
searchConfig?.onValueChange?.(value);
|
|
440
|
+
resetPagination();
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function handleSortChange(nextSort: TableSortState) {
|
|
444
|
+
if (sort === undefined) {
|
|
445
|
+
setUncontrolledSort(nextSort);
|
|
446
|
+
}
|
|
447
|
+
onSortChange?.(nextSort);
|
|
448
|
+
resetPagination();
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
return (
|
|
452
|
+
<section className={cx("ds-data-table", className)} dir={dir}>
|
|
453
|
+
{hasHeader && (
|
|
454
|
+
<header className="ds-data-table__header">
|
|
455
|
+
<div className="ds-data-table__heading">
|
|
456
|
+
{title && <h2>{title}</h2>}
|
|
457
|
+
{description && <p>{description}</p>}
|
|
458
|
+
</div>
|
|
459
|
+
{actions.length > 0 && (
|
|
460
|
+
<div className="ds-data-table__actions">
|
|
461
|
+
{actions.map((action) => (
|
|
462
|
+
<DataTableActionButton action={action} key={action.label} />
|
|
463
|
+
))}
|
|
464
|
+
</div>
|
|
465
|
+
)}
|
|
466
|
+
</header>
|
|
467
|
+
)}
|
|
468
|
+
|
|
469
|
+
{hasToolbar && (
|
|
470
|
+
<Toolbar className="ds-data-table__toolbar" dir={dir} layout="split" wrap>
|
|
471
|
+
<ToolbarSection grow wrap>
|
|
472
|
+
{searchConfig && (
|
|
473
|
+
<ToolbarSearch
|
|
474
|
+
aria-label={searchConfig.label ?? "Search table rows"}
|
|
475
|
+
disabled={searchConfig.disabled}
|
|
476
|
+
onChange={(event) => handleSearchChange(event.currentTarget.value)}
|
|
477
|
+
placeholder={searchConfig.placeholder ?? labels.searchPlaceholder}
|
|
478
|
+
value={searchValue}
|
|
479
|
+
width="full"
|
|
480
|
+
/>
|
|
481
|
+
)}
|
|
482
|
+
{filters.map((filter) => (
|
|
483
|
+
<ToolbarButton
|
|
484
|
+
aria-pressed={filter.active || undefined}
|
|
485
|
+
key={filter.id}
|
|
486
|
+
onClick={() => {
|
|
487
|
+
filter.onAction?.();
|
|
488
|
+
resetPagination();
|
|
489
|
+
}}
|
|
490
|
+
size="sm"
|
|
491
|
+
variant={filter.active ? "default" : "soft"}
|
|
492
|
+
>
|
|
493
|
+
{filter.value ? `${filter.label}: ${filter.value}` : filter.label}
|
|
494
|
+
</ToolbarButton>
|
|
495
|
+
))}
|
|
496
|
+
</ToolbarSection>
|
|
497
|
+
{(selectedRowIds.length > 0 || activeBulkActions.length > 0) && (
|
|
498
|
+
<ToolbarSection align="end" wrap>
|
|
499
|
+
{selectedRowIds.length > 0 && <ToolbarBadge variant="brand">{labels.selectedCount(selectedRowIds.length)}</ToolbarBadge>}
|
|
500
|
+
{activeBulkActions.map((action) => (
|
|
501
|
+
<DataTableActionButton action={action} key={action.label} />
|
|
502
|
+
))}
|
|
503
|
+
</ToolbarSection>
|
|
504
|
+
)}
|
|
505
|
+
</Toolbar>
|
|
506
|
+
)}
|
|
507
|
+
|
|
508
|
+
<div className="ds-data-table__body">
|
|
509
|
+
<Table
|
|
510
|
+
columns={columns}
|
|
511
|
+
dir={dir}
|
|
512
|
+
onSelectedRowIdsChange={onSelectedRowIdsChange}
|
|
513
|
+
onSortChange={handleSortChange}
|
|
514
|
+
rows={state ? [] : displayedRows}
|
|
515
|
+
selectedRowIds={selectedRowIds}
|
|
516
|
+
size={size}
|
|
517
|
+
sort={selectedSort}
|
|
518
|
+
/>
|
|
519
|
+
{state && <DataTableStateView loading={loading} state={state} />}
|
|
520
|
+
</div>
|
|
521
|
+
|
|
522
|
+
{paginationConfig && (
|
|
523
|
+
<footer className="ds-data-table__footer">
|
|
524
|
+
<ToolbarText>{resultsSummary}</ToolbarText>
|
|
525
|
+
<Pagination
|
|
526
|
+
aria-label={
|
|
527
|
+
paginationConfig.ariaLabel ??
|
|
528
|
+
paginationConfig.messages?.navigation ??
|
|
529
|
+
(typeof title === "string" ? `${title} pagination` : "Table pagination")
|
|
530
|
+
}
|
|
531
|
+
dir={dir}
|
|
532
|
+
messages={paginationConfig.messages}
|
|
533
|
+
nextDisabled={currentPage >= pageCount}
|
|
534
|
+
onPageChange={setDataTablePage}
|
|
535
|
+
page={currentPage}
|
|
536
|
+
pages={paginationConfig.pages ?? getDataTablePaginationPages(currentPage, pageCount)}
|
|
537
|
+
previousDisabled={currentPage <= 1}
|
|
538
|
+
caption={resultsSummary}
|
|
539
|
+
showCaption={paginationConfig.showCaption ?? false}
|
|
540
|
+
summary={resultsSummary}
|
|
541
|
+
type={paginationConfig.type ?? "numeric"}
|
|
542
|
+
variant={paginationConfig.variant ?? "soft"}
|
|
543
|
+
/>
|
|
544
|
+
</footer>
|
|
545
|
+
)}
|
|
546
|
+
</section>
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function columnClass<Row extends TableRowBase>(column: TableColumn<Row>) {
|
|
551
|
+
return cx(
|
|
552
|
+
"ds-table__cell",
|
|
553
|
+
column.width === "fill" && "ds-table__cell--fill",
|
|
554
|
+
column.align && `ds-table__cell--${column.align}`,
|
|
555
|
+
column.kind === "selection" && "ds-table__cell--selection",
|
|
556
|
+
column.kind === "actions" && "ds-table__cell--actions",
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
function columnStyle<Row extends TableRowBase>(column: TableColumn<Row>): CSSProperties {
|
|
561
|
+
return {
|
|
562
|
+
minWidth: column.minWidth,
|
|
563
|
+
width: typeof column.width === "number" ? column.width : undefined,
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
type ResolvedDataTableState = DataTableState & {
|
|
568
|
+
tone: "danger" | "default" | "loading";
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
function DataTableActionButton({ action }: { action: DataTableAction }) {
|
|
572
|
+
return (
|
|
573
|
+
<ToolbarButton
|
|
574
|
+
aria-label={action.ariaLabel}
|
|
575
|
+
disabled={action.disabled}
|
|
576
|
+
onClick={action.onAction}
|
|
577
|
+
size="sm"
|
|
578
|
+
variant={action.variant ?? "soft"}
|
|
579
|
+
>
|
|
580
|
+
{action.label}
|
|
581
|
+
</ToolbarButton>
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
function DataTableStateView({ loading, state }: { loading: boolean; state: ResolvedDataTableState }) {
|
|
586
|
+
return (
|
|
587
|
+
<div className={`ds-data-table__state ds-data-table__state--${state.tone}`} role={state.tone === "danger" ? "alert" : "status"}>
|
|
588
|
+
<div className="ds-data-table__state-copy">
|
|
589
|
+
{loading && <Spinner className="ds-data-table__spinner" />}
|
|
590
|
+
{state.title && <strong>{state.title}</strong>}
|
|
591
|
+
{state.description && <p>{state.description}</p>}
|
|
592
|
+
</div>
|
|
593
|
+
{state.action && (
|
|
594
|
+
<div className="ds-data-table__state-action">
|
|
595
|
+
<DataTableActionButton action={state.action} />
|
|
596
|
+
</div>
|
|
597
|
+
)}
|
|
598
|
+
</div>
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
function getDataTableState({
|
|
603
|
+
emptyState,
|
|
604
|
+
error,
|
|
605
|
+
labels,
|
|
606
|
+
loading,
|
|
607
|
+
rowCount,
|
|
608
|
+
}: {
|
|
609
|
+
emptyState?: DataTableState;
|
|
610
|
+
error: boolean | string | DataTableState;
|
|
611
|
+
labels: DataTableLabels;
|
|
612
|
+
loading: boolean;
|
|
613
|
+
rowCount: number;
|
|
614
|
+
}): ResolvedDataTableState | null {
|
|
615
|
+
if (loading) {
|
|
616
|
+
return {
|
|
617
|
+
description: labels.loadingDescription,
|
|
618
|
+
title: labels.loadingTitle,
|
|
619
|
+
tone: "loading",
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
if (error) {
|
|
624
|
+
if (typeof error === "string") {
|
|
625
|
+
return {
|
|
626
|
+
description: error,
|
|
627
|
+
title: labels.errorTitle,
|
|
628
|
+
tone: "danger",
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
if (typeof error === "object") {
|
|
633
|
+
return {
|
|
634
|
+
action: error.action,
|
|
635
|
+
description: error.description ?? labels.errorDescription,
|
|
636
|
+
title: error.title ?? labels.errorTitle,
|
|
637
|
+
tone: "danger",
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
return {
|
|
642
|
+
description: labels.errorDescription,
|
|
643
|
+
title: labels.errorTitle,
|
|
644
|
+
tone: "danger",
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
if (rowCount === 0) {
|
|
649
|
+
return {
|
|
650
|
+
action: emptyState?.action,
|
|
651
|
+
description: emptyState?.description ?? labels.emptyDescription,
|
|
652
|
+
title: emptyState?.title ?? labels.emptyTitle,
|
|
653
|
+
tone: "default",
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
return null;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
function getDataTableSearchText<Row extends TableRowBase>({
|
|
661
|
+
columns,
|
|
662
|
+
getRowSearchText,
|
|
663
|
+
row,
|
|
664
|
+
}: {
|
|
665
|
+
columns: TableColumn<Row>[];
|
|
666
|
+
getRowSearchText?: (row: Row) => string;
|
|
667
|
+
row: Row;
|
|
668
|
+
}) {
|
|
669
|
+
const values = [row.id, getRowSearchText?.(row)];
|
|
670
|
+
|
|
671
|
+
for (const column of columns) {
|
|
672
|
+
const columnValue = column.searchValue?.(row) ?? (column.item ? getTableItemText(column.item(row)) : undefined);
|
|
673
|
+
if (columnValue) values.push(columnValue);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
return values.filter(Boolean).join(" ");
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
function sortDataTableRows<Row extends TableRowBase>(rows: Row[], columns: TableColumn<Row>[], sort: TableSortState) {
|
|
680
|
+
if (!sort) return rows;
|
|
681
|
+
|
|
682
|
+
const column = columns.find((item) => item.id === sort.columnId);
|
|
683
|
+
if (!column) return rows;
|
|
684
|
+
|
|
685
|
+
const direction = sort.direction === "asc" ? 1 : -1;
|
|
686
|
+
|
|
687
|
+
return [...rows].sort((left, right) => {
|
|
688
|
+
const result = compareTableSortValues(getColumnSortValue(column, left), getColumnSortValue(column, right));
|
|
689
|
+
return result * direction;
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
function getColumnSortValue<Row extends TableRowBase>(column: TableColumn<Row>, row: Row): TableSortValue {
|
|
694
|
+
if (column.sortValue) return column.sortValue(row);
|
|
695
|
+
if (column.item) return getTableItemSortValue(column.item(row));
|
|
696
|
+
return undefined;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
function compareTableSortValues(left: TableSortValue, right: TableSortValue) {
|
|
700
|
+
if (left === right) return 0;
|
|
701
|
+
if (left === null || left === undefined) return 1;
|
|
702
|
+
if (right === null || right === undefined) return -1;
|
|
703
|
+
|
|
704
|
+
const normalizedLeft = normalizeTableSortValue(left);
|
|
705
|
+
const normalizedRight = normalizeTableSortValue(right);
|
|
706
|
+
|
|
707
|
+
if (typeof normalizedLeft === "number" && typeof normalizedRight === "number") {
|
|
708
|
+
return normalizedLeft - normalizedRight;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
return String(normalizedLeft).localeCompare(String(normalizedRight), undefined, {
|
|
712
|
+
numeric: true,
|
|
713
|
+
sensitivity: "base",
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
function normalizeTableSortValue(value: Exclude<TableSortValue, null | undefined>) {
|
|
718
|
+
if (value instanceof Date) return value.getTime();
|
|
719
|
+
if (typeof value === "boolean") return value ? 1 : 0;
|
|
720
|
+
return value;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
function getTableItemSortValue(item: TableItem): TableSortValue {
|
|
724
|
+
switch (item.type) {
|
|
725
|
+
case "avatarText":
|
|
726
|
+
return item.name;
|
|
727
|
+
case "badges":
|
|
728
|
+
return item.items.map((badge) => badge.label).join(" ");
|
|
729
|
+
case "brandLogoText":
|
|
730
|
+
return item.label;
|
|
731
|
+
case "file":
|
|
732
|
+
return item.label;
|
|
733
|
+
case "image":
|
|
734
|
+
return item.label;
|
|
735
|
+
case "payment":
|
|
736
|
+
return item.label ?? item.brand;
|
|
737
|
+
case "progress":
|
|
738
|
+
case "rating":
|
|
739
|
+
return item.value;
|
|
740
|
+
case "tags":
|
|
741
|
+
return item.items.join(" ");
|
|
742
|
+
case "text":
|
|
743
|
+
return item.value;
|
|
744
|
+
case "toggle":
|
|
745
|
+
return item.checked;
|
|
746
|
+
default:
|
|
747
|
+
return undefined;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
function getTableItemText(item: TableItem) {
|
|
752
|
+
const value = getTableItemSortValue(item);
|
|
753
|
+
return value === null || value === undefined ? "" : String(value);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
function getDataTablePaginationPages(currentPage: number, pageCount: number): PaginationPage[] {
|
|
757
|
+
if (pageCount <= 5) {
|
|
758
|
+
return Array.from({ length: pageCount }, (_, index) => index + 1);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
const pages: PaginationPage[] = [1];
|
|
762
|
+
const start = Math.max(2, currentPage - 1);
|
|
763
|
+
const end = Math.min(pageCount - 1, currentPage + 1);
|
|
764
|
+
|
|
765
|
+
if (start > 2) pages.push("ellipsis");
|
|
766
|
+
for (let page = start; page <= end; page += 1) {
|
|
767
|
+
pages.push(page);
|
|
768
|
+
}
|
|
769
|
+
if (end < pageCount - 1) pages.push("ellipsis");
|
|
770
|
+
pages.push(pageCount);
|
|
771
|
+
|
|
772
|
+
return pages;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
function getAriaSort(sort: TableSortState, columnId: string) {
|
|
776
|
+
if (sort?.columnId !== columnId) return "none";
|
|
777
|
+
return sort.direction === "asc" ? "ascending" : "descending";
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
function getNextSort(sort: TableSortState, columnId: string): TableSortState {
|
|
781
|
+
if (sort?.columnId !== columnId) {
|
|
782
|
+
return { columnId, direction: "asc" };
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
return {
|
|
786
|
+
columnId,
|
|
787
|
+
direction: sort.direction === "asc" ? "desc" : "asc",
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
function clampNumber(value: number, min: number, max: number) {
|
|
792
|
+
if (!Number.isFinite(value)) return min;
|
|
793
|
+
return Math.min(max, Math.max(min, Math.floor(value)));
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
function renderTableItem(item: TableItem, tableSize: TableSize) {
|
|
797
|
+
switch (item.type) {
|
|
798
|
+
case "checkbox":
|
|
799
|
+
return (
|
|
800
|
+
<SelectionCheckbox
|
|
801
|
+
checked={item.checked}
|
|
802
|
+
disabled={item.disabled ?? !item.onCheckedChange}
|
|
803
|
+
indeterminate={item.indeterminate}
|
|
804
|
+
label={item.ariaLabel ?? "Select row"}
|
|
805
|
+
onChange={item.onCheckedChange}
|
|
806
|
+
/>
|
|
807
|
+
);
|
|
808
|
+
case "text":
|
|
809
|
+
return <span className={`ds-table-item-text ds-table-item-text--${item.tone ?? "default"} ds-table-item-text--${item.weight ?? "regular"}`}>{item.value}</span>;
|
|
810
|
+
case "avatarText":
|
|
811
|
+
return (
|
|
812
|
+
<span className="ds-table-avatar-text">
|
|
813
|
+
<Avatar name={item.name} size={tableSize === "lg" ? "md" : "sm"} src={item.src} />
|
|
814
|
+
<span>
|
|
815
|
+
<strong dir="auto">{item.name}</strong>
|
|
816
|
+
{item.caption && <em dir="auto">{item.caption}</em>}
|
|
817
|
+
</span>
|
|
818
|
+
</span>
|
|
819
|
+
);
|
|
820
|
+
case "rating":
|
|
821
|
+
return <Rating value={item.value} max={item.max ?? 5} />;
|
|
822
|
+
case "progress":
|
|
823
|
+
return <Progress value={item.value} label={item.label} tone={item.tone ?? "success"} />;
|
|
824
|
+
case "toggle":
|
|
825
|
+
return (
|
|
826
|
+
<Toggle
|
|
827
|
+
aria-label={item.ariaLabel ?? "Toggle row value"}
|
|
828
|
+
checked={item.checked}
|
|
829
|
+
disabled={item.disabled ?? !item.onCheckedChange}
|
|
830
|
+
onCheckedChange={item.onCheckedChange}
|
|
831
|
+
size="sm"
|
|
832
|
+
/>
|
|
833
|
+
);
|
|
834
|
+
case "badges":
|
|
835
|
+
return <BadgeList items={item.items} maxVisible={item.maxVisible} />;
|
|
836
|
+
case "onlyAvatar":
|
|
837
|
+
return <Avatar name={item.alt} size={tableSize === "lg" ? "md" : "xs"} src={item.src} />;
|
|
838
|
+
case "avatarStack":
|
|
839
|
+
return (
|
|
840
|
+
<AvatarStack
|
|
841
|
+
addLabel={item.addLabel}
|
|
842
|
+
avatars={item.avatars}
|
|
843
|
+
canAdd={item.canAdd}
|
|
844
|
+
count={item.count}
|
|
845
|
+
onAdd={item.onAdd}
|
|
846
|
+
size={tableSize}
|
|
847
|
+
/>
|
|
848
|
+
);
|
|
849
|
+
case "tags":
|
|
850
|
+
return <TagList items={item.items} maxVisible={item.maxVisible} />;
|
|
851
|
+
case "file":
|
|
852
|
+
return item.label ? <IconLabel icon={<FileIcon />} label={item.label} /> : null;
|
|
853
|
+
case "brandLogoText":
|
|
854
|
+
return <IconLabel icon={item.logoSrc ? <img alt="" src={item.logoSrc} /> : <BrandIcon />} label={item.label} />;
|
|
855
|
+
case "payment":
|
|
856
|
+
return <IconLabel icon={<PaymentIcon />} label={item.label ?? item.brand} />;
|
|
857
|
+
case "image":
|
|
858
|
+
return <IconLabel icon={<img alt="" src={item.src} />} label={item.label} />;
|
|
859
|
+
case "action":
|
|
860
|
+
return <IconButton icon={item.icon} label={item.label} onClick={item.onAction} />;
|
|
861
|
+
case "actionGroup":
|
|
862
|
+
return (
|
|
863
|
+
<span className="ds-table-action-group">
|
|
864
|
+
{item.actions.map((action) => (
|
|
865
|
+
<IconButton disabled={action.disabled} key={action.label} icon={action.icon} label={action.label} onClick={action.onAction} />
|
|
866
|
+
))}
|
|
867
|
+
</span>
|
|
868
|
+
);
|
|
869
|
+
default:
|
|
870
|
+
return null;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
function SelectionCheckbox({
|
|
875
|
+
checked,
|
|
876
|
+
disabled = false,
|
|
877
|
+
indeterminate = false,
|
|
878
|
+
label,
|
|
879
|
+
onChange,
|
|
880
|
+
}: {
|
|
881
|
+
checked: boolean;
|
|
882
|
+
disabled?: boolean;
|
|
883
|
+
indeterminate?: boolean;
|
|
884
|
+
label: string;
|
|
885
|
+
onChange?: (checked: boolean) => void;
|
|
886
|
+
}) {
|
|
887
|
+
return (
|
|
888
|
+
<Checkbox
|
|
889
|
+
aria-label={label}
|
|
890
|
+
checked={indeterminate ? "indeterminate" : checked}
|
|
891
|
+
disabled={disabled}
|
|
892
|
+
onCheckedChange={(nextChecked) => onChange?.(nextChecked === true)}
|
|
893
|
+
/>
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
type TableAvatarSize = "xs" | "sm" | "md";
|
|
898
|
+
|
|
899
|
+
function Avatar({ name, size, src }: { name: string; size: TableAvatarSize; src?: string }) {
|
|
900
|
+
const initials = name
|
|
901
|
+
.split(" ")
|
|
902
|
+
.map((part) => part[0])
|
|
903
|
+
.slice(0, 2)
|
|
904
|
+
.join("")
|
|
905
|
+
.toUpperCase();
|
|
906
|
+
|
|
907
|
+
return (
|
|
908
|
+
<AvatarPrimitive className="ds-table-avatar" size={size}>
|
|
909
|
+
{src ? <AvatarImage alt="" src={src} /> : null}
|
|
910
|
+
<AvatarFallback size={size}>{initials}</AvatarFallback>
|
|
911
|
+
</AvatarPrimitive>
|
|
912
|
+
);
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
function AvatarStack({
|
|
916
|
+
addLabel = "Add person",
|
|
917
|
+
avatars,
|
|
918
|
+
canAdd,
|
|
919
|
+
count,
|
|
920
|
+
onAdd,
|
|
921
|
+
size,
|
|
922
|
+
}: {
|
|
923
|
+
addLabel?: string;
|
|
924
|
+
avatars: AvatarItem[];
|
|
925
|
+
canAdd?: boolean;
|
|
926
|
+
count?: number;
|
|
927
|
+
onAdd?: () => void;
|
|
928
|
+
size: TableSize;
|
|
929
|
+
}) {
|
|
930
|
+
return (
|
|
931
|
+
<span className={`ds-table-avatar-stack ds-table-avatar-stack--${size}`}>
|
|
932
|
+
{avatars.slice(0, 3).map((avatar) => (
|
|
933
|
+
<Avatar key={avatar.alt} name={avatar.alt} size={size === "lg" ? "md" : "xs"} src={avatar.src} />
|
|
934
|
+
))}
|
|
935
|
+
{count ? <span className="ds-table-avatar ds-table-avatar--count">+{count}</span> : null}
|
|
936
|
+
{canAdd ? (
|
|
937
|
+
<Button aria-label={addLabel} disabled={!onAdd} onClick={onAdd} size="icon-xs" type="button" variant="ghost">
|
|
938
|
+
+
|
|
939
|
+
</Button>
|
|
940
|
+
) : null}
|
|
941
|
+
</span>
|
|
942
|
+
);
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
function BadgeList({ items, maxVisible = items.length }: { items: BadgeItem[]; maxVisible?: number }) {
|
|
946
|
+
const visible = items.slice(0, maxVisible);
|
|
947
|
+
const overflow = items.length - visible.length;
|
|
948
|
+
|
|
949
|
+
return (
|
|
950
|
+
<span className="ds-table-badges">
|
|
951
|
+
{visible.map((item, index) => (
|
|
952
|
+
<Badge
|
|
953
|
+
badgeStyle="light"
|
|
954
|
+
color={badgeColor(item.tone)}
|
|
955
|
+
key={`${item.label}-${index}`}
|
|
956
|
+
size="xs"
|
|
957
|
+
type={item.dot ? "dot" : "default"}
|
|
958
|
+
>
|
|
959
|
+
{item.label}
|
|
960
|
+
</Badge>
|
|
961
|
+
))}
|
|
962
|
+
{overflow > 0 && <Badge size="xs">+{overflow}</Badge>}
|
|
963
|
+
</span>
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
function TagList({ items, maxVisible = items.length }: { items: string[]; maxVisible?: number }) {
|
|
968
|
+
const visible = items.slice(0, maxVisible);
|
|
969
|
+
const overflow = items.length - visible.length;
|
|
970
|
+
|
|
971
|
+
return (
|
|
972
|
+
<span className="ds-table-tags">
|
|
973
|
+
{visible.map((item, index) => (
|
|
974
|
+
<Tag key={`${item}-${index}`} size="xs">{item}</Tag>
|
|
975
|
+
))}
|
|
976
|
+
{overflow > 0 && <Tag size="xs">+{overflow}</Tag>}
|
|
977
|
+
</span>
|
|
978
|
+
);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
function Progress({ label, tone, value }: { label?: string; tone: "success" | "brand"; value: number }) {
|
|
982
|
+
return (
|
|
983
|
+
<ProgressPrimitive
|
|
984
|
+
aria-label={label ?? "Progress"}
|
|
985
|
+
className={`ds-table-progress ds-table-progress--${tone}`}
|
|
986
|
+
indicator={label}
|
|
987
|
+
labelPosition="inline"
|
|
988
|
+
size="lg"
|
|
989
|
+
value={value}
|
|
990
|
+
/>
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
function Rating({ max, value }: { max: number; value: number }) {
|
|
995
|
+
return (
|
|
996
|
+
<span
|
|
997
|
+
aria-label={`${value} out of ${max}`}
|
|
998
|
+
className="ds-table-rating"
|
|
999
|
+
role="img"
|
|
1000
|
+
>
|
|
1001
|
+
{Array.from({ length: max }, (_, index) => (
|
|
1002
|
+
<StarIcon
|
|
1003
|
+
aria-hidden="true"
|
|
1004
|
+
className={index < value ? "is-filled" : undefined}
|
|
1005
|
+
key={index}
|
|
1006
|
+
strokeWidth="var(--bh-icon-stroke-190)"
|
|
1007
|
+
/>
|
|
1008
|
+
))}
|
|
1009
|
+
</span>
|
|
1010
|
+
);
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
function IconLabel({ icon, label }: { icon: ReactNode; label: string }) {
|
|
1014
|
+
return (
|
|
1015
|
+
<span className="ds-table-icon-label">
|
|
1016
|
+
<span aria-hidden="true">{icon}</span>
|
|
1017
|
+
<span>{label}</span>
|
|
1018
|
+
</span>
|
|
1019
|
+
);
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
function IconButton({
|
|
1023
|
+
disabled,
|
|
1024
|
+
icon,
|
|
1025
|
+
label,
|
|
1026
|
+
onClick,
|
|
1027
|
+
}: {
|
|
1028
|
+
disabled?: boolean;
|
|
1029
|
+
icon: TableAction["icon"];
|
|
1030
|
+
label: string;
|
|
1031
|
+
onClick?: () => void;
|
|
1032
|
+
}) {
|
|
1033
|
+
return (
|
|
1034
|
+
<Button aria-label={label} className="ds-table-icon-button" disabled={disabled ?? !onClick} onClick={onClick} size="icon-xs" type="button" variant="ghost">
|
|
1035
|
+
{renderActionIcon(icon)}
|
|
1036
|
+
</Button>
|
|
1037
|
+
);
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
function badgeColor(tone: BadgeItem["tone"]) {
|
|
1041
|
+
if (tone === "success") return "green" as const;
|
|
1042
|
+
if (tone === "warning") return "amber" as const;
|
|
1043
|
+
return tone ?? "neutral";
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
function renderActionIcon(icon: TableAction["icon"]) {
|
|
1047
|
+
switch (icon) {
|
|
1048
|
+
case "view":
|
|
1049
|
+
return <ViewIcon />;
|
|
1050
|
+
case "edit":
|
|
1051
|
+
return <EditIcon />;
|
|
1052
|
+
case "delete":
|
|
1053
|
+
return <DeleteIcon />;
|
|
1054
|
+
case "more":
|
|
1055
|
+
default:
|
|
1056
|
+
return <MoreIcon />;
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
function SortIcon({ direction }: { direction?: TableSortDirection }) {
|
|
1061
|
+
return (
|
|
1062
|
+
<ArrowUpDownIcon aria-hidden="true" data-direction={direction ?? "none"} strokeWidth="var(--bh-icon-stroke-190)" />
|
|
1063
|
+
);
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
function MoreIcon() {
|
|
1067
|
+
return <EllipsisIcon aria-hidden="true" strokeWidth="var(--bh-icon-stroke-225)" />;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
function ViewIcon() {
|
|
1071
|
+
return <EyeIcon aria-hidden="true" strokeWidth="var(--bh-icon-stroke-190)" />;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
function EditIcon() {
|
|
1075
|
+
return <LucideEditIcon aria-hidden="true" strokeWidth="var(--bh-icon-stroke-190)" />;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
function DeleteIcon() {
|
|
1079
|
+
return <Trash2Icon aria-hidden="true" strokeWidth="var(--bh-icon-stroke-190)" />;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
function FileIcon() {
|
|
1083
|
+
return <LucideFileIcon strokeWidth="var(--bh-icon-stroke-190)" />;
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
function BrandIcon() {
|
|
1087
|
+
return <span className="ds-table-brand-icon" />;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
function PaymentIcon() {
|
|
1091
|
+
return <span className="ds-table-payment-icon" />;
|
|
1092
|
+
}
|