@dxos/react-ui-table 0.3.8-next.a5a9bfc → 0.3.8
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/lib/browser/index.mjs +511 -462
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/Cell/Cell.d.ts +12 -0
- package/dist/types/src/components/Cell/Cell.d.ts.map +1 -0
- package/dist/types/src/components/{ComboboxCell.d.ts → Cell/CellCombobox.d.ts} +4 -4
- package/dist/types/src/components/Cell/CellCombobox.d.ts.map +1 -0
- package/dist/types/src/components/Cell/index.d.ts +2 -0
- package/dist/types/src/components/Cell/index.d.ts.map +1 -0
- package/dist/types/src/components/Table/Table.d.ts +3 -0
- package/dist/types/src/components/Table/Table.d.ts.map +1 -0
- package/dist/types/src/components/{Table.stories.d.ts → Table/Table.stories.d.ts} +4 -7
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -0
- package/dist/types/src/components/Table/TableBody.d.ts +11 -0
- package/dist/types/src/components/Table/TableBody.d.ts.map +1 -0
- package/dist/types/src/components/Table/TableContext.d.ts +14 -0
- package/dist/types/src/components/Table/TableContext.d.ts.map +1 -0
- package/dist/types/src/components/Table/TableFooter.d.ts +7 -0
- package/dist/types/src/components/Table/TableFooter.d.ts.map +1 -0
- package/dist/types/src/components/Table/TableHead.d.ts +8 -0
- package/dist/types/src/components/Table/TableHead.d.ts.map +1 -0
- package/dist/types/src/components/Table/index.d.ts +3 -0
- package/dist/types/src/components/Table/index.d.ts.map +1 -0
- package/dist/types/src/components/Table/props.d.ts +37 -0
- package/dist/types/src/components/Table/props.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/helpers.d.ts +20 -14
- package/dist/types/src/helpers.d.ts.map +1 -1
- package/dist/types/src/theme.d.ts +32 -33
- package/dist/types/src/theme.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +13 -10
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +12 -10
- package/src/components/Cell/Cell.tsx +43 -0
- package/src/components/{ComboboxCell.tsx → Cell/CellCombobox.tsx} +6 -6
- package/src/components/Cell/index.ts +5 -0
- package/src/components/{Table.stories.tsx → Table/Table.stories.tsx} +51 -51
- package/src/components/Table/Table.tsx +179 -0
- package/src/components/Table/TableBody.tsx +69 -0
- package/src/components/Table/TableContext.tsx +28 -0
- package/src/components/Table/TableFooter.tsx +42 -0
- package/src/components/Table/TableHead.tsx +79 -0
- package/src/components/Table/index.ts +6 -0
- package/src/components/Table/props.ts +53 -0
- package/src/components/index.ts +1 -1
- package/src/helpers.tsx +255 -206
- package/src/theme.ts +95 -63
- package/src/types.ts +15 -10
- package/dist/types/src/components/ComboboxCell.d.ts.map +0 -1
- package/dist/types/src/components/Table.d.ts +0 -29
- package/dist/types/src/components/Table.d.ts.map +0 -1
- package/dist/types/src/components/Table.stories.d.ts.map +0 -1
- package/src/components/Table.tsx +0 -551
package/src/theme.ts
CHANGED
|
@@ -2,66 +2,98 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
5
|
+
import { type CellContext } from '@tanstack/react-table';
|
|
6
|
+
|
|
7
|
+
import { chromeSurface, fixedSurface, focusRing, groupBorder, hoverColors, mx } from '@dxos/react-ui-theme';
|
|
8
|
+
import { type ComponentFunction } from '@dxos/react-ui-types';
|
|
9
|
+
|
|
10
|
+
import { type TableContextValue, type TableFlags } from './components';
|
|
11
|
+
|
|
12
|
+
export const currentRow = '!bg-neutral-75 !dark:bg-neutral-850';
|
|
13
|
+
export const selectedRow = '!bg-primary-100 dark:!bg-primary-700';
|
|
14
|
+
export const flushPadding = 'pli-0 plb-0';
|
|
15
|
+
export const textPadding = 'pli-2 plb-0.5';
|
|
16
|
+
export const headPadding = 'pli-2 plb-1.5';
|
|
17
|
+
|
|
18
|
+
export const gridCellFocusRing = 'focus:z-[11] focus:outline outline-2 outline-primary-500 dark:outline-primary-400';
|
|
19
|
+
|
|
20
|
+
//
|
|
21
|
+
// table
|
|
22
|
+
//
|
|
23
|
+
|
|
24
|
+
export type TableStyleProps = Partial<TableContextValue<any>>;
|
|
25
|
+
|
|
26
|
+
export const tableRoot: ComponentFunction<TableStyleProps> = ({ fullWidth }, ...etc) =>
|
|
27
|
+
mx('table-fixed', fullWidth && 'is-full', ...etc);
|
|
28
|
+
|
|
29
|
+
export const groupTh: ComponentFunction<TableStyleProps> = (_props, ...etc) =>
|
|
30
|
+
mx('text-start font-medium', flushPadding, ...etc);
|
|
31
|
+
|
|
32
|
+
//
|
|
33
|
+
// thead
|
|
34
|
+
//
|
|
35
|
+
|
|
36
|
+
export type TheadStyleProps = Partial<TableFlags>;
|
|
37
|
+
|
|
38
|
+
export const theadRoot: ComponentFunction<TheadStyleProps> = ({ header }, ...etc) =>
|
|
39
|
+
mx(header ? 'sticky block-start-0 z-10' : 'collapse', header && fixedSurface, ...etc);
|
|
40
|
+
|
|
41
|
+
export const theadTr: ComponentFunction<TheadStyleProps> = (_props, ...etc) => mx('group', ...etc);
|
|
42
|
+
|
|
43
|
+
export const theadTh: ComponentFunction<TheadStyleProps> = ({ border }, ...etc) =>
|
|
44
|
+
mx(
|
|
45
|
+
'relative text-start font-medium select-none truncate',
|
|
46
|
+
headPadding,
|
|
47
|
+
border && 'border',
|
|
48
|
+
border && groupBorder,
|
|
49
|
+
...etc,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
export const theadResizeRoot: ComponentFunction<TheadStyleProps> = (_props, ...etc) =>
|
|
53
|
+
mx(
|
|
54
|
+
'absolute top-0 pis-1 h-full z-[10] w-[7px] -right-[5px] cursor-col-resize select-none touch-none opacity-20 hover:opacity-100',
|
|
55
|
+
...etc,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
export const theadResizeThumb: ComponentFunction<TheadStyleProps> = (_props, ...etc) =>
|
|
59
|
+
mx('flex group-hover:bg-neutral-700 -ml-[2px] w-[1px] h-full', ...etc);
|
|
60
|
+
|
|
61
|
+
//
|
|
62
|
+
// tbody
|
|
63
|
+
//
|
|
64
|
+
|
|
65
|
+
export type TbodyStyleProps = Partial<TableContextValue<any>>;
|
|
66
|
+
export const tbodyRoot: ComponentFunction<TbodyStyleProps> = (_props, ...etc) => mx(...etc);
|
|
67
|
+
|
|
68
|
+
export type TbodyTrStyleProps = Partial<{ isSelected?: boolean; isCurrent?: boolean; canBeCurrent?: boolean }>;
|
|
69
|
+
export const tbodyTr: ComponentFunction<TbodyTrStyleProps> = ({ isSelected, isCurrent, canBeCurrent }, ...etc) =>
|
|
70
|
+
mx(
|
|
71
|
+
'group',
|
|
72
|
+
isSelected ? selectedRow : isCurrent && currentRow,
|
|
73
|
+
canBeCurrent && focusRing,
|
|
74
|
+
canBeCurrent && hoverColors,
|
|
75
|
+
canBeCurrent && 'cursor-pointer rounded',
|
|
76
|
+
...etc,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
//
|
|
80
|
+
// td, th
|
|
81
|
+
//
|
|
82
|
+
|
|
83
|
+
export const tdRoot: ComponentFunction<TbodyStyleProps> = ({ border, isGrid }, ...etc) =>
|
|
84
|
+
mx('relative', flushPadding, border && 'border', border && groupBorder, isGrid && gridCellFocusRing, ...etc);
|
|
85
|
+
export const tdContent: ComponentFunction<CellContext<any, any>> = (_props, ...etc) => mx(...etc);
|
|
86
|
+
|
|
87
|
+
//
|
|
88
|
+
// tfoot
|
|
89
|
+
//
|
|
90
|
+
|
|
91
|
+
export type TfootStyleProps = Partial<TableContextValue<any>>;
|
|
92
|
+
|
|
93
|
+
export const tfootRoot: ComponentFunction<TfootStyleProps> = (_props, ...etc) =>
|
|
94
|
+
mx('sticky block-end-0 z-10', chromeSurface, ...etc);
|
|
95
|
+
|
|
96
|
+
export const tfootTr: ComponentFunction<TfootStyleProps> = (_props, ...etc) => mx(...etc);
|
|
97
|
+
|
|
98
|
+
export const tfootTh: ComponentFunction<TfootStyleProps> = ({ border }, ...etc) =>
|
|
99
|
+
mx(textPadding, chromeSurface, border && groupBorder, ...etc);
|
package/src/types.ts
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
import { type ColumnDef, type RowData } from '@tanstack/react-table';
|
|
6
6
|
|
|
7
|
+
import { type ClassNameValue } from '@dxos/react-ui-types';
|
|
8
|
+
|
|
9
|
+
import { type SearchListQueryModel, type ValueUpdater } from './helpers';
|
|
10
|
+
|
|
7
11
|
// Define custom meta definitions.
|
|
8
12
|
declare module '@tanstack/react-table' {
|
|
9
13
|
// Access via table.options.meta.
|
|
@@ -14,16 +18,17 @@ declare module '@tanstack/react-table' {
|
|
|
14
18
|
interface ColumnMeta<TData extends RowData, TValue> {
|
|
15
19
|
expand?: boolean;
|
|
16
20
|
resizable?: boolean;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
model?: SearchListQueryModel<TData>;
|
|
22
|
+
onUpdate?: ValueUpdater<TData, any>;
|
|
23
|
+
digits?: number;
|
|
24
|
+
header?: {
|
|
25
|
+
classNames?: ClassNameValue;
|
|
26
|
+
};
|
|
27
|
+
footer?: {
|
|
28
|
+
classNames?: ClassNameValue;
|
|
29
|
+
};
|
|
30
|
+
cell?: {
|
|
31
|
+
classNames?: ClassNameValue;
|
|
27
32
|
};
|
|
28
33
|
}
|
|
29
34
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ComboboxCell.d.ts","sourceRoot":"","sources":["../../../../src/components/ComboboxCell.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAOrD,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGnD,MAAM,MAAM,iBAAiB,CAAC,KAAK,SAAS,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,KAAK,CAAA;CAAE,CAAC,CAAC;AAStG,eAAO,MAAM,YAAY;;;qCAOU,IAAI;iBAiEtC,CAAC"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { type RowData, type RowSelectionState, type VisibilityState } from '@tanstack/react-table';
|
|
2
|
-
import { type TableSlots } from '../theme';
|
|
3
|
-
import { type TableColumnDef, type KeyValue } from '../types';
|
|
4
|
-
export type TableSelection<TData extends RowData> = {
|
|
5
|
-
select?: 'single' | 'single-toggle' | 'multiple' | 'multiple-toggle' | undefined;
|
|
6
|
-
selected?: TData[];
|
|
7
|
-
onSelectedChange?: (selected: TData[] | undefined) => void;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Util to update the selection based on the mode.
|
|
11
|
-
*/
|
|
12
|
-
export declare const updateSelection: (selectionState: RowSelectionState, id: string, selection: TableSelection<any>['select']) => RowSelectionState;
|
|
13
|
-
export type TableProps<TData extends RowData> = {
|
|
14
|
-
keyAccessor?: KeyValue<TData>;
|
|
15
|
-
data?: TData[];
|
|
16
|
-
columns?: TableColumnDef<TData>[];
|
|
17
|
-
columnVisibility?: VisibilityState;
|
|
18
|
-
onColumnResize?: (state: Record<string, number>) => void;
|
|
19
|
-
grouping?: string[];
|
|
20
|
-
header?: boolean;
|
|
21
|
-
footer?: boolean;
|
|
22
|
-
border?: boolean;
|
|
23
|
-
fullWidth?: boolean;
|
|
24
|
-
pinToBottom?: boolean;
|
|
25
|
-
slots?: TableSlots;
|
|
26
|
-
debug?: boolean;
|
|
27
|
-
} & TableSelection<TData>;
|
|
28
|
-
export declare const Table: <TData extends unknown>({ slots, ...props }: TableProps<TData>) => JSX.Element;
|
|
29
|
-
//# sourceMappingURL=Table.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../../../../src/components/Table.tsx"],"names":[],"mappings":"AAIA,OAAO,EAUL,KAAK,OAAO,EACZ,KAAK,iBAAiB,EAEtB,KAAK,eAAe,EACrB,MAAM,uBAAuB,CAAC;AAM/B,OAAO,EAAqB,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAM9D,MAAM,MAAM,cAAc,CAAC,KAAK,SAAS,OAAO,IAAI;IAElD,MAAM,CAAC,EAAE,QAAQ,GAAG,eAAe,GAAG,UAAU,GAAG,iBAAiB,GAAG,SAAS,CAAC;IACjF,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC;IACnB,gBAAgB,CAAC,EA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