@dxos/react-ui-list 0.8.4-main.b97322e → 0.8.4-main.bcb3aa67d6

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 (55) hide show
  1. package/dist/lib/browser/index.mjs +693 -725
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +693 -725
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/components/Accordion/Accordion.stories.d.ts +7 -4
  8. package/dist/types/src/components/Accordion/Accordion.stories.d.ts.map +1 -1
  9. package/dist/types/src/components/Accordion/AccordionItem.d.ts +1 -1
  10. package/dist/types/src/components/Accordion/AccordionItem.d.ts.map +1 -1
  11. package/dist/types/src/components/List/List.d.ts +11 -9
  12. package/dist/types/src/components/List/List.d.ts.map +1 -1
  13. package/dist/types/src/components/List/List.stories.d.ts +14 -5
  14. package/dist/types/src/components/List/List.stories.d.ts.map +1 -1
  15. package/dist/types/src/components/List/ListItem.d.ts +9 -10
  16. package/dist/types/src/components/List/ListItem.d.ts.map +1 -1
  17. package/dist/types/src/components/List/ListRoot.d.ts +2 -2
  18. package/dist/types/src/components/List/ListRoot.d.ts.map +1 -1
  19. package/dist/types/src/components/List/testing.d.ts +1 -1
  20. package/dist/types/src/components/List/testing.d.ts.map +1 -1
  21. package/dist/types/src/components/Tree/Tree.d.ts +10 -6
  22. package/dist/types/src/components/Tree/Tree.d.ts.map +1 -1
  23. package/dist/types/src/components/Tree/Tree.stories.d.ts +18 -7
  24. package/dist/types/src/components/Tree/Tree.stories.d.ts.map +1 -1
  25. package/dist/types/src/components/Tree/TreeContext.d.ts +24 -10
  26. package/dist/types/src/components/Tree/TreeContext.d.ts.map +1 -1
  27. package/dist/types/src/components/Tree/TreeItem.d.ts +32 -10
  28. package/dist/types/src/components/Tree/TreeItem.d.ts.map +1 -1
  29. package/dist/types/src/components/Tree/TreeItemHeading.d.ts +4 -3
  30. package/dist/types/src/components/Tree/TreeItemHeading.d.ts.map +1 -1
  31. package/dist/types/src/components/Tree/TreeItemToggle.d.ts +3 -3
  32. package/dist/types/src/components/Tree/TreeItemToggle.d.ts.map +1 -1
  33. package/dist/types/src/components/Tree/index.d.ts +2 -0
  34. package/dist/types/src/components/Tree/index.d.ts.map +1 -1
  35. package/dist/types/src/components/Tree/testing.d.ts +3 -3
  36. package/dist/types/src/components/Tree/testing.d.ts.map +1 -1
  37. package/dist/types/tsconfig.tsbuildinfo +1 -1
  38. package/package.json +32 -28
  39. package/src/components/Accordion/Accordion.stories.tsx +5 -7
  40. package/src/components/Accordion/Accordion.tsx +1 -1
  41. package/src/components/Accordion/AccordionItem.tsx +8 -5
  42. package/src/components/Accordion/AccordionRoot.tsx +1 -1
  43. package/src/components/List/List.stories.tsx +44 -30
  44. package/src/components/List/List.tsx +5 -13
  45. package/src/components/List/ListItem.tsx +79 -47
  46. package/src/components/List/ListRoot.tsx +3 -3
  47. package/src/components/List/testing.ts +3 -3
  48. package/src/components/Tree/Tree.stories.tsx +173 -80
  49. package/src/components/Tree/Tree.tsx +43 -40
  50. package/src/components/Tree/TreeContext.tsx +21 -9
  51. package/src/components/Tree/TreeItem.tsx +223 -135
  52. package/src/components/Tree/TreeItemHeading.tsx +11 -9
  53. package/src/components/Tree/TreeItemToggle.tsx +29 -18
  54. package/src/components/Tree/index.ts +2 -0
  55. package/src/components/Tree/testing.ts +5 -4
package/package.json CHANGED
@@ -1,14 +1,19 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-list",
3
- "version": "0.8.4-main.b97322e",
3
+ "version": "0.8.4-main.bcb3aa67d6",
4
4
  "description": "A list component.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dxos/dxos"
10
+ },
7
11
  "license": "MIT",
8
12
  "author": "DXOS.org",
9
13
  "type": "module",
10
14
  "exports": {
11
15
  ".": {
16
+ "source": "./src/index.ts",
12
17
  "types": "./dist/types/src/index.d.ts",
13
18
  "browser": "./dist/lib/browser/index.mjs",
14
19
  "node": "./dist/lib/node-esm/index.mjs"
@@ -23,39 +28,38 @@
23
28
  "src"
24
29
  ],
25
30
  "dependencies": {
26
- "@atlaskit/pragmatic-drag-and-drop": "^1.4.0",
27
- "@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.3",
28
- "@preact-signals/safe-react": "^0.9.0",
29
- "@preact/signals-core": "^1.9.0",
31
+ "@atlaskit/pragmatic-drag-and-drop": "1.7.7",
32
+ "@atlaskit/pragmatic-drag-and-drop-hitbox": "1.1.0",
33
+ "@effect-atom/atom-react": "^0.5.0",
30
34
  "@radix-ui/react-accordion": "1.2.3",
31
35
  "@radix-ui/react-context": "1.1.1",
32
- "@dxos/debug": "0.8.4-main.b97322e",
33
- "@dxos/echo-schema": "0.8.4-main.b97322e",
34
- "@dxos/invariant": "0.8.4-main.b97322e",
35
- "@dxos/live-object": "0.8.4-main.b97322e",
36
- "@dxos/log": "0.8.4-main.b97322e",
37
- "@dxos/react-ui": "0.8.4-main.b97322e",
38
- "@dxos/react-ui-text-tooltip": "0.8.4-main.b97322e",
39
- "@dxos/react-ui-theme": "0.8.4-main.b97322e",
40
- "@dxos/util": "0.8.4-main.b97322e",
41
- "@dxos/react-ui-types": "0.8.4-main.b97322e"
36
+ "@radix-ui/react-slot": "1.1.2",
37
+ "@dxos/debug": "0.8.4-main.bcb3aa67d6",
38
+ "@dxos/invariant": "0.8.4-main.bcb3aa67d6",
39
+ "@dxos/echo": "0.8.4-main.bcb3aa67d6",
40
+ "@dxos/log": "0.8.4-main.bcb3aa67d6",
41
+ "@dxos/react-ui-text-tooltip": "0.8.4-main.bcb3aa67d6",
42
+ "@dxos/ui-theme": "0.8.4-main.bcb3aa67d6",
43
+ "@dxos/ui-types": "0.8.4-main.bcb3aa67d6",
44
+ "@dxos/util": "0.8.4-main.bcb3aa67d6",
45
+ "@dxos/react-ui": "0.8.4-main.bcb3aa67d6"
42
46
  },
43
47
  "devDependencies": {
44
- "@types/react": "~18.2.0",
45
- "@types/react-dom": "~18.2.0",
46
- "effect": "3.17.0",
47
- "react": "~18.2.0",
48
- "react-dom": "~18.2.0",
49
- "vite": "5.4.7",
50
- "@dxos/random": "0.8.4-main.b97322e",
51
- "@dxos/storybook-utils": "0.8.4-main.b97322e"
48
+ "@types/react": "~19.2.7",
49
+ "@types/react-dom": "~19.2.3",
50
+ "effect": "3.20.0",
51
+ "react": "~19.2.3",
52
+ "react-dom": "~19.2.3",
53
+ "vite": "^7.1.11",
54
+ "@dxos/random": "0.8.4-main.bcb3aa67d6",
55
+ "@dxos/storybook-utils": "0.8.4-main.bcb3aa67d6"
52
56
  },
53
57
  "peerDependencies": {
54
- "effect": "^3.13.3",
55
- "react": "~18.2.0",
56
- "react-dom": "~18.2.0",
57
- "@dxos/react-ui": "0.8.4-main.b97322e",
58
- "@dxos/react-ui-theme": "0.8.4-main.b97322e"
58
+ "effect": "3.20.0",
59
+ "react": "~19.2.3",
60
+ "react-dom": "~19.2.3",
61
+ "@dxos/react-ui": "0.8.4-main.bcb3aa67d6",
62
+ "@dxos/ui-theme": "0.8.4-main.bcb3aa67d6"
59
63
  },
60
64
  "publishConfig": {
61
65
  "access": "public"
@@ -2,13 +2,11 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
7
- import { type StoryObj, type Meta } from '@storybook/react-vite';
5
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
8
6
  import React from 'react';
9
7
 
10
8
  import { faker } from '@dxos/random';
11
- import { withLayout, withTheme } from '@dxos/storybook-utils';
9
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
12
10
 
13
11
  import { Accordion } from './Accordion';
14
12
 
@@ -41,11 +39,11 @@ const DefaultStory = () => {
41
39
  );
42
40
  };
43
41
 
44
- const meta: Meta<typeof Accordion> = {
42
+ const meta = {
45
43
  title: 'ui/react-ui-list/Accordion',
46
44
  render: DefaultStory,
47
- decorators: [withTheme, withLayout({ fullscreen: true, classNames: 'flex justify-center' })],
48
- };
45
+ decorators: [withTheme(), withLayout({ layout: 'column' })],
46
+ } satisfies Meta<typeof Accordion>;
49
47
 
50
48
  export default meta;
51
49
 
@@ -2,7 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { AccordionItem, AccordionItemHeader, AccordionItemBody } from './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:
@@ -7,18 +7,21 @@ import { createContext } from '@radix-ui/react-context';
7
7
  import React, { type PropsWithChildren } from 'react';
8
8
 
9
9
  import { Icon, type ThemedClassName } from '@dxos/react-ui';
10
- import { mx } from '@dxos/react-ui-theme';
10
+ import { mx } from '@dxos/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
- export const [AccordionItemProvider, useAccordionItemContext] =
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 }>>;
@@ -40,7 +43,7 @@ export type AccordionItemHeaderProps = ThemedClassName<AccordionPrimitive.Accord
40
43
  export const AccordionItemHeader = ({ classNames, children, ...props }: AccordionItemHeaderProps) => {
41
44
  return (
42
45
  <AccordionPrimitive.Header {...props} className={mx(classNames)}>
43
- <AccordionPrimitive.Trigger className='group flex items-center p-2 dx-focus-ring-inset is-full text-start'>
46
+ <AccordionPrimitive.Trigger className='group flex items-center p-2 dx-focus-ring-inset w-full text-start'>
44
47
  {children}
45
48
  <Icon
46
49
  icon='ph--caret-right--regular'
@@ -56,7 +59,7 @@ export type AccordionItemBodyProps = ThemedClassName<PropsWithChildren>;
56
59
 
57
60
  export const AccordionItemBody = ({ children, classNames }: AccordionItemBodyProps) => {
58
61
  return (
59
- <AccordionPrimitive.Content className='overflow-hidden data-[state=closed]:animate-slideUp data-[state=open]:animate-slideDown'>
62
+ <AccordionPrimitive.Content className='overflow-hidden data-[state=closed]:animate-slide-up data-[state=open]:animate-slide-down'>
60
63
  <div role='none' className={mx('p-2', classNames)}>
61
64
  {children}
62
65
  </div>
@@ -7,7 +7,7 @@ import { createContext } from '@radix-ui/react-context';
7
7
  import React, { type ReactNode } from 'react';
8
8
 
9
9
  import { type ThemedClassName } from '@dxos/react-ui';
10
- import { mx } from '@dxos/react-ui-theme';
10
+ import { mx } from '@dxos/ui-theme';
11
11
 
12
12
  import { type ListItemRecord } from '../List';
13
13
 
@@ -2,40 +2,43 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
5
+ import { Atom, RegistryContext, useAtomValue } from '@effect-atom/atom-react';
7
6
  import { type Meta, type StoryObj } from '@storybook/react-vite';
8
- import { Schema } from 'effect';
9
- import React from 'react';
7
+ import * as Schema from 'effect/Schema';
8
+ import React, { useContext, useMemo } from 'react';
10
9
 
11
- import { live } from '@dxos/live-object';
12
- import { ghostHover, mx } from '@dxos/react-ui-theme';
13
- import { withLayout, withTheme } from '@dxos/storybook-utils';
10
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
11
+ import { withRegistry } from '@dxos/storybook-utils';
12
+ import { mx } from '@dxos/ui-theme';
14
13
  import { arrayMove } from '@dxos/util';
15
14
 
16
15
  import { List, type ListRootProps } from './List';
17
- import { createList, TestItemSchema, type TestItemType } from './testing';
16
+ import { TestItemSchema, type TestItemType, type TestList, createList } from './testing';
18
17
 
19
18
  // TODO(burdon): var-icon-size.
20
- const grid = 'grid grid-cols-[32px_1fr_32px] min-bs-[2rem] rounded';
19
+ const grid = 'grid grid-cols-[32px_1fr_32px] min-h-[2rem] rounded-sm';
21
20
 
22
- const meta: Meta = {
23
- title: 'ui/react-ui-list/List',
24
- decorators: [withTheme, withLayout({ fullscreen: true })],
25
- };
26
-
27
- export default meta;
21
+ const DefaultStory = (props: Omit<ListRootProps<TestItemType>, 'items'>) => {
22
+ const registry = useContext(RegistryContext);
23
+ const listAtom = useMemo(() => Atom.make<TestList>(createList(100)).pipe(Atom.keepAlive), []);
24
+ const list = useAtomValue(listAtom);
25
+ const items = list.items;
28
26
 
29
- const DefaultStory = ({ items = [], ...props }: ListRootProps<TestItemType>) => {
30
27
  const handleSelect = (item: TestItemType) => {
31
28
  console.log('select', item);
32
29
  };
33
30
  const handleDelete = (item: TestItemType) => {
34
- const idx = items.findIndex((i) => i.id === item.id);
35
- items.splice(idx, 1);
31
+ const prev = registry.get(listAtom);
32
+ registry.set(listAtom, {
33
+ ...prev,
34
+ items: prev.items.filter((i) => i.id !== item.id),
35
+ });
36
36
  };
37
37
  const handleMove = (from: number, to: number) => {
38
- arrayMove(items, from, to);
38
+ const prev = registry.get(listAtom);
39
+ const newItems = [...prev.items];
40
+ arrayMove(newItems, from, to);
41
+ registry.set(listAtom, { ...prev, items: newItems });
39
42
  };
40
43
 
41
44
  return (
@@ -48,9 +51,9 @@ const DefaultStory = ({ items = [], ...props }: ListRootProps<TestItemType>) =>
48
51
  <div className='flex items-center text-sm'>Items</div>
49
52
  </div>
50
53
 
51
- <div role='list' className='w-full h-full overflow-auto'>
54
+ <div role='list' className='h-full w-full overflow-auto'>
52
55
  {items?.map((item) => (
53
- <List.Item<TestItemType> key={item.id} item={item} classNames={mx(grid, ghostHover)}>
56
+ <List.Item<TestItemType> key={item.id} item={item} classNames={mx(grid)}>
54
57
  <List.ItemDragHandle />
55
58
  <List.ItemTitle onClick={() => handleSelect(item)}>{item.name}</List.ItemTitle>
56
59
  <List.ItemDeleteButton onClick={() => handleDelete(item)} />
@@ -66,7 +69,7 @@ const DefaultStory = ({ items = [], ...props }: ListRootProps<TestItemType>) =>
66
69
 
67
70
  <List.ItemDragPreview<TestItemType>>
68
71
  {({ item }) => (
69
- <List.ItemWrapper classNames={mx(grid, 'bg-modalSurface border border-separator')}>
72
+ <List.ItemWrapper classNames={mx(grid, 'bg-modal-surface border border-separator')}>
70
73
  <List.ItemDragHandle />
71
74
  <div className='flex items-center'>{item.name}</div>
72
75
  </List.ItemWrapper>
@@ -78,13 +81,17 @@ const DefaultStory = ({ items = [], ...props }: ListRootProps<TestItemType>) =>
78
81
  );
79
82
  };
80
83
 
81
- const SimpleStory = ({ items = [], ...props }: ListRootProps<TestItemType>) => {
84
+ const SimpleStory = (props: Omit<ListRootProps<TestItemType>, 'items'>) => {
85
+ const listAtom = useMemo(() => Atom.make<TestList>(createList(100)).pipe(Atom.keepAlive), []);
86
+ const list = useAtomValue(listAtom);
87
+ const items = list.items;
88
+
82
89
  return (
83
90
  <List.Root<TestItemType> dragPreview items={items} {...props}>
84
91
  {({ items }) => (
85
- <div role='list' className='w-full h-full overflow-auto'>
92
+ <div role='list' className='h-full w-full overflow-auto'>
86
93
  {items?.map((item) => (
87
- <List.Item<TestItemType> key={item.id} item={item} classNames={mx(grid, ghostHover)}>
94
+ <List.Item<TestItemType> key={item.id} item={item} classNames={mx(grid)}>
88
95
  <List.ItemDragHandle />
89
96
  <List.ItemTitle>{item.name}</List.ItemTitle>
90
97
  <List.ItemDeleteButton />
@@ -96,20 +103,27 @@ const SimpleStory = ({ items = [], ...props }: ListRootProps<TestItemType>) => {
96
103
  );
97
104
  };
98
105
 
99
- const list = live(createList(100));
106
+ const meta = {
107
+ title: 'ui/react-ui-list/List',
108
+ component: List.Root,
109
+ decorators: [withTheme(), withLayout({ layout: 'fullscreen' }), withRegistry],
110
+ parameters: {
111
+ layout: 'fullscreen',
112
+ },
113
+ } satisfies Meta<typeof List.Root>;
114
+
115
+ export default meta;
100
116
 
101
- export const Default: StoryObj<ListRootProps<TestItemType>> = {
117
+ export const Default: StoryObj<typeof DefaultStory> = {
102
118
  render: DefaultStory,
103
119
  args: {
104
- items: list.items,
105
120
  isItem: Schema.is(TestItemSchema),
106
121
  },
107
122
  };
108
123
 
109
- export const Simple: StoryObj<ListRootProps<TestItemType>> = {
124
+ export const Simple: StoryObj<typeof SimpleStory> = {
110
125
  render: SimpleStory,
111
126
  args: {
112
- items: list.items,
113
127
  isItem: Schema.is(TestItemSchema),
114
128
  },
115
129
  };
@@ -3,11 +3,9 @@
3
3
  //
4
4
 
5
5
  import {
6
- IconButton,
7
- type IconButtonProps,
8
6
  ListItem,
7
+ ListItemIconButton,
9
8
  ListItemDeleteButton,
10
- ListItemButton,
11
9
  ListItemDragHandle,
12
10
  ListItemDragPreview,
13
11
  type ListItemProps,
@@ -17,17 +15,12 @@ import {
17
15
  } from './ListItem';
18
16
  import { ListRoot, type ListRootProps } from './ListRoot';
19
17
 
20
- // TODO(burdon): Multi-select model.
21
- // TODO(burdon): Key nav.
22
- // TODO(burdon): Animation.
23
- // TODO(burdon): Constrain axis.
24
- // TODO(burdon): Tree view.
25
- // TODO(burdon): Fix autoscroll while dragging.
26
-
27
18
  /**
28
19
  * Draggable list.
29
20
  * Ref: https://github.com/atlassian/pragmatic-drag-and-drop
30
21
  * Ref: https://github.com/alexreardon/pdnd-react-tailwind/blob/main/src/task.tsx
22
+ *
23
+ * @deprecated Use react-ui-mosaic.
31
24
  */
32
25
  export const List = {
33
26
  Root: ListRoot,
@@ -35,12 +28,11 @@ export const List = {
35
28
  ItemDragPreview: ListItemDragPreview,
36
29
  ItemWrapper: ListItemWrapper,
37
30
  ItemDragHandle: ListItemDragHandle,
31
+ ItemIconButton: ListItemIconButton,
38
32
  ItemDeleteButton: ListItemDeleteButton,
39
- ItemButton: ListItemButton,
40
33
  ItemTitle: ListItemTitle,
41
- IconButton,
42
34
  };
43
35
 
44
36
  type ListItem = ListItemRecord;
45
37
 
46
- export type { ListRootProps, ListItemProps, IconButtonProps, ListItem, ListItemRecord };
38
+ export type { ListRootProps, ListItemProps, ListItem, ListItemRecord };
@@ -11,13 +11,13 @@ import {
11
11
  extractClosestEdge,
12
12
  } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
13
13
  import { createContext } from '@radix-ui/react-context';
14
+ import { Slot } from '@radix-ui/react-slot';
14
15
  import React, {
15
16
  type ComponentProps,
16
17
  type HTMLAttributes,
17
- type MutableRefObject,
18
18
  type PropsWithChildren,
19
19
  type ReactNode,
20
- forwardRef,
20
+ RefObject,
21
21
  useEffect,
22
22
  useRef,
23
23
  useState,
@@ -25,8 +25,14 @@ import React, {
25
25
  import { createPortal } from 'react-dom';
26
26
 
27
27
  import { invariant } from '@dxos/invariant';
28
- import { Icon, type ThemedClassName, ListItem as NaturalListItem } from '@dxos/react-ui';
29
- import { mx } from '@dxos/react-ui-theme';
28
+ import {
29
+ IconButton,
30
+ type IconButtonProps,
31
+ ListItem as NaturalListItem,
32
+ type ThemedClassName,
33
+ useTranslation,
34
+ } from '@dxos/react-ui';
35
+ import { mx, osTranslations } from '@dxos/ui-theme';
30
36
 
31
37
  import { useListContext } from './ListRoot';
32
38
 
@@ -56,7 +62,7 @@ const stateStyles: { [Key in ItemDragState['type']]?: HTMLAttributes<HTMLDivElem
56
62
 
57
63
  type ListItemContext<T extends ListItemRecord> = {
58
64
  item: T;
59
- dragHandleRef: MutableRefObject<HTMLElement | null>;
65
+ dragHandleRef: RefObject<HTMLButtonElement | null>;
60
66
  };
61
67
 
62
68
  /**
@@ -75,6 +81,8 @@ export type ListItemProps<T extends ListItemRecord> = ThemedClassName<
75
81
  PropsWithChildren<
76
82
  {
77
83
  item: T;
84
+ asChild?: boolean;
85
+ selected?: boolean;
78
86
  } & HTMLAttributes<HTMLDivElement>
79
87
  >
80
88
  >;
@@ -82,14 +90,22 @@ export type ListItemProps<T extends ListItemRecord> = ThemedClassName<
82
90
  /**
83
91
  * Draggable list item.
84
92
  */
85
- export const ListItem = <T extends ListItemRecord>({ children, classNames, item, ...props }: ListItemProps<T>) => {
93
+ export const ListItem = <T extends ListItemRecord>({
94
+ children,
95
+ classNames,
96
+ item,
97
+ asChild,
98
+ selected,
99
+ ...props
100
+ }: ListItemProps<T>) => {
101
+ const Comp = asChild ? Slot : 'div';
86
102
  const { isItem, readonly, dragPreview, setState: setRootState } = useListContext(LIST_ITEM_NAME);
87
- const ref = useRef<HTMLDivElement | null>(null);
88
- const dragHandleRef = useRef<HTMLElement | null>(null);
103
+ const rootRef = useRef<HTMLDivElement | null>(null);
104
+ const dragHandleRef = useRef<HTMLButtonElement | null>(null);
89
105
  const [state, setState] = useState<ItemDragState>(idle);
90
106
 
91
107
  useEffect(() => {
92
- const element = ref.current;
108
+ const element = rootRef.current;
93
109
  invariant(element);
94
110
  return combine(
95
111
  //
@@ -165,19 +181,18 @@ export const ListItem = <T extends ListItemRecord>({ children, classNames, item,
165
181
 
166
182
  return (
167
183
  <ListItemProvider item={item} dragHandleRef={dragHandleRef}>
168
- <div role='none' className='relative'>
169
- <div
170
- ref={ref}
171
- role='listitem'
172
- className={mx('flex overflow-hidden', classNames, stateStyles[state.type])}
173
- {...props}
174
- >
175
- {children}
176
- </div>
177
- {state.type === 'is-dragging-over' && state.closestEdge && (
178
- <NaturalListItem.DropIndicator edge={state.closestEdge} />
179
- )}
180
- </div>
184
+ <Comp
185
+ {...props}
186
+ role='listitem'
187
+ aria-selected={selected}
188
+ className={mx('relative p-1 dx-selected dx-hover', classNames, stateStyles[state.type])}
189
+ ref={rootRef}
190
+ >
191
+ {children}
192
+ </Comp>
193
+ {state.type === 'is-dragging-over' && state.closestEdge && (
194
+ <NaturalListItem.DropIndicator edge={state.closestEdge} />
195
+ )}
181
196
  </ListItemProvider>
182
197
  );
183
198
  };
@@ -186,51 +201,66 @@ export const ListItem = <T extends ListItemRecord>({ children, classNames, item,
186
201
  // List item components
187
202
  //
188
203
 
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
- export const ListItemDeleteButton = ({
204
+ export const ListItemIconButton = ({
202
205
  autoHide = true,
206
+ iconOnly = true,
207
+ variant = 'ghost',
203
208
  classNames,
204
209
  disabled,
205
- icon = 'ph--x--regular',
206
210
  ...props
207
- }: Partial<Pick<IconButtonProps, 'icon'>> & Omit<IconButtonProps, 'icon'> & { autoHide?: boolean }) => {
208
- const { state } = useListContext('DELETE_BUTTON');
211
+ }: IconButtonProps & { autoHide?: boolean }) => {
212
+ const { state } = useListContext('ITEM_BUTTON');
209
213
  const isDisabled = state.type !== 'idle' || disabled;
210
214
  return (
211
215
  <IconButton
212
- icon={icon}
216
+ {...props}
213
217
  disabled={isDisabled}
218
+ iconOnly={iconOnly}
219
+ variant={variant}
214
220
  classNames={[classNames, autoHide && disabled && 'hidden']}
215
- {...props}
216
221
  />
217
222
  );
218
223
  };
219
224
 
220
- export const ListItemButton = ({
225
+ // TODO(burdon): Generalize to action button.
226
+ export const ListItemDeleteButton = ({
221
227
  autoHide = true,
222
228
  classNames,
223
229
  disabled,
230
+ icon = 'ph--x--regular',
231
+ label,
224
232
  ...props
225
- }: IconButtonProps & { autoHide?: boolean }) => {
226
- const { state } = useListContext('ITEM_BUTTON');
233
+ }: Partial<Pick<IconButtonProps, 'icon'>> &
234
+ Omit<IconButtonProps, 'icon' | 'label'> & { autoHide?: boolean; label?: string }) => {
235
+ const { state } = useListContext('DELETE_BUTTON');
227
236
  const isDisabled = state.type !== 'idle' || disabled;
228
- return <IconButton disabled={isDisabled} classNames={[classNames, autoHide && disabled && 'hidden']} {...props} />;
237
+ const { t } = useTranslation(osTranslations);
238
+ return (
239
+ <IconButton
240
+ {...props}
241
+ variant='ghost'
242
+ disabled={isDisabled}
243
+ icon={icon}
244
+ iconOnly
245
+ label={label ?? t('delete.label')}
246
+ classNames={[classNames, autoHide && disabled && 'hidden']}
247
+ />
248
+ );
229
249
  };
230
250
 
231
251
  export const ListItemDragHandle = ({ disabled }: Pick<IconButtonProps, 'disabled'>) => {
232
252
  const { dragHandleRef } = useListItemContext('DRAG_HANDLE');
233
- return <IconButton ref={dragHandleRef as any} icon='ph--dots-six-vertical--regular' disabled={disabled} />;
253
+ const { t } = useTranslation(osTranslations);
254
+ return (
255
+ <IconButton
256
+ variant='ghost'
257
+ disabled={disabled}
258
+ icon='ph--dots-six-vertical--regular'
259
+ iconOnly
260
+ label={t('drag-handle.label')}
261
+ ref={dragHandleRef}
262
+ />
263
+ );
234
264
  };
235
265
 
236
266
  export const ListItemDragPreview = <T extends ListItemRecord>({
@@ -243,7 +273,9 @@ export const ListItemDragPreview = <T extends ListItemRecord>({
243
273
  };
244
274
 
245
275
  export const ListItemWrapper = ({ classNames, children }: ThemedClassName<PropsWithChildren>) => (
246
- <div className={mx('flex is-full gap-2', classNames)}>{children}</div>
276
+ <div role='none' className={mx('flex w-full gap-2', classNames)}>
277
+ {children}
278
+ </div>
247
279
  );
248
280
 
249
281
  export const ListItemTitle = ({
@@ -251,7 +283,7 @@ export const ListItemTitle = ({
251
283
  children,
252
284
  ...props
253
285
  }: ThemedClassName<PropsWithChildren<ComponentProps<'div'>>>) => (
254
- <div className={mx('flex grow items-center truncate', classNames)} {...props}>
286
+ <div role='none' className={mx('flex grow items-center truncate', classNames)} {...props}>
255
287
  {children}
256
288
  </div>
257
289
  );
@@ -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 { idle, type ItemDragState, type ListItemRecord } from './ListItem';
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.
@@ -26,14 +26,14 @@ export const [ListProvider, useListContext] = createContext<ListContext<any>>(LI
26
26
 
27
27
  export type ListRendererProps<T extends ListItemRecord> = {
28
28
  state: ListContext<T>['state'];
29
- items: T[];
29
+ items: readonly T[];
30
30
  };
31
31
 
32
32
  const defaultGetId = <T extends ListItemRecord>(item: T) => (item as any)?.id;
33
33
 
34
34
  export type ListRootProps<T extends ListItemRecord> = {
35
35
  children?: (props: ListRendererProps<T>) => ReactNode;
36
- items?: T[];
36
+ items?: readonly T[];
37
37
  onMove?: (fromIndex: number, toIndex: number) => void;
38
38
  } & Pick<ListContext<T>, 'isItem' | 'getId' | 'readonly' | 'dragPreview'>;
39
39
 
@@ -2,13 +2,13 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { Schema } from 'effect';
5
+ import * as Schema from 'effect/Schema';
6
6
 
7
- import { ObjectId } from '@dxos/echo-schema';
7
+ import { Obj } from '@dxos/echo';
8
8
  import { faker } from '@dxos/random';
9
9
 
10
10
  export const TestItemSchema = Schema.Struct({
11
- id: ObjectId,
11
+ id: Obj.ID,
12
12
  name: Schema.String,
13
13
  });
14
14