@dxos/react-ui-table 0.4.10-main.1ada56e → 0.4.10-main.1f36d57

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.
@@ -1,18 +1,17 @@
1
1
  //
2
- // Copyright 2023 DXOS.org
2
+ // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { Check, Trash, X, GearSix } from '@phosphor-icons/react';
6
- import { type HeaderContext, type RowData } from '@tanstack/react-table';
7
- import React, { type FC, type PropsWithChildren, useRef, useState } from 'react';
5
+ import { X, GearSix, CaretDown, ArrowDown, ArrowUp } from '@phosphor-icons/react';
6
+ import { type SortDirection, type HeaderContext, type RowData } from '@tanstack/react-table';
7
+ import React, { useRef, useState, useCallback } from 'react';
8
8
 
9
- import { Button, DensityProvider, Input, Popover, Select, Separator, useTranslation } from '@dxos/react-ui';
9
+ import { Button, DensityProvider, Popover, DropdownMenu } from '@dxos/react-ui';
10
10
  import { getSize, mx } from '@dxos/react-ui-theme';
11
- import { safeParseInt } from '@dxos/util';
12
11
 
13
- import { SortButton } from './SortButton';
14
- import { type TableDef, type ColumnProps, type ColumnType } from '../schema';
15
- import { translationKey } from '../translations';
12
+ import { ColumnSettingsForm } from './ColumnSettingsForm';
13
+ import { useColumnSorting } from './hooks/useColumnSorting';
14
+ import { type TableDef, type ColumnProps } from '../schema';
16
15
 
17
16
  export type ColumnMenuProps<TData extends RowData, TValue> = {
18
17
  context: HeaderContext<TData, TValue>;
@@ -25,224 +24,143 @@ export type ColumnMenuProps<TData extends RowData, TValue> = {
25
24
 
26
25
  export const ColumnMenu = <TData extends RowData, TValue>({ column, ...props }: ColumnMenuProps<TData, TValue>) => {
27
26
  const title = column.label?.length ? column.label : column.id;
28
-
29
27
  const header = props.context.header;
30
28
 
31
- const canSort = header.column.getCanSort();
32
- const sortDirection = header.column.getIsSorted();
33
- const toggleSort = header.column.getToggleSortingHandler();
29
+ const { canSort, sortDirection, onSelectSort, onToggleSort, onClearSort } = useColumnSorting(header.column);
30
+
31
+ const columnSettingsAnchorRef = useRef<any>(null);
32
+
33
+ const [isColumnSettingsOpen, setIsColumnSettingsOpen] = useState(false);
34
+
35
+ const shouldPreventFocusOnClose = useRef(false);
36
+
37
+ const onOpenColumnSettings = useCallback(() => {
38
+ shouldPreventFocusOnClose.current = true;
39
+ setIsColumnSettingsOpen(true);
40
+ }, [shouldPreventFocusOnClose, setIsColumnSettingsOpen]); // setIsColumnSettingsOpen is a dependency
41
+
42
+ const onDropdownCloseAutoFocus = useCallback(
43
+ (event: Event) => {
44
+ if (shouldPreventFocusOnClose.current) {
45
+ event.preventDefault();
46
+ shouldPreventFocusOnClose.current = false;
47
+ }
48
+ },
49
+ [shouldPreventFocusOnClose],
50
+ );
34
51
 
35
52
  return (
36
- <div className='flex items-center gap-2'>
37
- <div className='flex-1 min-is-0 truncate' title={title}>
38
- {title}
39
- </div>
40
- <div className='flex gap-0'>
41
- {canSort && toggleSort && <SortButton sortDirection={sortDirection} onClick={toggleSort} />}
42
- <ColumnPanel {...props} column={column} />
53
+ <div className='flex items-center justify-center justify-between'>
54
+ <div className='flex items-center gap-1 truncate' title={title}>
55
+ <SortIndicator direction={sortDirection} onClick={onToggleSort} />
56
+ <div className='truncate'>{title}</div>
43
57
  </div>
58
+
59
+ <DropdownMenu.Root modal={false}>
60
+ <Popover.Root open={isColumnSettingsOpen} onOpenChange={setIsColumnSettingsOpen} modal={false}>
61
+ <DropdownMenu.Trigger ref={columnSettingsAnchorRef} asChild>
62
+ <Popover.Anchor asChild>
63
+ <Button variant='ghost'>
64
+ <CaretDown className={getSize(4)} />
65
+ </Button>
66
+ </Popover.Anchor>
67
+ </DropdownMenu.Trigger>
68
+
69
+ <DropdownMenu.Content onCloseAutoFocus={onDropdownCloseAutoFocus} sideOffset={4} collisionPadding={8}>
70
+ <DropdownMenu.Viewport>
71
+ {canSort && (
72
+ <>
73
+ <DropdownMenu.Item onClick={() => onSelectSort('asc')}>
74
+ <span className='grow'>Sort ascending</span>
75
+ <span className='opacity-50'>
76
+ <ArrowUp className={getSize(4)} />
77
+ </span>
78
+ </DropdownMenu.Item>
79
+ <DropdownMenu.Item onClick={() => onSelectSort('desc')}>
80
+ <span className='grow'>Sort descending</span>
81
+ <span className='opacity-50'>
82
+ <ArrowDown className={getSize(4)} />
83
+ </span>
84
+ </DropdownMenu.Item>
85
+ {sortDirection !== false && (
86
+ <DropdownMenu.Item onClick={onClearSort}>
87
+ <span className='grow'>Clear sort</span>
88
+ <span className='opacity-50'>
89
+ <X className={getSize(4)} />
90
+ </span>
91
+ </DropdownMenu.Item>
92
+ )}
93
+ </>
94
+ )}
95
+ <DropdownMenu.Item onClick={onOpenColumnSettings}>
96
+ <span className='grow'>Column settings</span>
97
+ <span className='opacity-50'>
98
+ <GearSix className={mx(getSize(4), 'rotate-90')} />
99
+ </span>
100
+ </DropdownMenu.Item>
101
+ </DropdownMenu.Viewport>
102
+ <DropdownMenu.Arrow />
103
+ </DropdownMenu.Content>
104
+
105
+ <ColumnSettingsPanel {...props} column={column} onClose={() => setIsColumnSettingsOpen(false)} />
106
+ </Popover.Root>
107
+ </DropdownMenu.Root>
44
108
  </div>
45
109
  );
46
110
  };
47
111
 
48
- const Section: FC<PropsWithChildren & { className?: string }> = ({ children, className }) => (
49
- <div role='none' className={mx('p-2', className)}>
50
- {children}
51
- </div>
52
- );
53
-
54
- export const ColumnPanel = <TData extends RowData, TValue>({
55
- context,
112
+ export const ColumnSettingsPanel = <TData extends RowData, TValue>({
56
113
  tableDefs,
57
114
  tableDef,
58
115
  column,
59
116
  onUpdate,
60
117
  onDelete,
61
- }: ColumnMenuProps<TData, TValue>) => {
62
- const [open, setOpen] = useState(false);
63
- const [prop, setProp] = useState(column.id);
64
- const [refTable, setRefTable] = useState(column.refTable);
65
- const [refProp, setRefProp] = useState(column.refProp);
66
- const [type, setType] = useState(String(column.type));
67
- const [label, setLabel] = useState(column.label);
68
- const [digits, setDigits] = useState(String(column.digits ?? '0'));
69
- const propRef = useRef<HTMLInputElement>(null);
70
- const { t } = useTranslation(translationKey);
71
-
72
- const handleCancel = () => {
73
- setProp(column.id);
74
- setOpen(false);
75
- };
76
-
77
- const handleSave = () => {
78
- // Check valid.
79
- if (!prop.length || !prop.match(/^[a-zA-Z_].+/i)) {
80
- propRef.current?.focus();
81
- return;
82
- }
83
-
84
- // If already exists then check same type.
85
- const current = tableDef.columns.find((c) => c.id !== column.id && c.id === prop);
86
- if (current) {
87
- // TODO(burdon): Allow multiple columns with different refProps. Ensure correct table prop is updated.
88
- if (current.type !== 'ref' /* || current.ref !== refTable */) {
89
- // TODO(burdon): Show error.
90
- propRef.current?.focus();
91
- return;
92
- }
93
- }
94
-
95
- onUpdate?.(prop, {
96
- id: prop, // TODO(burdon): Make unique.
97
- prop,
98
- label,
99
- type: type as ColumnProps['type'],
100
- refTable,
101
- refProp,
102
- digits: safeParseInt(digits),
103
- });
118
+ onClose,
119
+ }: ColumnMenuProps<TData, TValue> & { onClose: () => void }) => (
120
+ <Popover.Portal>
121
+ <Popover.Content>
122
+ <Popover.Viewport classNames='w-60'>
123
+ <DensityProvider density='fine'>
124
+ <ColumnSettingsForm
125
+ column={column}
126
+ tableDefs={tableDefs}
127
+ tableDef={tableDef}
128
+ onUpdate={onUpdate}
129
+ onDelete={onDelete}
130
+ onClose={onClose}
131
+ />
132
+ </DensityProvider>
133
+ </Popover.Viewport>
134
+ <Popover.Arrow />
135
+ </Popover.Content>
136
+ </Popover.Portal>
137
+ );
104
138
 
105
- setOpen(false);
106
- };
139
+ export const SortIndicator = ({
140
+ direction,
141
+ onClick,
142
+ }: {
143
+ direction: SortDirection | false;
144
+ onClick: (e: any) => void;
145
+ }) => {
146
+ if (direction === false) {
147
+ return null;
148
+ }
149
+
150
+ let icon;
151
+
152
+ switch (direction) {
153
+ case 'asc':
154
+ icon = <ArrowUp className={getSize(3)} />;
155
+ break;
156
+ case 'desc':
157
+ icon = <ArrowDown className={getSize(3)} />;
158
+ break;
159
+ }
107
160
 
108
161
  return (
109
- <Popover.Root open={open} onOpenChange={(nextOpen) => setOpen(nextOpen)}>
110
- <Popover.Trigger asChild>
111
- <Button variant='ghost'>
112
- <GearSix className={mx(getSize(4), 'rotate-90')} />
113
- </Button>
114
- </Popover.Trigger>
115
- <Popover.Portal>
116
- <Popover.Content>
117
- <Popover.Viewport classNames='w-60'>
118
- <DensityProvider density='fine'>
119
- <div className='flex flex-col gap-1'>
120
- <Section>
121
- <Input.Root>
122
- <Input.Label classNames='mbe-1'>{t('column label label')}</Input.Label>
123
- <Input.TextInput
124
- placeholder='Column label'
125
- value={label ?? ''}
126
- onChange={(event) => setLabel(event.target.value)}
127
- autoFocus
128
- />
129
- </Input.Root>
130
- <Input.Root>
131
- <Input.Label classNames='mbe-1 mbs-3'>{t('property key label')}</Input.Label>
132
- <Input.TextInput
133
- ref={propRef}
134
- placeholder='Property key'
135
- // TODO(burdon): Provide hooks for value normalization, ENTER, ESC, etc.
136
- value={prop ?? ''}
137
- onChange={(event) => setProp(event.target.value.replace(/[^\w_]/g, ''))}
138
- />
139
- </Input.Root>
140
- <Input.Root>
141
- <Input.Label classNames='mbe-1 mbs-3'>{t('column type label')}</Input.Label>
142
- <Select.Root value={type} onValueChange={setType}>
143
- <Select.TriggerButton placeholder='Type' classNames='is-full' />
144
- <Select.Portal>
145
- <Select.Content>
146
- <Select.Viewport>
147
- {(['number', 'boolean', 'string', 'ref'] as ColumnType[]).map((type) => (
148
- <Select.Option key={type} value={type}>
149
- {t(`${type} column type label`)}
150
- </Select.Option>
151
- ))}
152
- </Select.Viewport>
153
- </Select.Content>
154
- </Select.Portal>
155
- </Select.Root>
156
- </Input.Root>
157
- </Section>
158
-
159
- {type === 'number' && (
160
- <>
161
- <Section>
162
- <Input.Root>
163
- <Input.Label classNames='mbe-1 mbs-3'>{t('digits label')}</Input.Label>
164
- {/* TODO(burdon): Constrain input to numbers. */}
165
- <Input.TextInput value={digits ?? ''} onChange={(event) => setDigits(event.target.value)} />
166
- </Input.Root>
167
- </Section>
168
- </>
169
- )}
170
-
171
- {/* TODO(burdon): Selectors on same line. */}
172
- {type === 'ref' && (
173
- <>
174
- <Section>
175
- <Input.Root>
176
- <Input.Label classNames='mbe-1 mbs-3'>Table</Input.Label>
177
- <Select.Root value={refTable} onValueChange={setRefTable}>
178
- <Select.TriggerButton placeholder='Table' classNames='is-full' />
179
- <Select.Portal>
180
- <Select.Content>
181
- <Select.Viewport>
182
- {tableDefs
183
- .filter((t) => t.id !== tableDef.id)
184
- .map(({ id, name }) => (
185
- <Select.Option key={id} value={id}>
186
- {name ?? id}
187
- </Select.Option>
188
- ))}
189
- </Select.Viewport>
190
- </Select.Content>
191
- </Select.Portal>
192
- </Select.Root>
193
- </Input.Root>
194
-
195
- {refTable && (
196
- <Input.Root>
197
- <Input.Label classNames='mbe-1 mbs-3'>Table property</Input.Label>
198
- <Select.Root value={refProp} onValueChange={setRefProp}>
199
- <Select.TriggerButton placeholder='Property' classNames='is-full' />
200
- <Select.Portal>
201
- <Select.Content>
202
- <Select.Viewport>
203
- {tableDefs
204
- .find((tableDef) => tableDef.id === refTable)
205
- ?.columns.map(({ id, label }) => (
206
- <Select.Option key={id} value={id}>
207
- {label ?? id}
208
- </Select.Option>
209
- ))}
210
- </Select.Viewport>
211
- </Select.Content>
212
- </Select.Portal>
213
- </Select.Root>
214
- </Input.Root>
215
- )}
216
- </Section>
217
- </>
218
- )}
219
-
220
- <Separator classNames='mli-2' />
221
-
222
- <Section className='space-b-1.5'>
223
- {/* TODO(burdon): Style as DropdownMenuItem. */}
224
- <Button variant='primary' classNames='is-full flex gap-2' onClick={handleSave}>
225
- <span>{t('save label')}</span>
226
- <div className='grow' />
227
- <Check className={getSize(5)} />
228
- </Button>
229
- <Button classNames='is-full flex gap-2' onClick={handleCancel}>
230
- <span>{t('cancel label', { ns: 'os' })}</span>
231
- <div className='grow' />
232
- <X className={getSize(5)} />
233
- </Button>
234
- <Button classNames='is-full flex gap-2' onClick={() => onDelete?.(column.id)}>
235
- <span>{t('delete label')}</span>
236
- <div className='grow' />
237
- <Trash className={getSize(5)} />
238
- </Button>
239
- </Section>
240
- </div>
241
- </DensityProvider>
242
- </Popover.Viewport>
243
- <Popover.Arrow />
244
- </Popover.Content>
245
- </Popover.Portal>
246
- </Popover.Root>
162
+ <div onClick={onClick} className='flex items-center cursor-pointer'>
163
+ {icon}
164
+ </div>
247
165
  );
248
166
  };
@@ -0,0 +1,206 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { Check, Trash, X } from '@phosphor-icons/react';
6
+ import React, { type FC, type PropsWithChildren, useRef, useState } from 'react';
7
+
8
+ import { Button, Input, Select, Separator, useTranslation } from '@dxos/react-ui';
9
+ import { getSize, mx } from '@dxos/react-ui-theme';
10
+ import { safeParseInt } from '@dxos/util';
11
+
12
+ import { type TableDef, type ColumnProps, type ColumnType } from '../schema';
13
+ import { translationKey } from '../translations';
14
+
15
+ const Section: FC<PropsWithChildren & { className?: string }> = ({ children, className }) => (
16
+ <div role='none' className={mx('p-2', className)}>
17
+ {children}
18
+ </div>
19
+ );
20
+
21
+ export const ColumnSettingsForm = ({
22
+ column,
23
+ tableDef,
24
+ tableDefs,
25
+ onUpdate,
26
+ onDelete,
27
+ onClose,
28
+ }: {
29
+ column: ColumnProps;
30
+ tableDef: TableDef;
31
+ tableDefs: TableDef[];
32
+ onUpdate?: ((id: string, column: ColumnProps) => void) | undefined;
33
+ onDelete?: ((id: string) => void) | undefined;
34
+ onClose: () => void;
35
+ }) => {
36
+ const [prop, setProp] = useState(column.id);
37
+ const [refTable, setRefTable] = useState(column.refTable);
38
+ const [refProp, setRefProp] = useState(column.refProp);
39
+ const [type, setType] = useState(String(column.type));
40
+ const [label, setLabel] = useState(column.label);
41
+ const [digits, setDigits] = useState(String(column.digits ?? '0'));
42
+ const propRef = useRef<HTMLInputElement>(null);
43
+ const { t } = useTranslation(translationKey);
44
+
45
+ const handleCancel = () => {
46
+ setProp(column.id);
47
+ onClose;
48
+ };
49
+
50
+ const handleSave = () => {
51
+ // Check valid.
52
+ if (!prop.length || !prop.match(/^[a-zA-Z_].+/i)) {
53
+ propRef.current?.focus();
54
+ return;
55
+ }
56
+
57
+ // If already exists then check same type.
58
+ const current = tableDef.columns.find((c) => c.id !== column.id && c.id === prop);
59
+
60
+ if (current) {
61
+ // TODO(burdon): Allow multiple columns with different refProps. Ensure correct table prop is updated.
62
+ if (current.type !== 'ref' /* || current.ref !== refTable */) {
63
+ // TODO(burdon): Show error.
64
+ propRef.current?.focus();
65
+ return;
66
+ }
67
+ }
68
+
69
+ onUpdate?.(prop, {
70
+ id: prop, // TODO(burdon): Make unique.
71
+ prop,
72
+ label,
73
+ type: type as ColumnProps['type'],
74
+ refTable,
75
+ refProp,
76
+ digits: safeParseInt(digits),
77
+ });
78
+
79
+ onClose();
80
+ };
81
+
82
+ return (
83
+ <div className='flex flex-col gap-1'>
84
+ <Section>
85
+ <Input.Root>
86
+ <Input.Label classNames='mbe-1'>{t('column label label')}</Input.Label>
87
+ <Input.TextInput
88
+ placeholder='Column label'
89
+ value={label ?? ''}
90
+ onChange={(event) => setLabel(event.target.value)}
91
+ autoFocus
92
+ />
93
+ </Input.Root>
94
+ <Input.Root>
95
+ <Input.Label classNames='mbe-1 mbs-3'>{t('property key label')}</Input.Label>
96
+ <Input.TextInput
97
+ ref={propRef}
98
+ placeholder='Property key'
99
+ // TODO(burdon): Provide hooks for value normalization, ENTER, ESC, etc.
100
+ value={prop ?? ''}
101
+ onChange={(event) => setProp(event.target.value.replace(/[^\w_]/g, ''))}
102
+ />
103
+ </Input.Root>
104
+ <Input.Root>
105
+ <Input.Label classNames='mbe-1 mbs-3'>{t('column type label')}</Input.Label>
106
+ <Select.Root value={type} onValueChange={setType}>
107
+ <Select.TriggerButton placeholder='Type' classNames='is-full' />
108
+ <Select.Portal>
109
+ <Select.Content>
110
+ <Select.Viewport>
111
+ {(['number', 'boolean', 'string', 'ref'] as ColumnType[]).map((type) => (
112
+ <Select.Option key={type} value={type}>
113
+ {t(`${type} column type label`)}
114
+ </Select.Option>
115
+ ))}
116
+ </Select.Viewport>
117
+ </Select.Content>
118
+ </Select.Portal>
119
+ </Select.Root>
120
+ </Input.Root>
121
+ </Section>
122
+
123
+ {type === 'number' && (
124
+ <>
125
+ <Section>
126
+ <Input.Root>
127
+ <Input.Label classNames='mbe-1 mbs-3'>{t('digits label')}</Input.Label>
128
+ {/* TODO(burdon): Constrain input to numbers. */}
129
+ <Input.TextInput value={digits ?? ''} onChange={(event) => setDigits(event.target.value)} />
130
+ </Input.Root>
131
+ </Section>
132
+ </>
133
+ )}
134
+
135
+ {/* TODO(burdon): Selectors on same line. */}
136
+ {type === 'ref' && (
137
+ <>
138
+ <Section>
139
+ <Input.Root>
140
+ <Input.Label classNames='mbe-1 mbs-3'>Table</Input.Label>
141
+ <Select.Root value={refTable} onValueChange={setRefTable}>
142
+ <Select.TriggerButton placeholder='Table' classNames='is-full' />
143
+ <Select.Portal>
144
+ <Select.Content>
145
+ <Select.Viewport>
146
+ {tableDefs
147
+ .filter((t) => t.id !== tableDef.id)
148
+ .map(({ id, name }) => (
149
+ <Select.Option key={id} value={id}>
150
+ {name ?? id}
151
+ </Select.Option>
152
+ ))}
153
+ </Select.Viewport>
154
+ </Select.Content>
155
+ </Select.Portal>
156
+ </Select.Root>
157
+ </Input.Root>
158
+
159
+ {refTable && (
160
+ <Input.Root>
161
+ <Input.Label classNames='mbe-1 mbs-3'>Table property</Input.Label>
162
+ <Select.Root value={refProp} onValueChange={setRefProp}>
163
+ <Select.TriggerButton placeholder='Property' classNames='is-full' />
164
+ <Select.Portal>
165
+ <Select.Content>
166
+ <Select.Viewport>
167
+ {tableDefs
168
+ .find((tableDef) => tableDef.id === refTable)
169
+ ?.columns.map(({ id, label }) => (
170
+ <Select.Option key={id} value={id}>
171
+ {label ?? id}
172
+ </Select.Option>
173
+ ))}
174
+ </Select.Viewport>
175
+ </Select.Content>
176
+ </Select.Portal>
177
+ </Select.Root>
178
+ </Input.Root>
179
+ )}
180
+ </Section>
181
+ </>
182
+ )}
183
+
184
+ <Separator classNames='mli-2' />
185
+
186
+ <Section className='space-b-1.5'>
187
+ {/* TODO(burdon): Style as DropdownMenuItem. */}
188
+ <Button variant='primary' classNames='is-full flex gap-2' onClick={handleSave}>
189
+ <span>{t('save label')}</span>
190
+ <div className='grow' />
191
+ <Check className={getSize(5)} />
192
+ </Button>
193
+ <Button classNames='is-full flex gap-2' onClick={handleCancel}>
194
+ <span>{t('cancel label', { ns: 'os' })}</span>
195
+ <div className='grow' />
196
+ <X className={getSize(5)} />
197
+ </Button>
198
+ <Button classNames='is-full flex gap-2' onClick={() => onDelete?.(column.id)}>
199
+ <span>{t('delete label')}</span>
200
+ <div className='grow' />
201
+ <Trash className={getSize(5)} />
202
+ </Button>
203
+ </Section>
204
+ </div>
205
+ );
206
+ };
@@ -0,0 +1,54 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { type SortDirection, type Column } from '@tanstack/react-table';
6
+ import { useState } from 'react';
7
+
8
+ export const useColumnSorting = (column: Column<any>) => {
9
+ const [sortDirection, setSortDirection] = useState<SortDirection | false>(column.getIsSorted());
10
+ const [firstSort, setFirstSort] = useState<SortDirection | undefined>();
11
+
12
+ const canSort = column.getCanSort();
13
+
14
+ const updateColumnSort = (direction: SortDirection | false) => {
15
+ setSortDirection(direction);
16
+
17
+ switch (direction) {
18
+ case false:
19
+ column.clearSorting();
20
+ break;
21
+ case 'asc':
22
+ column.toggleSorting(false); // descending false
23
+ break;
24
+ case 'desc':
25
+ column.toggleSorting(true); // descending true
26
+ break;
27
+ }
28
+ };
29
+
30
+ // Whichever sort is explicitly set first, will be the first sort direction
31
+ // When toggling, we always go to the other direction, and then to unsorted.
32
+ const onToggleSort = () => {
33
+ if (sortDirection === false) {
34
+ return;
35
+ }
36
+
37
+ if (sortDirection === firstSort) {
38
+ updateColumnSort(firstSort === 'asc' ? 'desc' : 'asc');
39
+ } else {
40
+ updateColumnSort(false);
41
+ }
42
+ };
43
+
44
+ const onSelectSort = (direction: SortDirection) => {
45
+ setFirstSort(direction);
46
+ updateColumnSort(direction);
47
+ };
48
+
49
+ const onClearSort = () => {
50
+ updateColumnSort(false);
51
+ };
52
+
53
+ return { canSort, sortDirection, onSelectSort, onToggleSort, onClearSort };
54
+ };
package/src/helpers.tsx CHANGED
@@ -340,7 +340,7 @@ export class ColumnBuilder<TData extends RowData> {
340
340
  ...props.meta,
341
341
  onUpdate,
342
342
  digits,
343
- header: { classNames: 'text-end', ...props.meta?.header },
343
+ header: { ...props.meta?.header },
344
344
  cell: { ...props.meta?.cell, classNames },
345
345
  },
346
346
  };
package/src/theme.ts CHANGED
@@ -82,7 +82,7 @@ export const tbodyTr: ComponentFunction<TbodyTrStyleProps> = ({ canBeCurrent, is
82
82
  canBeCurrent ? ghostSelectedCurrent : ghostSelected,
83
83
  canBeCurrent && focusRing,
84
84
  canBeCurrent && 'cursor-pointer rounded',
85
- isPinned && 'sticky z-[20] bottom-[-1px] base-surface shadow-sm',
85
+ isPinned && 'sticky z-1 bottom-[-1px] base-surface',
86
86
  ...etc,
87
87
  );
88
88
 
@@ -1,8 +0,0 @@
1
- import { type SortDirection } from '@tanstack/react-table';
2
- type SortButtonProps = {
3
- sortDirection: false | SortDirection;
4
- onClick: (e: any) => void;
5
- };
6
- export declare const SortButton: ({ sortDirection, onClick }: SortButtonProps) => JSX.Element;
7
- export {};
8
- //# sourceMappingURL=SortButton.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SortButton.d.ts","sourceRoot":"","sources":["../../../../src/components/SortButton.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAM3D,KAAK,eAAe,GAAG;IAAE,aAAa,EAAE,KAAK,GAAG,aAAa,CAAC;IAAC,OAAO,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;CAAE,CAAC;AAE3F,eAAO,MAAM,UAAU,+BAAgC,eAAe,gBAoBrE,CAAC"}