@dxos/react-ui-table 0.3.7 → 0.3.8-main.0694b57
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 +546 -475
- 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/Cell/CellCombobox.d.ts +12 -0
- 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 -0
- 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/translations.d.ts +10 -0
- package/dist/types/src/translations.d.ts.map +1 -0
- 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/Cell/CellCombobox.tsx +97 -0
- package/src/components/Cell/index.ts +5 -0
- package/src/components/{Table.stories.tsx → Table/Table.stories.tsx} +51 -50
- 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 -0
- package/src/helpers.tsx +250 -282
- package/src/theme.ts +95 -63
- package/src/translations.ts +15 -0
- package/src/types.ts +15 -10
- 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
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Row, type RowData } from '@tanstack/react-table';
|
|
2
|
+
type TableBodyProps<TData extends RowData> = {
|
|
3
|
+
rows: Row<TData>[];
|
|
4
|
+
};
|
|
5
|
+
declare const TableBody: {
|
|
6
|
+
<TData extends unknown>({ rows }: TableBodyProps<TData>): JSX.Element;
|
|
7
|
+
displayName: string;
|
|
8
|
+
};
|
|
9
|
+
export { TableBody };
|
|
10
|
+
export type { TableBodyProps };
|
|
11
|
+
//# sourceMappingURL=TableBody.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableBody.d.ts","sourceRoot":"","sources":["../../../../../src/components/Table/TableBody.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAc,KAAK,GAAG,EAAE,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAO3E,KAAK,cAAc,CAAC,KAAK,SAAS,OAAO,IAAI;IAC3C,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;CACpB,CAAC;AAIF,QAAA,MAAM,SAAS;;;CA4Cd,CAAC;AAIF,OAAO,EAAE,SAAS,EAAE,CAAC;AAErB,YAAY,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type RowData } from '@tanstack/react-table';
|
|
2
|
+
import { type ReactNode } from 'react';
|
|
3
|
+
import { type TableContextValue } from './props';
|
|
4
|
+
export declare const TABLE_NAME = "Table";
|
|
5
|
+
export type TypedTableProvider<TData extends RowData> = {
|
|
6
|
+
(props: TableContextValue<TData> & {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
}): JSX.Element;
|
|
9
|
+
displayName: string;
|
|
10
|
+
};
|
|
11
|
+
declare const TableProvider: TypedTableProvider<unknown>;
|
|
12
|
+
export declare const useTableContext: <TData extends unknown>(consumerName: string) => TableContextValue<TData>;
|
|
13
|
+
export { TableProvider };
|
|
14
|
+
//# sourceMappingURL=TableContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableContext.d.ts","sourceRoot":"","sources":["../../../../../src/components/Table/TableContext.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,eAAO,MAAM,UAAU,UAAU,CAAC;AAMlC,MAAM,MAAM,kBAAkB,CAAC,KAAK,SAAS,OAAO,IAAI;IACtD,CAAC,KAAK,EAAE,iBAAiB,CAAC,KAAK,CAAC,GAAG;QAAE,QAAQ,EAAE,SAAS,CAAA;KAAE,GAAG,GAAG,CAAC,OAAO,CAAC;IACzE,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,QAAA,MAAO,aAAa,6BACmC,CAAC;AAExD,eAAO,MAAM,eAAe,wCAAyC,MAAM,6BACT,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableFooter.d.ts","sourceRoot":"","sources":["../../../../../src/components/Table/TableFooter.tsx"],"names":[],"mappings":"AAUA,MAAM,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAIlC,QAAA,MAAM,WAAW;mCAAkC,gBAAgB;;CAuBlE,CAAC;AAIF,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableHead.d.ts","sourceRoot":"","sources":["../../../../../src/components/Table/TableHead.tsx"],"names":[],"mappings":"AAcA,KAAK,cAAc,GAAG,EAAE,CAAC;AAEzB,QAAA,MAAM,SAAS;oCAAmC,cAAc;;CAwD/D,CAAC;AAIF,OAAO,EAAE,SAAS,EAAE,CAAC;AAErB,YAAY,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/Table/index.ts"],"names":[],"mappings":"AAIA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type RowData, type RowSelectionState, type Table, type VisibilityState } from '@tanstack/react-table';
|
|
2
|
+
import { type KeyValue, type TableColumnDef } from '../../types';
|
|
3
|
+
export type TableFlags = Partial<{
|
|
4
|
+
role: 'table' | 'grid' | 'treegrid';
|
|
5
|
+
grouping: string[];
|
|
6
|
+
header: boolean;
|
|
7
|
+
footer: boolean;
|
|
8
|
+
border: boolean;
|
|
9
|
+
fullWidth: boolean;
|
|
10
|
+
debug: boolean;
|
|
11
|
+
expand: boolean;
|
|
12
|
+
rowsSelectable: boolean | 'multi';
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* This is ‘current’ in the `aria-current` sense.
|
|
16
|
+
*/
|
|
17
|
+
export type TableCurrent<TData extends RowData> = Partial<{
|
|
18
|
+
currentDatum: TData;
|
|
19
|
+
onDatumClick: (datum: TData) => void;
|
|
20
|
+
}>;
|
|
21
|
+
export type TableProps<TData extends RowData> = TableFlags & TableCurrent<TData> & Partial<{
|
|
22
|
+
keyAccessor: KeyValue<TData>;
|
|
23
|
+
data: TData[];
|
|
24
|
+
columns: TableColumnDef<TData>[];
|
|
25
|
+
onColumnResize: (state: Record<string, number>) => void;
|
|
26
|
+
columnVisibility: VisibilityState;
|
|
27
|
+
rowSelection: RowSelectionState;
|
|
28
|
+
defaultRowSelection: RowSelectionState;
|
|
29
|
+
onRowSelectionChange: (rowSelection: RowSelectionState) => void;
|
|
30
|
+
onDataSelectionChange: (dataSelection: TData[]) => void;
|
|
31
|
+
}>;
|
|
32
|
+
export type { RowSelectionState, VisibilityState, TableColumnDef, KeyValue };
|
|
33
|
+
export type TableContextValue<TData extends RowData> = TableFlags & TableCurrent<TData> & Pick<TableProps<TData>, 'keyAccessor'> & {
|
|
34
|
+
table: Table<TData>;
|
|
35
|
+
isGrid: boolean;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../../../../src/components/Table/props.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,KAAK,EAAE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE/G,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAEjE,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC;IAC/B,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,UAAU,CAAC;IACpC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,MA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KAAK,CAAC,KAAK,CAAC,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { type Icon } from '@phosphor-icons/react';
|
|
2
|
-
import { type ColumnDef, type ColumnMeta, type RowData } from '@tanstack/react-table';
|
|
2
|
+
import { type ColumnDef, type ColumnMeta, type RowData, type ColumnHelper } from '@tanstack/react-table';
|
|
3
3
|
import { type PublicKey } from '@dxos/keys';
|
|
4
|
+
import { type ClassNameValue } from '@dxos/react-ui';
|
|
4
5
|
export type ValueUpdater<TData extends RowData, TValue> = (row: TData, id: string, value: TValue) => void;
|
|
5
6
|
export declare const createColumnBuilder: <TData extends unknown>() => {
|
|
6
|
-
helper:
|
|
7
|
+
helper: ColumnHelper<TData>;
|
|
7
8
|
builder: ColumnBuilder<TData>;
|
|
8
9
|
};
|
|
9
10
|
/**
|
|
@@ -12,18 +13,19 @@ export declare const createColumnBuilder: <TData extends unknown>() => {
|
|
|
12
13
|
export type BaseColumnOptions<TData, TValue> = Partial<ColumnDef<TData, TValue>> & {
|
|
13
14
|
meta?: ColumnMeta<TData, TValue>;
|
|
14
15
|
label?: string;
|
|
15
|
-
|
|
16
|
+
classNames?: ClassNameValue;
|
|
16
17
|
onUpdate?: ValueUpdater<TData, TValue | undefined>;
|
|
17
18
|
};
|
|
18
|
-
export type
|
|
19
|
+
export type SearchListQueryModel<TData extends RowData> = {
|
|
19
20
|
getId(object: TData): string;
|
|
20
21
|
getText(object: TData): string;
|
|
21
22
|
query(text?: string): Promise<TData[]>;
|
|
22
23
|
};
|
|
23
|
-
export type
|
|
24
|
-
model:
|
|
24
|
+
export type ComboboxColumnOptions<TData extends RowData> = BaseColumnOptions<TData, any> & {
|
|
25
|
+
model: SearchListQueryModel<TData>;
|
|
25
26
|
};
|
|
26
27
|
export type StringColumnOptions<TData extends RowData> = BaseColumnOptions<TData, string> & {};
|
|
28
|
+
export type SelectRowColumnOptions<TData extends RowData> = BaseColumnOptions<TData, string> & {};
|
|
27
29
|
export type NumberColumnOptions<TData extends RowData> = BaseColumnOptions<TData, number> & {
|
|
28
30
|
digits?: number;
|
|
29
31
|
};
|
|
@@ -34,7 +36,7 @@ export type DateColumnOptions<TData extends RowData> = BaseColumnOptions<TData,
|
|
|
34
36
|
format?: string;
|
|
35
37
|
relative?: boolean;
|
|
36
38
|
};
|
|
37
|
-
export type
|
|
39
|
+
export type SwitchColumnOptions<TData extends RowData> = BaseColumnOptions<TData, boolean> & {};
|
|
38
40
|
export type IconColumnOptions<TData extends RowData> = BaseColumnOptions<TData, boolean> & {
|
|
39
41
|
on?: {
|
|
40
42
|
Icon?: Icon;
|
|
@@ -50,29 +52,33 @@ export type IconColumnOptions<TData extends RowData> = BaseColumnOptions<TData,
|
|
|
50
52
|
*/
|
|
51
53
|
export declare class ColumnBuilder<TData extends RowData> {
|
|
52
54
|
/**
|
|
53
|
-
*
|
|
55
|
+
* Combobox value
|
|
54
56
|
*/
|
|
55
|
-
|
|
57
|
+
combobox({ label, classNames, model, onUpdate, ...props }: ComboboxColumnOptions<TData>): Partial<ColumnDef<TData, any>>;
|
|
56
58
|
/**
|
|
57
59
|
* String formats.
|
|
58
60
|
*/
|
|
59
|
-
string({ label,
|
|
61
|
+
string({ label, classNames, onUpdate, ...props }?: StringColumnOptions<TData>): Partial<ColumnDef<TData, string>>;
|
|
60
62
|
/**
|
|
61
63
|
* Number formats.
|
|
62
64
|
*/
|
|
63
|
-
number({ label, minSize,
|
|
65
|
+
number({ label, minSize, classNames, digits, onUpdate, ...props }?: NumberColumnOptions<TData>): Partial<ColumnDef<TData, number>>;
|
|
64
66
|
/**
|
|
65
67
|
* Date formats.
|
|
66
68
|
*/
|
|
67
|
-
date({ label, format: formatSpec, relative,
|
|
69
|
+
date({ label, format: formatSpec, relative, classNames, ...props }?: DateColumnOptions<TData>): Partial<ColumnDef<TData, Date>>;
|
|
68
70
|
/**
|
|
69
71
|
* PublicKey with tooltip.
|
|
70
72
|
*/
|
|
71
73
|
key({ label, tooltip, ...props }?: KeyColumnOptions<TData>): Partial<ColumnDef<TData, PublicKey>>;
|
|
72
74
|
/**
|
|
73
|
-
*
|
|
75
|
+
* Row selector
|
|
74
76
|
*/
|
|
75
|
-
|
|
77
|
+
selectRow({ label, classNames, onUpdate, id, ...props }?: SelectRowColumnOptions<TData>): Parameters<ColumnHelper<TData>['display']>[0];
|
|
78
|
+
/**
|
|
79
|
+
* Switch
|
|
80
|
+
*/
|
|
81
|
+
switch({ label, classNames, onUpdate, ...props }?: SwitchColumnOptions<TData>): Partial<ColumnDef<TData, boolean>>;
|
|
76
82
|
/**
|
|
77
83
|
* Icon based on boolean value.
|
|
78
84
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/helpers.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/helpers.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAwB,KAAK,IAAI,EAAK,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,YAAY,EAElB,MAAM,uBAAuB,CAAC;AAM/B,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,KAAK,cAAc,EAAkB,MAAM,gBAAgB,CAAC;AAQrE,MAAM,MAAM,YAAY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CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;CAkB5G"}
|
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
export declare const defaultTableSlots: TableSlots;
|
|
1
|
+
import { type CellContext } from '@tanstack/react-table';
|
|
2
|
+
import { type ComponentFunction } from '@dxos/react-ui-types';
|
|
3
|
+
import { type TableContextValue, type TableFlags } from './components';
|
|
4
|
+
export declare const currentRow = "!bg-neutral-75 !dark:bg-neutral-850";
|
|
5
|
+
export declare const selectedRow = "!bg-primary-100 dark:!bg-primary-700";
|
|
6
|
+
export declare const flushPadding = "pli-0 plb-0";
|
|
7
|
+
export declare const textPadding = "pli-2 plb-0.5";
|
|
8
|
+
export declare const headPadding = "pli-2 plb-1.5";
|
|
9
|
+
export declare const gridCellFocusRing = "focus:z-[11] focus:outline outline-2 outline-primary-500 dark:outline-primary-400";
|
|
10
|
+
export type TableStyleProps = Partial<TableContextValue<any>>;
|
|
11
|
+
export declare const tableRoot: ComponentFunction<TableStyleProps>;
|
|
12
|
+
export declare const groupTh: ComponentFunction<TableStyleProps>;
|
|
13
|
+
export type TheadStyleProps = Partial<TableFlags>;
|
|
14
|
+
export declare const theadRoot: ComponentFunction<TheadStyleProps>;
|
|
15
|
+
export declare const theadTr: ComponentFunction<TheadStyleProps>;
|
|
16
|
+
export declare const theadTh: ComponentFunction<TheadStyleProps>;
|
|
17
|
+
export declare const theadResizeRoot: ComponentFunction<TheadStyleProps>;
|
|
18
|
+
export declare const theadResizeThumb: ComponentFunction<TheadStyleProps>;
|
|
19
|
+
export type TbodyStyleProps = Partial<TableContextValue<any>>;
|
|
20
|
+
export declare const tbodyRoot: ComponentFunction<TbodyStyleProps>;
|
|
21
|
+
export type TbodyTrStyleProps = Partial<{
|
|
22
|
+
isSelected?: boolean;
|
|
23
|
+
isCurrent?: boolean;
|
|
24
|
+
canBeCurrent?: boolean;
|
|
25
|
+
}>;
|
|
26
|
+
export declare const tbodyTr: ComponentFunction<TbodyTrStyleProps>;
|
|
27
|
+
export declare const tdRoot: ComponentFunction<TbodyStyleProps>;
|
|
28
|
+
export declare const tdContent: ComponentFunction<CellContext<any, any>>;
|
|
29
|
+
export type TfootStyleProps = Partial<TableContextValue<any>>;
|
|
30
|
+
export declare const tfootRoot: ComponentFunction<TfootStyleProps>;
|
|
31
|
+
export declare const tfootTr: ComponentFunction<TfootStyleProps>;
|
|
32
|
+
export declare const tfootTh: ComponentFunction<TfootStyleProps>;
|
|
34
33
|
//# sourceMappingURL=theme.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../src/theme.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../src/theme.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAEvE,eAAO,MAAM,UAAU,wCAAwC,CAAC;AAChE,eAAO,MAAM,WAAW,yCAAyC,CAAC;AAClE,eAAO,MAAM,YAAY,gBAAgB,CAAC;AAC1C,eAAO,MAAM,WAAW,kBAAkB,CAAC;A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AAM,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC;AAE9D,eAAO,MAAM,SAAS,EAAE,iBAAiB,CAAC,eAAe,CACH,CAAC;AAEvD,eAAO,MAAM,OAAO,EAAE,iBAAiB,CAAC,eAAe,CAAkC,CAAC;AAE1F,eAAO,MAAM,OAAO,EAAE,iBAAiB,CAAC,eAAe,CACQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translations.d.ts","sourceRoot":"","sources":["../../../src/translations.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc,UAAU,CAAC;;;;;;;;AAEtC,wBAQE"}
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { type ColumnDef, type RowData } from '@tanstack/react-table';
|
|
2
|
+
import { type ClassNameValue } from '@dxos/react-ui-types';
|
|
3
|
+
import { type SearchListQueryModel, type ValueUpdater } from './helpers';
|
|
2
4
|
declare module '@tanstack/react-table' {
|
|
3
5
|
interface TableMeta<TData extends RowData> {
|
|
4
6
|
}
|
|
5
7
|
interface ColumnMeta<TData extends RowData, TValue> {
|
|
6
8
|
expand?: boolean;
|
|
7
9
|
resizable?: boolean;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
model?: SearchListQueryModel<TData>;
|
|
11
|
+
onUpdate?: ValueUpdater<TData, any>;
|
|
12
|
+
digits?: number;
|
|
13
|
+
header?: {
|
|
14
|
+
classNames?: ClassNameValue;
|
|
15
|
+
};
|
|
16
|
+
footer?: {
|
|
17
|
+
classNames?: ClassNameValue;
|
|
18
|
+
};
|
|
19
|
+
cell?: {
|
|
20
|
+
classNames?: ClassNameValue;
|
|
18
21
|
};
|
|
19
22
|
}
|
|
20
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EAAE,KAAK,oBAAoB,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzE,OAAO,QAAQ,uBAAuB,CAAC;IAGrC,UAAU,SAAS,CAAC,KAAK,SAAS,OAAO;KAAI;IAG7C,UAAU,UAAU,CAAC,KAAK,SAAS,OAAO,EAAE,MAAM;QAChD,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,KAAK,CAAC,EAAE,oBAAoB,CAAC,KAAK,CAAC,CAAC;QACpC,QAAQ,CAAC,EAAE,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACpC,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE;YACP,UAAU,CAAC,EAAE,cAAc,CAAC;SAC7B,CAAC;QACF,MAAM,CAAC,EAAE;YACP,UAAU,CAAC,EAAE,cAAc,CAAC;SAC7B,CAAC;QACF,IAAI,CAAC,EAAE;YACL,UAAU,CAAC,EAAE,cAAc,CAAC;SAC7B,CAAC;KACH;CACF;AAED,MAAM,MAAM,QAAQ,CAAC,KAAK,SAAS,OAAO,IAAI,CAAC,GAAG,EAAE,KAAK,KAAK,MAAM,CAAC;AAErE,MAAM,MAAM,cAAc,CAAC,KAAK,SAAS,OAAO,EAAE,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-table",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8-main.0694b57",
|
|
4
4
|
"description": "A table component.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -17,17 +17,19 @@
|
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@fluentui/react-tabster": "^9.12.0",
|
|
20
|
+
"@radix-ui/react-context": "^1.0.0",
|
|
21
|
+
"@radix-ui/react-use-controllable-state": "^1.0.0",
|
|
20
22
|
"@tanstack/react-table": "^8.9.3",
|
|
21
23
|
"date-fns": "^2.29.3",
|
|
22
24
|
"lodash.defaultsdeep": "^4.6.1",
|
|
23
|
-
"@dxos/
|
|
24
|
-
"@dxos/
|
|
25
|
-
"@dxos/
|
|
26
|
-
"@dxos/react-ui": "0.3.
|
|
27
|
-
"@dxos/react-ui-
|
|
28
|
-
"@dxos/react-ui-theme": "0.3.
|
|
29
|
-
"@dxos/
|
|
30
|
-
"@dxos/
|
|
25
|
+
"@dxos/invariant": "0.3.8-main.0694b57",
|
|
26
|
+
"@dxos/async": "0.3.8-main.0694b57",
|
|
27
|
+
"@dxos/react-ui": "0.3.8-main.0694b57",
|
|
28
|
+
"@dxos/react-ui-searchlist": "0.3.8-main.0694b57",
|
|
29
|
+
"@dxos/react-ui-types": "0.3.8-main.0694b57",
|
|
30
|
+
"@dxos/react-ui-theme": "0.3.8-main.0694b57",
|
|
31
|
+
"@dxos/util": "0.3.8-main.0694b57",
|
|
32
|
+
"@dxos/keys": "0.3.8-main.0694b57"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
33
35
|
"@faker-js/faker": "^8.0.2",
|
|
@@ -41,7 +43,7 @@
|
|
|
41
43
|
"react-dom": "^18.2.0",
|
|
42
44
|
"vite": "^4.3.9",
|
|
43
45
|
"vite-plugin-turbosnap": "^1.0.2",
|
|
44
|
-
"@dxos/react-ui-theme": "0.3.
|
|
46
|
+
"@dxos/react-ui-theme": "0.3.8-main.0694b57"
|
|
45
47
|
},
|
|
46
48
|
"peerDependencies": {
|
|
47
49
|
"@phosphor-icons/react": "^2.0.5",
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useFocusableGroup } from '@fluentui/react-tabster';
|
|
6
|
+
import { type Cell as CellType, type RowData } from '@tanstack/react-table';
|
|
7
|
+
import React, { type PropsWithChildren } from 'react';
|
|
8
|
+
|
|
9
|
+
import { tdRoot } from '../../theme';
|
|
10
|
+
import { useTableContext } from '../Table/TableContext';
|
|
11
|
+
|
|
12
|
+
type CellProps<TData extends RowData, TValue> = PropsWithChildren<{
|
|
13
|
+
cell: CellType<TData, TValue>;
|
|
14
|
+
}>;
|
|
15
|
+
|
|
16
|
+
const CELL_NAME = 'Cell';
|
|
17
|
+
|
|
18
|
+
const FocusableCell = <TData extends RowData, TValue>({ cell, children }: CellProps<TData, TValue>) => {
|
|
19
|
+
const tableContext = useTableContext(CELL_NAME);
|
|
20
|
+
const domAttributes = useFocusableGroup({ tabBehavior: 'limited' });
|
|
21
|
+
return (
|
|
22
|
+
<td tabIndex={0} {...domAttributes} className={tdRoot(tableContext, cell.column.columnDef.meta?.cell?.classNames)}>
|
|
23
|
+
{children}
|
|
24
|
+
</td>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const StaticCell = <TData extends RowData, TValue>({ cell, children }: CellProps<TData, TValue>) => {
|
|
29
|
+
const tableContext = useTableContext(CELL_NAME);
|
|
30
|
+
return <td className={tdRoot(tableContext, cell.column.columnDef.meta?.cell?.classNames)}>{children}</td>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const Cell = <TData extends RowData, TValue>({ cell, children }: CellProps<TData, TValue>) => {
|
|
34
|
+
const { isGrid } = useTableContext(CELL_NAME);
|
|
35
|
+
const Root = isGrid ? FocusableCell : StaticCell;
|
|
36
|
+
return <Root cell={cell}>{children}</Root>;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
Cell.displayName = CELL_NAME;
|
|
40
|
+
|
|
41
|
+
export { Cell };
|
|
42
|
+
|
|
43
|
+
export type { CellProps };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { CaretDown } from '@phosphor-icons/react';
|
|
6
|
+
import { type RowData } from '@tanstack/react-table';
|
|
7
|
+
import React, { useCallback, useState } from 'react';
|
|
8
|
+
|
|
9
|
+
import { Popover, useTranslation } from '@dxos/react-ui';
|
|
10
|
+
import { PopoverCombobox } from '@dxos/react-ui-searchlist';
|
|
11
|
+
import { descriptionText, getSize, mx, staticPlaceholderText } from '@dxos/react-ui-theme';
|
|
12
|
+
|
|
13
|
+
import { type SearchListQueryModel } from '../../helpers';
|
|
14
|
+
import { translationKey } from '../../translations';
|
|
15
|
+
|
|
16
|
+
export type ComboboxCellItems<TData extends RowData> = Record<string, { label: string; data: TData }>;
|
|
17
|
+
|
|
18
|
+
const initialItems = <TData extends RowData>(model: SearchListQueryModel<TData>, value?: TData) =>
|
|
19
|
+
value
|
|
20
|
+
? {
|
|
21
|
+
[model.getId(value)]: { label: model.getText(value), data: value },
|
|
22
|
+
}
|
|
23
|
+
: {};
|
|
24
|
+
|
|
25
|
+
export const CellCombobox = <TData extends RowData>({
|
|
26
|
+
model,
|
|
27
|
+
value,
|
|
28
|
+
onValueChange,
|
|
29
|
+
}: {
|
|
30
|
+
model: SearchListQueryModel<TData>;
|
|
31
|
+
value: TData;
|
|
32
|
+
onValueChange: (value: TData) => void;
|
|
33
|
+
}) => {
|
|
34
|
+
const { t } = useTranslation(translationKey);
|
|
35
|
+
const [items, setItems] = useState<ComboboxCellItems<TData>>(initialItems(model, value));
|
|
36
|
+
const [loading, setLoading] = useState(false);
|
|
37
|
+
const [searchInputValue, setSearchInputValue] = useState('');
|
|
38
|
+
const handleSearchInputValueChange = async (text?: string) => {
|
|
39
|
+
setSearchInputValue(text ?? '');
|
|
40
|
+
setLoading(true);
|
|
41
|
+
const items = await model.query(text);
|
|
42
|
+
setItems(
|
|
43
|
+
items.reduce((acc: ComboboxCellItems<TData>, item) => {
|
|
44
|
+
acc[model.getId(item)] = {
|
|
45
|
+
label: model.getText(item),
|
|
46
|
+
data: item,
|
|
47
|
+
};
|
|
48
|
+
return acc;
|
|
49
|
+
}, initialItems(model, value)),
|
|
50
|
+
);
|
|
51
|
+
setLoading(false);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const handleValueChange = useCallback(
|
|
55
|
+
(id: string) => {
|
|
56
|
+
onValueChange(items[id]?.data);
|
|
57
|
+
},
|
|
58
|
+
[items, onValueChange],
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<PopoverCombobox.Root placeholder={t('no selection label')}>
|
|
63
|
+
<PopoverCombobox.Trigger variant='ghost' classNames='is-full rounded-none ring-inset'>
|
|
64
|
+
{value ? (
|
|
65
|
+
<>
|
|
66
|
+
<span
|
|
67
|
+
className={mx('font-normal text-start flex-1 min-is-0 truncate mie-2', !value && staticPlaceholderText)}
|
|
68
|
+
>
|
|
69
|
+
{model.getText(value)}
|
|
70
|
+
</span>
|
|
71
|
+
<CaretDown weight='bold' className={getSize(3)} />
|
|
72
|
+
</>
|
|
73
|
+
) : null}
|
|
74
|
+
</PopoverCombobox.Trigger>
|
|
75
|
+
<PopoverCombobox.Content shouldFilter={false} classNames='is-[--radix-popover-trigger-width]'>
|
|
76
|
+
<PopoverCombobox.Input value={searchInputValue} onValueChange={handleSearchInputValueChange} />
|
|
77
|
+
<PopoverCombobox.List>
|
|
78
|
+
{searchInputValue.length < 1 ? (
|
|
79
|
+
<p className={mx('text-center', descriptionText)}>Start typing to search</p>
|
|
80
|
+
) : loading ? (
|
|
81
|
+
<p className={mx('text-center', descriptionText)}>Searching…</p>
|
|
82
|
+
) : (
|
|
83
|
+
<>
|
|
84
|
+
<PopoverCombobox.Empty classNames={['text-center', descriptionText]}>No results</PopoverCombobox.Empty>
|
|
85
|
+
{Object.entries(items).map(([id, { label }]) => (
|
|
86
|
+
<PopoverCombobox.Item key={id} value={id} onSelect={handleValueChange} classNames='truncate'>
|
|
87
|
+
{label}
|
|
88
|
+
</PopoverCombobox.Item>
|
|
89
|
+
))}
|
|
90
|
+
</>
|
|
91
|
+
)}
|
|
92
|
+
</PopoverCombobox.List>
|
|
93
|
+
<Popover.Arrow />
|
|
94
|
+
</PopoverCombobox.Content>
|
|
95
|
+
</PopoverCombobox.Root>
|
|
96
|
+
);
|
|
97
|
+
};
|