@gentleduck/registry-ui 0.2.1
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 +62 -0
- package/index.css +3 -0
- package/package.json +59 -0
- package/src/_old/_table/index.ts +5 -0
- package/src/_old/_table/table-advanced.constants.tsx +24 -0
- package/src/_old/_table/table-advanced.tsx +311 -0
- package/src/_old/_table/table-advanced.types.ts +272 -0
- package/src/_old/_table/table.constants.ts +2 -0
- package/src/_old/_table/table.hook.tsx +115 -0
- package/src/_old/_table/table.lib.ts +85 -0
- package/src/_old/_table/table.tsx +916 -0
- package/src/_old/_table/table.types.ts +118 -0
- package/src/_old/_table/todo.md +11 -0
- package/src/_old/_upload/index.ts +9 -0
- package/src/_old/_upload/todo.md +38 -0
- package/src/_old/_upload/upload-advanced-chunks.tsx +1624 -0
- package/src/_old/_upload/upload-advanced.tsx +507 -0
- package/src/_old/_upload/upload-sonner.tsx +58 -0
- package/src/_old/_upload/upload.assets.tsx +239 -0
- package/src/_old/_upload/upload.constants.tsx +75 -0
- package/src/_old/_upload/upload.dto.ts +19 -0
- package/src/_old/_upload/upload.lib.tsx +630 -0
- package/src/_old/_upload/upload.tsx +491 -0
- package/src/_old/_upload/upload.types.ts +436 -0
- package/src/accordion/accordion.tsx +247 -0
- package/src/accordion/index.ts +1 -0
- package/src/alert/alert.constants.ts +17 -0
- package/src/alert/alert.tsx +52 -0
- package/src/alert/index.ts +2 -0
- package/src/alert-dialog/alert-dialog.tsx +107 -0
- package/src/alert-dialog/index.ts +1 -0
- package/src/aspect-ratio/aspect-ratio.tsx +33 -0
- package/src/aspect-ratio/index.ts +1 -0
- package/src/audio/audio-record.tsx +776 -0
- package/src/audio/audio-visualizer.tsx +377 -0
- package/src/audio/audio.libs.ts +5 -0
- package/src/audio/audio.types.ts +50 -0
- package/src/audio/index.ts +2 -0
- package/src/avatar/avatar.tsx +78 -0
- package/src/avatar/index.ts +1 -0
- package/src/badge/badge.constants.ts +38 -0
- package/src/badge/badge.tsx +19 -0
- package/src/badge/index.ts +2 -0
- package/src/breadcrumb/breadcrumb.tsx +119 -0
- package/src/breadcrumb/index.ts +1 -0
- package/src/button/button.constants.ts +44 -0
- package/src/button/button.tsx +79 -0
- package/src/button/button.types.ts +38 -0
- package/src/button/index.ts +3 -0
- package/src/button-group/button-group.constants.ts +26 -0
- package/src/button-group/button-group.tsx +65 -0
- package/src/button-group/index.ts +2 -0
- package/src/calendar/calendar.tsx +191 -0
- package/src/calendar/index.ts +1 -0
- package/src/card/card.tsx +81 -0
- package/src/card/index.ts +1 -0
- package/src/carousel/carousel.tsx +211 -0
- package/src/carousel/carousel.types.ts +23 -0
- package/src/carousel/index.ts +2 -0
- package/src/chart/chart.libs.ts +27 -0
- package/src/chart/chart.tsx +260 -0
- package/src/chart/chart.types.ts +38 -0
- package/src/chart/index.ts +3 -0
- package/src/checkbox/checkbox.tsx +144 -0
- package/src/checkbox/checkbox.types.ts +24 -0
- package/src/checkbox/index.ts +2 -0
- package/src/collapsible/collapsible.tsx +151 -0
- package/src/collapsible/index.ts +1 -0
- package/src/combobox/combobox.tsx +132 -0
- package/src/combobox/index.ts +1 -0
- package/src/command/command.tsx +192 -0
- package/src/command/command.types.ts +11 -0
- package/src/command/index.ts +2 -0
- package/src/context-menu/context-menu.tsx +178 -0
- package/src/context-menu/index.ts +1 -0
- package/src/dialog/dialog-responsive.tsx +137 -0
- package/src/dialog/dialog.tsx +97 -0
- package/src/dialog/index.ts +2 -0
- package/src/direction/direction.tsx +13 -0
- package/src/direction/index.ts +1 -0
- package/src/drawer/drawer.tsx +185 -0
- package/src/drawer/index.ts +1 -0
- package/src/dropdown-menu/dropdown-menu.tsx +181 -0
- package/src/dropdown-menu/index.ts +1 -0
- package/src/empty/empty.constants.ts +15 -0
- package/src/empty/empty.tsx +73 -0
- package/src/empty/index.ts +2 -0
- package/src/field/field.constants.ts +22 -0
- package/src/field/field.tsx +203 -0
- package/src/field/index.ts +2 -0
- package/src/hover-card/hover-card.tsx +79 -0
- package/src/hover-card/index.ts +1 -0
- package/src/input/index.ts +1 -0
- package/src/input/input.tsx +45 -0
- package/src/input-group/index.ts +1 -0
- package/src/input-group/input-group.tsx +170 -0
- package/src/input-otp/index.ts +1 -0
- package/src/input-otp/input-otp.tsx +66 -0
- package/src/item/index.ts +2 -0
- package/src/item/item.constants.ts +22 -0
- package/src/item/item.tsx +185 -0
- package/src/json-editor/index.ts +4 -0
- package/src/json-editor/json-editor.hooks.ts +21 -0
- package/src/json-editor/json-editor.libs.ts +34 -0
- package/src/json-editor/json-editor.tsx +425 -0
- package/src/json-editor/json-editor.types.ts +80 -0
- package/src/json-editor/json-editor.view.tsx +110 -0
- package/src/json-editor/json-text-area.tsx +7 -0
- package/src/kbd/index.ts +1 -0
- package/src/kbd/kbd.tsx +39 -0
- package/src/label/index.ts +1 -0
- package/src/label/label.tsx +28 -0
- package/src/menubar/index.ts +1 -0
- package/src/menubar/menubar.tsx +213 -0
- package/src/navigation-menu/index.ts +1 -0
- package/src/navigation-menu/navigation-menu.tsx +152 -0
- package/src/pagination/index.ts +2 -0
- package/src/pagination/pagination.tsx +191 -0
- package/src/pagination/pagination.types.ts +17 -0
- package/src/popover/index.ts +1 -0
- package/src/popover/popover.tsx +35 -0
- package/src/preview-panel/index.ts +3 -0
- package/src/preview-panel/preview-panel-dialog.tsx +99 -0
- package/src/preview-panel/preview-panel.tsx +389 -0
- package/src/preview-panel/preview-panel.types.ts +49 -0
- package/src/progress/index.ts +1 -0
- package/src/progress/progress.tsx +32 -0
- package/src/radio-group/index.ts +1 -0
- package/src/radio-group/radio-group.tsx +92 -0
- package/src/resizable/index.ts +1 -0
- package/src/resizable/resizable.tsx +52 -0
- package/src/scroll-area/index.ts +1 -0
- package/src/scroll-area/scroll-area.tsx +30 -0
- package/src/select/index.ts +1 -0
- package/src/select/select.tsx +138 -0
- package/src/separator/index.ts +1 -0
- package/src/separator/separator.tsx +28 -0
- package/src/sheet/index.ts +2 -0
- package/src/sheet/sheet.constants.tsx +20 -0
- package/src/sheet/sheet.tsx +92 -0
- package/src/sidebar/index.ts +4 -0
- package/src/sidebar/sidebar.constants.ts +30 -0
- package/src/sidebar/sidebar.hooks.ts +13 -0
- package/src/sidebar/sidebar.tsx +676 -0
- package/src/sidebar/sidebar.types.ts +28 -0
- package/src/skeleton/index.ts +1 -0
- package/src/skeleton/skeleton.tsx +22 -0
- package/src/slider/index.ts +1 -0
- package/src/slider/slider.tsx +57 -0
- package/src/sonner/index.ts +4 -0
- package/src/sonner/sonner.chunks.tsx +80 -0
- package/src/sonner/sonner.libs.ts +13 -0
- package/src/sonner/sonner.tsx +31 -0
- package/src/sonner/sonner.types.ts +9 -0
- package/src/switch/index.ts +1 -0
- package/src/switch/switch.tsx +63 -0
- package/src/table/index.ts +1 -0
- package/src/table/table.tsx +95 -0
- package/src/tabs/index.ts +1 -0
- package/src/tabs/tabs.tsx +151 -0
- package/src/textarea/index.ts +1 -0
- package/src/textarea/textarea.tsx +24 -0
- package/src/toggle/index.ts +2 -0
- package/src/toggle/toggle.constants.ts +22 -0
- package/src/toggle/toggle.tsx +24 -0
- package/src/toggle-group/index.ts +1 -0
- package/src/toggle-group/toggle-group.tsx +69 -0
- package/src/tooltip/index.ts +1 -0
- package/src/tooltip/tooltip.tsx +32 -0
- package/src/upload/index.ts +1 -0
- package/src/upload/upload.constants.tsx +19 -0
- package/src/upload/upload.libs.ts +97 -0
- package/src/upload/upload.tsx +340 -0
- package/src/upload/upload.types.ts +44 -0
- package/tsconfig.json +25 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @gentleduck/registry-ui
|
|
2
|
+
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ad86755: Fix popover width, update calendar and date-picker examples, and migrate registry packages.
|
|
8
|
+
- Updated dependencies [ad86755]
|
|
9
|
+
- Updated dependencies [ad86755]
|
|
10
|
+
- @gentleduck/primitives@0.2.1
|
|
11
|
+
- @gentleduck/hooks@0.1.9
|
|
12
|
+
- @gentleduck/libs@0.1.12
|
|
13
|
+
- @gentleduck/variants@0.1.17
|
|
14
|
+
- @gentleduck/motion@0.1.14
|
|
15
|
+
- @gentleduck/vim@0.1.13
|
|
16
|
+
|
|
17
|
+
## 0.2.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- 36f9364: Add json-editor component with inline, sheet, and popover editing modes for JSON data with validation. Includes registry entries and three example demos.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- d46534e: Upgrade recharts peer dependency from v2 to v3.7.0
|
|
26
|
+
- Updated dependencies [36f9364]
|
|
27
|
+
- @gentleduck/primitives@0.2.0
|
|
28
|
+
|
|
29
|
+
## 0.1.17
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- Updated dependencies [4f93768]
|
|
34
|
+
- @gentleduck/primitives@0.1.45
|
|
35
|
+
|
|
36
|
+
## 0.1.16
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- Updated dependencies [d0a2c1d]
|
|
41
|
+
- Updated dependencies [d0a2c1d]
|
|
42
|
+
- @gentleduck/primitives@0.1.44
|
|
43
|
+
|
|
44
|
+
## 0.1.15
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- Updated dependencies [45ec82f]
|
|
49
|
+
- @gentleduck/primitives@0.1.43
|
|
50
|
+
|
|
51
|
+
## 0.1.14
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- Updated dependencies [cd47e32]
|
|
56
|
+
- @gentleduck/primitives@0.1.42
|
|
57
|
+
|
|
58
|
+
## 0.1.13
|
|
59
|
+
|
|
60
|
+
### Patch Changes
|
|
61
|
+
|
|
62
|
+
- df94032: publish for internal use only
|
package/index.css
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
+
"engines": {
|
|
4
|
+
"node": ">=22.0.0"
|
|
5
|
+
},
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@gentleduck/hooks": "workspace:*",
|
|
8
|
+
"@gentleduck/libs": "workspace:*",
|
|
9
|
+
"@gentleduck/motion": "workspace:*",
|
|
10
|
+
"@gentleduck/primitives": "workspace:*",
|
|
11
|
+
"@gentleduck/variants": "workspace:*",
|
|
12
|
+
"@gentleduck/vim": "workspace:*",
|
|
13
|
+
"embla-carousel-react": "8.6.0",
|
|
14
|
+
"lucide-react": "0.562.0",
|
|
15
|
+
"next-themes": "^0.4.6",
|
|
16
|
+
"react": "^19.2.3",
|
|
17
|
+
"react-day-picker": "^9.8.1",
|
|
18
|
+
"react-dom": "^19.2.3",
|
|
19
|
+
"react-hook-form": "^7.71.1",
|
|
20
|
+
"react-resizable-panels": "^3.0.6",
|
|
21
|
+
"recharts": "^3.7.0",
|
|
22
|
+
"sonner": "^2.0.7",
|
|
23
|
+
"tailwindcss": "^4.2.0",
|
|
24
|
+
"uuidv7": "^1.1.0",
|
|
25
|
+
"vaul": "1.1.2",
|
|
26
|
+
"zod": "4.2.1"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@gentleduck/typescript-config": "workspace:*",
|
|
30
|
+
"@types/react": "19.2.7",
|
|
31
|
+
"@types/react-dom": "19.2.3",
|
|
32
|
+
"typescript": "5.9.3"
|
|
33
|
+
},
|
|
34
|
+
"exports": {
|
|
35
|
+
"./*": "./src/*/index.ts"
|
|
36
|
+
},
|
|
37
|
+
"name": "@gentleduck/registry-ui",
|
|
38
|
+
"author": "gentleduck contributors",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"homepage": "https://github.com/gentleeduck/duck-ui/tree/master/packages/registry-ui#readme",
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/gentleeduck/duck-ui/issues"
|
|
43
|
+
},
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/gentleeduck/duck-ui.git",
|
|
47
|
+
"directory": "packages/registry-ui"
|
|
48
|
+
},
|
|
49
|
+
"packageManager": "bun@1.3.5",
|
|
50
|
+
"private": false,
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"check-types": "tsc -p tsconfig.json --noEmit --pretty false --skipLibCheck"
|
|
56
|
+
},
|
|
57
|
+
"type": "module",
|
|
58
|
+
"version": "0.2.1"
|
|
59
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ArrowDownIcon, ArrowUpIcon, EyeOff } from 'lucide-react'
|
|
2
|
+
import { TableColumnSortableType } from './table-advanced.types'
|
|
3
|
+
|
|
4
|
+
export const dropdownMenuOptions: TableColumnSortableType[] = [
|
|
5
|
+
{
|
|
6
|
+
children: 'ascending',
|
|
7
|
+
icon: <ArrowDownIcon className="mr-2 text-muted-foreground/80" />,
|
|
8
|
+
size: 'sm',
|
|
9
|
+
variant: 'ghost',
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
{
|
|
13
|
+
children: 'descending',
|
|
14
|
+
icon: <ArrowUpIcon className="mr-2 text-muted-foreground/80" />,
|
|
15
|
+
size: 'sm',
|
|
16
|
+
variant: 'ghost',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
children: 'hide' as 'other',
|
|
20
|
+
icon: <EyeOff className="mr-2 text-muted-foreground/80" />,
|
|
21
|
+
size: 'sm',
|
|
22
|
+
variant: 'ghost',
|
|
23
|
+
},
|
|
24
|
+
]
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { cn } from '@gentleduck/libs/cn'
|
|
2
|
+
import { ArrowDownIcon, ArrowUpDown, ArrowUpIcon } from 'lucide-react'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { Button } from '../button'
|
|
5
|
+
import { Checkbox } from '../checkbox'
|
|
6
|
+
import {
|
|
7
|
+
DropdownMenu,
|
|
8
|
+
DropdownMenuContent,
|
|
9
|
+
DropdownMenuGroup,
|
|
10
|
+
DropdownMenuItem,
|
|
11
|
+
DropdownMenuSeparator,
|
|
12
|
+
DropdownMenuTrigger,
|
|
13
|
+
} from '../dropdown-menu'
|
|
14
|
+
import { Input } from '../input'
|
|
15
|
+
import { ScrollArea } from '../scroll-area/'
|
|
16
|
+
import { TableHead, TableHeader, TableRow } from '../table'
|
|
17
|
+
import { Table, TableBody } from './table'
|
|
18
|
+
import { dropdownMenuOptions } from './table-advanced.constants'
|
|
19
|
+
import {
|
|
20
|
+
DuckTableBodyProps,
|
|
21
|
+
DuckTableContextType,
|
|
22
|
+
DuckTableHeadCheckboxProps,
|
|
23
|
+
DuckTableHeaderProps,
|
|
24
|
+
DuckTableHeadSelectableProps,
|
|
25
|
+
DuckTableProps,
|
|
26
|
+
DuckTableProviderProps,
|
|
27
|
+
DuckTableRowCheckboxProps,
|
|
28
|
+
GetColumnLabel,
|
|
29
|
+
TableColumnType,
|
|
30
|
+
TableContentDataType,
|
|
31
|
+
TableSearchStateType,
|
|
32
|
+
} from './table-advanced.types'
|
|
33
|
+
|
|
34
|
+
export const DuckTableContext = React.createContext<DuckTableContextType<any> | null>(null)
|
|
35
|
+
|
|
36
|
+
export function useDuckTable<TColumnName extends readonly TableColumnType[]>() {
|
|
37
|
+
const context = React.useContext<DuckTableContextType<GetColumnLabel<TColumnName>>>(
|
|
38
|
+
DuckTableContext as unknown as React.Context<DuckTableContextType<GetColumnLabel<TColumnName>>>,
|
|
39
|
+
)
|
|
40
|
+
if (!context) {
|
|
41
|
+
throw new Error('useTableProvider must be used within an TableProvider')
|
|
42
|
+
}
|
|
43
|
+
return context
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function DuckTableProvider<TColumnName extends string[]>({
|
|
47
|
+
table_rows,
|
|
48
|
+
table_columns,
|
|
49
|
+
children,
|
|
50
|
+
className,
|
|
51
|
+
...props
|
|
52
|
+
}: DuckTableProviderProps<TColumnName>) {
|
|
53
|
+
const [search, setSearch] = React.useState<TableSearchStateType>({
|
|
54
|
+
query: '',
|
|
55
|
+
queryBy: [],
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const [tableColumns, setTableColumns] = React.useState<Map<string, TableColumnType>>(
|
|
59
|
+
new Map(table_columns.map((column) => [column.label, column])),
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
const [selectedRows, setSelectedRows] = React.useState<Set<TableContentDataType<TColumnName>>>(new Set())
|
|
63
|
+
|
|
64
|
+
const DuckTable = DuckTableContext //<TColumnName>()
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<DuckTable.Provider
|
|
68
|
+
value={{
|
|
69
|
+
search,
|
|
70
|
+
selectedRows,
|
|
71
|
+
setSearch,
|
|
72
|
+
setSelectedRows,
|
|
73
|
+
setTableColumns,
|
|
74
|
+
tableColumns,
|
|
75
|
+
tableRows: table_rows,
|
|
76
|
+
}}>
|
|
77
|
+
<div className={cn(`w-full- flex flex-col gap-4 w-[800px] h-[500px]`, className)} {...props}>
|
|
78
|
+
{children}
|
|
79
|
+
</div>
|
|
80
|
+
</DuckTable.Provider>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
DuckTableProvider.displayName = 'DuckTableProvider'
|
|
84
|
+
|
|
85
|
+
export function DuckTable({ wrapper, className, children, ...props }: DuckTableProps) {
|
|
86
|
+
const { className: wrapperClassName, ...wrapperProps } = wrapper! ?? {}
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<ScrollArea
|
|
90
|
+
className={cn('border border-border rounded-lg !overflow-visible relative', wrapperClassName)}
|
|
91
|
+
{...wrapperProps}>
|
|
92
|
+
<Table {...props}>{children}</Table>
|
|
93
|
+
</ScrollArea>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
DuckTable.displayName = 'DuckTable'
|
|
97
|
+
|
|
98
|
+
// ------------------------------------------------------------------------------------------------
|
|
99
|
+
|
|
100
|
+
export function DuckTableHeader({}: DuckTableHeaderProps) {
|
|
101
|
+
const { tableColumns } = useDuckTable()
|
|
102
|
+
return (
|
|
103
|
+
<>
|
|
104
|
+
<TableHeader>
|
|
105
|
+
<TableRow>
|
|
106
|
+
{Array.from(tableColumns.values())?.map((column, idx) => {
|
|
107
|
+
const { children, className, sortable, label, showLabel, ...props } = column
|
|
108
|
+
|
|
109
|
+
const Component = () =>
|
|
110
|
+
sortable ? (
|
|
111
|
+
<DuckTableHeadSelectable column={column} label={(label as string) ?? children} showLabel={showLabel} />
|
|
112
|
+
) : (
|
|
113
|
+
<span className="capitalize">{(label as string) ?? children}</span>
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
!column['aria-hidden'] && (
|
|
118
|
+
<React.Fragment key={idx}>
|
|
119
|
+
<TableHead
|
|
120
|
+
className={cn('py-2', idx === 0 && 'justify-start ', sortable && 'px-2', className)}
|
|
121
|
+
{...props}>
|
|
122
|
+
{idx === 0 ? (
|
|
123
|
+
<div className="flex items-center gap-4">
|
|
124
|
+
<DuckTableHeadCheckbox className={cn(sortable && 'justify-end')} type="header" />
|
|
125
|
+
{/*NOTE: Rendering Sorting else rendering label*/}
|
|
126
|
+
<Component />
|
|
127
|
+
</div>
|
|
128
|
+
) : (
|
|
129
|
+
<Component />
|
|
130
|
+
)}
|
|
131
|
+
</TableHead>
|
|
132
|
+
</React.Fragment>
|
|
133
|
+
)
|
|
134
|
+
)
|
|
135
|
+
})}
|
|
136
|
+
</TableRow>
|
|
137
|
+
</TableHeader>
|
|
138
|
+
</>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
DuckTableHeader.displayName = 'TableCustomViewHeader'
|
|
142
|
+
|
|
143
|
+
export function DuckTableHeadCheckbox({ className, ...props }: DuckTableHeadCheckboxProps) {
|
|
144
|
+
const { selectedRows, setSelectedRows, tableRows } = useDuckTable()
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<div className={cn('flex items-center w-fit data-[state=open]:bg-accent text-xs capitalize', className)} {...props}>
|
|
148
|
+
<Checkbox
|
|
149
|
+
checked={
|
|
150
|
+
selectedRows.size === tableRows.length
|
|
151
|
+
? true
|
|
152
|
+
: selectedRows.size < tableRows.length && selectedRows.size
|
|
153
|
+
? 'indeterminate'
|
|
154
|
+
: false
|
|
155
|
+
}
|
|
156
|
+
className="border-border"
|
|
157
|
+
onClick={() => {
|
|
158
|
+
setSelectedRows(() => {
|
|
159
|
+
if (selectedRows.size === tableRows.length) {
|
|
160
|
+
return new Set()
|
|
161
|
+
}
|
|
162
|
+
return new Set(tableRows.map((item) => item))
|
|
163
|
+
})
|
|
164
|
+
}}
|
|
165
|
+
/>
|
|
166
|
+
</div>
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function DuckTableHeadSelectable<TSort extends boolean = true>({
|
|
171
|
+
column,
|
|
172
|
+
label,
|
|
173
|
+
showLabel,
|
|
174
|
+
children,
|
|
175
|
+
}: DuckTableHeadSelectableProps<TSort>) {
|
|
176
|
+
const { setTableColumns } = useDuckTable()
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<div className={cn('flex items-center space-x-2')}>
|
|
180
|
+
{(dropdownMenuOptions?.length ?? 0) > 0 && (
|
|
181
|
+
<DropdownMenu>
|
|
182
|
+
<DropdownMenuTrigger asChild>
|
|
183
|
+
<Button
|
|
184
|
+
aria-controls="dropdown-menu"
|
|
185
|
+
aria-label="table-column-options"
|
|
186
|
+
aria-sort={column['aria-sort']}
|
|
187
|
+
className="data-[state=open]:bg-accent [&>div]:justify-between w-full [&>div]:w-full capitalize"
|
|
188
|
+
label={
|
|
189
|
+
showLabel
|
|
190
|
+
? {
|
|
191
|
+
children: label.toString() + ' options',
|
|
192
|
+
className: 'capitalize',
|
|
193
|
+
showLabel: true,
|
|
194
|
+
side: 'top',
|
|
195
|
+
}
|
|
196
|
+
: undefined
|
|
197
|
+
}
|
|
198
|
+
name="dropdown-menu-trigger"
|
|
199
|
+
secondIcon={
|
|
200
|
+
column['aria-sort'] === 'ascending' ? (
|
|
201
|
+
<ArrowDownIcon className="text-muted-foreground" />
|
|
202
|
+
) : column['aria-sort'] === 'descending' ? (
|
|
203
|
+
<ArrowUpIcon className="text-muted-foreground" />
|
|
204
|
+
) : (
|
|
205
|
+
<ArrowUpDown className="text-muted-foreground" />
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
size="sm"
|
|
209
|
+
variant="ghost">
|
|
210
|
+
{(label as string) ?? children}
|
|
211
|
+
</Button>
|
|
212
|
+
</DropdownMenuTrigger>
|
|
213
|
+
<DropdownMenuContent className="w-48">
|
|
214
|
+
<DropdownMenuGroup>
|
|
215
|
+
{dropdownMenuOptions.map((item, idx) => {
|
|
216
|
+
return (
|
|
217
|
+
<>
|
|
218
|
+
{idx === dropdownMenuOptions.length - 1 && <DropdownMenuSeparator />}
|
|
219
|
+
<DropdownMenuItem
|
|
220
|
+
className="p-0"
|
|
221
|
+
key={idx}
|
|
222
|
+
onClick={() => {
|
|
223
|
+
setTableColumns((prev) => {
|
|
224
|
+
const newSet = new Map(prev)
|
|
225
|
+
|
|
226
|
+
if (item.children === ('hide' as 'other')) {
|
|
227
|
+
newSet.set(label, {
|
|
228
|
+
...column,
|
|
229
|
+
'aria-hidden': true,
|
|
230
|
+
hidden: true,
|
|
231
|
+
})
|
|
232
|
+
} else {
|
|
233
|
+
if (newSet.get(label)?.label === item.children) {
|
|
234
|
+
newSet.set(label, {
|
|
235
|
+
...column,
|
|
236
|
+
'aria-sort': 'none',
|
|
237
|
+
})
|
|
238
|
+
} else {
|
|
239
|
+
newSet.set(label, {
|
|
240
|
+
...column,
|
|
241
|
+
'aria-sort': item.children,
|
|
242
|
+
})
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return newSet
|
|
247
|
+
})
|
|
248
|
+
}}>
|
|
249
|
+
<Button {...item} className={cn('w-full justify-start capitalize', item.className)}>
|
|
250
|
+
{item.children}
|
|
251
|
+
</Button>
|
|
252
|
+
</DropdownMenuItem>
|
|
253
|
+
</>
|
|
254
|
+
)
|
|
255
|
+
})}
|
|
256
|
+
</DropdownMenuGroup>
|
|
257
|
+
</DropdownMenuContent>
|
|
258
|
+
</DropdownMenu>
|
|
259
|
+
)}
|
|
260
|
+
</div>
|
|
261
|
+
)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export function DuckTableBody({ children }: DuckTableBodyProps) {
|
|
265
|
+
return <TableBody>{children}</TableBody>
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export function DuckTableRowCheckbox<TColumnName extends readonly TableColumnType[]>({
|
|
269
|
+
className,
|
|
270
|
+
tableRow,
|
|
271
|
+
...props
|
|
272
|
+
}: DuckTableRowCheckboxProps<TColumnName>) {
|
|
273
|
+
const { selectedRows, setSelectedRows } = useDuckTable()
|
|
274
|
+
|
|
275
|
+
return (
|
|
276
|
+
<div className={cn('flex items-center w-fit data-[state=open]:bg-accent text-xs capitalize', className)} {...props}>
|
|
277
|
+
<Checkbox
|
|
278
|
+
checked={selectedRows.has(tableRow) ? true : false}
|
|
279
|
+
className="border-border"
|
|
280
|
+
onClick={() => {
|
|
281
|
+
setSelectedRows(() => {
|
|
282
|
+
if (selectedRows.has(tableRow)) {
|
|
283
|
+
return new Set(Array.from(selectedRows.values()).filter((item) => item !== tableRow))
|
|
284
|
+
}
|
|
285
|
+
return new Set([...selectedRows, tableRow])
|
|
286
|
+
})
|
|
287
|
+
}}
|
|
288
|
+
/>
|
|
289
|
+
</div>
|
|
290
|
+
)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export interface DuckTableTopBarProps extends React.HTMLProps<HTMLDivElement> {}
|
|
294
|
+
|
|
295
|
+
export function DuckTableTopBar({ className, children, ...props }: DuckTableTopBarProps) {
|
|
296
|
+
return (
|
|
297
|
+
<div className={cn('', className)} {...props}>
|
|
298
|
+
{children}
|
|
299
|
+
</div>
|
|
300
|
+
)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export interface DuckTableSearchInputProps extends React.HTMLProps<HTMLDivElement> {}
|
|
304
|
+
|
|
305
|
+
export function DuckTableSearchInput({ className, ...props }: DuckTableSearchInputProps) {
|
|
306
|
+
return (
|
|
307
|
+
<div className={cn('flex-1', className)} {...props}>
|
|
308
|
+
<Input placeholder="Search..." />
|
|
309
|
+
</div>
|
|
310
|
+
)
|
|
311
|
+
}
|