@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.
Files changed (54) hide show
  1. package/dist/lib/browser/index.mjs +511 -462
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/types/src/components/Cell/Cell.d.ts +12 -0
  5. package/dist/types/src/components/Cell/Cell.d.ts.map +1 -0
  6. package/dist/types/src/components/{ComboboxCell.d.ts → Cell/CellCombobox.d.ts} +4 -4
  7. package/dist/types/src/components/Cell/CellCombobox.d.ts.map +1 -0
  8. package/dist/types/src/components/Cell/index.d.ts +2 -0
  9. package/dist/types/src/components/Cell/index.d.ts.map +1 -0
  10. package/dist/types/src/components/Table/Table.d.ts +3 -0
  11. package/dist/types/src/components/Table/Table.d.ts.map +1 -0
  12. package/dist/types/src/components/{Table.stories.d.ts → Table/Table.stories.d.ts} +4 -7
  13. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -0
  14. package/dist/types/src/components/Table/TableBody.d.ts +11 -0
  15. package/dist/types/src/components/Table/TableBody.d.ts.map +1 -0
  16. package/dist/types/src/components/Table/TableContext.d.ts +14 -0
  17. package/dist/types/src/components/Table/TableContext.d.ts.map +1 -0
  18. package/dist/types/src/components/Table/TableFooter.d.ts +7 -0
  19. package/dist/types/src/components/Table/TableFooter.d.ts.map +1 -0
  20. package/dist/types/src/components/Table/TableHead.d.ts +8 -0
  21. package/dist/types/src/components/Table/TableHead.d.ts.map +1 -0
  22. package/dist/types/src/components/Table/index.d.ts +3 -0
  23. package/dist/types/src/components/Table/index.d.ts.map +1 -0
  24. package/dist/types/src/components/Table/props.d.ts +37 -0
  25. package/dist/types/src/components/Table/props.d.ts.map +1 -0
  26. package/dist/types/src/components/index.d.ts +1 -1
  27. package/dist/types/src/components/index.d.ts.map +1 -1
  28. package/dist/types/src/helpers.d.ts +20 -14
  29. package/dist/types/src/helpers.d.ts.map +1 -1
  30. package/dist/types/src/theme.d.ts +32 -33
  31. package/dist/types/src/theme.d.ts.map +1 -1
  32. package/dist/types/src/types.d.ts +13 -10
  33. package/dist/types/src/types.d.ts.map +1 -1
  34. package/package.json +12 -10
  35. package/src/components/Cell/Cell.tsx +43 -0
  36. package/src/components/{ComboboxCell.tsx → Cell/CellCombobox.tsx} +6 -6
  37. package/src/components/Cell/index.ts +5 -0
  38. package/src/components/{Table.stories.tsx → Table/Table.stories.tsx} +51 -51
  39. package/src/components/Table/Table.tsx +179 -0
  40. package/src/components/Table/TableBody.tsx +69 -0
  41. package/src/components/Table/TableContext.tsx +28 -0
  42. package/src/components/Table/TableFooter.tsx +42 -0
  43. package/src/components/Table/TableHead.tsx +79 -0
  44. package/src/components/Table/index.ts +6 -0
  45. package/src/components/Table/props.ts +53 -0
  46. package/src/components/index.ts +1 -1
  47. package/src/helpers.tsx +255 -206
  48. package/src/theme.ts +95 -63
  49. package/src/types.ts +15 -10
  50. package/dist/types/src/components/ComboboxCell.d.ts.map +0 -1
  51. package/dist/types/src/components/Table.d.ts +0 -29
  52. package/dist/types/src/components/Table.d.ts.map +0 -1
  53. package/dist/types/src/components/Table.stories.d.ts.map +0 -1
  54. 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 { chromeSurface } from '@dxos/react-ui-theme';
6
-
7
- // TODO(burdon): Remove nested classNames? Add to theme?
8
- export type TableSlots = {
9
- root?: {
10
- className?: string | string[];
11
- };
12
- table?: {
13
- className?: string | string[];
14
- };
15
- header?: {
16
- className?: string | string[];
17
- };
18
- footer?: {
19
- className?: string | string[];
20
- };
21
- group?: {
22
- className?: string | string[];
23
- };
24
- row?: {
25
- className?: string | string[];
26
- };
27
- cell?: {
28
- className?: string | string[];
29
- };
30
- focus?: {
31
- className?: string | string[];
32
- };
33
- selected?: {
34
- className?: string | string[];
35
- };
36
- margin?: {
37
- className?: string | string[];
38
- };
39
- };
40
-
41
- // TODO(burdon): Change to groups.
42
- /*
43
- head: {
44
- default:
45
- cell:
46
- }
47
- row: {
48
- default: '',
49
- selected: ''
50
- }
51
- */
52
-
53
- // TODO(burdon): Scrollbar area.
54
- // TODO(burdon): Overscroll horizontal (full width).
55
-
56
- // TODO(burdon): Integrate with DXOS UI theme (direct dependency -- see react-ui-editor, tailwind.ts).
57
- // See Link.tsx const { tx } = useThemeContext();
58
- // Reuse button fragments for hoverColors, selected, primary, etc.
59
- export const defaultTableSlots: TableSlots = {
60
- // TODO(burdon): head/body/table rows.
61
- header: { className: [chromeSurface, 'px-2 font-light select-none'] },
62
- footer: { className: [chromeSurface, 'px-2 font-light'] },
63
- cell: { className: 'px-2' },
64
- group: { className: 'px-2 font-light text-xs text-left' },
65
- focus: { className: 'ring ring-primary-600 ring-inset' },
66
- selected: { className: '!bg-teal-100 dark:!bg-teal-700' },
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
- slots?: {
18
- header?: {
19
- className?: string;
20
- };
21
- footer?: {
22
- className?: string;
23
- };
24
- cell?: {
25
- className?: string;
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,E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