@duro-app/ui 0.22.0 → 0.24.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/dist/components/Alert/Alert.meta.d.ts.map +1 -1
- package/dist/components/ButtonGroup/ButtonGroup.d.ts +14 -0
- package/dist/components/ButtonGroup/ButtonGroup.d.ts.map +1 -0
- package/dist/components/ButtonGroup/ButtonGroup.meta.d.ts +3 -0
- package/dist/components/ButtonGroup/ButtonGroup.meta.d.ts.map +1 -0
- package/dist/components/ButtonGroup/ButtonGroup.stories.d.ts +11 -0
- package/dist/components/ButtonGroup/ButtonGroup.stories.d.ts.map +1 -0
- package/dist/components/ButtonGroup/styles.css.d.ts +45 -0
- package/dist/components/ButtonGroup/styles.css.d.ts.map +1 -0
- package/dist/components/Callout/Callout.meta.d.ts.map +1 -1
- package/dist/components/Card/Card.meta.d.ts.map +1 -1
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +22 -0
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts.map +1 -0
- package/dist/components/CheckboxGroup/CheckboxGroup.meta.d.ts +3 -0
- package/dist/components/CheckboxGroup/CheckboxGroup.meta.d.ts.map +1 -0
- package/dist/components/CheckboxGroup/CheckboxGroup.stories.d.ts +9 -0
- package/dist/components/CheckboxGroup/CheckboxGroup.stories.d.ts.map +1 -0
- package/dist/components/CheckboxGroup/styles.css.d.ts +12 -0
- package/dist/components/CheckboxGroup/styles.css.d.ts.map +1 -0
- package/dist/components/EmptyState/EmptyState.meta.d.ts.map +1 -1
- package/dist/components/InputGroup/InputGroup.meta.d.ts.map +1 -1
- package/dist/components/List/List.d.ts.map +1 -1
- package/dist/components/List/List.meta.d.ts.map +1 -1
- package/dist/components/List/List.stories.d.ts.map +1 -1
- package/dist/components/RadioGroup/RadioGroup.d.ts +22 -0
- package/dist/components/RadioGroup/RadioGroup.d.ts.map +1 -0
- package/dist/components/RadioGroup/RadioGroup.meta.d.ts +3 -0
- package/dist/components/RadioGroup/RadioGroup.meta.d.ts.map +1 -0
- package/dist/components/RadioGroup/RadioGroup.stories.d.ts +9 -0
- package/dist/components/RadioGroup/RadioGroup.stories.d.ts.map +1 -0
- package/dist/components/RadioGroup/styles.css.d.ts +60 -0
- package/dist/components/RadioGroup/styles.css.d.ts.map +1 -0
- package/dist/components/StatusIcon/StatusIcon.meta.d.ts.map +1 -1
- package/dist/components/Table/ColumnFilter.d.ts +8 -0
- package/dist/components/Table/ColumnFilter.d.ts.map +1 -0
- package/dist/components/Table/Pagination.d.ts +7 -0
- package/dist/components/Table/Pagination.d.ts.map +1 -0
- package/dist/components/Table/SortIndicator.d.ts +16 -0
- package/dist/components/Table/SortIndicator.d.ts.map +1 -0
- package/dist/components/Table/Table.d.ts +10 -3
- package/dist/components/Table/Table.d.ts.map +1 -1
- package/dist/components/Table/Table.stories.d.ts +4 -0
- package/dist/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/components/Table/styles.css.d.ts +12 -4
- package/dist/components/Table/styles.css.d.ts.map +1 -1
- package/dist/components/Table/useDataTable.d.ts +32 -0
- package/dist/components/Table/useDataTable.d.ts.map +1 -0
- package/dist/components/ThemeProvider/ThemeProvider.meta.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2399 -1927
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/src/components/ActionBar/ActionBar.stories.tsx +3 -3
- package/src/components/Alert/Alert.meta.ts +4 -1
- package/src/components/ButtonGroup/ButtonGroup.meta.ts +24 -0
- package/src/components/ButtonGroup/ButtonGroup.stories.tsx +103 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +59 -0
- package/src/components/ButtonGroup/styles.css.ts +28 -0
- package/src/components/Callout/Callout.meta.ts +4 -1
- package/src/components/Card/Card.meta.ts +4 -1
- package/src/components/Checkbox/styles.css.ts +1 -1
- package/src/components/CheckboxGroup/CheckboxGroup.meta.ts +25 -0
- package/src/components/CheckboxGroup/CheckboxGroup.stories.tsx +88 -0
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +105 -0
- package/src/components/CheckboxGroup/styles.css.ts +13 -0
- package/src/components/EmptyState/EmptyState.meta.ts +1 -4
- package/src/components/Icon/Icon.meta.ts +5 -5
- package/src/components/InputGroup/InputGroup.meta.ts +4 -1
- package/src/components/List/List.meta.ts +8 -2
- package/src/components/List/List.stories.tsx +35 -15
- package/src/components/List/List.tsx +1 -5
- package/src/components/RadioGroup/RadioGroup.meta.ts +25 -0
- package/src/components/RadioGroup/RadioGroup.stories.tsx +83 -0
- package/src/components/RadioGroup/RadioGroup.tsx +113 -0
- package/src/components/RadioGroup/styles.css.ts +66 -0
- package/src/components/StatusIcon/StatusIcon.meta.ts +1 -4
- package/src/components/Table/ColumnFilter.tsx +46 -0
- package/src/components/Table/Pagination.tsx +82 -0
- package/src/components/Table/SortIndicator.tsx +56 -0
- package/src/components/Table/Table.stories.tsx +355 -9
- package/src/components/Table/Table.tsx +62 -17
- package/src/components/Table/styles.css.ts +18 -8
- package/src/components/Table/useDataTable.ts +113 -0
- package/src/components/ThemeProvider/ThemeProvider.meta.ts +1 -3
- package/src/docs/helpers.tsx +2 -2
- package/src/index.ts +5 -0
- package/src/strict.css +5 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {useState} from 'react'
|
|
2
|
+
import {
|
|
3
|
+
useReactTable,
|
|
4
|
+
getCoreRowModel,
|
|
5
|
+
getPaginationRowModel,
|
|
6
|
+
getSortedRowModel,
|
|
7
|
+
getFilteredRowModel,
|
|
8
|
+
type ColumnDef,
|
|
9
|
+
type SortingState,
|
|
10
|
+
type ColumnFiltersState,
|
|
11
|
+
type PaginationState,
|
|
12
|
+
type RowSelectionState,
|
|
13
|
+
type TableOptions,
|
|
14
|
+
type Table,
|
|
15
|
+
} from '@tanstack/react-table'
|
|
16
|
+
|
|
17
|
+
export interface UseDataTableOptions<TData> {
|
|
18
|
+
/** Initial pagination state */
|
|
19
|
+
pagination?: {pageSize?: number; pageIndex?: number}
|
|
20
|
+
/** Enable sorting on columns that don't explicitly disable it */
|
|
21
|
+
enableSorting?: boolean
|
|
22
|
+
/** Enable column filtering */
|
|
23
|
+
enableFiltering?: boolean
|
|
24
|
+
/** Enable row selection (checkbox) */
|
|
25
|
+
enableRowSelection?: boolean | ((row: any) => boolean)
|
|
26
|
+
/** Callback when row selection changes */
|
|
27
|
+
onRowSelectionChange?: (selection: RowSelectionState) => void
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Thin wrapper around TanStack's useReactTable.
|
|
32
|
+
* Pre-configures row models for pagination, sorting, and filtering.
|
|
33
|
+
* Returns the full TanStack table instance.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```tsx
|
|
37
|
+
* const table = useDataTable(users, columns, {
|
|
38
|
+
* pagination: { pageSize: 20 },
|
|
39
|
+
* enableSorting: true,
|
|
40
|
+
* enableFiltering: true,
|
|
41
|
+
* })
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export function useDataTable<TData>(
|
|
45
|
+
data: TData[],
|
|
46
|
+
columns: ColumnDef<TData, any>[],
|
|
47
|
+
options: UseDataTableOptions<TData> = {},
|
|
48
|
+
): Table<TData> {
|
|
49
|
+
const {
|
|
50
|
+
pagination: paginationInit,
|
|
51
|
+
enableSorting = false,
|
|
52
|
+
enableFiltering = false,
|
|
53
|
+
enableRowSelection = false,
|
|
54
|
+
onRowSelectionChange: onSelectionChangeProp,
|
|
55
|
+
} = options
|
|
56
|
+
|
|
57
|
+
const [sorting, setSorting] = useState<SortingState>([])
|
|
58
|
+
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([])
|
|
59
|
+
const [pagination, setPagination] = useState<PaginationState>({
|
|
60
|
+
pageIndex: paginationInit?.pageIndex ?? 0,
|
|
61
|
+
pageSize: paginationInit?.pageSize ?? 10,
|
|
62
|
+
})
|
|
63
|
+
const [rowSelection, setRowSelection] = useState<RowSelectionState>({})
|
|
64
|
+
|
|
65
|
+
const handleRowSelectionChange = (updater: any) => {
|
|
66
|
+
setRowSelection(updater)
|
|
67
|
+
if (onSelectionChangeProp) {
|
|
68
|
+
const next = typeof updater === 'function' ? updater(rowSelection) : updater
|
|
69
|
+
onSelectionChangeProp(next)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const tableOptions: TableOptions<TData> = {
|
|
74
|
+
data,
|
|
75
|
+
columns,
|
|
76
|
+
getCoreRowModel: getCoreRowModel(),
|
|
77
|
+
|
|
78
|
+
// Sorting
|
|
79
|
+
...(enableSorting && {
|
|
80
|
+
getSortedRowModel: getSortedRowModel(),
|
|
81
|
+
onSortingChange: setSorting,
|
|
82
|
+
state: {sorting},
|
|
83
|
+
}),
|
|
84
|
+
|
|
85
|
+
// Filtering
|
|
86
|
+
...(enableFiltering && {
|
|
87
|
+
getFilteredRowModel: getFilteredRowModel(),
|
|
88
|
+
onColumnFiltersChange: setColumnFilters,
|
|
89
|
+
}),
|
|
90
|
+
|
|
91
|
+
// Pagination
|
|
92
|
+
...(paginationInit && {
|
|
93
|
+
getPaginationRowModel: getPaginationRowModel(),
|
|
94
|
+
onPaginationChange: setPagination,
|
|
95
|
+
}),
|
|
96
|
+
|
|
97
|
+
// Row selection
|
|
98
|
+
...(enableRowSelection && {
|
|
99
|
+
enableRowSelection: typeof enableRowSelection === 'function' ? enableRowSelection : true,
|
|
100
|
+
onRowSelectionChange: handleRowSelectionChange,
|
|
101
|
+
}),
|
|
102
|
+
|
|
103
|
+
// Merge all state
|
|
104
|
+
state: {
|
|
105
|
+
...(enableSorting && {sorting}),
|
|
106
|
+
...(enableFiltering && {columnFilters}),
|
|
107
|
+
...(paginationInit && {pagination}),
|
|
108
|
+
...(enableRowSelection && {rowSelection}),
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return useReactTable(tableOptions)
|
|
113
|
+
}
|
|
@@ -7,9 +7,7 @@ export const meta: ComponentMeta = {
|
|
|
7
7
|
'App root — required for all Duro components to render correctly',
|
|
8
8
|
'Theme switching (dark/light mode toggle)',
|
|
9
9
|
],
|
|
10
|
-
whenNotToUse: [
|
|
11
|
-
'Never omit — all Duro components require ThemeProvider',
|
|
12
|
-
],
|
|
10
|
+
whenNotToUse: ['Never omit — all Duro components require ThemeProvider'],
|
|
13
11
|
example: `<ThemeProvider theme="dark">
|
|
14
12
|
<App />
|
|
15
13
|
</ThemeProvider>`,
|
package/src/docs/helpers.tsx
CHANGED
|
@@ -64,7 +64,7 @@ export function TypeScaleTable({rows, label}: TypeScaleTableProps) {
|
|
|
64
64
|
return (
|
|
65
65
|
<html.div>
|
|
66
66
|
{label && <html.h3 style={styles.label}>{label}</html.h3>}
|
|
67
|
-
<Table.Root
|
|
67
|
+
<Table.Root variant="striped" size="sm">
|
|
68
68
|
<Table.Header>
|
|
69
69
|
<Table.Row>
|
|
70
70
|
<Table.HeaderCell>Step</Table.HeaderCell>
|
|
@@ -106,7 +106,7 @@ export function TokenTable({tokens, label}: TokenTableProps) {
|
|
|
106
106
|
return (
|
|
107
107
|
<html.div>
|
|
108
108
|
{label && <html.h3 style={styles.label}>{label}</html.h3>}
|
|
109
|
-
<Table.Root
|
|
109
|
+
<Table.Root variant="striped" size="sm">
|
|
110
110
|
<Table.Header>
|
|
111
111
|
<Table.Row>
|
|
112
112
|
<Table.HeaderCell>Token</Table.HeaderCell>
|
package/src/index.ts
CHANGED
|
@@ -8,9 +8,11 @@ export {Alert, type AlertVariant} from './components/Alert/Alert'
|
|
|
8
8
|
export {Icon, type IconName} from './components/Icon'
|
|
9
9
|
export {Badge, type BadgeVariant, type BadgeSize} from './components/Badge/Badge'
|
|
10
10
|
export {Button, type ButtonVariant, type ButtonSize} from './components/Button/Button'
|
|
11
|
+
export {ButtonGroup} from './components/ButtonGroup/ButtonGroup'
|
|
11
12
|
export {Callout, type CalloutVariant} from './components/Callout/Callout'
|
|
12
13
|
export {Card, type CardVariant, type CardSize} from './components/Card/Card'
|
|
13
14
|
export {Checkbox} from './components/Checkbox/Checkbox'
|
|
15
|
+
export {CheckboxGroup} from './components/CheckboxGroup/CheckboxGroup'
|
|
14
16
|
export {Dialog, type DialogSize} from './components/Dialog/Dialog'
|
|
15
17
|
export {DetailPanel, type DetailPanelSize} from './components/DetailPanel/DetailPanel'
|
|
16
18
|
export {Drawer, type DrawerAnchor, type DrawerSize} from './components/Drawer/Drawer'
|
|
@@ -29,6 +31,7 @@ export {
|
|
|
29
31
|
} from './components/LinkButton/LinkButton'
|
|
30
32
|
export {Menu} from './components/Menu/Menu'
|
|
31
33
|
export {Panel} from './components/Panel/Panel'
|
|
34
|
+
export {RadioGroup} from './components/RadioGroup/RadioGroup'
|
|
32
35
|
export {ScrollArea} from './components/ScrollArea/ScrollArea'
|
|
33
36
|
export {Select} from './components/Select/Select'
|
|
34
37
|
export {SideNav} from './components/SideNav/SideNav'
|
|
@@ -39,6 +42,8 @@ export {
|
|
|
39
42
|
type StatusIconVariant,
|
|
40
43
|
} from './components/StatusIcon/StatusIcon'
|
|
41
44
|
export {Table, type TableVariant, type TableSize} from './components/Table/Table'
|
|
45
|
+
// TanStack Table: consumers install @tanstack/react-table directly and use
|
|
46
|
+
// Table.Pagination, Table.SortIndicator, Table.ColumnFilter for styled integration
|
|
42
47
|
export {Tabs} from './components/Tabs/Tabs'
|
|
43
48
|
export {Textarea, type TextareaVariant} from './components/Textarea/Textarea'
|
|
44
49
|
export {ThemeProvider, type ThemeName} from './components/ThemeProvider/ThemeProvider'
|