@jakubmazanec/ui 0.4.2 → 0.5.0-next.7fc14073
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/build/components/Button.js +8 -5
- package/build/components/Button.js.map +2 -2
- package/build/components/Checkbox.js +2 -2
- package/build/components/Checkbox.js.map +1 -1
- package/build/components/Combobox.js +1 -1
- package/build/components/Combobox.js.map +1 -1
- package/build/components/DialogPanel.js +1 -1
- package/build/components/DialogPanel.js.map +1 -1
- package/build/components/DialogTitle.js +1 -1
- package/build/components/DialogTitle.js.map +1 -1
- package/build/components/Heading.d.ts +21 -0
- package/build/components/Heading.js +48 -0
- package/build/components/Heading.js.map +7 -0
- package/build/components/Icon.js +1 -1
- package/build/components/Icon.js.map +1 -1
- package/build/components/Input.js +4 -4
- package/build/components/Input.js.map +2 -2
- package/build/components/Legend.js +1 -1
- package/build/components/Legend.js.map +1 -1
- package/build/components/ListboxOption.js +1 -1
- package/build/components/ListboxOption.js.map +1 -1
- package/build/components/Radio.js +2 -2
- package/build/components/Radio.js.map +1 -1
- package/build/components/Spinner.js +1 -1
- package/build/components/Spinner.js.map +1 -1
- package/build/components/TableHead.js +1 -1
- package/build/components/TableHead.js.map +1 -1
- package/build/components/TableHeader.js +1 -1
- package/build/components/TableHeader.js.map +2 -2
- package/build/components/Textarea.js +2 -2
- package/build/components/Textarea.js.map +1 -1
- package/build/components/data-table/DataTable.d.ts +2 -1
- package/build/components/data-table/DataTable.js +78 -76
- package/build/components/data-table/DataTable.js.map +2 -2
- package/build/components/data-table/internals/DataTableFilter.d.ts +12 -0
- package/build/components/data-table/internals/DataTableFilter.js +275 -0
- package/build/components/data-table/internals/DataTableFilter.js.map +7 -0
- package/build/components/data-table/internals/DataTableFilters.d.ts +11 -0
- package/build/components/data-table/internals/DataTableFilters.js +40 -0
- package/build/components/data-table/internals/DataTableFilters.js.map +7 -0
- package/build/components/data-table/internals/DataTableHeader.d.ts +2 -11
- package/build/components/data-table/internals/DataTableHeader.js +18 -112
- package/build/components/data-table/internals/DataTableHeader.js.map +2 -2
- package/build/components/data-table/internals/DataTableMenu.d.ts +11 -0
- package/build/components/data-table/internals/DataTableMenu.js +34 -0
- package/build/components/data-table/internals/DataTableMenu.js.map +7 -0
- package/build/components/data-table/internals/DataTablePagination.js +2 -2
- package/build/components/data-table/internals/DataTablePagination.js.map +2 -2
- package/build/components/data-table/internals/DataTableRow.d.ts +6 -0
- package/build/components/data-table/internals/DataTableRow.js +26 -0
- package/build/components/data-table/internals/DataTableRow.js.map +7 -0
- package/build/components/data-table/internals/DataTableSetting.d.ts +10 -0
- package/build/components/data-table/internals/DataTableSetting.js +111 -0
- package/build/components/data-table/internals/DataTableSetting.js.map +7 -0
- package/build/components/data-table/internals/DataTableSettings.d.ts +9 -0
- package/build/components/data-table/internals/DataTableSettings.js +63 -0
- package/build/components/data-table/internals/DataTableSettings.js.map +7 -0
- package/build/components/data-table/internals/constants.d.ts +1 -1
- package/build/components/data-table/internals/constants.js +1 -1
- package/build/components/data-table/internals/constants.js.map +2 -2
- package/build/components/data-table/internals.d.ts +5 -0
- package/build/components/data-table/internals.js +5 -0
- package/build/components/data-table/internals.js.map +2 -2
- package/build/components.d.ts +1 -0
- package/build/components.js +1 -0
- package/build/components.js.map +2 -2
- package/build/development/createTailwindConfig.d.ts +79 -2
- package/build/development/createTailwindConfig.js +10 -55
- package/build/development/createTailwindConfig.js.map +2 -2
- package/build/development/internals/createTailwindThemeColors.d.ts +2 -0
- package/build/development/internals/createTailwindThemeColors.js +51 -0
- package/build/development/internals/createTailwindThemeColors.js.map +7 -0
- package/build/development/internals.d.ts +1 -0
- package/build/development/internals.js +1 -0
- package/build/development/internals.js.map +2 -2
- package/build/styles.css +15 -1
- package/build/styles.css.map +2 -2
- package/build/theme/Theme.d.ts +3 -0
- package/build/theme/defaultTheme.js +2 -0
- package/build/theme/defaultTheme.js.map +2 -2
- package/build/theme/internals/themeContext.d.ts +10 -0
- package/build/theme/internals/useTheme.d.ts +10 -0
- package/package.json +1 -1
- package/source/components/Button.tsx +12 -5
- package/source/components/Checkbox.tsx +2 -2
- package/source/components/Combobox.tsx +1 -1
- package/source/components/DialogPanel.tsx +1 -1
- package/source/components/DialogTitle.tsx +1 -1
- package/source/components/Heading.ts +69 -0
- package/source/components/Icon.tsx +1 -1
- package/source/components/Input.tsx +5 -5
- package/source/components/Legend.tsx +1 -1
- package/source/components/ListboxOption.tsx +1 -1
- package/source/components/Radio.tsx +2 -2
- package/source/components/Spinner.tsx +1 -1
- package/source/components/TableHead.ts +1 -1
- package/source/components/TableHeader.ts +2 -1
- package/source/components/Textarea.tsx +2 -2
- package/source/components/data-table/DataTable.tsx +97 -82
- package/source/components/data-table/internals/DataTableFilter.tsx +354 -0
- package/source/components/data-table/internals/DataTableFilters.tsx +56 -0
- package/source/components/data-table/internals/DataTableHeader.tsx +7 -145
- package/source/components/data-table/internals/DataTableMenu.tsx +60 -0
- package/source/components/data-table/internals/DataTablePagination.tsx +79 -77
- package/source/components/data-table/internals/DataTableRow.tsx +40 -0
- package/source/components/data-table/internals/DataTableSetting.tsx +142 -0
- package/source/components/data-table/internals/DataTableSettings.tsx +83 -0
- package/source/components/data-table/internals/constants.ts +1 -1
- package/source/components/data-table/internals.ts +5 -0
- package/source/components.ts +1 -0
- package/source/development/createTailwindConfig.ts +11 -57
- package/source/development/internals/createTailwindThemeColors.ts +53 -0
- package/source/development/internals.ts +1 -0
- package/source/styles.css +19 -3
- package/source/theme/Theme.ts +2 -0
- package/source/theme/defaultTheme.ts +2 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ComponentPropsWithoutRef,
|
|
3
|
+
createElement,
|
|
4
|
+
type ElementType,
|
|
5
|
+
type PropsWithChildren,
|
|
6
|
+
} from 'react';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
type ComponentProps,
|
|
10
|
+
type ComponentTheme,
|
|
11
|
+
createComponentTheme,
|
|
12
|
+
} from '../theme/internals.js';
|
|
13
|
+
import {type ComponentRef} from './ComponentRef.js';
|
|
14
|
+
|
|
15
|
+
export const useHeadingTheme = createComponentTheme('Heading', {
|
|
16
|
+
variants: {
|
|
17
|
+
size: ['small', 'medium', 'large'],
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const HEADING_ELEMENT = 'h1';
|
|
22
|
+
|
|
23
|
+
export type HeadingProps<T extends ElementType> = ComponentProps<typeof useHeadingTheme> &
|
|
24
|
+
ComponentPropsWithoutRef<T> &
|
|
25
|
+
ComponentRef<T> &
|
|
26
|
+
PropsWithChildren & {
|
|
27
|
+
as?: T | undefined;
|
|
28
|
+
className?: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export function Heading<T extends ElementType = typeof HEADING_ELEMENT>({
|
|
32
|
+
size = 'medium',
|
|
33
|
+
as: Component,
|
|
34
|
+
className,
|
|
35
|
+
ref,
|
|
36
|
+
children,
|
|
37
|
+
...rest
|
|
38
|
+
}: HeadingProps<T>) {
|
|
39
|
+
let theme = useHeadingTheme({size});
|
|
40
|
+
let props = {
|
|
41
|
+
ref,
|
|
42
|
+
className: theme(null, className),
|
|
43
|
+
'data-component': 'heading',
|
|
44
|
+
...rest,
|
|
45
|
+
};
|
|
46
|
+
// TODO: is this ok typings-wise? Are types for <h1> and <h2> different?
|
|
47
|
+
let DefaultComponent = HEADING_ELEMENT;
|
|
48
|
+
|
|
49
|
+
if (size === 'small') {
|
|
50
|
+
DefaultComponent = 'h3';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (size === 'medium') {
|
|
54
|
+
DefaultComponent = 'h2';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return createElement(Component ?? DefaultComponent, props, children);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const headingTheme: ComponentTheme<typeof useHeadingTheme> = {
|
|
61
|
+
className: 'm-0',
|
|
62
|
+
variants: {
|
|
63
|
+
size: {
|
|
64
|
+
small: 'text-lg font-medium',
|
|
65
|
+
medium: 'text-xl font-medium',
|
|
66
|
+
large: 'text-2xl font-medium',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
};
|
|
@@ -82,7 +82,7 @@ export function Icon<T extends ElementType = typeof ICON_ELEMENT>({
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
export const iconTheme: ComponentTheme<typeof useIconTheme> = {
|
|
85
|
-
className: 'inline-block shrink-0 *:w-full *:h-full
|
|
85
|
+
className: 'inline-block shrink-0 *:w-full *:h-full select-none',
|
|
86
86
|
variants: {
|
|
87
87
|
size: {
|
|
88
88
|
small: 'size-4',
|
|
@@ -117,9 +117,9 @@ export function Input<T extends ElementType = typeof INPUT_ELEMENT>({
|
|
|
117
117
|
</span>
|
|
118
118
|
: null}
|
|
119
119
|
{showClearButton ?
|
|
120
|
-
<
|
|
120
|
+
<button type="button" {...clearButtonProps} onClick={handleClear}>
|
|
121
121
|
<Icon name="XMark" />
|
|
122
|
-
</
|
|
122
|
+
</button>
|
|
123
123
|
: null}
|
|
124
124
|
</span>
|
|
125
125
|
);
|
|
@@ -127,11 +127,11 @@ export function Input<T extends ElementType = typeof INPUT_ELEMENT>({
|
|
|
127
127
|
|
|
128
128
|
export const inputTheme: ComponentTheme<typeof useInputTheme> = {
|
|
129
129
|
classNames: {
|
|
130
|
-
root: 'group flex w-full items-center rounded-2 border-2 border-neutral-100 hover:border-neutral-200 px-2.5 h-9 bg-white shadow-inner transition-colors',
|
|
130
|
+
root: 'group flex w-full items-center rounded-2 border-2 border-neutral-100 hover:border-neutral-200 px-2.5 h-9 bg-white shadow-inner transition-colors focus-within:outline-solid focus-within:outline-2 focus-within:outline-blue-400/50 focus-within:outline-offset-[calc(var(--spacing)*0.5)]',
|
|
131
131
|
input:
|
|
132
|
-
'p-0 focus
|
|
132
|
+
'p-0 focus:outline-none w-full group-data-[icon]:pl-6 group-data-[clear-button]:pr-4 bg-transparent font-sans text-sm',
|
|
133
133
|
icon: 'size-6 left-[0.3125rem] top-[0.3125rem] text-neutral-300',
|
|
134
|
-
clearButton: 'text-neutral-500 size-5 right-2 cursor-pointer',
|
|
134
|
+
clearButton: 'rounded-1 text-neutral-500 size-5 right-2 cursor-pointer',
|
|
135
135
|
},
|
|
136
136
|
variants: {
|
|
137
137
|
disabled: {
|
|
@@ -68,7 +68,7 @@ export function ListboxOption<
|
|
|
68
68
|
|
|
69
69
|
export const listboxOptionTheme: ComponentTheme<typeof useListboxOptionTheme> = {
|
|
70
70
|
classNames: {
|
|
71
|
-
root: 'group/option p-1 pr-6 rounded-1 hover:bg-neutral-50 data-[active]:bg-neutral-50 text-sm transition-colors',
|
|
71
|
+
root: 'group/option p-1 pr-6 rounded-1 hover:bg-neutral-50 data-[active]:bg-neutral-50 text-sm transition-colors relative',
|
|
72
72
|
icon: 'hidden group-data-[selected]/option:block right-1 top-1 text-neutral-500',
|
|
73
73
|
},
|
|
74
74
|
variants: {
|
|
@@ -70,8 +70,8 @@ export function Radio<
|
|
|
70
70
|
|
|
71
71
|
export const radioTheme: ComponentTheme<typeof useRadioTheme> = {
|
|
72
72
|
classNames: {
|
|
73
|
-
root: 'group/radio inline-block size-5',
|
|
74
|
-
icon: 'flex justify-content justify-item size-5 *:rounded-full *:bg-white *:border-2 *:border-neutral-100 *:hover:border-neutral-200 *:shadow-inner *:transition-colors *:text-transparent *:hover:text-neutral-100 group-data-[checked]/radio:*:bg-neutral-950 group-data-[checked]/radio:*:border-neutral-950 group-data-[checked]/radio:*:text-white',
|
|
73
|
+
root: 'group/radio inline-block size-5 rounded-full',
|
|
74
|
+
icon: 'flex justify-content justify-item size-5 *:rounded-full *:bg-white *:border-2 *:border-neutral-100 *:hover:border-neutral-200 *:shadow-inner *:transition-colors *:text-transparent *:hover:text-neutral-100 group-data-[checked]/radio:*:bg-neutral-950 group-data-[checked]/radio:*:border-neutral-950 group-data-[checked]/radio:*:text-white group-data-[checked]/radio:*:hover:border-neutral-950',
|
|
75
75
|
},
|
|
76
76
|
variants: {
|
|
77
77
|
disabled: {
|
|
@@ -44,7 +44,7 @@ export const Spinner = memo(({size = 'medium', className, ...rest}: SpinnerProps
|
|
|
44
44
|
|
|
45
45
|
export const spinnerTheme: ComponentTheme<typeof useSpinnerTheme> = {
|
|
46
46
|
classNames: {
|
|
47
|
-
root: 'inline-flex items-center justify-center fill-neutral-900 text-neutral-200
|
|
47
|
+
root: 'inline-flex items-center justify-center fill-neutral-900 text-neutral-200',
|
|
48
48
|
icon: 'animate-spin',
|
|
49
49
|
},
|
|
50
50
|
variants: {
|
|
@@ -43,5 +43,5 @@ export function TableHead<T extends ElementType = typeof TABLE_HEAD_ELEMENT>({
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export const tableHeadTheme: ComponentTheme<typeof useTableHeadTheme> = {
|
|
46
|
-
className: 'font-sans border-b-2 border-neutral-100',
|
|
46
|
+
className: 'font-sans border-t-2 border-b-2 border-neutral-100',
|
|
47
47
|
};
|
|
@@ -43,5 +43,6 @@ export function TableHeader<T extends ElementType = typeof TABLE_HEADER_ELEMENT>
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export const tableHeaderTheme: ComponentTheme<typeof useTableHeaderTheme> = {
|
|
46
|
-
className:
|
|
46
|
+
className:
|
|
47
|
+
'relative p-1 text-sm font-medium z-20 font-sans tabular-nums whitespace-nowrap empty:p-0',
|
|
47
48
|
};
|
|
@@ -79,9 +79,9 @@ export function Textarea<T extends ElementType = typeof TEXTAREA_ELEMENT>({
|
|
|
79
79
|
|
|
80
80
|
export const textareaTheme: ComponentTheme<typeof useTextareaTheme> = {
|
|
81
81
|
classNames: {
|
|
82
|
-
root: 'group flex w-full items-center rounded border-2 border-neutral-100 hover:border-neutral-200 py-2 px-2.5 min-h-19 bg-white shadow-inner transition-colors',
|
|
82
|
+
root: 'group flex w-full items-center rounded border-2 border-neutral-100 hover:border-neutral-200 py-2 px-2.5 min-h-19 bg-white shadow-inner transition-colors focus-within:outline-solid focus-within:outline-2 focus-within:outline-blue-400/50 focus-within:outline-offset-[calc(var(--spacing)*0.5)]',
|
|
83
83
|
textarea:
|
|
84
|
-
'min-h-15 p-0 focus
|
|
84
|
+
'min-h-15 p-0 focus:outline-none w-full group-data-[icon]:pl-6 bg-transparent font-sans text-sm',
|
|
85
85
|
icon: 'size-6 left-[0.3125rem] top-[0.3125rem] text-neutral-300',
|
|
86
86
|
},
|
|
87
87
|
variants: {
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
closestCenter,
|
|
3
|
-
DndContext,
|
|
4
|
-
type DragEndEvent,
|
|
5
|
-
KeyboardSensor,
|
|
6
|
-
MouseSensor,
|
|
7
|
-
TouchSensor,
|
|
8
|
-
useSensor,
|
|
9
|
-
useSensors,
|
|
10
|
-
} from '@dnd-kit/core';
|
|
11
|
-
import {restrictToHorizontalAxis} from '@dnd-kit/modifiers';
|
|
12
|
-
import {arrayMove, horizontalListSortingStrategy, SortableContext} from '@dnd-kit/sortable';
|
|
1
|
+
import {horizontalListSortingStrategy, SortableContext} from '@dnd-kit/sortable';
|
|
13
2
|
import {
|
|
14
3
|
type ColumnDef,
|
|
15
4
|
type ColumnFiltersState,
|
|
@@ -23,15 +12,21 @@ import {
|
|
|
23
12
|
getFilteredRowModel,
|
|
24
13
|
getPaginationRowModel,
|
|
25
14
|
getSortedRowModel,
|
|
15
|
+
type Header,
|
|
26
16
|
type PaginationState,
|
|
17
|
+
type Row,
|
|
27
18
|
type RowData,
|
|
28
19
|
type SortingState,
|
|
29
20
|
type Updater,
|
|
30
21
|
useReactTable,
|
|
31
22
|
type VisibilityState,
|
|
32
23
|
} from '@tanstack/react-table';
|
|
33
|
-
import {useCallback,
|
|
24
|
+
import {useCallback, useState} from 'react';
|
|
34
25
|
|
|
26
|
+
import {Button} from '../Button.js';
|
|
27
|
+
import {Container} from '../Container.js';
|
|
28
|
+
import {Dialog} from '../Dialog.js';
|
|
29
|
+
import {DialogPanel} from '../DialogPanel.js';
|
|
35
30
|
import {Table} from '../Table.js';
|
|
36
31
|
import {TableBody} from '../TableBody.js';
|
|
37
32
|
import {TableCell} from '../TableCell.js';
|
|
@@ -48,15 +43,16 @@ import {type DataTablePagination} from './DataTablePagination.js';
|
|
|
48
43
|
import {type DataTableSearch} from './DataTableSearch.js';
|
|
49
44
|
import {type DataTableSorting} from './DataTableSorting.js';
|
|
50
45
|
import {
|
|
46
|
+
DataTableFilters as DataTableFiltersComponent,
|
|
51
47
|
DataTableHeader,
|
|
48
|
+
DataTableMenu,
|
|
52
49
|
DataTablePagination as DataTablePaginationComponent,
|
|
53
50
|
DataTableSearch as DataTableSearchComponent,
|
|
54
51
|
DEFAULT_PAGE_SIZE,
|
|
55
52
|
fromPinningState,
|
|
56
53
|
fuzzyFilter,
|
|
57
|
-
getCommonPinningClasses,
|
|
58
|
-
getCommonPinningStyles,
|
|
59
54
|
} from './internals.js';
|
|
55
|
+
import {DataTableRow} from './internals/DataTableRow.js';
|
|
60
56
|
|
|
61
57
|
declare module '@tanstack/react-table' {
|
|
62
58
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- false positive
|
|
@@ -100,6 +96,7 @@ export type DataTableProps<D, C> = {
|
|
|
100
96
|
hideSearch?: boolean | undefined;
|
|
101
97
|
search?: DataTableSearch | undefined;
|
|
102
98
|
onSearchChange?: ((search: DataTableSearch) => void) | undefined;
|
|
99
|
+
showRowSummaryOnClick?: boolean | undefined;
|
|
103
100
|
};
|
|
104
101
|
|
|
105
102
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- needed so the type parameters are useful
|
|
@@ -134,6 +131,7 @@ export function DataTable<D extends RowData, C extends Array<ColumnDef<D, any>>>
|
|
|
134
131
|
hideSearch = false,
|
|
135
132
|
search: controlledSearch,
|
|
136
133
|
onSearchChange,
|
|
134
|
+
showRowSummaryOnClick = false,
|
|
137
135
|
}: DataTableProps<D, C>) {
|
|
138
136
|
let [pagination, setPagination] = useState<PaginationState>(
|
|
139
137
|
controlledPagination ?
|
|
@@ -199,7 +197,10 @@ export function DataTable<D extends RowData, C extends Array<ColumnDef<D, any>>>
|
|
|
199
197
|
);
|
|
200
198
|
let [sorting, setSorting] = useState<SortingState>([]);
|
|
201
199
|
let [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
|
|
200
|
+
let [showFilters, setShowFilters] = useState(false);
|
|
202
201
|
let [search, setSearch] = useState('');
|
|
202
|
+
let [showRowSummary, setShowRowSummary] = useState(false);
|
|
203
|
+
let [rowSummaryRow, setRowSummaryRow] = useState<Row<D> | null>(null);
|
|
203
204
|
|
|
204
205
|
let handleColumnVisibilityChange = useCallback(
|
|
205
206
|
(columnVisibilityState: Updater<VisibilityState>) => {
|
|
@@ -268,36 +269,6 @@ export function DataTable<D extends RowData, C extends Array<ColumnDef<D, any>>>
|
|
|
268
269
|
globalFilterFn: fuzzyFilter,
|
|
269
270
|
});
|
|
270
271
|
|
|
271
|
-
let handleDragEnd = useCallback(
|
|
272
|
-
({active, over}: DragEndEvent) => {
|
|
273
|
-
if (over && active.id !== over.id) {
|
|
274
|
-
table.setColumnOrder((previousColumnOrder) => {
|
|
275
|
-
let oldIndex = previousColumnOrder.indexOf(active.id as string);
|
|
276
|
-
let newIndex = previousColumnOrder.indexOf(over.id as string);
|
|
277
|
-
|
|
278
|
-
return arrayMove(previousColumnOrder, oldIndex, newIndex);
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
},
|
|
282
|
-
[table],
|
|
283
|
-
);
|
|
284
|
-
|
|
285
|
-
let sensors = useSensors(
|
|
286
|
-
useSensor(MouseSensor, {
|
|
287
|
-
activationConstraint: {
|
|
288
|
-
distance: 5,
|
|
289
|
-
},
|
|
290
|
-
}),
|
|
291
|
-
useSensor(TouchSensor, {
|
|
292
|
-
activationConstraint: {
|
|
293
|
-
distance: 5,
|
|
294
|
-
},
|
|
295
|
-
}),
|
|
296
|
-
useSensor(KeyboardSensor, {}),
|
|
297
|
-
);
|
|
298
|
-
|
|
299
|
-
let id = useId();
|
|
300
|
-
|
|
301
272
|
let page =
|
|
302
273
|
clientPagination ?
|
|
303
274
|
table.getState().pagination.pageIndex + 1
|
|
@@ -308,20 +279,52 @@ export function DataTable<D extends RowData, C extends Array<ColumnDef<D, any>>>
|
|
|
308
279
|
: (controlledPagination?.pageSize ?? DEFAULT_PAGE_SIZE);
|
|
309
280
|
let pageCount = clientPagination ? table.getPageCount() : (controlledPagination?.pageCount ?? 1);
|
|
310
281
|
|
|
282
|
+
let toggleFilters = useCallback(() => {
|
|
283
|
+
setShowFilters((value) => !value);
|
|
284
|
+
}, []);
|
|
285
|
+
|
|
286
|
+
let handleRowClick = useCallback((row: Row<D>) => {
|
|
287
|
+
setRowSummaryRow(row);
|
|
288
|
+
setShowRowSummary(true);
|
|
289
|
+
}, []);
|
|
290
|
+
|
|
291
|
+
let handleCloseRowDialog = useCallback(() => {
|
|
292
|
+
setShowRowSummary(false);
|
|
293
|
+
}, []);
|
|
294
|
+
|
|
311
295
|
return (
|
|
312
|
-
<
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
modifiers={[restrictToHorizontalAxis]}
|
|
316
|
-
sensors={sensors}
|
|
317
|
-
onDragEnd={handleDragEnd}
|
|
296
|
+
<div
|
|
297
|
+
className="group/table grid w-full grid-cols-[100%] grid-rows-[min-content_min-content_1fr] gap-6 sm:gap-4 sm:data-[show-filters]:grid-cols-[1fr_2fr] md:data-[show-filters]:grid-cols-[1fr_3fr] lg:data-[show-filters]:grid-cols-[1fr_4fr]"
|
|
298
|
+
data-show-filters={showFilters || undefined}
|
|
318
299
|
>
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
300
|
+
<div className="flex flex-col gap-2">
|
|
301
|
+
{hideSearch ? null : (
|
|
302
|
+
<DataTableSearchComponent
|
|
303
|
+
clientSearch={clientSearch}
|
|
304
|
+
search={controlledSearch}
|
|
305
|
+
table={table}
|
|
306
|
+
onSearch={onSearchChange}
|
|
307
|
+
/>
|
|
308
|
+
)}
|
|
309
|
+
{hideColumnOrder && hideColumnPinning && hideColumnVisibility && hideFilters ? null : (
|
|
310
|
+
<DataTableMenu
|
|
311
|
+
hideColumnOrder={hideColumnOrder}
|
|
312
|
+
hideColumnPinning={hideColumnPinning}
|
|
313
|
+
hideColumnVisibility={hideColumnVisibility}
|
|
314
|
+
hideFilters={hideFilters}
|
|
315
|
+
table={table}
|
|
316
|
+
toggleFilters={toggleFilters}
|
|
317
|
+
/>
|
|
318
|
+
)}
|
|
319
|
+
</div>
|
|
320
|
+
{hideFilters ? null : (
|
|
321
|
+
<DataTableFiltersComponent
|
|
322
|
+
clientFaceting={clientFaceting}
|
|
323
|
+
clientFilters={clientFilters}
|
|
324
|
+
faceting={faceting}
|
|
325
|
+
filters={controlledFilters}
|
|
323
326
|
table={table}
|
|
324
|
-
|
|
327
|
+
onFiltering={onFiltersChange}
|
|
325
328
|
/>
|
|
326
329
|
)}
|
|
327
330
|
<div className="w-full overflow-x-scroll overflow-y-visible [scrollbar-width:thin]">
|
|
@@ -338,21 +341,12 @@ export function DataTable<D extends RowData, C extends Array<ColumnDef<D, any>>>
|
|
|
338
341
|
{headerGroup.headers.map((header) => (
|
|
339
342
|
<DataTableHeader
|
|
340
343
|
key={header.id}
|
|
341
|
-
clientFaceting={clientFaceting}
|
|
342
|
-
clientFilters={clientFilters}
|
|
343
344
|
clientSorting={clientSorting}
|
|
344
|
-
faceting={faceting}
|
|
345
|
-
filters={controlledFilters}
|
|
346
345
|
header={header}
|
|
347
346
|
hideColumnOrder={hideColumnOrder}
|
|
348
|
-
hideColumnPinning={hideColumnPinning}
|
|
349
347
|
hideColumnResizing={hideColumnResizing}
|
|
350
|
-
hideColumnVisibility={hideColumnVisibility}
|
|
351
|
-
hideFilters={hideFilters}
|
|
352
348
|
hideSorting={hideSorting}
|
|
353
349
|
sorting={controlledSorting}
|
|
354
|
-
table={table}
|
|
355
|
-
onFiltering={onFiltersChange}
|
|
356
350
|
onSorting={onSortingChange}
|
|
357
351
|
/>
|
|
358
352
|
))}
|
|
@@ -362,22 +356,11 @@ export function DataTable<D extends RowData, C extends Array<ColumnDef<D, any>>>
|
|
|
362
356
|
</TableHead>
|
|
363
357
|
<TableBody>
|
|
364
358
|
{table.getRowModel().rows.map((row) => (
|
|
365
|
-
<
|
|
366
|
-
{row.
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
<TableCell
|
|
371
|
-
key={cell.id}
|
|
372
|
-
className={getCommonPinningClasses(cell.column)}
|
|
373
|
-
style={{...getCommonPinningStyles(cell.column)}}
|
|
374
|
-
title={value === null || value === undefined ? undefined : String(value)}
|
|
375
|
-
>
|
|
376
|
-
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
377
|
-
</TableCell>
|
|
378
|
-
);
|
|
379
|
-
})}
|
|
380
|
-
</TableRow>
|
|
359
|
+
<DataTableRow
|
|
360
|
+
key={row.id}
|
|
361
|
+
row={row}
|
|
362
|
+
onClick={showRowSummaryOnClick ? handleRowClick : undefined}
|
|
363
|
+
/>
|
|
381
364
|
))}
|
|
382
365
|
</TableBody>
|
|
383
366
|
<TableFoot>
|
|
@@ -405,6 +388,38 @@ export function DataTable<D extends RowData, C extends Array<ColumnDef<D, any>>>
|
|
|
405
388
|
onPagination={onPaginationChange}
|
|
406
389
|
/>
|
|
407
390
|
)}
|
|
408
|
-
|
|
391
|
+
{showRowSummaryOnClick ?
|
|
392
|
+
<Dialog open={showRowSummary} onClose={handleCloseRowDialog}>
|
|
393
|
+
<DialogPanel className="flex flex-col gap-4">
|
|
394
|
+
{rowSummaryRow ?
|
|
395
|
+
<Table className="w-full">
|
|
396
|
+
<TableBody>
|
|
397
|
+
{rowSummaryRow.getVisibleCells().map((cell) => (
|
|
398
|
+
<TableRow key={cell.id}>
|
|
399
|
+
<TableHeader className="px-4">
|
|
400
|
+
{flexRender(cell.column.columnDef.header, {
|
|
401
|
+
table,
|
|
402
|
+
column: cell.column,
|
|
403
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions -- needed
|
|
404
|
+
header: {column: cell.column} as Header<any, any>,
|
|
405
|
+
})}
|
|
406
|
+
</TableHeader>
|
|
407
|
+
<TableCell className="overflow-visible whitespace-normal">
|
|
408
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
409
|
+
</TableCell>
|
|
410
|
+
</TableRow>
|
|
411
|
+
))}
|
|
412
|
+
</TableBody>
|
|
413
|
+
</Table>
|
|
414
|
+
: null}
|
|
415
|
+
<Container align="center" direction="column">
|
|
416
|
+
<Button className="self-center" onClick={handleCloseRowDialog}>
|
|
417
|
+
Close
|
|
418
|
+
</Button>
|
|
419
|
+
</Container>
|
|
420
|
+
</DialogPanel>
|
|
421
|
+
</Dialog>
|
|
422
|
+
: null}
|
|
423
|
+
</div>
|
|
409
424
|
);
|
|
410
425
|
}
|