@blenx-dev/core 0.1.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 +77 -0
- package/LICENSE +21 -0
- package/package.json +49 -0
- package/src/DataTable/data-table-column-toggle.tsx +73 -0
- package/src/DataTable/data-table-empty.tsx +27 -0
- package/src/DataTable/data-table-error.tsx +25 -0
- package/src/DataTable/data-table-infinite-loader.tsx +73 -0
- package/src/DataTable/data-table-loading.tsx +67 -0
- package/src/DataTable/data-table-pagination.tsx +80 -0
- package/src/DataTable/data-table-toolbar.tsx +62 -0
- package/src/DataTable/data-table.css.ts +420 -0
- package/src/DataTable/data-table.tsx +507 -0
- package/src/DataTable/index.ts +24 -0
- package/src/DataTable/types.ts +169 -0
- package/src/DataTable/use-infinite-scroll.ts +67 -0
- package/src/components/Accordion/accordion.css.ts +84 -0
- package/src/components/Accordion/accordion.tsx +87 -0
- package/src/components/Accordion/index.ts +8 -0
- package/src/components/Alert/alert.css.ts +29 -0
- package/src/components/Alert/alert.tsx +40 -0
- package/src/components/Alert/index.ts +1 -0
- package/src/components/AlertDialog/alert-dialog.css.ts +62 -0
- package/src/components/AlertDialog/alert-dialog.tsx +199 -0
- package/src/components/AlertDialog/index.ts +1 -0
- package/src/components/AspectRatio/aspect-ratio.css.ts +7 -0
- package/src/components/AspectRatio/aspect-ratio.tsx +20 -0
- package/src/components/AspectRatio/index.ts +1 -0
- package/src/components/Autocomplete/autocomplete.css.ts +167 -0
- package/src/components/Autocomplete/autocomplete.tsx +226 -0
- package/src/components/Autocomplete/index.ts +1 -0
- package/src/components/Avatar/avatar.css.ts +65 -0
- package/src/components/Avatar/avatar.tsx +44 -0
- package/src/components/Avatar/index.ts +1 -0
- package/src/components/Badge/badge.css.ts +180 -0
- package/src/components/Badge/badge.tsx +47 -0
- package/src/components/Badge/index.ts +1 -0
- package/src/components/Box/box.css.ts +5 -0
- package/src/components/Box/box.tsx +21 -0
- package/src/components/Box/index.ts +1 -0
- package/src/components/Breadcrumbs/breadcrumbs.css.ts +72 -0
- package/src/components/Breadcrumbs/breadcrumbs.tsx +79 -0
- package/src/components/Breadcrumbs/index.ts +9 -0
- package/src/components/Button/button.css.ts +200 -0
- package/src/components/Button/button.tsx +55 -0
- package/src/components/Button/index.ts +1 -0
- package/src/components/Calendar/calendar.css.ts +187 -0
- package/src/components/Calendar/calendar.tsx +143 -0
- package/src/components/Calendar/index.ts +1 -0
- package/src/components/Card/card.tsx +32 -0
- package/src/components/Card/index.ts +1 -0
- package/src/components/Checkbox/checkbox.css.ts +76 -0
- package/src/components/Checkbox/checkbox.tsx +94 -0
- package/src/components/Checkbox/index.ts +1 -0
- package/src/components/CloseButton/close-button.css.ts +11 -0
- package/src/components/CloseButton/close-button.tsx +15 -0
- package/src/components/CloseButton/index.ts +2 -0
- package/src/components/ColorPicker/color-picker.tsx +123 -0
- package/src/components/ColorPicker/index.ts +1 -0
- package/src/components/ColorSwatch/color-swatch.tsx +21 -0
- package/src/components/ColorSwatch/index.ts +1 -0
- package/src/components/Combobox/combobox.css.ts +333 -0
- package/src/components/Combobox/combobox.tsx +350 -0
- package/src/components/Combobox/index.ts +1 -0
- package/src/components/Command/command.css.ts +130 -0
- package/src/components/Command/command.tsx +413 -0
- package/src/components/Command/index.ts +7 -0
- package/src/components/Container/container.css.ts +41 -0
- package/src/components/Container/container.tsx +25 -0
- package/src/components/Container/index.ts +1 -0
- package/src/components/CopyButton/copy-button.css.ts +11 -0
- package/src/components/CopyButton/copy-button.tsx +45 -0
- package/src/components/CopyButton/index.ts +2 -0
- package/src/components/DatePicker/date-picker.tsx +75 -0
- package/src/components/DatePicker/index.ts +1 -0
- package/src/components/Dialog/dialog.css.ts +57 -0
- package/src/components/Dialog/dialog.tsx +181 -0
- package/src/components/Dialog/index.ts +1 -0
- package/src/components/Drawer/drawer.css.ts +404 -0
- package/src/components/Drawer/drawer.tsx +573 -0
- package/src/components/Drawer/index.ts +1 -0
- package/src/components/Field/field.css.ts +35 -0
- package/src/components/Field/field.tsx +101 -0
- package/src/components/Field/index.ts +1 -0
- package/src/components/Grid/grid.css.ts +12 -0
- package/src/components/Grid/grid.tsx +32 -0
- package/src/components/Grid/index.ts +1 -0
- package/src/components/Icon/icon.css.ts +10 -0
- package/src/components/Icon/icon.tsx +15 -0
- package/src/components/Icon/index.ts +1 -0
- package/src/components/IconButton/icon-button.css.ts +6 -0
- package/src/components/IconButton/icon-button.tsx +11 -0
- package/src/components/IconButton/index.ts +2 -0
- package/src/components/Input/index.ts +1 -0
- package/src/components/Input/input.css.ts +72 -0
- package/src/components/Input/input.tsx +50 -0
- package/src/components/InputGroup/index.ts +1 -0
- package/src/components/InputGroup/input-group.css.ts +156 -0
- package/src/components/InputGroup/input-group.tsx +133 -0
- package/src/components/Menu/index.ts +1 -0
- package/src/components/Menu/menu.css.ts +121 -0
- package/src/components/Menu/menu.tsx +115 -0
- package/src/components/OTPField/index.ts +1 -0
- package/src/components/OTPField/otp-field.css.ts +54 -0
- package/src/components/OTPField/otp-field.tsx +46 -0
- package/src/components/Popover/index.ts +1 -0
- package/src/components/Popover/popover.css.ts +81 -0
- package/src/components/Popover/popover.tsx +113 -0
- package/src/components/Progress/index.ts +7 -0
- package/src/components/Progress/progress.css.ts +37 -0
- package/src/components/Progress/progress.tsx +62 -0
- package/src/components/Radio/index.ts +1 -0
- package/src/components/Radio/radio.css.ts +72 -0
- package/src/components/Radio/radio.tsx +49 -0
- package/src/components/ScrollArea/index.ts +1 -0
- package/src/components/ScrollArea/scroll-area.css.ts +79 -0
- package/src/components/ScrollArea/scroll-area.tsx +96 -0
- package/src/components/SegmentedControl/index.ts +1 -0
- package/src/components/SegmentedControl/segmented-control.tsx +42 -0
- package/src/components/Select/index.ts +1 -0
- package/src/components/Select/select.css.ts +182 -0
- package/src/components/Select/select.tsx +165 -0
- package/src/components/Separator/index.ts +1 -0
- package/src/components/Separator/separator.css.ts +59 -0
- package/src/components/Separator/separator.tsx +34 -0
- package/src/components/Sheet/index.ts +1 -0
- package/src/components/Sheet/sheet.css.ts +184 -0
- package/src/components/Sheet/sheet.tsx +215 -0
- package/src/components/Slider/index.ts +1 -0
- package/src/components/Slider/slider.css.ts +81 -0
- package/src/components/Slider/slider.tsx +100 -0
- package/src/components/Spinner/index.ts +1 -0
- package/src/components/Spinner/spinner.css.ts +17 -0
- package/src/components/Spinner/spinner.tsx +15 -0
- package/src/components/Splitter/index.ts +1 -0
- package/src/components/Splitter/splitter.css.ts +69 -0
- package/src/components/Splitter/splitter.tsx +521 -0
- package/src/components/Stack/index.ts +1 -0
- package/src/components/Stack/stack.css.ts +42 -0
- package/src/components/Stack/stack.tsx +32 -0
- package/src/components/Surface/index.ts +1 -0
- package/src/components/Surface/surface.css.ts +40 -0
- package/src/components/Surface/surface.tsx +19 -0
- package/src/components/Switch/index.ts +1 -0
- package/src/components/Switch/switch.css.ts +46 -0
- package/src/components/Switch/switch.tsx +25 -0
- package/src/components/Table/index.ts +2 -0
- package/src/components/Table/table.css.ts +71 -0
- package/src/components/Table/table.tsx +117 -0
- package/src/components/Tabs/index.ts +1 -0
- package/src/components/Tabs/tabs.css.ts +250 -0
- package/src/components/Tabs/tabs.tsx +119 -0
- package/src/components/Text/index.ts +2 -0
- package/src/components/Text/text.css.ts +118 -0
- package/src/components/Text/text.tsx +66 -0
- package/src/components/Textarea/index.ts +1 -0
- package/src/components/Textarea/textarea.css.ts +66 -0
- package/src/components/Textarea/textarea.tsx +48 -0
- package/src/components/Toggle/index.ts +1 -0
- package/src/components/Toggle/toggle.css.ts +91 -0
- package/src/components/Toggle/toggle.tsx +44 -0
- package/src/components/ToggleGroup/index.ts +1 -0
- package/src/components/ToggleGroup/toggle-group.css.ts +77 -0
- package/src/components/ToggleGroup/toggle-group.tsx +131 -0
- package/src/components/index.ts +54 -0
- package/src/index.ts +3 -0
- package/src/utils/drawer-styles.css.ts +85 -0
- package/src/utils/heights.ts +16 -0
- package/src/utils/sprinkles.css.ts +197 -0
- package/src/utils/sprinkles.tokens.ts +74 -0
- package/src/utils/types.ts +10 -0
- package/src/utils/ve-style.utils.ts +51 -0
- package/tsconfig.json +10 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @blenx-dev/core
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b6f481c: New Theme Structure
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [b6f481c]
|
|
12
|
+
- @blenx-dev/theme@1.0.0
|
|
13
|
+
|
|
14
|
+
## 0.2.2
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- e30d5bc: update peer dependency
|
|
19
|
+
|
|
20
|
+
## 0.2.1
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- 4994172: update peer dependencies
|
|
25
|
+
- Updated dependencies [4994172]
|
|
26
|
+
- @blenx-dev/theme@0.2.1
|
|
27
|
+
|
|
28
|
+
## 0.2.0
|
|
29
|
+
|
|
30
|
+
### Minor Changes
|
|
31
|
+
|
|
32
|
+
- d2b8ab1: improve on configurable themes
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- 4a56dc0: move fonts to configurable tokens
|
|
37
|
+
- Updated dependencies [d2b8ab1]
|
|
38
|
+
- Updated dependencies [4a56dc0]
|
|
39
|
+
- @blenx-dev/theme@0.2.0
|
|
40
|
+
|
|
41
|
+
## 0.1.4
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- Migrate repository from bun to pnpm
|
|
46
|
+
- Replace bun.lock with pnpm-lock.yaml and add pnpm-workspace.yaml
|
|
47
|
+
- Add explicit dependencies to packages/ui for strict pnpm isolation
|
|
48
|
+
- Remove stale @stylexjs/stylex import from OTPField demo
|
|
49
|
+
- Update CI, git hooks, and contributing docs for pnpm
|
|
50
|
+
- Fix content frontmatter in vite-configuration guide
|
|
51
|
+
|
|
52
|
+
- Updated dependencies
|
|
53
|
+
- @blenx-dev/theme@0.1.4
|
|
54
|
+
|
|
55
|
+
## 0.1.2
|
|
56
|
+
|
|
57
|
+
### Patch Changes
|
|
58
|
+
|
|
59
|
+
- Updated dependencies [423768f]
|
|
60
|
+
- @blenx-dev/theme@0.1.2
|
|
61
|
+
|
|
62
|
+
## 0.1.1
|
|
63
|
+
|
|
64
|
+
### Patch Changes
|
|
65
|
+
|
|
66
|
+
- f8303b1: update exports
|
|
67
|
+
|
|
68
|
+
## 0.1.0
|
|
69
|
+
|
|
70
|
+
### Minor Changes
|
|
71
|
+
|
|
72
|
+
- finalizing initial versions
|
|
73
|
+
|
|
74
|
+
### Patch Changes
|
|
75
|
+
|
|
76
|
+
- Updated dependencies
|
|
77
|
+
- @blenx-dev/theme@0.1.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Prashanth Kumar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@blenx-dev/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.ts",
|
|
8
|
+
"./*": "./src/components/*/index.ts",
|
|
9
|
+
"./components": {
|
|
10
|
+
"types": "./src/components/index.ts",
|
|
11
|
+
"default": "./src/components/index.ts"
|
|
12
|
+
},
|
|
13
|
+
"./components/*": {
|
|
14
|
+
"types": "./src/components/*",
|
|
15
|
+
"default": "./src/components/*"
|
|
16
|
+
},
|
|
17
|
+
"./utils/*": {
|
|
18
|
+
"types": "./src/utils/*",
|
|
19
|
+
"default": "./src/utils/*"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@base-ui/react": "^1.0.0",
|
|
27
|
+
"@phosphor-icons/react": "^2.1.10",
|
|
28
|
+
"@tanstack/react-table": "^8.21.3",
|
|
29
|
+
"@vanilla-extract/css": "^1.20.1",
|
|
30
|
+
"@vanilla-extract/recipes": "^0.5.7",
|
|
31
|
+
"@vanilla-extract/sprinkles": "^1.6.5",
|
|
32
|
+
"clsx": "^2.1.1",
|
|
33
|
+
"react-colorful": "^5.7.0",
|
|
34
|
+
"react-day-picker": "^10.0.1",
|
|
35
|
+
"sonner": "^2.0.5",
|
|
36
|
+
"tailwind-merge": "^3.3.1",
|
|
37
|
+
"@blenx-dev/theme": "1.0.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/react": "^19.2.15",
|
|
41
|
+
"@types/react-dom": "^19.2.3",
|
|
42
|
+
"changeset": "^0.2.6"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"react": "^19.2.6",
|
|
46
|
+
"react-dom": "^19.2.6",
|
|
47
|
+
"@blenx-dev/theme": "1.0.0"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { semanticVars } from "@blenx-dev/theme/contract";
|
|
2
|
+
import { ListIcon } from "@phosphor-icons/react";
|
|
3
|
+
import type { Table } from "@tanstack/react-table";
|
|
4
|
+
import * as styles from "./data-table.css";
|
|
5
|
+
import { Button, Menu, MenuItem, MenuPopup, MenuSeparator, MenuTrigger } from "../components";
|
|
6
|
+
|
|
7
|
+
interface DataTableColumnToggleProps<TData> {
|
|
8
|
+
table: Table<TData>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function DataTableColumnToggle<TData>({ table }: DataTableColumnToggleProps<TData>) {
|
|
12
|
+
const columns = table.getAllLeafColumns().filter((column) => column.getCanHide());
|
|
13
|
+
|
|
14
|
+
if (columns.length === 0) return null;
|
|
15
|
+
|
|
16
|
+
const allVisible = columns.every((column) => column.getIsVisible());
|
|
17
|
+
const someVisible = columns.some((column) => column.getIsVisible());
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<Menu>
|
|
21
|
+
<MenuTrigger render={<Button variant="outline" size="sm" />}>
|
|
22
|
+
<ListIcon size={16} />
|
|
23
|
+
<span>Columns</span>
|
|
24
|
+
</MenuTrigger>
|
|
25
|
+
<MenuPopup align="end">
|
|
26
|
+
<MenuItem
|
|
27
|
+
onClick={() => {
|
|
28
|
+
for (const column of columns) {
|
|
29
|
+
column.toggleVisibility(allVisible);
|
|
30
|
+
}
|
|
31
|
+
}}
|
|
32
|
+
>
|
|
33
|
+
<span className={styles.deselectLabel}>{allVisible ? "Deselect all" : "Select all"}</span>
|
|
34
|
+
<span className={allVisible ? styles.checkboxChecked : styles.checkboxUnchecked}>
|
|
35
|
+
{allVisible && <CheckMark />}
|
|
36
|
+
{!allVisible && someVisible && <div className={styles.partial} />}
|
|
37
|
+
</span>
|
|
38
|
+
</MenuItem>
|
|
39
|
+
<MenuSeparator />
|
|
40
|
+
{columns.map((column) => {
|
|
41
|
+
const label = column.columnDef.header?.toString() ?? column.id;
|
|
42
|
+
const isVisible = column.getIsVisible();
|
|
43
|
+
return (
|
|
44
|
+
<MenuItem key={column.id} onClick={() => column.toggleVisibility(!isVisible)}>
|
|
45
|
+
<span className={styles.itemLabel}>{label}</span>
|
|
46
|
+
<span className={isVisible ? styles.checkboxChecked : styles.checkboxUnchecked}>
|
|
47
|
+
{isVisible && <CheckMark />}
|
|
48
|
+
</span>
|
|
49
|
+
</MenuItem>
|
|
50
|
+
);
|
|
51
|
+
})}
|
|
52
|
+
</MenuPopup>
|
|
53
|
+
</Menu>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function CheckMark() {
|
|
58
|
+
return (
|
|
59
|
+
<svg
|
|
60
|
+
width="12"
|
|
61
|
+
height="12"
|
|
62
|
+
viewBox="0 0 24 24"
|
|
63
|
+
fill="none"
|
|
64
|
+
stroke={semanticVars.interactive.primaryFg}
|
|
65
|
+
strokeWidth="3"
|
|
66
|
+
strokeLinecap="round"
|
|
67
|
+
strokeLinejoin="round"
|
|
68
|
+
>
|
|
69
|
+
<title>Visible</title>
|
|
70
|
+
<polyline points="20 6 9 17 4 12" />
|
|
71
|
+
</svg>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FolderOpenIcon } from "@phosphor-icons/react";
|
|
2
|
+
import * as styles from "./data-table.css";
|
|
3
|
+
|
|
4
|
+
interface DataTableEmptyProps {
|
|
5
|
+
message?: string;
|
|
6
|
+
icon?: React.ReactNode;
|
|
7
|
+
action?: React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function DataTableEmpty({
|
|
11
|
+
message = "No results found",
|
|
12
|
+
icon,
|
|
13
|
+
action,
|
|
14
|
+
}: DataTableEmptyProps) {
|
|
15
|
+
return (
|
|
16
|
+
<output aria-label={message} className={styles.emptyContainer}>
|
|
17
|
+
{icon && <div className={styles.iconWrap}>{icon}</div>}
|
|
18
|
+
{!icon && (
|
|
19
|
+
<div className={styles.iconWrap}>
|
|
20
|
+
<FolderOpenIcon size={48} />
|
|
21
|
+
</div>
|
|
22
|
+
)}
|
|
23
|
+
<p className={styles.message}>{message}</p>
|
|
24
|
+
{action && <div className={styles.actionWrap}>{action}</div>}
|
|
25
|
+
</output>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { WarningCircleIcon } from "@phosphor-icons/react";
|
|
2
|
+
import * as styles from "./data-table.css";
|
|
3
|
+
import { Button } from "../components";
|
|
4
|
+
|
|
5
|
+
interface DataTableErrorProps {
|
|
6
|
+
message?: string;
|
|
7
|
+
onRetry?: () => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function DataTableError({
|
|
11
|
+
message = "Something went wrong while loading data",
|
|
12
|
+
onRetry,
|
|
13
|
+
}: DataTableErrorProps) {
|
|
14
|
+
return (
|
|
15
|
+
<div role="alert" aria-label={message} className={styles.errorContainer}>
|
|
16
|
+
<WarningCircleIcon size={48} />
|
|
17
|
+
<p className={styles.errorMessage}>{message}</p>
|
|
18
|
+
{onRetry && (
|
|
19
|
+
<Button variant="outline" size="sm" onClick={onRetry}>
|
|
20
|
+
Retry
|
|
21
|
+
</Button>
|
|
22
|
+
)}
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Button, Spinner } from "../components";
|
|
2
|
+
import type { InfiniteScrollConfig } from "./types";
|
|
3
|
+
import { useInfiniteScroll } from "./use-infinite-scroll";
|
|
4
|
+
import * as styles from "./data-table.css";
|
|
5
|
+
|
|
6
|
+
interface DataTableInfiniteLoaderProps {
|
|
7
|
+
fetchNextPage: () => void;
|
|
8
|
+
hasNextPage: boolean;
|
|
9
|
+
isFetchingNextPage: boolean;
|
|
10
|
+
isFetching?: boolean;
|
|
11
|
+
config?: InfiniteScrollConfig;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function DataTableInfiniteLoader({
|
|
15
|
+
fetchNextPage,
|
|
16
|
+
hasNextPage,
|
|
17
|
+
isFetchingNextPage,
|
|
18
|
+
isFetching,
|
|
19
|
+
config,
|
|
20
|
+
}: DataTableInfiniteLoaderProps) {
|
|
21
|
+
const isAuto = config?.mode === "auto";
|
|
22
|
+
const loadingText = config?.loadingText ?? "Loading...";
|
|
23
|
+
const noMoreText = config?.noMoreText ?? "No more results";
|
|
24
|
+
|
|
25
|
+
const { sentinelRef } = useInfiniteScroll({
|
|
26
|
+
hasNextPage,
|
|
27
|
+
isFetchingNextPage: isFetchingNextPage || Boolean(isFetching),
|
|
28
|
+
fetchNextPage,
|
|
29
|
+
rootMargin: config?.rootMargin,
|
|
30
|
+
threshold: config?.threshold,
|
|
31
|
+
enabled: isAuto,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (isAuto) {
|
|
35
|
+
return (
|
|
36
|
+
<div
|
|
37
|
+
ref={sentinelRef}
|
|
38
|
+
aria-label={isFetchingNextPage ? loadingText : noMoreText}
|
|
39
|
+
className={styles.sentinel}
|
|
40
|
+
>
|
|
41
|
+
{isFetchingNextPage && (
|
|
42
|
+
<div className={styles.loadingInline}>
|
|
43
|
+
<Spinner />
|
|
44
|
+
<span className={styles.loaderLoadingText}>{loadingText}</span>
|
|
45
|
+
</div>
|
|
46
|
+
)}
|
|
47
|
+
{!hasNextPage && !isFetchingNextPage && <span className={styles.noMore}>{noMoreText}</span>}
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!hasNextPage) {
|
|
53
|
+
return (
|
|
54
|
+
<div className={styles.center}>
|
|
55
|
+
<span className={styles.noMore}>{noMoreText}</span>
|
|
56
|
+
</div>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<div className={styles.center}>
|
|
62
|
+
<Button
|
|
63
|
+
variant="outline"
|
|
64
|
+
onClick={fetchNextPage}
|
|
65
|
+
disabled={isFetchingNextPage}
|
|
66
|
+
loading={isFetchingNextPage}
|
|
67
|
+
aria-label={config?.loadMoreText ?? "Load more"}
|
|
68
|
+
>
|
|
69
|
+
{config?.loadMoreText ?? "Load more"}
|
|
70
|
+
</Button>
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Spinner } from "../components";
|
|
2
|
+
import type { TableSize } from "./types";
|
|
3
|
+
import * as styles from "./data-table.css";
|
|
4
|
+
|
|
5
|
+
interface DataTableLoadingProps {
|
|
6
|
+
rowCount?: number;
|
|
7
|
+
columnCount?: number;
|
|
8
|
+
size?: TableSize;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const ROW_HEIGHTS: Record<TableSize, number> = {
|
|
12
|
+
sm: 36,
|
|
13
|
+
md: 48,
|
|
14
|
+
lg: 60,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function DataTableLoading({
|
|
18
|
+
rowCount = 5,
|
|
19
|
+
columnCount = 4,
|
|
20
|
+
size = "md",
|
|
21
|
+
}: DataTableLoadingProps) {
|
|
22
|
+
const rowHeight = ROW_HEIGHTS[size];
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<output className={styles.loadingWrapper} aria-label="Loading table data">
|
|
26
|
+
<table className={styles.loadingTable}>
|
|
27
|
+
<thead>
|
|
28
|
+
<tr>
|
|
29
|
+
{Array.from({ length: columnCount }).map((_, i) => (
|
|
30
|
+
<th key={`skeleton-header-${i.toString()}`} className={styles.headerCell}>
|
|
31
|
+
<div
|
|
32
|
+
className={styles.skeletonBar}
|
|
33
|
+
style={{ height: 14, width: `${60 + ((i * 10) % 40)}px` }}
|
|
34
|
+
/>
|
|
35
|
+
</th>
|
|
36
|
+
))}
|
|
37
|
+
</tr>
|
|
38
|
+
</thead>
|
|
39
|
+
<tbody>
|
|
40
|
+
{Array.from({ length: rowCount }).map((_unknown, rowIdx) => (
|
|
41
|
+
<tr key={`skeleton-row-${rowIdx.toString()}`}>
|
|
42
|
+
{Array.from({ length: columnCount }).map((_, colIdx) => (
|
|
43
|
+
<td
|
|
44
|
+
key={`skeleton-cell-${rowIdx.toString()}-${colIdx.toString()}`}
|
|
45
|
+
className={styles.cell}
|
|
46
|
+
style={{ height: rowHeight }}
|
|
47
|
+
>
|
|
48
|
+
<div
|
|
49
|
+
className={styles.skeletonBar}
|
|
50
|
+
style={{
|
|
51
|
+
height: 12,
|
|
52
|
+
width: `${80 + ((rowIdx * 7 + colIdx * 13) % 20)}%`,
|
|
53
|
+
}}
|
|
54
|
+
/>
|
|
55
|
+
</td>
|
|
56
|
+
))}
|
|
57
|
+
</tr>
|
|
58
|
+
))}
|
|
59
|
+
</tbody>
|
|
60
|
+
</table>
|
|
61
|
+
<div className={styles.loadingFooter}>
|
|
62
|
+
<Spinner />
|
|
63
|
+
<span className={styles.loadingText}>Loading data...</span>
|
|
64
|
+
</div>
|
|
65
|
+
</output>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Button } from "../components";
|
|
2
|
+
import { CaretLeftIcon, CaretRightIcon } from "@phosphor-icons/react";
|
|
3
|
+
import type { Table } from "@tanstack/react-table";
|
|
4
|
+
import * as styles from "./data-table.css";
|
|
5
|
+
|
|
6
|
+
interface DataTablePaginationProps<TData> {
|
|
7
|
+
table: Table<TData>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function DataTablePagination<TData>({ table }: DataTablePaginationProps<TData>) {
|
|
11
|
+
const { pageIndex } = table.getState().pagination;
|
|
12
|
+
const pageCount = table.getPageCount();
|
|
13
|
+
const totalRows = table.getPrePaginationRowModel().rows.length;
|
|
14
|
+
const { pageSize } = table.getState().pagination;
|
|
15
|
+
const startRow = pageIndex * pageSize + 1;
|
|
16
|
+
const endRow = Math.min((pageIndex + 1) * pageSize, totalRows);
|
|
17
|
+
const canPreviousPage = table.getCanPreviousPage();
|
|
18
|
+
const canNextPage = table.getCanNextPage();
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<nav aria-label="Pagination" className={styles.nav}>
|
|
22
|
+
<span className={styles.info}>{totalRows} results</span>
|
|
23
|
+
<div className={styles.controls}>
|
|
24
|
+
<span className={styles.range}>
|
|
25
|
+
{startRow}-{endRow} of {totalRows}
|
|
26
|
+
</span>
|
|
27
|
+
<div className={styles.buttonGroup}>
|
|
28
|
+
<Button
|
|
29
|
+
variant="outline"
|
|
30
|
+
size="sm"
|
|
31
|
+
disabled={!canPreviousPage}
|
|
32
|
+
onClick={() => table.previousPage()}
|
|
33
|
+
aria-label="Previous page"
|
|
34
|
+
>
|
|
35
|
+
<CaretLeftIcon size={16} />
|
|
36
|
+
</Button>
|
|
37
|
+
{Array.from({ length: pageCount }, (_, i) => i + 1)
|
|
38
|
+
.filter((page) => {
|
|
39
|
+
const current = pageIndex + 1;
|
|
40
|
+
if (pageCount <= 7) return true;
|
|
41
|
+
if (page === 1 || page === pageCount) return true;
|
|
42
|
+
if (Math.abs(page - current) <= 1) return true;
|
|
43
|
+
return false;
|
|
44
|
+
})
|
|
45
|
+
.map((page, idx, filtered) => {
|
|
46
|
+
const pageIdx = page - 1;
|
|
47
|
+
const isActive = pageIdx === pageIndex;
|
|
48
|
+
const showGap = idx > 0 && page - filtered[idx - 1]! > 1;
|
|
49
|
+
return (
|
|
50
|
+
<div key={`page-${page.toString()}`} className={styles.pageWrap}>
|
|
51
|
+
{showGap && <span className={styles.ellipsis}>...</span>}
|
|
52
|
+
<Button
|
|
53
|
+
variant={isActive ? "solid" : "ghost"}
|
|
54
|
+
intent={isActive ? "primary" : undefined}
|
|
55
|
+
size="sm"
|
|
56
|
+
disabled={isActive}
|
|
57
|
+
onClick={() => table.setPageIndex(pageIdx)}
|
|
58
|
+
aria-label={`Page ${page.toString()}`}
|
|
59
|
+
aria-current={isActive ? "page" : undefined}
|
|
60
|
+
className={styles.pageButton}
|
|
61
|
+
>
|
|
62
|
+
{page.toString()}
|
|
63
|
+
</Button>
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
})}
|
|
67
|
+
<Button
|
|
68
|
+
variant="outline"
|
|
69
|
+
size="sm"
|
|
70
|
+
disabled={!canNextPage}
|
|
71
|
+
onClick={() => table.nextPage()}
|
|
72
|
+
aria-label="Next page"
|
|
73
|
+
>
|
|
74
|
+
<CaretRightIcon size={16} />
|
|
75
|
+
</Button>
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
</nav>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Button, Input } from "../components";
|
|
2
|
+
import type { Table } from "@tanstack/react-table";
|
|
3
|
+
import { DataTableColumnToggle } from "./data-table-column-toggle";
|
|
4
|
+
import type { BulkAction, TableFeatures } from "./types";
|
|
5
|
+
import * as styles from "./data-table.css";
|
|
6
|
+
|
|
7
|
+
interface DataTableToolbarProps<TData> {
|
|
8
|
+
table: Table<TData>;
|
|
9
|
+
features?: TableFeatures;
|
|
10
|
+
globalSearch?: string;
|
|
11
|
+
onGlobalSearchChange?: (value: string) => void;
|
|
12
|
+
customToolbar?: React.ReactNode;
|
|
13
|
+
bulkActions?: BulkAction<TData>[];
|
|
14
|
+
selectedRows: TData[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function DataTableToolbar<TData>({
|
|
18
|
+
table,
|
|
19
|
+
features,
|
|
20
|
+
globalSearch,
|
|
21
|
+
onGlobalSearchChange,
|
|
22
|
+
customToolbar,
|
|
23
|
+
bulkActions,
|
|
24
|
+
selectedRows,
|
|
25
|
+
}: DataTableToolbarProps<TData>) {
|
|
26
|
+
return (
|
|
27
|
+
<div className={styles.toolbarContainer}>
|
|
28
|
+
<div className={styles.leftGroup}>
|
|
29
|
+
{features?.globalSearch && (
|
|
30
|
+
<div className={styles.searchWrap}>
|
|
31
|
+
<Input
|
|
32
|
+
size="sm"
|
|
33
|
+
placeholder="Search..."
|
|
34
|
+
value={globalSearch ?? ""}
|
|
35
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
36
|
+
onGlobalSearchChange?.(e.target.value);
|
|
37
|
+
}}
|
|
38
|
+
/>
|
|
39
|
+
</div>
|
|
40
|
+
)}
|
|
41
|
+
{selectedRows.length > 0 &&
|
|
42
|
+
bulkActions?.map((action, index) => (
|
|
43
|
+
<Button
|
|
44
|
+
key={`bulk-action-${index.toString()}`}
|
|
45
|
+
variant={action.variant === "destructive" ? "solid" : "outline"}
|
|
46
|
+
intent={action.variant === "destructive" ? "danger" : undefined}
|
|
47
|
+
size="sm"
|
|
48
|
+
disabled={action.disabled}
|
|
49
|
+
onClick={() => action.onClick(selectedRows)}
|
|
50
|
+
>
|
|
51
|
+
{action.icon && <span>{action.icon}</span>}
|
|
52
|
+
{action.label}
|
|
53
|
+
</Button>
|
|
54
|
+
))}
|
|
55
|
+
</div>
|
|
56
|
+
<div className={styles.rightGroup}>
|
|
57
|
+
{customToolbar}
|
|
58
|
+
{features?.columnVisibility && <DataTableColumnToggle table={table} />}
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
);
|
|
62
|
+
}
|