@dxos/react-ui 0.6.4 → 0.6.5-staging.435ed25

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 (34) hide show
  1. package/dist/lib/browser/index.mjs +232 -148
  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/Lists/List.d.ts.map +1 -0
  5. package/dist/types/src/components/Lists/List.stories.d.ts.map +1 -0
  6. package/dist/types/src/components/Lists/Tree.d.ts.map +1 -0
  7. package/dist/types/src/components/Lists/Tree.stories.d.ts.map +1 -0
  8. package/dist/types/src/components/Lists/Treegrid.d.ts +37 -0
  9. package/dist/types/src/components/Lists/Treegrid.d.ts.map +1 -0
  10. package/dist/types/src/components/Lists/Treegrid.stories.d.ts +9 -0
  11. package/dist/types/src/components/Lists/Treegrid.stories.d.ts.map +1 -0
  12. package/dist/types/src/components/Lists/index.d.ts +4 -0
  13. package/dist/types/src/components/Lists/index.d.ts.map +1 -0
  14. package/dist/types/src/components/index.d.ts +1 -1
  15. package/dist/types/src/components/index.d.ts.map +1 -1
  16. package/package.json +23 -14
  17. package/src/components/Lists/Treegrid.stories.tsx +152 -0
  18. package/src/components/Lists/Treegrid.tsx +142 -0
  19. package/src/components/{List → Lists}/index.ts +1 -0
  20. package/src/components/index.ts +1 -1
  21. package/dist/types/src/components/List/List.d.ts.map +0 -1
  22. package/dist/types/src/components/List/List.stories.d.ts.map +0 -1
  23. package/dist/types/src/components/List/Tree.d.ts.map +0 -1
  24. package/dist/types/src/components/List/Tree.stories.d.ts.map +0 -1
  25. package/dist/types/src/components/List/index.d.ts +0 -3
  26. package/dist/types/src/components/List/index.d.ts.map +0 -1
  27. /package/dist/types/src/components/{List → Lists}/List.d.ts +0 -0
  28. /package/dist/types/src/components/{List → Lists}/List.stories.d.ts +0 -0
  29. /package/dist/types/src/components/{List → Lists}/Tree.d.ts +0 -0
  30. /package/dist/types/src/components/{List → Lists}/Tree.stories.d.ts +0 -0
  31. /package/src/components/{List → Lists}/List.stories.tsx +0 -0
  32. /package/src/components/{List → Lists}/List.tsx +0 -0
  33. /package/src/components/{List → Lists}/Tree.stories.tsx +0 -0
  34. /package/src/components/{List → Lists}/Tree.tsx +0 -0
@@ -0,0 +1,152 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+ import React from 'react';
5
+
6
+ import { faker } from '@dxos/random';
7
+
8
+ import { Treegrid as Tg } from './Treegrid';
9
+ import { withTheme } from '../../testing';
10
+
11
+ faker.seed(1234);
12
+
13
+ type StorybookNode = {
14
+ id: string;
15
+ title: string;
16
+ icon?: string;
17
+ nodes?: StorybookNode[];
18
+ };
19
+
20
+ type StorybookIteratorNode = {
21
+ node: StorybookNode;
22
+ path: string[];
23
+ parentOf?: string[];
24
+ };
25
+
26
+ const content = {
27
+ id: 'root',
28
+ title: 'Root',
29
+ nodes: [
30
+ {
31
+ id: faker.string.uuid(),
32
+ title: 'Personal Space',
33
+ icon: 'ph--house--regular',
34
+ nodes: [
35
+ {
36
+ id: faker.string.uuid(),
37
+ title: faker.commerce.productName(),
38
+ },
39
+ {
40
+ id: faker.string.uuid(),
41
+ title: faker.commerce.productName(),
42
+ },
43
+ {
44
+ id: faker.string.uuid(),
45
+ title: faker.commerce.productName(),
46
+ nodes: [
47
+ {
48
+ id: faker.string.uuid(),
49
+ title: faker.commerce.productName(),
50
+ nodes: [
51
+ {
52
+ id: faker.string.uuid(),
53
+ title: faker.commerce.productName(),
54
+ },
55
+ {
56
+ id: faker.string.uuid(),
57
+ title: faker.commerce.productName(),
58
+ },
59
+ ],
60
+ },
61
+ ],
62
+ },
63
+ ],
64
+ },
65
+ {
66
+ id: faker.string.uuid(),
67
+ title: faker.commerce.productName(),
68
+ icon: 'ph--planet--regular',
69
+ nodes: [
70
+ {
71
+ id: faker.string.uuid(),
72
+ title: faker.commerce.productName(),
73
+ },
74
+ ],
75
+ },
76
+ {
77
+ id: faker.string.uuid(),
78
+ title: faker.commerce.productName(),
79
+ icon: 'ph--sailboat--regular',
80
+ },
81
+ {
82
+ id: faker.string.uuid(),
83
+ title: faker.commerce.productName(),
84
+ icon: 'ph--planet--regular',
85
+ },
86
+ ],
87
+ } satisfies StorybookNode;
88
+
89
+ function* visitor(node: StorybookNode, isOpen?: (node: StorybookNode) => boolean): Generator<StorybookIteratorNode> {
90
+ const stack: StorybookIteratorNode[] = [
91
+ {
92
+ node,
93
+ path: [node.id],
94
+ parentOf: (node.nodes ?? []).map(({ id }) => id),
95
+ },
96
+ ];
97
+ while (stack.length > 0) {
98
+ const { node, path, parentOf } = stack.pop()!;
99
+ if (path.length > 1) {
100
+ yield { node, path, parentOf };
101
+ }
102
+
103
+ const children = Array.from(node.nodes ?? []);
104
+ if (path.length === 1 || isOpen?.(node)) {
105
+ for (let i = children.length - 1; i >= 0; i--) {
106
+ const child = children[i];
107
+ stack.push({
108
+ node: child,
109
+ path: [...path, child.id],
110
+ ...((child.nodes?.length ?? 0) > 0 && {
111
+ parentOf: child.nodes!.map(({ id }) => id),
112
+ }),
113
+ });
114
+ }
115
+ }
116
+ }
117
+ }
118
+
119
+ const flattenedContent = Array.from(visitor(content, () => true));
120
+
121
+ const StorybookTreegrid = () => {
122
+ return (
123
+ <Tg.Root gridTemplateColumns='1fr'>
124
+ {flattenedContent.map(({ node, parentOf, path }) => {
125
+ return (
126
+ <Tg.Row
127
+ key={node.id}
128
+ id={path.join(Tg.PATH_SEPARATOR)}
129
+ {...(parentOf && { parentOf: parentOf.join(Tg.PARENT_OF_SEPARATOR) })}
130
+ >
131
+ <Tg.Cell indent classNames='flex items-center'>
132
+ {node.icon && (
133
+ <svg className='is-[1em] bs-[1em] mlb-1'>
134
+ <use href={`/icons.svg#${node.icon}`} />
135
+ </svg>
136
+ )}
137
+ {node.title}
138
+ </Tg.Cell>
139
+ </Tg.Row>
140
+ );
141
+ })}
142
+ </Tg.Root>
143
+ );
144
+ };
145
+
146
+ export default {
147
+ title: 'react-ui/Treegrid',
148
+ component: StorybookTreegrid,
149
+ decorators: [withTheme],
150
+ };
151
+
152
+ export const Treegrid = () => <StorybookTreegrid />;
@@ -0,0 +1,142 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { useFocusableGroup, useArrowNavigationGroup } from '@fluentui/react-tabster';
6
+ import { createContextScope, type Scope } from '@radix-ui/react-context';
7
+ import { Primitive } from '@radix-ui/react-primitive';
8
+ import { Slot } from '@radix-ui/react-slot';
9
+ import { useControllableState } from '@radix-ui/react-use-controllable-state';
10
+ import React, { type ComponentPropsWithRef, type CSSProperties, forwardRef } from 'react';
11
+
12
+ import { useThemeContext } from '../../hooks';
13
+ import { type ThemedClassName } from '../../util';
14
+
15
+ // TODO(thure): A lot of the accessible affordances for this kind of thing need to be implemented per https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/treegrid_role
16
+
17
+ const TREEGRID_ROW_NAME = 'TreegridRow';
18
+
19
+ type TreegridRowScopedProps<P> = P & { __treegridRowScope?: Scope };
20
+
21
+ const [createTreegridRowContext, createTreegridRowScope] = createContextScope(TREEGRID_ROW_NAME, []);
22
+
23
+ type TreegridRowContextValue = {
24
+ open?: boolean;
25
+ onOpenChange?: (nextOpen: boolean) => void;
26
+ };
27
+
28
+ const [TreegridRowProvider, useTreegridRowContext] =
29
+ createTreegridRowContext<TreegridRowContextValue>(TREEGRID_ROW_NAME);
30
+
31
+ const PATH_SEPARATOR = '~';
32
+ const PARENT_OF_SEPARATOR = ' ';
33
+
34
+ type TreegridRootProps = ThemedClassName<ComponentPropsWithRef<typeof Primitive.div>> & {
35
+ gridTemplateColumns: CSSProperties['gridTemplateColumns'];
36
+ asChild?: boolean;
37
+ };
38
+
39
+ const TreegridRoot = forwardRef<HTMLDivElement, TreegridRootProps>(
40
+ ({ asChild, classNames, children, style, gridTemplateColumns, ...props }, forwardedRef) => {
41
+ const { tx } = useThemeContext();
42
+ const Root = asChild ? Slot : Primitive.div;
43
+ const arrowNavigationAttrs = useArrowNavigationGroup({ axis: 'vertical' });
44
+ return (
45
+ <Root
46
+ role='treegrid'
47
+ {...arrowNavigationAttrs}
48
+ {...props}
49
+ className={tx('treegrid.root', 'treegrid', {}, classNames)}
50
+ style={{ ...style, gridTemplateColumns }}
51
+ ref={forwardedRef}
52
+ >
53
+ {children}
54
+ </Root>
55
+ );
56
+ },
57
+ );
58
+
59
+ type TreegridRowProps = ThemedClassName<ComponentPropsWithRef<typeof Primitive.div>> & {
60
+ id: string;
61
+ asChild?: boolean;
62
+ parentOf?: string;
63
+ defaultOpen?: boolean;
64
+ open?: boolean;
65
+ onOpenChange?(open: boolean): void;
66
+ };
67
+
68
+ const TreegridRow = forwardRef<HTMLDivElement, TreegridRowScopedProps<TreegridRowProps>>(
69
+ (
70
+ {
71
+ __treegridRowScope,
72
+ asChild,
73
+ classNames,
74
+ children,
75
+ id,
76
+ parentOf,
77
+ open: propsOpen,
78
+ defaultOpen,
79
+ onOpenChange: propsOnOpenChange,
80
+ ...props
81
+ },
82
+ forwardedRef,
83
+ ) => {
84
+ const { tx } = useThemeContext();
85
+ const Root = asChild ? Slot : Primitive.div;
86
+ const pathParts = id.split(PATH_SEPARATOR);
87
+ const level = pathParts.length - 1;
88
+ const [open, onOpenChange] = useControllableState({
89
+ prop: propsOpen,
90
+ onChange: propsOnOpenChange,
91
+ defaultProp: defaultOpen,
92
+ });
93
+ const focusableGroupAttrs = useFocusableGroup();
94
+ return (
95
+ <TreegridRowProvider open={open} onOpenChange={onOpenChange} scope={__treegridRowScope}>
96
+ <Root
97
+ role='row'
98
+ aria-level={level}
99
+ className={tx('treegrid.row', 'treegrid__row', { level }, classNames)}
100
+ {...(parentOf && { 'aria-expanded': open, 'aria-owns': parentOf })}
101
+ tabIndex={0}
102
+ {...focusableGroupAttrs}
103
+ {...props}
104
+ id={id}
105
+ ref={forwardedRef}
106
+ >
107
+ {children}
108
+ </Root>
109
+ </TreegridRowProvider>
110
+ );
111
+ },
112
+ );
113
+
114
+ type TreegridCellProps = ThemedClassName<ComponentPropsWithRef<typeof Primitive.div>> & { indent?: boolean };
115
+
116
+ const TreegridCell = forwardRef<HTMLDivElement, TreegridCellProps>(
117
+ ({ classNames, children, indent, ...props }, forwardedRef) => {
118
+ const { tx } = useThemeContext();
119
+ return (
120
+ <div
121
+ role='gridcell'
122
+ className={tx('treegrid.cell', 'treegrid__cell', { indent }, classNames)}
123
+ {...props}
124
+ ref={forwardedRef}
125
+ >
126
+ {children}
127
+ </div>
128
+ );
129
+ },
130
+ );
131
+
132
+ export type { TreegridRootProps, TreegridRowProps };
133
+
134
+ export const Treegrid = {
135
+ Root: TreegridRoot,
136
+ Row: TreegridRow,
137
+ Cell: TreegridCell,
138
+ PARENT_OF_SEPARATOR,
139
+ PATH_SEPARATOR,
140
+ createTreegridRowScope,
141
+ useTreegridRowContext,
142
+ };
@@ -4,3 +4,4 @@
4
4
 
5
5
  export * from './List';
6
6
  export * from './Tree';
7
+ export * from './Treegrid';
@@ -10,7 +10,7 @@ export * from './Dialogs';
10
10
  export * from './Menus';
11
11
  export * from './Input';
12
12
  export * from './Link';
13
- export * from './List';
13
+ export * from './Lists';
14
14
  export * from './Main';
15
15
  export * from './Message';
16
16
  export * from './Popover';
@@ -1 +0,0 @@
1
- {"version":3,"file":"List.d.ts","sourceRoot":"","sources":["../../../../../src/components/List/List.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,EAAE,KAAK,wBAAwB,EAAE,KAAK,EAAE,EAAc,KAAK,yBAAyB,EAAE,MAAM,OAAO,CAAC;AAElH,OAAO,EAEL,KAAK,SAAS,IAAI,kBAAkB,EACpC,KAAK,eAAe,EAEpB,KAAK,oBAAoB,IAAI,6BAA6B,EAE1D,KAAK,wBAAwB,IAAI,iCAAiC,EAElE,KAAK,+BAA+B,EAEpC,KAAK,aAAa,IAAI,sBAAsB,EAC5C,KAAK,mBAAmB,EACxB,SAAS,EACT,cAAc,EACd,cAAc,EACd,kBAAkB,EACn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C,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"List.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/List/List.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,YAAY,CAAC;AAOpB,OAAO,KAA4C,MAAM,OAAO,CAAC;AAWjE,OAAO,EAAkB,KAAK,SAAS,EAAwB,MAAM,QAAQ,CAAC;;;;;;;;;;;AAG9E,wBAKE;AAuBF,eAAO,MAAM,oBAAoB;;;;;CAgChC,CAAC;AAgCF,eAAO,MAAM,kBAAkB;;;;;CA8C9B,CAAC;AAEF,eAAO,MAAM,WAAW;;;;;;;CA+BvB,CAAC;AAEF,eAAO,MAAM,iBAAiB;;CAqC7B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Tree.d.ts","sourceRoot":"","sources":["../../../../../src/components/List/Tree.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAE,KAAK,wBAAwB,EAAE,KAAK,EAAE,EAAc,KAAK,yBAAyB,EAAE,MAAM,OAAO,CAAC;AAElH,OAAO,EAGL,KAAK,+BAA+B,EACpC,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,iBAAiB,EACtB,KAAK,SAAS,EAIf,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,KAAK,aAAa,GAAG,SAAS,CAAC;AAE/B,KAAK,aAAa,GAAG,iBAAiB,CAAC;AAwBvC,KAAK,oBAAoB,GAAG,oBAAoB,CAAC;AAIjD,KAAK,wBAAwB,GAAG,wBAAwB,CAAC;AAMzD,KAAK,iBAAiB,GAAG,+BAA+B,CAAC;AAIzD,eAAO,MAAM,IAAI;;;CAAyC,CAAC;AAC3D,eAAO,MAAM,QAAQ,EAAE;IACrB,IAAI,EAAE,yBAAyB,CAAC,aAAa,CAAC,CAAC;IAC/C,OAAO,EAAE,yBAAyB,CAAC,oBAAoB,CAAC,CAAC;IACzD,IAAI,EAAE,yBAAyB,CAAC,iBAAiB,CAAC,CAAC;IACnD,WAAW,EAAE,yBAAyB,CAAC,wBAAwB,CAAC,CAAC;IACjE,eAAe,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;CAOzF,CAAC;AAEF,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Tree.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/List/Tree.stories.tsx"],"names":[],"mappings":";AAIA,OAAO,YAAY,CAAC;AAOpB,KAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,GAAG,CAAC;CACX,CAAC;;;;;;;;;;;AA4CF,wBAKE;AAEF,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;CAmBnB,CAAC"}
@@ -1,3 +0,0 @@
1
- export * from './List';
2
- export * from './Tree';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/List/index.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC"}
File without changes
File without changes
File without changes
File without changes