@dxos/react-ui-list 0.8.4-main.c1de068 → 0.8.4-main.dedc0f3
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 +40 -50
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +40 -50
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Accordion/Accordion.stories.d.ts +7 -3
- package/dist/types/src/components/Accordion/Accordion.stories.d.ts.map +1 -1
- package/dist/types/src/components/Accordion/AccordionItem.d.ts +1 -1
- package/dist/types/src/components/Accordion/AccordionItem.d.ts.map +1 -1
- package/dist/types/src/components/List/List.d.ts +6 -6
- package/dist/types/src/components/List/List.d.ts.map +1 -1
- package/dist/types/src/components/List/List.stories.d.ts +11 -4
- package/dist/types/src/components/List/List.stories.d.ts.map +1 -1
- package/dist/types/src/components/List/ListItem.d.ts +4 -7
- package/dist/types/src/components/List/ListItem.d.ts.map +1 -1
- package/dist/types/src/components/List/ListRoot.d.ts.map +1 -1
- package/dist/types/src/components/Tree/Tree.stories.d.ts +36 -5
- package/dist/types/src/components/Tree/Tree.stories.d.ts.map +1 -1
- package/dist/types/src/components/Tree/TreeItem.d.ts +8 -7
- package/dist/types/src/components/Tree/TreeItem.d.ts.map +1 -1
- package/dist/types/src/components/Tree/TreeItemHeading.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -17
- package/src/components/Accordion/Accordion.stories.tsx +3 -3
- package/src/components/Accordion/Accordion.tsx +1 -1
- package/src/components/Accordion/AccordionItem.tsx +5 -2
- package/src/components/List/List.stories.tsx +11 -10
- package/src/components/List/List.tsx +2 -5
- package/src/components/List/ListItem.tsx +39 -27
- package/src/components/List/ListRoot.tsx +1 -1
- package/src/components/Tree/Tree.stories.tsx +48 -44
- package/src/components/Tree/TreeItem.tsx +14 -13
- package/src/components/Tree/TreeItemHeading.tsx +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-list",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.dedc0f3",
|
|
4
4
|
"description": "A list component.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"type": "module",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
+
"source": "./src/index.ts",
|
|
12
13
|
"types": "./dist/types/src/index.d.ts",
|
|
13
14
|
"browser": "./dist/lib/browser/index.mjs",
|
|
14
15
|
"node": "./dist/lib/node-esm/index.mjs"
|
|
@@ -29,33 +30,33 @@
|
|
|
29
30
|
"@preact/signals-core": "^1.9.0",
|
|
30
31
|
"@radix-ui/react-accordion": "1.2.3",
|
|
31
32
|
"@radix-ui/react-context": "1.1.1",
|
|
32
|
-
"@dxos/debug": "0.8.4-main.
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/live-object": "0.8.4-main.
|
|
36
|
-
"@dxos/log": "0.8.4-main.
|
|
37
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
38
|
-
"@dxos/react-ui-text-tooltip": "0.8.4-main.
|
|
39
|
-
"@dxos/react-ui-theme": "0.8.4-main.
|
|
40
|
-
"@dxos/
|
|
41
|
-
"@dxos/
|
|
33
|
+
"@dxos/debug": "0.8.4-main.dedc0f3",
|
|
34
|
+
"@dxos/invariant": "0.8.4-main.dedc0f3",
|
|
35
|
+
"@dxos/echo-schema": "0.8.4-main.dedc0f3",
|
|
36
|
+
"@dxos/live-object": "0.8.4-main.dedc0f3",
|
|
37
|
+
"@dxos/log": "0.8.4-main.dedc0f3",
|
|
38
|
+
"@dxos/react-ui": "0.8.4-main.dedc0f3",
|
|
39
|
+
"@dxos/react-ui-text-tooltip": "0.8.4-main.dedc0f3",
|
|
40
|
+
"@dxos/react-ui-theme": "0.8.4-main.dedc0f3",
|
|
41
|
+
"@dxos/util": "0.8.4-main.dedc0f3",
|
|
42
|
+
"@dxos/react-ui-types": "0.8.4-main.dedc0f3"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@types/react": "~18.2.0",
|
|
45
46
|
"@types/react-dom": "~18.2.0",
|
|
46
|
-
"effect": "3.17.
|
|
47
|
+
"effect": "3.17.7",
|
|
47
48
|
"react": "~18.2.0",
|
|
48
49
|
"react-dom": "~18.2.0",
|
|
49
|
-
"vite": "
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
50
|
+
"vite": "7.1.1",
|
|
51
|
+
"@dxos/storybook-utils": "0.8.4-main.dedc0f3",
|
|
52
|
+
"@dxos/random": "0.8.4-main.dedc0f3"
|
|
52
53
|
},
|
|
53
54
|
"peerDependencies": {
|
|
54
55
|
"effect": "^3.13.3",
|
|
55
56
|
"react": "~18.2.0",
|
|
56
57
|
"react-dom": "~18.2.0",
|
|
57
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
58
|
-
"@dxos/react-ui-theme": "0.8.4-main.
|
|
58
|
+
"@dxos/react-ui": "0.8.4-main.dedc0f3",
|
|
59
|
+
"@dxos/react-ui-theme": "0.8.4-main.dedc0f3"
|
|
59
60
|
},
|
|
60
61
|
"publishConfig": {
|
|
61
62
|
"access": "public"
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
|
-
import { type
|
|
7
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
8
|
import React from 'react';
|
|
9
9
|
|
|
10
10
|
import { faker } from '@dxos/random';
|
|
@@ -41,11 +41,11 @@ const DefaultStory = () => {
|
|
|
41
41
|
);
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
const meta
|
|
44
|
+
const meta = {
|
|
45
45
|
title: 'ui/react-ui-list/Accordion',
|
|
46
46
|
render: DefaultStory,
|
|
47
47
|
decorators: [withTheme, withLayout({ fullscreen: true, classNames: 'flex justify-center' })],
|
|
48
|
-
}
|
|
48
|
+
} satisfies Meta<typeof Accordion>;
|
|
49
49
|
|
|
50
50
|
export default meta;
|
|
51
51
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { AccordionItem,
|
|
5
|
+
import { AccordionItem, AccordionItemBody, AccordionItemHeader } from './AccordionItem';
|
|
6
6
|
import { AccordionRoot } from './AccordionRoot';
|
|
7
7
|
|
|
8
8
|
// TODO(burdon): Next iteration should be based on Radix UI Accordion:
|
|
@@ -9,16 +9,19 @@ import React, { type PropsWithChildren } from 'react';
|
|
|
9
9
|
import { Icon, type ThemedClassName } from '@dxos/react-ui';
|
|
10
10
|
import { mx } from '@dxos/react-ui-theme';
|
|
11
11
|
|
|
12
|
-
import { useAccordionContext } from './AccordionRoot';
|
|
13
12
|
import { type ListItemRecord } from '../List';
|
|
14
13
|
|
|
14
|
+
import { useAccordionContext } from './AccordionRoot';
|
|
15
|
+
|
|
15
16
|
const ACCORDION_ITEM_NAME = 'AccordionItem';
|
|
16
17
|
|
|
17
18
|
type AccordionItemContext<T extends ListItemRecord> = {
|
|
18
19
|
item: T;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
// TODO(wittjosiah): This seems to be conflicting with something in the bundle.
|
|
23
|
+
// Perhaps @radix-ui/react-accordion?
|
|
24
|
+
export const [AccordionItemProvider, useDxAccordionItemContext] =
|
|
22
25
|
createContext<AccordionItemContext<any>>(ACCORDION_ITEM_NAME);
|
|
23
26
|
|
|
24
27
|
export type AccordionItemProps<T extends ListItemRecord> = ThemedClassName<PropsWithChildren<{ item: T }>>;
|
|
@@ -14,18 +14,11 @@ import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
|
14
14
|
import { arrayMove } from '@dxos/util';
|
|
15
15
|
|
|
16
16
|
import { List, type ListRootProps } from './List';
|
|
17
|
-
import {
|
|
17
|
+
import { TestItemSchema, type TestItemType, createList } from './testing';
|
|
18
18
|
|
|
19
19
|
// TODO(burdon): var-icon-size.
|
|
20
20
|
const grid = 'grid grid-cols-[32px_1fr_32px] min-bs-[2rem] rounded';
|
|
21
21
|
|
|
22
|
-
const meta: Meta = {
|
|
23
|
-
title: 'ui/react-ui-list/List',
|
|
24
|
-
decorators: [withTheme, withLayout({ fullscreen: true })],
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export default meta;
|
|
28
|
-
|
|
29
22
|
const DefaultStory = ({ items = [], ...props }: ListRootProps<TestItemType>) => {
|
|
30
23
|
const handleSelect = (item: TestItemType) => {
|
|
31
24
|
console.log('select', item);
|
|
@@ -98,7 +91,15 @@ const SimpleStory = ({ items = [], ...props }: ListRootProps<TestItemType>) => {
|
|
|
98
91
|
|
|
99
92
|
const list = live(createList(100));
|
|
100
93
|
|
|
101
|
-
|
|
94
|
+
const meta = {
|
|
95
|
+
title: 'ui/react-ui-list/List',
|
|
96
|
+
component: List.Root,
|
|
97
|
+
decorators: [withTheme, withLayout({ fullscreen: true })],
|
|
98
|
+
} satisfies Meta<typeof List.Root>;
|
|
99
|
+
|
|
100
|
+
export default meta;
|
|
101
|
+
|
|
102
|
+
export const Default: StoryObj<typeof DefaultStory> = {
|
|
102
103
|
render: DefaultStory,
|
|
103
104
|
args: {
|
|
104
105
|
items: list.items,
|
|
@@ -106,7 +107,7 @@ export const Default: StoryObj<ListRootProps<TestItemType>> = {
|
|
|
106
107
|
},
|
|
107
108
|
};
|
|
108
109
|
|
|
109
|
-
export const Simple: StoryObj<
|
|
110
|
+
export const Simple: StoryObj<typeof SimpleStory> = {
|
|
110
111
|
render: SimpleStory,
|
|
111
112
|
args: {
|
|
112
113
|
items: list.items,
|
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
IconButton,
|
|
7
|
-
type IconButtonProps,
|
|
8
6
|
ListItem,
|
|
9
|
-
ListItemDeleteButton,
|
|
10
7
|
ListItemButton,
|
|
8
|
+
ListItemDeleteButton,
|
|
11
9
|
ListItemDragHandle,
|
|
12
10
|
ListItemDragPreview,
|
|
13
11
|
type ListItemProps,
|
|
@@ -38,9 +36,8 @@ export const List = {
|
|
|
38
36
|
ItemDeleteButton: ListItemDeleteButton,
|
|
39
37
|
ItemButton: ListItemButton,
|
|
40
38
|
ItemTitle: ListItemTitle,
|
|
41
|
-
IconButton,
|
|
42
39
|
};
|
|
43
40
|
|
|
44
41
|
type ListItem = ListItemRecord;
|
|
45
42
|
|
|
46
|
-
export type { ListRootProps, ListItemProps,
|
|
43
|
+
export type { ListRootProps, ListItemProps, ListItem, ListItemRecord };
|
|
@@ -17,7 +17,6 @@ import React, {
|
|
|
17
17
|
type MutableRefObject,
|
|
18
18
|
type PropsWithChildren,
|
|
19
19
|
type ReactNode,
|
|
20
|
-
forwardRef,
|
|
21
20
|
useEffect,
|
|
22
21
|
useRef,
|
|
23
22
|
useState,
|
|
@@ -25,7 +24,13 @@ import React, {
|
|
|
25
24
|
import { createPortal } from 'react-dom';
|
|
26
25
|
|
|
27
26
|
import { invariant } from '@dxos/invariant';
|
|
28
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
IconButton,
|
|
29
|
+
type IconButtonProps,
|
|
30
|
+
ListItem as NaturalListItem,
|
|
31
|
+
type ThemedClassName,
|
|
32
|
+
useTranslation,
|
|
33
|
+
} from '@dxos/react-ui';
|
|
29
34
|
import { mx } from '@dxos/react-ui-theme';
|
|
30
35
|
|
|
31
36
|
import { useListContext } from './ListRoot';
|
|
@@ -165,15 +170,8 @@ export const ListItem = <T extends ListItemRecord>({ children, classNames, item,
|
|
|
165
170
|
|
|
166
171
|
return (
|
|
167
172
|
<ListItemProvider item={item} dragHandleRef={dragHandleRef}>
|
|
168
|
-
<div role='
|
|
169
|
-
|
|
170
|
-
ref={ref}
|
|
171
|
-
role='listitem'
|
|
172
|
-
className={mx('flex overflow-hidden', classNames, stateStyles[state.type])}
|
|
173
|
-
{...props}
|
|
174
|
-
>
|
|
175
|
-
{children}
|
|
176
|
-
</div>
|
|
173
|
+
<div ref={ref} role='listitem' className={mx('flex relative', classNames, stateStyles[state.type])} {...props}>
|
|
174
|
+
{children}
|
|
177
175
|
{state.type === 'is-dragging-over' && state.closestEdge && (
|
|
178
176
|
<NaturalListItem.DropIndicator edge={state.closestEdge} />
|
|
179
177
|
)}
|
|
@@ -186,51 +184,65 @@ export const ListItem = <T extends ListItemRecord>({ children, classNames, item,
|
|
|
186
184
|
// List item components
|
|
187
185
|
//
|
|
188
186
|
|
|
189
|
-
export type IconButtonProps = ThemedClassName<ComponentProps<'button'>> & { icon: string };
|
|
190
|
-
|
|
191
|
-
export const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(
|
|
192
|
-
({ classNames, icon, ...props }, forwardedRef) => {
|
|
193
|
-
return (
|
|
194
|
-
<button ref={forwardedRef} className={mx('flex items-center justify-center', classNames)} {...props}>
|
|
195
|
-
<Icon icon={icon} classNames='cursor-pointer' size={4} />
|
|
196
|
-
</button>
|
|
197
|
-
);
|
|
198
|
-
},
|
|
199
|
-
);
|
|
200
|
-
|
|
201
187
|
export const ListItemDeleteButton = ({
|
|
202
188
|
autoHide = true,
|
|
203
189
|
classNames,
|
|
204
190
|
disabled,
|
|
205
191
|
icon = 'ph--x--regular',
|
|
192
|
+
label,
|
|
206
193
|
...props
|
|
207
|
-
}: Partial<Pick<IconButtonProps, 'icon'>> &
|
|
194
|
+
}: Partial<Pick<IconButtonProps, 'icon'>> &
|
|
195
|
+
Omit<IconButtonProps, 'icon' | 'label'> & { autoHide?: boolean; label?: string }) => {
|
|
208
196
|
const { state } = useListContext('DELETE_BUTTON');
|
|
209
197
|
const isDisabled = state.type !== 'idle' || disabled;
|
|
198
|
+
const { t } = useTranslation('os');
|
|
210
199
|
return (
|
|
211
200
|
<IconButton
|
|
201
|
+
iconOnly
|
|
202
|
+
variant='ghost'
|
|
203
|
+
{...props}
|
|
212
204
|
icon={icon}
|
|
213
205
|
disabled={isDisabled}
|
|
206
|
+
label={label ?? t('delete label')}
|
|
214
207
|
classNames={[classNames, autoHide && disabled && 'hidden']}
|
|
215
|
-
{...props}
|
|
216
208
|
/>
|
|
217
209
|
);
|
|
218
210
|
};
|
|
219
211
|
|
|
220
212
|
export const ListItemButton = ({
|
|
221
213
|
autoHide = true,
|
|
214
|
+
iconOnly = true,
|
|
215
|
+
variant = 'ghost',
|
|
222
216
|
classNames,
|
|
223
217
|
disabled,
|
|
224
218
|
...props
|
|
225
219
|
}: IconButtonProps & { autoHide?: boolean }) => {
|
|
226
220
|
const { state } = useListContext('ITEM_BUTTON');
|
|
227
221
|
const isDisabled = state.type !== 'idle' || disabled;
|
|
228
|
-
return
|
|
222
|
+
return (
|
|
223
|
+
<IconButton
|
|
224
|
+
{...props}
|
|
225
|
+
disabled={isDisabled}
|
|
226
|
+
iconOnly={iconOnly}
|
|
227
|
+
variant={variant}
|
|
228
|
+
classNames={[classNames, autoHide && disabled && 'hidden']}
|
|
229
|
+
/>
|
|
230
|
+
);
|
|
229
231
|
};
|
|
230
232
|
|
|
231
233
|
export const ListItemDragHandle = ({ disabled }: Pick<IconButtonProps, 'disabled'>) => {
|
|
232
234
|
const { dragHandleRef } = useListItemContext('DRAG_HANDLE');
|
|
233
|
-
|
|
235
|
+
const { t } = useTranslation('os');
|
|
236
|
+
return (
|
|
237
|
+
<IconButton
|
|
238
|
+
iconOnly
|
|
239
|
+
variant='ghost'
|
|
240
|
+
label={t('drag handle label')}
|
|
241
|
+
ref={dragHandleRef as any}
|
|
242
|
+
icon='ph--dots-six-vertical--regular'
|
|
243
|
+
disabled={disabled}
|
|
244
|
+
/>
|
|
245
|
+
);
|
|
234
246
|
};
|
|
235
247
|
|
|
236
248
|
export const ListItemDragPreview = <T extends ListItemRecord>({
|
|
@@ -8,7 +8,7 @@ import { getReorderDestinationIndex } from '@atlaskit/pragmatic-drag-and-drop-hi
|
|
|
8
8
|
import { createContext } from '@radix-ui/react-context';
|
|
9
9
|
import React, { type ReactNode, useCallback, useEffect, useState } from 'react';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { type ItemDragState, type ListItemRecord, idle } from './ListItem';
|
|
12
12
|
|
|
13
13
|
type ListContext<T extends ListItemRecord> = {
|
|
14
14
|
// TODO(burdon): Rename drag state.
|
|
@@ -5,67 +5,69 @@
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
7
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
8
|
-
import {
|
|
8
|
+
import { type Instruction, extractInstruction } from '@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item';
|
|
9
9
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
10
10
|
import React, { useEffect } from 'react';
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import { type Live, live } from '@dxos/live-object';
|
|
13
13
|
import { faker } from '@dxos/random';
|
|
14
14
|
import { Icon } from '@dxos/react-ui';
|
|
15
15
|
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
16
16
|
|
|
17
|
-
import { Tree } from './Tree';
|
|
18
|
-
import { type TreeData } from './TreeItem';
|
|
19
|
-
import { createTree, updateState, type TestItem } from './testing';
|
|
20
17
|
import { Path } from '../../util';
|
|
21
18
|
|
|
19
|
+
import { type TestItem, createTree, updateState } from './testing';
|
|
20
|
+
import { Tree, type TreeProps } from './Tree';
|
|
21
|
+
import { type TreeData } from './TreeItem';
|
|
22
|
+
|
|
22
23
|
faker.seed(1234);
|
|
23
24
|
|
|
25
|
+
const DefaultStory = (props: TreeProps) => {
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
return monitorForElements({
|
|
28
|
+
canMonitor: ({ source }) => typeof source.data.id === 'string' && Array.isArray(source.data.path),
|
|
29
|
+
onDrop: ({ location, source }) => {
|
|
30
|
+
// Didn't drop on anything.
|
|
31
|
+
if (!location.current.dropTargets.length) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const target = location.current.dropTargets[0];
|
|
36
|
+
const instruction: Instruction | null = extractInstruction(target.data);
|
|
37
|
+
if (instruction !== null) {
|
|
38
|
+
updateState({
|
|
39
|
+
state: tree,
|
|
40
|
+
instruction,
|
|
41
|
+
source: source.data as TreeData,
|
|
42
|
+
target: target.data as TreeData,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}, []);
|
|
48
|
+
|
|
49
|
+
return <Tree {...props} />;
|
|
50
|
+
};
|
|
51
|
+
|
|
24
52
|
const tree = live<TestItem>(createTree());
|
|
25
53
|
const state = new Map<string, Live<{ open: boolean; current: boolean }>>();
|
|
26
54
|
|
|
27
|
-
const meta
|
|
55
|
+
const meta = {
|
|
28
56
|
title: 'ui/react-ui-list/Tree',
|
|
29
57
|
component: Tree,
|
|
58
|
+
render: DefaultStory,
|
|
30
59
|
decorators: [withTheme, withLayout()],
|
|
31
|
-
render: (args) => {
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
return monitorForElements({
|
|
34
|
-
canMonitor: ({ source }) => typeof source.data.id === 'string' && Array.isArray(source.data.path),
|
|
35
|
-
onDrop: ({ location, source }) => {
|
|
36
|
-
// Didn't drop on anything.
|
|
37
|
-
if (!location.current.dropTargets.length) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const target = location.current.dropTargets[0];
|
|
42
|
-
|
|
43
|
-
const instruction: Instruction | null = extractInstruction(target.data);
|
|
44
|
-
if (instruction !== null) {
|
|
45
|
-
updateState({
|
|
46
|
-
state: tree,
|
|
47
|
-
instruction,
|
|
48
|
-
source: source.data as TreeData,
|
|
49
|
-
target: target.data as TreeData,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
}, []);
|
|
55
|
-
|
|
56
|
-
return <Tree {...args} />;
|
|
57
|
-
},
|
|
58
60
|
args: {
|
|
59
61
|
id: tree.id,
|
|
60
|
-
useItems: (
|
|
61
|
-
return
|
|
62
|
+
useItems: (parent?: TestItem) => {
|
|
63
|
+
return parent?.items ?? tree.items;
|
|
62
64
|
},
|
|
63
|
-
getProps: (
|
|
64
|
-
id:
|
|
65
|
-
label:
|
|
66
|
-
icon:
|
|
67
|
-
...((
|
|
68
|
-
parentOf:
|
|
65
|
+
getProps: (parent: TestItem) => ({
|
|
66
|
+
id: parent.id,
|
|
67
|
+
label: parent.name,
|
|
68
|
+
icon: parent.icon,
|
|
69
|
+
...((parent.items?.length ?? 0) > 0 && {
|
|
70
|
+
parentOf: parent.items!.map(({ id }) => id),
|
|
69
71
|
}),
|
|
70
72
|
}),
|
|
71
73
|
isOpen: (_path: string[]) => {
|
|
@@ -104,13 +106,15 @@ const meta: Meta<typeof Tree<TestItem>> = {
|
|
|
104
106
|
object!.current = current;
|
|
105
107
|
},
|
|
106
108
|
},
|
|
107
|
-
}
|
|
109
|
+
} satisfies Meta<typeof Tree<TestItem>>;
|
|
108
110
|
|
|
109
111
|
export default meta;
|
|
110
112
|
|
|
111
|
-
|
|
113
|
+
type Story = StoryObj<typeof meta>;
|
|
114
|
+
|
|
115
|
+
export const Default: Story = {};
|
|
112
116
|
|
|
113
|
-
export const Draggable:
|
|
117
|
+
export const Draggable: Story = {
|
|
114
118
|
args: {
|
|
115
119
|
draggable: true,
|
|
116
120
|
},
|
|
@@ -5,17 +5,17 @@
|
|
|
5
5
|
import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
|
|
6
6
|
import { draggable, dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
7
7
|
import {
|
|
8
|
-
attachInstruction,
|
|
9
|
-
extractInstruction,
|
|
10
8
|
type Instruction,
|
|
11
9
|
type ItemMode,
|
|
10
|
+
attachInstruction,
|
|
11
|
+
extractInstruction,
|
|
12
12
|
} from '@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item';
|
|
13
13
|
import { Schema } from 'effect';
|
|
14
|
-
import React, { memo, useCallback, useEffect, useMemo, useRef, useState
|
|
14
|
+
import React, { type FC, type KeyboardEvent, memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
15
15
|
|
|
16
16
|
import { type HasId } from '@dxos/echo-schema';
|
|
17
17
|
import { invariant } from '@dxos/invariant';
|
|
18
|
-
import {
|
|
18
|
+
import { TreeItem as NaturalTreeItem, Treegrid } from '@dxos/react-ui';
|
|
19
19
|
import {
|
|
20
20
|
ghostHover,
|
|
21
21
|
hoverableControls,
|
|
@@ -23,10 +23,10 @@ import {
|
|
|
23
23
|
hoverableFocusedWithinControls,
|
|
24
24
|
} from '@dxos/react-ui-theme';
|
|
25
25
|
|
|
26
|
+
import { DEFAULT_INDENTATION, paddingIndentation } from './helpers';
|
|
26
27
|
import { useTree } from './TreeContext';
|
|
27
28
|
import { TreeItemHeading } from './TreeItemHeading';
|
|
28
29
|
import { TreeItemToggle } from './TreeItemToggle';
|
|
29
|
-
import { DEFAULT_INDENTATION, paddingIndentation } from './helpers';
|
|
30
30
|
|
|
31
31
|
type TreeItemState = 'idle' | 'dragging' | 'preview' | 'parent-of-instruction';
|
|
32
32
|
|
|
@@ -40,22 +40,23 @@ export const TreeDataSchema = Schema.Struct({
|
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
export type TreeData = Schema.Schema.Type<typeof TreeDataSchema>;
|
|
43
|
-
|
|
44
43
|
export const isTreeData = (data: unknown): data is TreeData => Schema.is(TreeDataSchema)(data);
|
|
45
44
|
|
|
45
|
+
export type ColumnRenderer<T extends HasId = any> = FC<{
|
|
46
|
+
item: T;
|
|
47
|
+
path: string[];
|
|
48
|
+
open: boolean;
|
|
49
|
+
menuOpen: boolean;
|
|
50
|
+
setMenuOpen: (open: boolean) => void;
|
|
51
|
+
}>;
|
|
52
|
+
|
|
46
53
|
export type TreeItemProps<T extends HasId = any> = {
|
|
47
54
|
item: T;
|
|
48
55
|
path: string[];
|
|
49
56
|
levelOffset?: number;
|
|
50
57
|
last: boolean;
|
|
51
58
|
draggable?: boolean;
|
|
52
|
-
renderColumns?:
|
|
53
|
-
item: T;
|
|
54
|
-
path: string[];
|
|
55
|
-
open: boolean;
|
|
56
|
-
menuOpen: boolean;
|
|
57
|
-
setMenuOpen: (open: boolean) => void;
|
|
58
|
-
}>;
|
|
59
|
+
renderColumns?: ColumnRenderer<T>;
|
|
59
60
|
canDrop?: (params: { source: TreeData; target: TreeData }) => boolean;
|
|
60
61
|
onOpenChange?: (params: { item: T; path: string[]; open: boolean }) => void;
|
|
61
62
|
onSelect?: (params: { item: T; path: string[]; current: boolean; option: boolean }) => void;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { type KeyboardEvent, type MouseEvent, forwardRef, memo, useCallback } from 'react';
|
|
6
6
|
|
|
7
|
-
import { Button, Icon, toLocalizedString, useTranslation
|
|
7
|
+
import { Button, Icon, type Label, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
8
8
|
import { TextTooltip } from '@dxos/react-ui-text-tooltip';
|
|
9
9
|
|
|
10
10
|
// TODO(wittjosiah): Consider whether there should be a separate disabled prop which was visually distinct
|