@shohojdhara/atomix 0.3.14 → 0.4.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 +20 -0
- package/build-tools/EXAMPLES.md +372 -0
- package/build-tools/README.md +242 -0
- package/build-tools/__tests__/error-handler.test.js +230 -0
- package/build-tools/__tests__/index.test.js +141 -0
- package/build-tools/__tests__/rollup-plugin.test.js +194 -0
- package/build-tools/__tests__/utils.test.js +161 -0
- package/build-tools/__tests__/vite-plugin.test.js +129 -0
- package/build-tools/__tests__/webpack-loader.test.js +190 -0
- package/build-tools/error-handler.js +308 -0
- package/build-tools/index.d.ts +44 -0
- package/build-tools/index.js +88 -0
- package/build-tools/package.json +50 -0
- package/build-tools/rollup-plugin.js +236 -0
- package/build-tools/types.d.ts +163 -0
- package/build-tools/utils.js +203 -0
- package/build-tools/vite-plugin.js +161 -0
- package/build-tools/webpack-loader.js +123 -0
- package/dist/atomix.css +21044 -2618
- package/dist/atomix.css.map +1 -1
- package/dist/atomix.min.css +77 -3
- package/dist/atomix.min.css.map +1 -1
- package/dist/build-tools/EXAMPLES.md +372 -0
- package/dist/build-tools/README.md +242 -0
- package/dist/build-tools/__tests__/error-handler.test.js +230 -0
- package/dist/build-tools/__tests__/index.test.js +141 -0
- package/dist/build-tools/__tests__/rollup-plugin.test.js +194 -0
- package/dist/build-tools/__tests__/utils.test.js +161 -0
- package/dist/build-tools/__tests__/vite-plugin.test.js +129 -0
- package/dist/build-tools/__tests__/webpack-loader.test.js +190 -0
- package/dist/build-tools/error-handler.js +308 -0
- package/dist/build-tools/index.d.ts +44 -0
- package/dist/build-tools/index.js +88 -0
- package/dist/build-tools/package.json +50 -0
- package/dist/build-tools/rollup-plugin.js +236 -0
- package/dist/build-tools/types.d.ts +163 -0
- package/dist/build-tools/utils.js +203 -0
- package/dist/build-tools/vite-plugin.js +161 -0
- package/dist/build-tools/webpack-loader.js +123 -0
- package/dist/charts.d.ts +1 -1
- package/dist/charts.js +86 -57
- package/dist/charts.js.map +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +136 -112
- package/dist/core.js.map +1 -1
- package/dist/forms.d.ts +2 -5
- package/dist/forms.js +140 -128
- package/dist/forms.js.map +1 -1
- package/dist/heavy.d.ts +1 -1
- package/dist/heavy.js +136 -112
- package/dist/heavy.js.map +1 -1
- package/dist/index.d.ts +152 -78
- package/dist/index.esm.js +346 -340
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +359 -353
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/layout.js.map +1 -1
- package/dist/theme.d.ts +9 -9
- package/dist/theme.js.map +1 -1
- package/package.json +23 -8
- package/scripts/atomix-cli.js +170 -73
- package/scripts/cli/__tests__/README.md +81 -0
- package/scripts/cli/__tests__/basic.test.js +115 -0
- package/scripts/cli/__tests__/component-generator.test.js +332 -0
- package/scripts/cli/__tests__/integration.test.js +327 -0
- package/scripts/cli/__tests__/test-setup.js +133 -0
- package/scripts/cli/__tests__/token-manager.test.js +251 -0
- package/scripts/cli/__tests__/utils.test.js +161 -0
- package/scripts/cli/component-generator.js +253 -299
- package/scripts/cli/dependency-checker.js +355 -0
- package/scripts/cli/interactive-init.js +46 -5
- package/scripts/cli/template-manager.js +0 -2
- package/scripts/cli/templates/common-templates.js +636 -0
- package/scripts/cli/templates/composable-templates.js +148 -126
- package/scripts/cli/templates/index.js +23 -16
- package/scripts/cli/templates/project-templates.js +151 -23
- package/scripts/cli/templates/react-templates.js +280 -210
- package/scripts/cli/templates/scss-templates.js +90 -91
- package/scripts/cli/templates/testing-templates.js +206 -27
- package/scripts/cli/templates/testing-utils.js +278 -0
- package/scripts/cli/templates/types-templates.js +70 -56
- package/scripts/cli/theme-bridge.js +8 -2
- package/scripts/cli/token-manager.js +318 -206
- package/scripts/cli/utils.js +0 -1
- package/src/components/Accordion/Accordion.stories.tsx +358 -850
- package/src/components/Accordion/Accordion.test.tsx +70 -50
- package/src/components/Accordion/Accordion.tsx +99 -94
- package/src/components/AtomixGlass/AtomixGlass.test.tsx +1 -1
- package/src/components/AtomixGlass/AtomixGlass.tsx +80 -39
- package/src/components/AtomixGlass/AtomixGlassContainer.tsx +103 -81
- package/src/components/AtomixGlass/GlassFilter.tsx +9 -16
- package/src/components/AtomixGlass/__snapshots__/AtomixGlass.test.tsx.snap +8 -7
- package/src/components/AtomixGlass/glass-utils.ts +6 -5
- package/src/components/AtomixGlass/shader-utils.ts +133 -52
- package/src/components/AtomixGlass/stories/Customization.stories.tsx +131 -0
- package/src/components/AtomixGlass/stories/Examples.stories.tsx +2957 -2853
- package/src/components/AtomixGlass/stories/Modes.stories.tsx +1 -1
- package/src/components/AtomixGlass/stories/Overview.stories.tsx +348 -0
- package/src/components/AtomixGlass/stories/Performance.stories.tsx +103 -0
- package/src/components/AtomixGlass/stories/Playground.stories.tsx +51 -36
- package/src/components/AtomixGlass/stories/{ShaderVariants.stories.tsx → Shaders.stories.tsx} +2 -2
- package/src/components/AtomixGlass/stories/shared-components.tsx +90 -190
- package/src/components/Avatar/Avatar.stories.tsx +195 -0
- package/src/components/Avatar/Avatar.tsx +58 -56
- package/src/components/Badge/Badge.stories.tsx +122 -352
- package/src/components/Badge/Badge.test.tsx +41 -41
- package/src/components/Badge/Badge.tsx +64 -62
- package/src/components/Block/Block.stories.tsx +30 -11
- package/src/components/Breadcrumb/Breadcrumb.stories.tsx +142 -23
- package/src/components/Breadcrumb/Breadcrumb.tsx +62 -60
- package/src/components/Button/Button.stories.tsx +454 -1126
- package/src/components/Button/Button.test.tsx +123 -0
- package/src/components/Button/Button.tsx +88 -60
- package/src/components/Button/ButtonGroup.stories.tsx +376 -215
- package/src/components/Button/ButtonGroup.tsx +4 -15
- package/src/components/Callout/Callout.stories.tsx +316 -568
- package/src/components/Card/Card.stories.tsx +292 -81
- package/src/components/Card/Card.tsx +30 -14
- package/src/components/Chart/AreaChart.tsx +1 -1
- package/src/components/Chart/CandlestickChart.tsx +23 -16
- package/src/components/Chart/Chart.stories.tsx +153 -16
- package/src/components/Chart/Chart.tsx +40 -44
- package/src/components/Chart/ChartRenderer.tsx +39 -12
- package/src/components/Chart/ChartToolbar.tsx +21 -5
- package/src/components/Chart/DonutChart.tsx +1 -1
- package/src/components/Chart/FunnelChart.tsx +4 -1
- package/src/components/Chart/GaugeChart.tsx +3 -1
- package/src/components/Chart/HeatmapChart.tsx +50 -37
- package/src/components/Chart/LineChart.tsx +3 -2
- package/src/components/Chart/MultiAxisChart.tsx +24 -16
- package/src/components/Chart/RadarChart.tsx +19 -17
- package/src/components/Chart/ScatterChart.tsx +29 -21
- package/src/components/ColorModeToggle/ColorModeToggle.stories.tsx +152 -66
- package/src/components/ColorModeToggle/ColorModeToggle.tsx +15 -3
- package/src/components/Countdown/Countdown.stories.tsx +114 -7
- package/src/components/DataTable/DataTable.stories.tsx +349 -144
- package/src/components/DataTable/DataTable.test.tsx +26 -148
- package/src/components/DataTable/DataTable.tsx +485 -456
- package/src/components/DatePicker/DatePicker.stories.tsx +310 -1066
- package/src/components/DatePicker/DatePicker.tsx +31 -26
- package/src/components/Dropdown/Dropdown.stories.tsx +153 -36
- package/src/components/Dropdown/Dropdown.tsx +313 -299
- package/src/components/EdgePanel/EdgePanel.stories.tsx +221 -25
- package/src/components/EdgePanel/EdgePanel.tsx +1 -3
- package/src/components/Footer/Footer.stories.tsx +396 -327
- package/src/components/Footer/Footer.tsx +130 -128
- package/src/components/Footer/FooterLink.tsx +2 -2
- package/src/components/Form/Checkbox.stories.tsx +140 -6
- package/src/components/Form/Checkbox.test.tsx +63 -0
- package/src/components/Form/Checkbox.tsx +122 -78
- package/src/components/Form/Form.stories.tsx +110 -19
- package/src/components/Form/FormGroup.stories.tsx +127 -4
- package/src/components/Form/Input.stories.tsx +22 -39
- package/src/components/Form/Input.test.tsx +38 -44
- package/src/components/Form/Radio.stories.tsx +146 -17
- package/src/components/Form/Radio.tsx +68 -66
- package/src/components/Form/Select.stories.tsx +140 -8
- package/src/components/Form/Select.tsx +184 -182
- package/src/components/Form/Textarea.stories.tsx +149 -6
- package/src/components/Form/Textarea.test.tsx +27 -32
- package/src/components/Hero/Hero.stories.tsx +372 -38
- package/src/components/Hero/Hero.tsx +201 -55
- package/src/components/Icon/index.ts +7 -1
- package/src/components/List/List.stories.tsx +141 -3
- package/src/components/List/List.tsx +19 -23
- package/src/components/Modal/Modal.stories.tsx +183 -43
- package/src/components/Modal/Modal.tsx +130 -127
- package/src/components/Navigation/Menu/MegaMenu.tsx +70 -70
- package/src/components/Navigation/Nav/NavDropdown.tsx +1 -5
- package/src/components/Navigation/SideMenu/SideMenu.stories.tsx +128 -28
- package/src/components/Navigation/SideMenu/SideMenu.tsx +5 -7
- package/src/components/Navigation/SideMenu/SideMenuItem.tsx +4 -5
- package/src/components/Pagination/Pagination.stories.tsx +7 -4
- package/src/components/Pagination/Pagination.tsx +199 -202
- package/src/components/PhotoViewer/PhotoViewer.tsx +4 -1
- package/src/components/Popover/Popover.stories.tsx +354 -97
- package/src/components/Popover/Popover.tsx +41 -37
- package/src/components/Progress/Progress.stories.tsx +160 -7
- package/src/components/River/River.stories.tsx +3 -2
- package/src/components/SectionIntro/SectionIntro.stories.tsx +239 -47
- package/src/components/Slider/Slider.stories.tsx +12 -4
- package/src/components/Spinner/Spinner.stories.tsx +104 -8
- package/src/components/Spinner/Spinner.test.tsx +23 -23
- package/src/components/Spinner/Spinner.tsx +43 -46
- package/src/components/Steps/Steps.stories.tsx +173 -42
- package/src/components/Tabs/Tabs.stories.tsx +141 -12
- package/src/components/Tabs/Tabs.tsx +74 -72
- package/src/components/Testimonial/Testimonial.stories.tsx +120 -3
- package/src/components/Todo/Todo.stories.tsx +198 -9
- package/src/components/Toggle/Toggle.stories.tsx +137 -36
- package/src/components/Toggle/Toggle.test.tsx +65 -70
- package/src/components/Toggle/Toggle.tsx +4 -1
- package/src/components/Tooltip/Tooltip.stories.tsx +194 -100
- package/src/components/Tooltip/Tooltip.tsx +104 -106
- package/src/components/Upload/Upload.stories.tsx +241 -150
- package/src/components/Upload/Upload.tsx +287 -283
- package/src/components/VideoPlayer/VideoPlayer.tsx +6 -1
- package/src/components/index.ts +13 -2
- package/src/layouts/Grid/Grid.stories.tsx +9 -3
- package/src/layouts/MasonryGrid/MasonryGrid.tsx +5 -1
- package/src/lib/README.md +2 -2
- package/src/lib/__tests__/theme-tools.test.ts +219 -0
- package/src/lib/composables/index.ts +2 -2
- package/src/lib/composables/shared-mouse-tracker.ts +13 -14
- package/src/lib/composables/useAtomixGlass.ts +126 -97
- package/src/lib/composables/useChartExport.ts +3 -8
- package/src/lib/composables/useDataTable.ts +72 -43
- package/src/lib/composables/useHero.ts +58 -14
- package/src/lib/composables/useHeroBackgroundSlider.ts +2 -9
- package/src/lib/composables/useInput.ts +10 -8
- package/src/lib/composables/useSideMenu.ts +6 -5
- package/src/lib/composables/useTooltip.ts +1 -2
- package/src/lib/composables/useVideoPlayer.ts +44 -35
- package/src/lib/config/index.ts +154 -154
- package/src/lib/constants/components.ts +9 -32
- package/src/lib/constants/cssVariables.ts +29 -29
- package/src/lib/hooks/__tests__/useComponentCustomization.test.ts +2 -6
- package/src/lib/hooks/index.ts +1 -1
- package/src/lib/hooks/useComponentCustomization.ts +11 -17
- package/src/lib/hooks/usePerformanceMonitor.ts +6 -7
- package/src/lib/patterns/__tests__/slots.test.ts +1 -1
- package/src/lib/patterns/index.ts +1 -1
- package/src/lib/patterns/slots.tsx +8 -13
- package/src/lib/storybook/InteractiveDemo.tsx +13 -18
- package/src/lib/storybook/PreviewContainer.tsx +1 -1
- package/src/lib/storybook/VariantsGrid.tsx +3 -7
- package/src/lib/storybook/index.ts +1 -1
- package/src/lib/theme/adapters/cssVariableMapper.ts +47 -74
- package/src/lib/theme/adapters/index.ts +3 -9
- package/src/lib/theme/adapters/themeAdapter.ts +41 -26
- package/src/lib/theme/config/index.ts +1 -1
- package/src/lib/theme/config/types.ts +2 -2
- package/src/lib/theme/config/validator.ts +10 -5
- package/src/lib/theme/constants/constants.ts +2 -2
- package/src/lib/theme/constants/index.ts +1 -2
- package/src/lib/theme/core/__tests__/createTheme.test.ts +20 -22
- package/src/lib/theme/core/composeTheme.ts +32 -26
- package/src/lib/theme/core/createTheme.ts +1 -1
- package/src/lib/theme/core/createThemeObject.ts +308 -301
- package/src/lib/theme/core/index.ts +3 -3
- package/src/lib/theme/devtools/CLI.ts +107 -105
- package/src/lib/theme/devtools/Comparator.tsx +50 -32
- package/src/lib/theme/devtools/DesignTokensCustomizer.stories.tsx +50 -48
- package/src/lib/theme/devtools/DesignTokensCustomizer.tsx +257 -63
- package/src/lib/theme/devtools/Inspector.tsx +75 -60
- package/src/lib/theme/devtools/LiveEditor.tsx +97 -76
- package/src/lib/theme/devtools/Preview.tsx +150 -106
- package/src/lib/theme/devtools/ThemeValidator.ts +29 -21
- package/src/lib/theme/devtools/index.ts +3 -9
- package/src/lib/theme/devtools/useHistory.ts +23 -21
- package/src/lib/theme/errors/errors.ts +12 -11
- package/src/lib/theme/errors/index.ts +2 -7
- package/src/lib/theme/generators/generateCSS.ts +9 -13
- package/src/lib/theme/generators/generateCSSNested.ts +1 -6
- package/src/lib/theme/generators/generateCSSVariables.ts +673 -630
- package/src/lib/theme/generators/index.ts +1 -4
- package/src/lib/theme/i18n/index.ts +1 -1
- package/src/lib/theme/i18n/rtl.ts +13 -13
- package/src/lib/theme/index.ts +7 -16
- package/src/lib/theme/runtime/ThemeApplicator.ts +4 -4
- package/src/lib/theme/runtime/ThemeContext.tsx +1 -1
- package/src/lib/theme/runtime/ThemeErrorBoundary.tsx +19 -23
- package/src/lib/theme/runtime/ThemeProvider.tsx +230 -239
- package/src/lib/theme/runtime/__tests__/ThemeProvider.integration.test.tsx +1 -1
- package/src/lib/theme/runtime/__tests__/ThemeProvider.test.tsx +24 -29
- package/src/lib/theme/runtime/index.ts +2 -5
- package/src/lib/theme/runtime/useTheme.ts +18 -18
- package/src/lib/theme/runtime/useThemeTokens.ts +22 -22
- package/src/lib/theme/test/testTheme.ts +15 -16
- package/src/lib/theme/tokens/index.ts +2 -7
- package/src/lib/theme/tokens/tokens.ts +25 -24
- package/src/lib/theme/types.ts +428 -411
- package/src/lib/theme/utils/__tests__/themeValidation.test.ts +3 -3
- package/src/lib/theme/utils/componentTheming.ts +18 -18
- package/src/lib/theme/utils/domUtils.ts +277 -289
- package/src/lib/theme/utils/index.ts +1 -2
- package/src/lib/theme/utils/injectCSS.ts +10 -14
- package/src/lib/theme/utils/naming.ts +20 -16
- package/src/lib/theme/utils/themeHelpers.ts +10 -12
- package/src/lib/theme/utils/themeUtils.ts +85 -86
- package/src/lib/theme/utils/themeValidation.ts +82 -33
- package/src/lib/theme-tools.ts +8 -6
- package/src/lib/types/components.ts +172 -71
- package/src/lib/types/partProps.ts +1 -1
- package/src/lib/utils/__tests__/csv.test.ts +45 -0
- package/src/lib/utils/componentUtils.ts +8 -12
- package/src/lib/utils/csv.ts +19 -0
- package/src/lib/utils/dataTableExport.ts +2 -15
- package/src/lib/utils/fontPreloader.ts +10 -19
- package/src/lib/utils/icons.ts +4 -1
- package/src/lib/utils/index.ts +2 -6
- package/src/lib/utils/memoryMonitor.ts +10 -8
- package/src/lib/utils/themeNaming.ts +2 -2
- package/src/styles/01-settings/_index.scss +1 -1
- package/src/styles/01-settings/_settings.accordion.scss +28 -7
- package/src/styles/01-settings/_settings.colors.scss +11 -11
- package/src/styles/01-settings/_settings.design-tokens.scss +61 -50
- package/src/styles/01-settings/_settings.navbar.scss +1 -1
- package/src/styles/01-settings/_settings.spacing.scss +3 -4
- package/src/styles/01-settings/_settings.tooltip.scss +1 -1
- package/src/styles/01-settings/_settings.typography.scss +4 -4
- package/src/styles/02-tools/_tools.button.scss +51 -21
- package/src/styles/02-tools/_tools.utility-api.scss +38 -12
- package/src/styles/03-generic/_generic.root.scss +4 -3
- package/src/styles/06-components/_components.accordion.scss +56 -14
- package/src/styles/06-components/_components.atomix-glass.scss +13 -9
- package/src/styles/06-components/_components.button.scss +16 -4
- package/src/styles/06-components/_components.callout.scss +27 -21
- package/src/styles/06-components/_components.card.scss +5 -14
- package/src/styles/06-components/_components.chart.scss +22 -19
- package/src/styles/06-components/_components.checkbox.scss +25 -17
- package/src/styles/06-components/_components.color-mode-toggle.scss +3 -1
- package/src/styles/06-components/_components.edge-panel.scss +9 -2
- package/src/styles/06-components/_components.footer.scss +1 -1
- package/src/styles/06-components/_components.side-menu.scss +5 -5
- package/src/styles/06-components/_components.toggle.scss +18 -0
- package/src/styles/06-components/_index.scss +1 -1
- package/src/styles/06-components/old.chart.styles.scss +0 -2
- package/src/styles/99-utilities/_index.scss +2 -0
- package/src/styles/99-utilities/_utilities.border.scss +69 -27
- package/src/styles/99-utilities/_utilities.display.scss +1 -1
- package/src/styles/99-utilities/_utilities.opacity.scss +10 -0
- package/src/styles/99-utilities/_utilities.position.scss +16 -9
- package/src/styles/99-utilities/_utilities.scss +2 -0
- package/src/styles/99-utilities/_utilities.sizes.scss +47 -18
- package/src/styles/99-utilities/_utilities.spacing.scss +118 -66
- package/src/styles/99-utilities/_utilities.text-gradient.scss +45 -0
- package/src/styles/99-utilities/_utilities.text.scss +67 -46
- package/themes/dark-complementary/README.md +98 -0
- package/themes/dark-complementary/index.scss +158 -0
- package/themes/default-light/README.md +81 -0
- package/themes/default-light/index.scss +154 -0
- package/themes/high-contrast/README.md +105 -0
- package/themes/high-contrast/index.scss +172 -0
- package/themes/test-theme/README.md +38 -0
- package/themes/test-theme/index.scss +47 -0
- package/scripts/cli/templates-original-backup.js +0 -1655
- package/scripts/cli/templates_backup.js +0 -684
- package/src/components/AtomixGlass/stories/AtomixGlass.stories.tsx +0 -1438
- package/src/lib/composables/useButton.ts +0 -93
- package/src/lib/composables/useCheckbox.ts +0 -70
|
@@ -37,500 +37,529 @@ function getRowId(row: any, rowKey?: string | ((row: any) => string | number)):
|
|
|
37
37
|
* />
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
|
-
export const DataTable: React.FC<DataTableProps> = memo(
|
|
41
|
-
|
|
42
|
-
columns,
|
|
43
|
-
className,
|
|
44
|
-
style,
|
|
45
|
-
sortable = false,
|
|
46
|
-
filterable = false,
|
|
47
|
-
paginated = false,
|
|
48
|
-
pageSize = 10,
|
|
49
|
-
striped = false,
|
|
50
|
-
bordered = false,
|
|
51
|
-
dense = false,
|
|
52
|
-
loading = false,
|
|
53
|
-
emptyMessage = 'No data available',
|
|
54
|
-
onRowClick,
|
|
55
|
-
onSort,
|
|
56
|
-
selectionMode = 'none',
|
|
57
|
-
selectedRowIds: controlledSelectedRowIds,
|
|
58
|
-
onSelectionChange,
|
|
59
|
-
rowKey,
|
|
60
|
-
resizable = false,
|
|
61
|
-
reorderable = false,
|
|
62
|
-
onColumnReorder,
|
|
63
|
-
showColumnVisibility = false,
|
|
64
|
-
onColumnVisibilityChange,
|
|
65
|
-
stickyHeader = false,
|
|
66
|
-
stickyHeaderOffset = '0px',
|
|
67
|
-
virtualScrolling = false,
|
|
68
|
-
estimatedRowHeight = 50,
|
|
69
|
-
overscan = 5,
|
|
70
|
-
exportable = false,
|
|
71
|
-
exportFormats = ['csv', 'excel', 'json'],
|
|
72
|
-
exportFilename = 'data-table',
|
|
73
|
-
onExport,
|
|
74
|
-
columnFilters = false,
|
|
75
|
-
...props
|
|
76
|
-
}) => {
|
|
77
|
-
const tableRef = useRef<HTMLTableElement>(null);
|
|
78
|
-
const headerRef = useRef<HTMLTableSectionElement>(null);
|
|
79
|
-
const [resizingColumn, setResizingColumn] = useState<string | null>(null);
|
|
80
|
-
const [columnWidths, setColumnWidths] = useState<Record<string, number>>({});
|
|
81
|
-
const [dragStartIndex, setDragStartIndex] = useState<number | null>(null);
|
|
82
|
-
const [dragOverIndex, setDragOverIndex] = useState<number | null>(null);
|
|
83
|
-
|
|
84
|
-
const {
|
|
85
|
-
displayData,
|
|
86
|
-
sortConfig,
|
|
87
|
-
currentPage,
|
|
88
|
-
totalPages,
|
|
89
|
-
handleSort,
|
|
90
|
-
handlePageChange,
|
|
91
|
-
handleSearch,
|
|
92
|
-
selectedRowIds,
|
|
93
|
-
selectedRows,
|
|
94
|
-
handleRowSelect,
|
|
95
|
-
handleSelectAll,
|
|
96
|
-
isAllSelected,
|
|
97
|
-
isIndeterminate,
|
|
98
|
-
visibleColumns,
|
|
99
|
-
columnVisibility,
|
|
100
|
-
handleColumnVisibilityToggle,
|
|
101
|
-
columnFilterValues,
|
|
102
|
-
handleColumnFilterChange,
|
|
103
|
-
clearColumnFilters,
|
|
104
|
-
} = useDataTable({
|
|
40
|
+
export const DataTable: React.FC<DataTableProps> = memo(
|
|
41
|
+
({
|
|
105
42
|
data,
|
|
106
43
|
columns,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
44
|
+
className,
|
|
45
|
+
style,
|
|
46
|
+
sortable = false,
|
|
47
|
+
filterable = false,
|
|
48
|
+
paginated = false,
|
|
49
|
+
pageSize = 10,
|
|
50
|
+
striped = false,
|
|
51
|
+
bordered = false,
|
|
52
|
+
dense = false,
|
|
53
|
+
loading = false,
|
|
54
|
+
emptyMessage = 'No data available',
|
|
55
|
+
onRowClick,
|
|
110
56
|
onSort,
|
|
111
|
-
selectionMode,
|
|
57
|
+
selectionMode = 'none',
|
|
112
58
|
selectedRowIds: controlledSelectedRowIds,
|
|
113
59
|
onSelectionChange,
|
|
114
60
|
rowKey,
|
|
115
|
-
|
|
116
|
-
reorderable,
|
|
61
|
+
resizable = false,
|
|
62
|
+
reorderable = false,
|
|
117
63
|
onColumnReorder,
|
|
64
|
+
showColumnVisibility = false,
|
|
118
65
|
onColumnVisibilityChange,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
66
|
+
stickyHeader = false,
|
|
67
|
+
stickyHeaderOffset = '0px',
|
|
68
|
+
virtualScrolling = false,
|
|
69
|
+
estimatedRowHeight = 50,
|
|
70
|
+
overscan = 5,
|
|
71
|
+
exportable = false,
|
|
72
|
+
exportFormats = ['csv', 'excel', 'json'],
|
|
73
|
+
exportFilename = 'data-table',
|
|
74
|
+
onExport,
|
|
75
|
+
columnFilters = false,
|
|
76
|
+
...props
|
|
77
|
+
}) => {
|
|
78
|
+
const tableRef = useRef<HTMLTableElement>(null);
|
|
79
|
+
const headerRef = useRef<HTMLTableSectionElement>(null);
|
|
80
|
+
const [resizingColumn, setResizingColumn] = useState<string | null>(null);
|
|
81
|
+
const [columnWidths, setColumnWidths] = useState<Record<string, number>>({});
|
|
82
|
+
const [dragStartIndex, setDragStartIndex] = useState<number | null>(null);
|
|
83
|
+
const [dragOverIndex, setDragOverIndex] = useState<number | null>(null);
|
|
84
|
+
|
|
85
|
+
const {
|
|
86
|
+
displayData,
|
|
87
|
+
sortConfig,
|
|
88
|
+
currentPage,
|
|
89
|
+
totalPages,
|
|
90
|
+
handleSort,
|
|
91
|
+
handlePageChange,
|
|
92
|
+
handleSearch,
|
|
93
|
+
selectedRowIds,
|
|
94
|
+
selectedRows,
|
|
95
|
+
handleRowSelect,
|
|
96
|
+
handleSelectAll,
|
|
97
|
+
isAllSelected,
|
|
98
|
+
isIndeterminate,
|
|
99
|
+
visibleColumns,
|
|
100
|
+
columnVisibility,
|
|
101
|
+
handleColumnVisibilityToggle,
|
|
102
|
+
columnFilterValues,
|
|
103
|
+
handleColumnFilterChange,
|
|
104
|
+
clearColumnFilters,
|
|
105
|
+
} = useDataTable({
|
|
106
|
+
data,
|
|
107
|
+
columns,
|
|
108
|
+
sortable,
|
|
109
|
+
paginated,
|
|
110
|
+
pageSize,
|
|
111
|
+
onSort,
|
|
112
|
+
selectionMode,
|
|
113
|
+
selectedRowIds: controlledSelectedRowIds,
|
|
114
|
+
onSelectionChange,
|
|
115
|
+
rowKey,
|
|
116
|
+
columnFilters,
|
|
117
|
+
reorderable,
|
|
118
|
+
onColumnReorder,
|
|
119
|
+
onColumnVisibilityChange,
|
|
131
120
|
});
|
|
132
|
-
setColumnWidths(widths);
|
|
133
|
-
}, [visibleColumns]);
|
|
134
|
-
|
|
135
|
-
// Handle column resize start
|
|
136
|
-
const handleResizeStart = useCallback((columnKey: string, e: React.MouseEvent) => {
|
|
137
|
-
e.preventDefault();
|
|
138
|
-
e.stopPropagation();
|
|
139
|
-
setResizingColumn(columnKey);
|
|
140
|
-
|
|
141
|
-
const startX = e.clientX;
|
|
142
|
-
const startWidth = columnWidths[columnKey] || 100;
|
|
143
|
-
|
|
144
|
-
const handleMouseMove = (moveEvent: MouseEvent) => {
|
|
145
|
-
const diff = moveEvent.clientX - startX;
|
|
146
|
-
const newWidth = Math.max(50, startWidth + diff); // Minimum width of 50px
|
|
147
|
-
|
|
148
|
-
setColumnWidths(prev => ({
|
|
149
|
-
...prev,
|
|
150
|
-
[columnKey]: newWidth,
|
|
151
|
-
}));
|
|
152
|
-
};
|
|
153
121
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
122
|
+
// Initialize column widths
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
const widths: Record<string, number> = {};
|
|
125
|
+
visibleColumns.forEach(col => {
|
|
126
|
+
if (col.width) {
|
|
127
|
+
const widthValue = parseInt(col.width, 10);
|
|
128
|
+
if (!isNaN(widthValue)) {
|
|
129
|
+
widths[col.key] = widthValue;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
setColumnWidths(widths);
|
|
134
|
+
}, [visibleColumns]);
|
|
135
|
+
|
|
136
|
+
// Handle column resize start
|
|
137
|
+
const handleResizeStart = useCallback(
|
|
138
|
+
(columnKey: string, e: React.MouseEvent) => {
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
e.stopPropagation();
|
|
141
|
+
setResizingColumn(columnKey);
|
|
142
|
+
|
|
143
|
+
const startX = e.clientX;
|
|
144
|
+
const startWidth = columnWidths[columnKey] || 100;
|
|
145
|
+
|
|
146
|
+
const handleMouseMove = (moveEvent: MouseEvent) => {
|
|
147
|
+
const diff = moveEvent.clientX - startX;
|
|
148
|
+
const newWidth = Math.max(50, startWidth + diff); // Minimum width of 50px
|
|
149
|
+
|
|
150
|
+
setColumnWidths(prev => ({
|
|
151
|
+
...prev,
|
|
152
|
+
[columnKey]: newWidth,
|
|
153
|
+
}));
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const handleMouseUp = () => {
|
|
157
|
+
setResizingColumn(null);
|
|
158
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
159
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
163
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
164
|
+
},
|
|
165
|
+
[columnWidths]
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
// Handle column drag start
|
|
169
|
+
const handleDragStart = useCallback((index: number) => {
|
|
170
|
+
setDragStartIndex(index);
|
|
171
|
+
}, []);
|
|
172
|
+
|
|
173
|
+
// Handle column drag over
|
|
174
|
+
const handleDragOver = useCallback((e: React.DragEvent, index: number) => {
|
|
175
|
+
e.preventDefault();
|
|
176
|
+
setDragOverIndex(index);
|
|
177
|
+
}, []);
|
|
178
|
+
|
|
179
|
+
// Handle column drop
|
|
180
|
+
const handleDrop = useCallback(
|
|
181
|
+
(e: React.DragEvent, dropIndex: number) => {
|
|
182
|
+
e.preventDefault();
|
|
183
|
+
if (dragStartIndex !== null && dragStartIndex !== dropIndex && onColumnReorder) {
|
|
184
|
+
const newOrder = [...visibleColumns.map(col => col.key)];
|
|
185
|
+
const [removed] = newOrder.splice(dragStartIndex, 1);
|
|
186
|
+
if (removed) {
|
|
187
|
+
newOrder.splice(dropIndex, 0, removed);
|
|
188
|
+
onColumnReorder(newOrder);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
setDragStartIndex(null);
|
|
192
|
+
setDragOverIndex(null);
|
|
193
|
+
},
|
|
194
|
+
[dragStartIndex, visibleColumns, onColumnReorder]
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
// Handle export
|
|
198
|
+
const handleExport = useCallback(
|
|
199
|
+
(format: ExportFormat) => {
|
|
200
|
+
if (onExport) {
|
|
201
|
+
onExport(format, displayData);
|
|
202
|
+
} else {
|
|
203
|
+
exportData(format, displayData, visibleColumns, exportFilename);
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
[displayData, visibleColumns, exportFilename, onExport]
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
// Generate component classes
|
|
210
|
+
const tableClass = [
|
|
211
|
+
DATA_TABLE_CLASSES.base,
|
|
212
|
+
striped && DATA_TABLE_CLASSES.striped,
|
|
213
|
+
bordered && DATA_TABLE_CLASSES.bordered,
|
|
214
|
+
dense && DATA_TABLE_CLASSES.dense,
|
|
215
|
+
loading && DATA_TABLE_CLASSES.loading,
|
|
216
|
+
stickyHeader && DATA_TABLE_CLASSES.stickyHeader,
|
|
217
|
+
className,
|
|
218
|
+
]
|
|
219
|
+
.filter(Boolean)
|
|
220
|
+
.join(' ');
|
|
221
|
+
|
|
222
|
+
const containerStyle: React.CSSProperties = {
|
|
223
|
+
...style,
|
|
224
|
+
...(stickyHeader &&
|
|
225
|
+
({
|
|
226
|
+
'--sticky-header-offset': stickyHeaderOffset,
|
|
227
|
+
} as React.CSSProperties)),
|
|
158
228
|
};
|
|
159
229
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}, [columnWidths]);
|
|
163
|
-
|
|
164
|
-
// Handle column drag start
|
|
165
|
-
const handleDragStart = useCallback((index: number) => {
|
|
166
|
-
setDragStartIndex(index);
|
|
167
|
-
}, []);
|
|
168
|
-
|
|
169
|
-
// Handle column drag over
|
|
170
|
-
const handleDragOver = useCallback((e: React.DragEvent, index: number) => {
|
|
171
|
-
e.preventDefault();
|
|
172
|
-
setDragOverIndex(index);
|
|
173
|
-
}, []);
|
|
174
|
-
|
|
175
|
-
// Handle column drop
|
|
176
|
-
const handleDrop = useCallback((e: React.DragEvent, dropIndex: number) => {
|
|
177
|
-
e.preventDefault();
|
|
178
|
-
if (dragStartIndex !== null && dragStartIndex !== dropIndex && onColumnReorder) {
|
|
179
|
-
const newOrder = [...visibleColumns.map(col => col.key)];
|
|
180
|
-
const [removed] = newOrder.splice(dragStartIndex, 1);
|
|
181
|
-
if (removed) {
|
|
182
|
-
newOrder.splice(dropIndex, 0, removed);
|
|
183
|
-
onColumnReorder(newOrder);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
setDragStartIndex(null);
|
|
187
|
-
setDragOverIndex(null);
|
|
188
|
-
}, [dragStartIndex, visibleColumns, onColumnReorder]);
|
|
189
|
-
|
|
190
|
-
// Handle export
|
|
191
|
-
const handleExport = useCallback((format: ExportFormat) => {
|
|
192
|
-
if (onExport) {
|
|
193
|
-
onExport(format, displayData);
|
|
194
|
-
} else {
|
|
195
|
-
exportData(format, displayData, visibleColumns, exportFilename);
|
|
196
|
-
}
|
|
197
|
-
}, [displayData, visibleColumns, exportFilename, onExport]);
|
|
198
|
-
|
|
199
|
-
// Generate component classes
|
|
200
|
-
const tableClass = [
|
|
201
|
-
DATA_TABLE_CLASSES.base,
|
|
202
|
-
striped && DATA_TABLE_CLASSES.striped,
|
|
203
|
-
bordered && DATA_TABLE_CLASSES.bordered,
|
|
204
|
-
dense && DATA_TABLE_CLASSES.dense,
|
|
205
|
-
loading && DATA_TABLE_CLASSES.loading,
|
|
206
|
-
stickyHeader && DATA_TABLE_CLASSES.stickyHeader,
|
|
207
|
-
className,
|
|
208
|
-
]
|
|
209
|
-
.filter(Boolean)
|
|
210
|
-
.join(' ');
|
|
230
|
+
const renderSelectionHeader = () => {
|
|
231
|
+
if (selectionMode === 'none') return null;
|
|
211
232
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
233
|
+
return (
|
|
234
|
+
<th
|
|
235
|
+
className={`${DATA_TABLE_CLASSES.headerCell} ${DATA_TABLE_CLASSES.selectionCell}`}
|
|
236
|
+
style={{ width: '48px' }}
|
|
237
|
+
>
|
|
238
|
+
{selectionMode === 'multiple' && (
|
|
239
|
+
<Checkbox
|
|
240
|
+
checked={isAllSelected}
|
|
241
|
+
indeterminate={isIndeterminate}
|
|
242
|
+
onChange={e => handleSelectAll(e.target.checked)}
|
|
243
|
+
aria-label="Select all rows"
|
|
244
|
+
/>
|
|
245
|
+
)}
|
|
246
|
+
</th>
|
|
247
|
+
);
|
|
248
|
+
};
|
|
218
249
|
|
|
219
|
-
|
|
220
|
-
|
|
250
|
+
const renderHeader = () => {
|
|
251
|
+
return (
|
|
252
|
+
<thead
|
|
253
|
+
ref={headerRef}
|
|
254
|
+
className={DATA_TABLE_CLASSES.header}
|
|
255
|
+
style={
|
|
256
|
+
stickyHeader ? { position: 'sticky', top: stickyHeaderOffset, zIndex: 10 } : undefined
|
|
257
|
+
}
|
|
258
|
+
>
|
|
259
|
+
<tr>
|
|
260
|
+
{renderSelectionHeader()}
|
|
261
|
+
{visibleColumns.map((column, index) => {
|
|
262
|
+
const isDragging = dragStartIndex === index;
|
|
263
|
+
const isDragOver = dragOverIndex === index;
|
|
264
|
+
|
|
265
|
+
return (
|
|
266
|
+
<th
|
|
267
|
+
key={`header-${column.key}`}
|
|
268
|
+
className={[
|
|
269
|
+
DATA_TABLE_CLASSES.headerCell,
|
|
270
|
+
column.sortable !== false && sortable ? DATA_TABLE_CLASSES.sortable : '',
|
|
271
|
+
isDragging ? DATA_TABLE_CLASSES.dragging : '',
|
|
272
|
+
isDragOver ? DATA_TABLE_CLASSES.dragOver : '',
|
|
273
|
+
]
|
|
274
|
+
.filter(Boolean)
|
|
275
|
+
.join(' ')}
|
|
276
|
+
style={{
|
|
277
|
+
...(columnWidths[column.key] && { width: `${columnWidths[column.key]}px` }),
|
|
278
|
+
...(column.width && !columnWidths[column.key] && { width: column.width }),
|
|
279
|
+
}}
|
|
280
|
+
onClick={() =>
|
|
281
|
+
column.sortable !== false && sortable ? handleSort(column.key) : null
|
|
282
|
+
}
|
|
283
|
+
onDragStart={reorderable ? () => handleDragStart(index) : undefined}
|
|
284
|
+
onDragOver={reorderable ? e => handleDragOver(e, index) : undefined}
|
|
285
|
+
onDrop={reorderable ? e => handleDrop(e, index) : undefined}
|
|
286
|
+
draggable={reorderable}
|
|
287
|
+
aria-sort={
|
|
288
|
+
sortConfig?.key === column.key
|
|
289
|
+
? sortConfig.direction === 'asc'
|
|
290
|
+
? 'ascending'
|
|
291
|
+
: 'descending'
|
|
292
|
+
: undefined
|
|
293
|
+
}
|
|
294
|
+
>
|
|
295
|
+
<div className={DATA_TABLE_CLASSES.headerContent}>
|
|
296
|
+
<span>{column.title}</span>
|
|
297
|
+
<div className={DATA_TABLE_CLASSES.headerActions}>
|
|
298
|
+
{column.sortable !== false && sortable && (
|
|
299
|
+
<span className={DATA_TABLE_CLASSES.sortIcon}>
|
|
300
|
+
{sortConfig?.key === column.key ? (
|
|
301
|
+
sortConfig.direction === 'asc' ? (
|
|
302
|
+
<Icon name="CaretUp" size="sm" />
|
|
303
|
+
) : (
|
|
304
|
+
<Icon name="CaretDown" size="sm" />
|
|
305
|
+
)
|
|
306
|
+
) : null}
|
|
307
|
+
</span>
|
|
308
|
+
)}
|
|
309
|
+
{columnFilters && column.filterable !== false && (
|
|
310
|
+
<input
|
|
311
|
+
type="text"
|
|
312
|
+
className={DATA_TABLE_CLASSES.columnFilter}
|
|
313
|
+
placeholder="Filter..."
|
|
314
|
+
value={columnFilterValues[column.key] || ''}
|
|
315
|
+
onChange={e => handleColumnFilterChange(column.key, e.target.value)}
|
|
316
|
+
onClick={e => e.stopPropagation()}
|
|
317
|
+
aria-label={`Filter ${column.title}`}
|
|
318
|
+
/>
|
|
319
|
+
)}
|
|
320
|
+
</div>
|
|
321
|
+
</div>
|
|
322
|
+
{resizable && column.resizable !== false && (
|
|
323
|
+
<div
|
|
324
|
+
className={DATA_TABLE_CLASSES.resizeHandle}
|
|
325
|
+
onMouseDown={e => handleResizeStart(column.key, e)}
|
|
326
|
+
/>
|
|
327
|
+
)}
|
|
328
|
+
</th>
|
|
329
|
+
);
|
|
330
|
+
})}
|
|
331
|
+
</tr>
|
|
332
|
+
</thead>
|
|
333
|
+
);
|
|
334
|
+
};
|
|
221
335
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
336
|
+
const renderBody = () => {
|
|
337
|
+
if (loading) {
|
|
338
|
+
return (
|
|
339
|
+
<tbody>
|
|
340
|
+
<tr>
|
|
341
|
+
<td
|
|
342
|
+
colSpan={visibleColumns.length + (selectionMode !== 'none' ? 1 : 0)}
|
|
343
|
+
className={DATA_TABLE_CLASSES.loadingCell}
|
|
344
|
+
>
|
|
345
|
+
<div className={DATA_TABLE_CLASSES.loadingIndicator}>
|
|
346
|
+
<Spinner size="md" variant="primary" />
|
|
347
|
+
</div>
|
|
348
|
+
</td>
|
|
349
|
+
</tr>
|
|
350
|
+
</tbody>
|
|
351
|
+
);
|
|
352
|
+
}
|
|
238
353
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
354
|
+
if (displayData.length === 0) {
|
|
355
|
+
return (
|
|
356
|
+
<tbody>
|
|
357
|
+
<tr>
|
|
358
|
+
<td
|
|
359
|
+
colSpan={visibleColumns.length + (selectionMode !== 'none' ? 1 : 0)}
|
|
360
|
+
className={DATA_TABLE_CLASSES.emptyCell}
|
|
361
|
+
>
|
|
362
|
+
{emptyMessage}
|
|
363
|
+
</td>
|
|
364
|
+
</tr>
|
|
365
|
+
</tbody>
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return (
|
|
370
|
+
<tbody>
|
|
371
|
+
{displayData.map((row: any, rowIndex: number) => {
|
|
372
|
+
const rowId = getRowId(row, rowKey);
|
|
373
|
+
const isSelected = selectedRowIds.includes(rowId);
|
|
251
374
|
|
|
252
375
|
return (
|
|
253
|
-
<
|
|
254
|
-
key={`
|
|
376
|
+
<tr
|
|
377
|
+
key={`row-${rowId}`}
|
|
255
378
|
className={[
|
|
256
|
-
DATA_TABLE_CLASSES.
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}}
|
|
265
|
-
onClick={() => column.sortable !== false && sortable ? handleSort(column.key) : null}
|
|
266
|
-
onDragStart={reorderable ? () => handleDragStart(index) : undefined}
|
|
267
|
-
onDragOver={reorderable ? (e) => handleDragOver(e, index) : undefined}
|
|
268
|
-
onDrop={reorderable ? (e) => handleDrop(e, index) : undefined}
|
|
269
|
-
draggable={reorderable}
|
|
270
|
-
aria-sort={
|
|
271
|
-
sortConfig?.key === column.key
|
|
272
|
-
? sortConfig.direction === 'asc'
|
|
273
|
-
? 'ascending'
|
|
274
|
-
: 'descending'
|
|
275
|
-
: undefined
|
|
276
|
-
}
|
|
379
|
+
DATA_TABLE_CLASSES.row,
|
|
380
|
+
isSelected ? DATA_TABLE_CLASSES.rowSelected : '',
|
|
381
|
+
]
|
|
382
|
+
.filter(Boolean)
|
|
383
|
+
.join(' ')}
|
|
384
|
+
onClick={onRowClick ? () => onRowClick(row) : undefined}
|
|
385
|
+
tabIndex={onRowClick ? 0 : undefined}
|
|
386
|
+
role={onRowClick ? 'button' : undefined}
|
|
277
387
|
>
|
|
278
|
-
|
|
279
|
-
<
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
{
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
</span>
|
|
291
|
-
)}
|
|
292
|
-
{columnFilters && column.filterable !== false && (
|
|
388
|
+
{selectionMode !== 'none' && (
|
|
389
|
+
<td className={`${DATA_TABLE_CLASSES.cell} ${DATA_TABLE_CLASSES.selectionCell}`}>
|
|
390
|
+
{selectionMode === 'multiple' ? (
|
|
391
|
+
<Checkbox
|
|
392
|
+
checked={isSelected}
|
|
393
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
|
|
394
|
+
handleRowSelect(rowId, e.target.checked)
|
|
395
|
+
}
|
|
396
|
+
onClick={(e: React.MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
397
|
+
aria-label={`Select row ${rowIndex + 1}`}
|
|
398
|
+
/>
|
|
399
|
+
) : (
|
|
293
400
|
<input
|
|
294
|
-
type="
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
401
|
+
type="radio"
|
|
402
|
+
checked={isSelected}
|
|
403
|
+
onChange={() => handleRowSelect(rowId, true)}
|
|
404
|
+
onClick={e => e.stopPropagation()}
|
|
405
|
+
name="data-table-row-selection"
|
|
406
|
+
aria-label={`Select row ${rowIndex + 1}`}
|
|
407
|
+
className="c-data-table__radio"
|
|
301
408
|
/>
|
|
302
409
|
)}
|
|
303
|
-
</
|
|
304
|
-
</div>
|
|
305
|
-
{resizable && (column.resizable !== false) && (
|
|
306
|
-
<div
|
|
307
|
-
className={DATA_TABLE_CLASSES.resizeHandle}
|
|
308
|
-
onMouseDown={(e) => handleResizeStart(column.key, e)}
|
|
309
|
-
/>
|
|
410
|
+
</td>
|
|
310
411
|
)}
|
|
311
|
-
|
|
412
|
+
{visibleColumns.map(column => (
|
|
413
|
+
<td
|
|
414
|
+
key={`cell-${rowId}-${column.key}`}
|
|
415
|
+
className={DATA_TABLE_CLASSES.cell}
|
|
416
|
+
style={{
|
|
417
|
+
...(columnWidths[column.key] && { width: `${columnWidths[column.key]}px` }),
|
|
418
|
+
...(column.width && !columnWidths[column.key] && { width: column.width }),
|
|
419
|
+
}}
|
|
420
|
+
>
|
|
421
|
+
{column.render ? column.render(row[column.key], row) : row[column.key]}
|
|
422
|
+
</td>
|
|
423
|
+
))}
|
|
424
|
+
</tr>
|
|
312
425
|
);
|
|
313
426
|
})}
|
|
314
|
-
</tr>
|
|
315
|
-
</thead>
|
|
316
|
-
);
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
const renderBody = () => {
|
|
320
|
-
if (loading) {
|
|
321
|
-
return (
|
|
322
|
-
<tbody>
|
|
323
|
-
<tr>
|
|
324
|
-
<td colSpan={visibleColumns.length + (selectionMode !== 'none' ? 1 : 0)} className={DATA_TABLE_CLASSES.loadingCell}>
|
|
325
|
-
<div className={DATA_TABLE_CLASSES.loadingIndicator}>
|
|
326
|
-
<Spinner size="md" variant="primary" />
|
|
327
|
-
</div>
|
|
328
|
-
</td>
|
|
329
|
-
</tr>
|
|
330
427
|
</tbody>
|
|
331
428
|
);
|
|
332
|
-
}
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
const renderPagination = () => {
|
|
432
|
+
if (!paginated || totalPages <= 1) return null;
|
|
333
433
|
|
|
334
|
-
if (displayData.length === 0) {
|
|
335
434
|
return (
|
|
336
|
-
<
|
|
337
|
-
<
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
435
|
+
<div className={DATA_TABLE_CLASSES.pagination}>
|
|
436
|
+
<Pagination
|
|
437
|
+
currentPage={currentPage}
|
|
438
|
+
totalPages={totalPages}
|
|
439
|
+
onPageChange={handlePageChange}
|
|
440
|
+
showFirstLastButtons={true}
|
|
441
|
+
showPrevNextButtons={true}
|
|
442
|
+
size="sm"
|
|
443
|
+
aria-label="Data table pagination"
|
|
444
|
+
className="c-data-table__pagination"
|
|
445
|
+
/>
|
|
446
|
+
</div>
|
|
343
447
|
);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
return (
|
|
347
|
-
<tbody>
|
|
348
|
-
{displayData.map((row: any, rowIndex: number) => {
|
|
349
|
-
const rowId = getRowId(row, rowKey);
|
|
350
|
-
const isSelected = selectedRowIds.includes(rowId);
|
|
351
|
-
|
|
352
|
-
return (
|
|
353
|
-
<tr
|
|
354
|
-
key={`row-${rowId}`}
|
|
355
|
-
className={[
|
|
356
|
-
DATA_TABLE_CLASSES.row,
|
|
357
|
-
isSelected ? DATA_TABLE_CLASSES.rowSelected : '',
|
|
358
|
-
].filter(Boolean).join(' ')}
|
|
359
|
-
onClick={onRowClick ? () => onRowClick(row) : undefined}
|
|
360
|
-
tabIndex={onRowClick ? 0 : undefined}
|
|
361
|
-
role={onRowClick ? 'button' : undefined}
|
|
362
|
-
>
|
|
363
|
-
{selectionMode !== 'none' && (
|
|
364
|
-
<td className={`${DATA_TABLE_CLASSES.cell} ${DATA_TABLE_CLASSES.selectionCell}`}>
|
|
365
|
-
{selectionMode === 'multiple' ? (
|
|
366
|
-
<Checkbox
|
|
367
|
-
checked={isSelected}
|
|
368
|
-
onChange={(e: React.ChangeEvent<HTMLInputElement>) => handleRowSelect(rowId, e.target.checked)}
|
|
369
|
-
onClick={(e: React.MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
370
|
-
aria-label={`Select row ${rowIndex + 1}`}
|
|
371
|
-
/>
|
|
372
|
-
) : (
|
|
373
|
-
<input
|
|
374
|
-
type="radio"
|
|
375
|
-
checked={isSelected}
|
|
376
|
-
onChange={() => handleRowSelect(rowId, true)}
|
|
377
|
-
onClick={(e) => e.stopPropagation()}
|
|
378
|
-
name="data-table-row-selection"
|
|
379
|
-
aria-label={`Select row ${rowIndex + 1}`}
|
|
380
|
-
className="c-data-table__radio"
|
|
381
|
-
/>
|
|
382
|
-
)}
|
|
383
|
-
</td>
|
|
384
|
-
)}
|
|
385
|
-
{visibleColumns.map((column) => (
|
|
386
|
-
<td
|
|
387
|
-
key={`cell-${rowId}-${column.key}`}
|
|
388
|
-
className={DATA_TABLE_CLASSES.cell}
|
|
389
|
-
style={{
|
|
390
|
-
...(columnWidths[column.key] && { width: `${columnWidths[column.key]}px` }),
|
|
391
|
-
...(column.width && !columnWidths[column.key] && { width: column.width }),
|
|
392
|
-
}}
|
|
393
|
-
>
|
|
394
|
-
{column.render ? column.render(row[column.key], row) : row[column.key]}
|
|
395
|
-
</td>
|
|
396
|
-
))}
|
|
397
|
-
</tr>
|
|
398
|
-
);
|
|
399
|
-
})}
|
|
400
|
-
</tbody>
|
|
401
|
-
);
|
|
402
|
-
};
|
|
448
|
+
};
|
|
403
449
|
|
|
404
|
-
|
|
405
|
-
|
|
450
|
+
const renderToolbar = () => {
|
|
451
|
+
const hasToolbar = filterable || exportable || showColumnVisibility || columnFilters;
|
|
452
|
+
if (!hasToolbar) return null;
|
|
406
453
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
454
|
+
return (
|
|
455
|
+
<div className={DATA_TABLE_CLASSES.toolbar}>
|
|
456
|
+
<div className={DATA_TABLE_CLASSES.toolbarLeft}>
|
|
457
|
+
{filterable && (
|
|
458
|
+
<div className={DATA_TABLE_CLASSES.search}>
|
|
459
|
+
<input
|
|
460
|
+
type="text"
|
|
461
|
+
placeholder="Search..."
|
|
462
|
+
className={`${DATA_TABLE_CLASSES.searchInput} c-input`}
|
|
463
|
+
onChange={e => handleSearch(e.target.value)}
|
|
464
|
+
aria-label="Search table"
|
|
465
|
+
/>
|
|
466
|
+
</div>
|
|
467
|
+
)}
|
|
468
|
+
{columnFilters && Object.keys(columnFilterValues).length > 0 && (
|
|
469
|
+
<Button size="sm" variant="secondary" onClick={clearColumnFilters}>
|
|
470
|
+
Clear Filters
|
|
471
|
+
</Button>
|
|
472
|
+
)}
|
|
473
|
+
</div>
|
|
474
|
+
<div className={DATA_TABLE_CLASSES.toolbarRight}>
|
|
475
|
+
{showColumnVisibility && (
|
|
476
|
+
<Dropdown
|
|
477
|
+
trigger="click"
|
|
478
|
+
placement="bottom-end"
|
|
479
|
+
menu={
|
|
480
|
+
<>
|
|
481
|
+
{columns.map(column => (
|
|
482
|
+
<DropdownItem
|
|
483
|
+
key={column.key}
|
|
484
|
+
onClick={e => {
|
|
485
|
+
e.preventDefault();
|
|
486
|
+
e.stopPropagation();
|
|
487
|
+
handleColumnVisibilityToggle(column.key);
|
|
488
|
+
}}
|
|
489
|
+
>
|
|
490
|
+
<label
|
|
491
|
+
style={{
|
|
492
|
+
display: 'flex',
|
|
493
|
+
alignItems: 'center',
|
|
494
|
+
cursor: 'pointer',
|
|
495
|
+
width: '100%',
|
|
496
|
+
}}
|
|
497
|
+
>
|
|
498
|
+
<Checkbox
|
|
499
|
+
checked={columnVisibility[column.key] !== false}
|
|
500
|
+
onChange={() => handleColumnVisibilityToggle(column.key)}
|
|
501
|
+
onClick={(e: React.MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
502
|
+
/>
|
|
503
|
+
<span style={{ marginLeft: '0.5rem' }}>{column.title}</span>
|
|
504
|
+
</label>
|
|
505
|
+
</DropdownItem>
|
|
506
|
+
))}
|
|
507
|
+
</>
|
|
508
|
+
}
|
|
509
|
+
>
|
|
510
|
+
<Button size="sm" variant="secondary">
|
|
511
|
+
<Icon name="Columns" size="sm" />
|
|
512
|
+
Columns
|
|
513
|
+
</Button>
|
|
514
|
+
</Dropdown>
|
|
515
|
+
)}
|
|
516
|
+
{exportable && (
|
|
517
|
+
<Dropdown
|
|
518
|
+
trigger="click"
|
|
519
|
+
placement="bottom-end"
|
|
520
|
+
menu={
|
|
521
|
+
<>
|
|
522
|
+
{exportFormats.includes('csv') && (
|
|
523
|
+
<DropdownItem onClick={() => handleExport('csv')}>Export as CSV</DropdownItem>
|
|
524
|
+
)}
|
|
525
|
+
{exportFormats.includes('excel') && (
|
|
526
|
+
<DropdownItem onClick={() => handleExport('excel')}>
|
|
527
|
+
Export as Excel
|
|
528
|
+
</DropdownItem>
|
|
529
|
+
)}
|
|
530
|
+
{exportFormats.includes('json') && (
|
|
531
|
+
<DropdownItem onClick={() => handleExport('json')}>
|
|
532
|
+
Export as JSON
|
|
533
|
+
</DropdownItem>
|
|
534
|
+
)}
|
|
535
|
+
</>
|
|
536
|
+
}
|
|
537
|
+
>
|
|
538
|
+
<Button size="sm" variant="secondary">
|
|
539
|
+
<Icon name="Download" size="sm" />
|
|
540
|
+
Export
|
|
541
|
+
</Button>
|
|
542
|
+
</Dropdown>
|
|
543
|
+
)}
|
|
544
|
+
</div>
|
|
545
|
+
</div>
|
|
546
|
+
);
|
|
547
|
+
};
|
|
426
548
|
|
|
427
549
|
return (
|
|
428
|
-
<div className={DATA_TABLE_CLASSES.
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
className={`${DATA_TABLE_CLASSES.searchInput} c-input`}
|
|
436
|
-
onChange={e => handleSearch(e.target.value)}
|
|
437
|
-
aria-label="Search table"
|
|
438
|
-
/>
|
|
439
|
-
</div>
|
|
440
|
-
)}
|
|
441
|
-
{columnFilters && Object.keys(columnFilterValues).length > 0 && (
|
|
442
|
-
<Button
|
|
443
|
-
size="sm"
|
|
444
|
-
variant="secondary"
|
|
445
|
-
onClick={clearColumnFilters}
|
|
446
|
-
>
|
|
447
|
-
Clear Filters
|
|
448
|
-
</Button>
|
|
449
|
-
)}
|
|
450
|
-
</div>
|
|
451
|
-
<div className={DATA_TABLE_CLASSES.toolbarRight}>
|
|
452
|
-
{showColumnVisibility && (
|
|
453
|
-
<Dropdown
|
|
454
|
-
trigger="click"
|
|
455
|
-
placement="bottom-end"
|
|
456
|
-
menu={
|
|
457
|
-
<>
|
|
458
|
-
{columns.map((column) => (
|
|
459
|
-
<DropdownItem
|
|
460
|
-
key={column.key}
|
|
461
|
-
onClick={(e) => {
|
|
462
|
-
e.preventDefault();
|
|
463
|
-
e.stopPropagation();
|
|
464
|
-
handleColumnVisibilityToggle(column.key);
|
|
465
|
-
}}
|
|
466
|
-
>
|
|
467
|
-
<label style={{ display: 'flex', alignItems: 'center', cursor: 'pointer', width: '100%' }}>
|
|
468
|
-
<Checkbox
|
|
469
|
-
checked={columnVisibility[column.key] !== false}
|
|
470
|
-
onChange={() => handleColumnVisibilityToggle(column.key)}
|
|
471
|
-
onClick={(e: React.MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
472
|
-
/>
|
|
473
|
-
<span style={{ marginLeft: '0.5rem' }}>{column.title}</span>
|
|
474
|
-
</label>
|
|
475
|
-
</DropdownItem>
|
|
476
|
-
))}
|
|
477
|
-
</>
|
|
478
|
-
}
|
|
479
|
-
>
|
|
480
|
-
<Button size="sm" variant="secondary">
|
|
481
|
-
<Icon name="Columns" size="sm" />
|
|
482
|
-
Columns
|
|
483
|
-
</Button>
|
|
484
|
-
</Dropdown>
|
|
485
|
-
)}
|
|
486
|
-
{exportable && (
|
|
487
|
-
<Dropdown
|
|
488
|
-
trigger="click"
|
|
489
|
-
placement="bottom-end"
|
|
490
|
-
menu={
|
|
491
|
-
<>
|
|
492
|
-
{exportFormats.includes('csv') && (
|
|
493
|
-
<DropdownItem onClick={() => handleExport('csv')}>
|
|
494
|
-
Export as CSV
|
|
495
|
-
</DropdownItem>
|
|
496
|
-
)}
|
|
497
|
-
{exportFormats.includes('excel') && (
|
|
498
|
-
<DropdownItem onClick={() => handleExport('excel')}>
|
|
499
|
-
Export as Excel
|
|
500
|
-
</DropdownItem>
|
|
501
|
-
)}
|
|
502
|
-
{exportFormats.includes('json') && (
|
|
503
|
-
<DropdownItem onClick={() => handleExport('json')}>
|
|
504
|
-
Export as JSON
|
|
505
|
-
</DropdownItem>
|
|
506
|
-
)}
|
|
507
|
-
</>
|
|
508
|
-
}
|
|
509
|
-
>
|
|
510
|
-
<Button size="sm" variant="secondary">
|
|
511
|
-
<Icon name="Download" size="sm" />
|
|
512
|
-
Export
|
|
513
|
-
</Button>
|
|
514
|
-
</Dropdown>
|
|
515
|
-
)}
|
|
550
|
+
<div className={DATA_TABLE_CLASSES.container} style={containerStyle} {...props}>
|
|
551
|
+
{renderToolbar()}
|
|
552
|
+
<div className={DATA_TABLE_CLASSES.tableWrapper}>
|
|
553
|
+
<table ref={tableRef} className={tableClass}>
|
|
554
|
+
{renderHeader()}
|
|
555
|
+
{renderBody()}
|
|
556
|
+
</table>
|
|
516
557
|
</div>
|
|
558
|
+
{renderPagination()}
|
|
517
559
|
</div>
|
|
518
560
|
);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
return (
|
|
522
|
-
<div className={DATA_TABLE_CLASSES.container} style={containerStyle} {...props}>
|
|
523
|
-
{renderToolbar()}
|
|
524
|
-
<div className={DATA_TABLE_CLASSES.tableWrapper}>
|
|
525
|
-
<table ref={tableRef} className={tableClass}>
|
|
526
|
-
{renderHeader()}
|
|
527
|
-
{renderBody()}
|
|
528
|
-
</table>
|
|
529
|
-
</div>
|
|
530
|
-
{renderPagination()}
|
|
531
|
-
</div>
|
|
532
|
-
);
|
|
533
|
-
});
|
|
561
|
+
}
|
|
562
|
+
);
|
|
534
563
|
|
|
535
564
|
export type { DataTableProps };
|
|
536
565
|
|