@fluentui/react-tree 9.0.0-beta.20 → 9.0.0-beta.22
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/CHANGELOG.json +131 -9
- package/CHANGELOG.md +41 -10
- package/dist/index.d.ts +71 -148
- package/lib/components/Tree/Tree.js.map +1 -1
- package/lib/components/Tree/Tree.types.js.map +1 -1
- package/lib/components/Tree/useRootTree.js +1 -1
- package/lib/components/Tree/useRootTree.js.map +1 -1
- package/lib/components/TreeItem/TreeItem.js.map +1 -1
- package/lib/components/TreeItem/TreeItem.types.js.map +1 -1
- package/lib/components/TreeItem/index.js +1 -0
- package/lib/components/TreeItem/index.js.map +1 -1
- package/lib/components/TreeItem/useTreeItem.js +8 -6
- package/lib/components/TreeItem/useTreeItem.js.map +1 -1
- package/lib/components/TreeItem/useTreeItemStyles.styles.js +3 -5
- package/lib/components/TreeItem/useTreeItemStyles.styles.js.map +1 -1
- package/lib/components/TreeItemLayout/TreeItemLayout.types.js.map +1 -1
- package/lib/components/TreeItemLayout/renderTreeItemLayout.js +4 -1
- package/lib/components/TreeItemLayout/renderTreeItemLayout.js.map +1 -1
- package/lib/components/TreeItemLayout/useTreeItemLayout.js +26 -2
- package/lib/components/TreeItemLayout/useTreeItemLayout.js.map +1 -1
- package/lib/components/TreeItemLayout/useTreeItemLayoutStyles.styles.js +103 -11
- package/lib/components/TreeItemLayout/useTreeItemLayoutStyles.styles.js.map +1 -1
- package/lib/components/TreeItemPersonaLayout/TreeItemPersonaLayout.types.js.map +1 -1
- package/lib/components/TreeItemPersonaLayout/renderTreeItemPersonaLayout.js +4 -1
- package/lib/components/TreeItemPersonaLayout/renderTreeItemPersonaLayout.js.map +1 -1
- package/lib/components/TreeItemPersonaLayout/useTreeItemPersonaLayout.js +5 -7
- package/lib/components/TreeItemPersonaLayout/useTreeItemPersonaLayout.js.map +1 -1
- package/lib/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.styles.js +95 -25
- package/lib/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.styles.js.map +1 -1
- package/lib/contexts/treeContext.js.map +1 -1
- package/lib/contexts/treeItemContext.js +1 -1
- package/lib/contexts/treeItemContext.js.map +1 -1
- package/lib/hooks/useFlatTree.js +11 -2
- package/lib/hooks/useFlatTree.js.map +1 -1
- package/lib/hooks/useFlatTreeNavigation.js +8 -5
- package/lib/hooks/useFlatTreeNavigation.js.map +1 -1
- package/lib/hooks/useNestedTreeNavigation.js.map +1 -1
- package/lib/hooks/useOpenItemsState.js +3 -0
- package/lib/hooks/useOpenItemsState.js.map +1 -1
- package/lib/index.js +1 -2
- package/lib/index.js.map +1 -1
- package/lib/utils/createFlatTreeItems.js +4 -11
- package/lib/utils/createFlatTreeItems.js.map +1 -1
- package/lib/utils/flattenTree.js.map +1 -1
- package/lib/utils/getTreeItemValueFromElement.js +4 -0
- package/lib/utils/getTreeItemValueFromElement.js.map +1 -0
- package/lib-commonjs/components/Tree/useRootTree.js +1 -1
- package/lib-commonjs/components/Tree/useRootTree.js.map +1 -1
- package/lib-commonjs/components/TreeItem/index.js +1 -0
- package/lib-commonjs/components/TreeItem/index.js.map +1 -1
- package/lib-commonjs/components/TreeItem/useTreeItem.js +8 -6
- package/lib-commonjs/components/TreeItem/useTreeItem.js.map +1 -1
- package/lib-commonjs/components/TreeItem/useTreeItemStyles.styles.js +4 -8
- package/lib-commonjs/components/TreeItem/useTreeItemStyles.styles.js.map +1 -1
- package/lib-commonjs/components/TreeItemLayout/renderTreeItemLayout.js +4 -1
- package/lib-commonjs/components/TreeItemLayout/renderTreeItemLayout.js.map +1 -1
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayout.js +25 -2
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayout.js.map +1 -1
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayoutStyles.styles.js +180 -13
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayoutStyles.styles.js.map +1 -1
- package/lib-commonjs/components/TreeItemPersonaLayout/renderTreeItemPersonaLayout.js +4 -1
- package/lib-commonjs/components/TreeItemPersonaLayout/renderTreeItemPersonaLayout.js.map +1 -1
- package/lib-commonjs/components/TreeItemPersonaLayout/useTreeItemPersonaLayout.js +5 -7
- package/lib-commonjs/components/TreeItemPersonaLayout/useTreeItemPersonaLayout.js.map +1 -1
- package/lib-commonjs/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.styles.js +175 -30
- package/lib-commonjs/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.styles.js.map +1 -1
- package/lib-commonjs/contexts/treeItemContext.js +1 -1
- package/lib-commonjs/contexts/treeItemContext.js.map +1 -1
- package/lib-commonjs/hooks/useFlatTree.js +10 -1
- package/lib-commonjs/hooks/useFlatTree.js.map +1 -1
- package/lib-commonjs/hooks/useFlatTreeNavigation.js +8 -5
- package/lib-commonjs/hooks/useFlatTreeNavigation.js.map +1 -1
- package/lib-commonjs/hooks/useOpenItemsState.js +3 -0
- package/lib-commonjs/hooks/useOpenItemsState.js.map +1 -1
- package/lib-commonjs/index.js +1 -6
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utils/createFlatTreeItems.js +8 -13
- package/lib-commonjs/utils/createFlatTreeItems.js.map +1 -1
- package/lib-commonjs/utils/getTreeItemValueFromElement.js +18 -0
- package/lib-commonjs/utils/getTreeItemValueFromElement.js.map +1 -0
- package/package.json +9 -9
- package/lib/TreeItemAside.js +0 -1
- package/lib/TreeItemAside.js.map +0 -1
- package/lib/components/TreeItemAside/TreeItemAside.js +0 -13
- package/lib/components/TreeItemAside/TreeItemAside.js.map +0 -1
- package/lib/components/TreeItemAside/TreeItemAside.types.js +0 -1
- package/lib/components/TreeItemAside/TreeItemAside.types.js.map +0 -1
- package/lib/components/TreeItemAside/index.js +0 -5
- package/lib/components/TreeItemAside/index.js.map +0 -1
- package/lib/components/TreeItemAside/renderTreeItemAside.js +0 -14
- package/lib/components/TreeItemAside/renderTreeItemAside.js.map +0 -1
- package/lib/components/TreeItemAside/useTreeItemAside.js +0 -30
- package/lib/components/TreeItemAside/useTreeItemAside.js.map +0 -1
- package/lib/components/TreeItemAside/useTreeItemAsideStyles.styles.js +0 -47
- package/lib/components/TreeItemAside/useTreeItemAsideStyles.styles.js.map +0 -1
- package/lib-commonjs/TreeItemAside.js +0 -6
- package/lib-commonjs/TreeItemAside.js.map +0 -1
- package/lib-commonjs/components/TreeItemAside/TreeItemAside.js +0 -19
- package/lib-commonjs/components/TreeItemAside/TreeItemAside.js.map +0 -1
- package/lib-commonjs/components/TreeItemAside/TreeItemAside.types.js +0 -4
- package/lib-commonjs/components/TreeItemAside/TreeItemAside.types.js.map +0 -1
- package/lib-commonjs/components/TreeItemAside/index.js +0 -10
- package/lib-commonjs/components/TreeItemAside/index.js.map +0 -1
- package/lib-commonjs/components/TreeItemAside/renderTreeItemAside.js +0 -20
- package/lib-commonjs/components/TreeItemAside/renderTreeItemAside.js.map +0 -1
- package/lib-commonjs/components/TreeItemAside/useTreeItemAside.js +0 -31
- package/lib-commonjs/components/TreeItemAside/useTreeItemAside.js.map +0 -1
- package/lib-commonjs/components/TreeItemAside/useTreeItemAsideStyles.styles.js +0 -90
- package/lib-commonjs/components/TreeItemAside/useTreeItemAsideStyles.styles.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -21,9 +21,8 @@ import { ProviderProps } from 'react';
|
|
|
21
21
|
import * as React_2 from 'react';
|
|
22
22
|
import type { Slot } from '@fluentui/react-utilities';
|
|
23
23
|
import type { SlotClassNames } from '@fluentui/react-utilities';
|
|
24
|
-
import { SlotRenderFunction } from '@fluentui/react-utilities';
|
|
25
24
|
|
|
26
|
-
declare type FlattenedTreeItem<Props extends TreeItemProps
|
|
25
|
+
declare type FlattenedTreeItem<Props extends TreeItemProps> = FlatTreeItemProps & Props;
|
|
27
26
|
|
|
28
27
|
/**
|
|
29
28
|
* Converts a nested structure to a flat one which can be consumed by `useFlatTreeItems`
|
|
@@ -65,7 +64,7 @@ declare type FlattenedTreeItem<Props extends TreeItemProps<unknown>> = FlatTreeI
|
|
|
65
64
|
* ]);
|
|
66
65
|
* ```
|
|
67
66
|
*/
|
|
68
|
-
export declare const flattenTree_unstable: <Props extends TreeItemProps
|
|
67
|
+
export declare const flattenTree_unstable: <Props extends TreeItemProps>(items: NestedTreeItem<Props>[]) => FlattenedTreeItem<Props>[];
|
|
69
68
|
|
|
70
69
|
/**
|
|
71
70
|
* FlatTree API to manage all required mechanisms to convert a list of items into renderable TreeItems
|
|
@@ -77,13 +76,13 @@ export declare const flattenTree_unstable: <Props extends TreeItemProps<unknown>
|
|
|
77
76
|
*
|
|
78
77
|
* On simple scenarios it is advised to simply use a nested structure instead.
|
|
79
78
|
*/
|
|
80
|
-
export declare type FlatTree<Props extends FlatTreeItemProps
|
|
79
|
+
export declare type FlatTree<Props extends FlatTreeItemProps = FlatTreeItemProps> = {
|
|
81
80
|
/**
|
|
82
81
|
* returns the properties required for the Tree component to work properly.
|
|
83
82
|
* That includes:
|
|
84
83
|
* `openItems`, `onOpenChange`, `onNavigation_unstable` and `ref`
|
|
85
84
|
*/
|
|
86
|
-
getTreeProps(): FlatTreeProps
|
|
85
|
+
getTreeProps(): FlatTreeProps;
|
|
87
86
|
/**
|
|
88
87
|
* internal method used to react to an `onNavigation` event.
|
|
89
88
|
* This method ensures proper navigation on keyboard and mouse interaction.
|
|
@@ -97,7 +96,7 @@ export declare type FlatTree<Props extends FlatTreeItemProps<unknown> = FlatTree
|
|
|
97
96
|
* event.preventDefault();
|
|
98
97
|
* const nextItem = tree.getNextNavigableItem(data);
|
|
99
98
|
* // scroll to item using virtualization scroll mechanism
|
|
100
|
-
* if (nextItem &&
|
|
99
|
+
* if (nextItem && tree.getElementFromItem(nextItem)) {
|
|
101
100
|
* listRef.current.scrollToItem(nextItem.index);
|
|
102
101
|
* }
|
|
103
102
|
* // wait for scrolling to happen and then invoke navigate method
|
|
@@ -107,7 +106,7 @@ export declare type FlatTree<Props extends FlatTreeItemProps<unknown> = FlatTree
|
|
|
107
106
|
* };
|
|
108
107
|
*```
|
|
109
108
|
*/
|
|
110
|
-
navigate(data: TreeNavigationData_unstable
|
|
109
|
+
navigate(data: TreeNavigationData_unstable): void;
|
|
111
110
|
/**
|
|
112
111
|
* returns next item to be focused on a navigation.
|
|
113
112
|
* This method is provided to decouple the element that needs to be focused from
|
|
@@ -115,7 +114,11 @@ export declare type FlatTree<Props extends FlatTreeItemProps<unknown> = FlatTree
|
|
|
115
114
|
*
|
|
116
115
|
* On the case of TypeAhead navigation this method returns the current item.
|
|
117
116
|
*/
|
|
118
|
-
getNextNavigableItem(visibleItems: FlatTreeItem<Props>[], data: TreeNavigationData_unstable
|
|
117
|
+
getNextNavigableItem(visibleItems: FlatTreeItem<Props>[], data: TreeNavigationData_unstable): FlatTreeItem<Props> | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* similar to getElementById but for FlatTreeItems
|
|
120
|
+
*/
|
|
121
|
+
getElementFromItem(item: FlatTreeItem<Props>): HTMLElement | null;
|
|
119
122
|
/**
|
|
120
123
|
* an iterable containing all visually available flat tree items
|
|
121
124
|
*/
|
|
@@ -126,31 +129,25 @@ export declare type FlatTree<Props extends FlatTreeItemProps<unknown> = FlatTree
|
|
|
126
129
|
* The item that is returned by `useFlatTree`, it represents a wrapper around the properties provided to
|
|
127
130
|
* `useFlatTree` but with extra information that might be useful on flat tree scenarios
|
|
128
131
|
*/
|
|
129
|
-
export declare type FlatTreeItem<Props extends FlatTreeItemProps
|
|
132
|
+
export declare type FlatTreeItem<Props extends FlatTreeItemProps = FlatTreeItemProps> = {
|
|
130
133
|
index: number;
|
|
131
134
|
level: number;
|
|
132
135
|
childrenSize: number;
|
|
133
|
-
value:
|
|
134
|
-
parentValue:
|
|
135
|
-
|
|
136
|
-
* A reference to the element that will render the `TreeItem`,
|
|
137
|
-
* this is necessary for nodes with parents (to ensure child to parent navigation),
|
|
138
|
-
* if a node has no parent then this reference will be null.
|
|
139
|
-
*/
|
|
140
|
-
ref: React_2.RefObject<HTMLDivElement>;
|
|
141
|
-
getTreeItemProps(): Required<Pick<Props, 'value' | 'aria-setsize' | 'aria-level' | 'aria-posinset' | 'itemType'>> & Omit<Props, 'parentValue'>;
|
|
136
|
+
value: TreeItemValue;
|
|
137
|
+
parentValue: TreeItemValue | undefined;
|
|
138
|
+
getTreeItemProps(): Required<Pick<Props, 'value' | 'aria-setsize' | 'aria-level' | 'aria-posinset' | 'itemType'>> & Omit<Props, 'parentId'>;
|
|
142
139
|
};
|
|
143
140
|
|
|
144
|
-
export declare type FlatTreeItemProps
|
|
145
|
-
value:
|
|
146
|
-
parentValue?:
|
|
141
|
+
export declare type FlatTreeItemProps = Omit<TreeItemProps, 'itemType'> & Partial<Pick<TreeItemProps, 'itemType'>> & {
|
|
142
|
+
value: TreeItemValue;
|
|
143
|
+
parentValue?: TreeItemValue;
|
|
147
144
|
};
|
|
148
145
|
|
|
149
|
-
declare type FlatTreeOptions
|
|
146
|
+
declare type FlatTreeOptions = Pick<TreeProps, 'openItems' | 'defaultOpenItems' | 'onOpenChange' | 'onNavigation_unstable'>;
|
|
150
147
|
|
|
151
|
-
export declare type FlatTreeProps
|
|
148
|
+
export declare type FlatTreeProps = Required<Pick<TreeProps, 'openItems' | 'onOpenChange' | 'onNavigation_unstable'>> & {
|
|
152
149
|
ref: React_2.Ref<HTMLDivElement>;
|
|
153
|
-
openItems: ImmutableSet<
|
|
150
|
+
openItems: ImmutableSet<string>;
|
|
154
151
|
};
|
|
155
152
|
|
|
156
153
|
declare interface ImmutableSet<Value> {
|
|
@@ -179,7 +176,7 @@ declare interface ImmutableSet<Value> {
|
|
|
179
176
|
[Symbol.iterator](): IterableIterator<Value>;
|
|
180
177
|
}
|
|
181
178
|
|
|
182
|
-
export declare type NestedTreeItem<Props extends TreeItemProps
|
|
179
|
+
export declare type NestedTreeItem<Props extends TreeItemProps> = Omit<Props, 'subtree' | 'itemType'> & {
|
|
183
180
|
subtree?: NestedTreeItem<Props>[];
|
|
184
181
|
};
|
|
185
182
|
|
|
@@ -192,11 +189,6 @@ export declare const renderTree_unstable: (state: TreeState, contextValues: Tree
|
|
|
192
189
|
*/
|
|
193
190
|
export declare const renderTreeItem_unstable: (state: TreeItemState, contextValues: TreeItemContextValues) => JSX.Element;
|
|
194
191
|
|
|
195
|
-
/**
|
|
196
|
-
* Render the final JSX of TreeItemAside
|
|
197
|
-
*/
|
|
198
|
-
export declare const renderTreeItemAside_unstable: (state: TreeItemAsideState) => JSX.Element | null;
|
|
199
|
-
|
|
200
192
|
/**
|
|
201
193
|
* Render the final JSX of TreeItemLayout
|
|
202
194
|
*/
|
|
@@ -215,22 +207,7 @@ export declare const renderTreeItemPersonaLayout_unstable: (state: TreeItemPerso
|
|
|
215
207
|
* an item representing a folder can be expanded to reveal the contents of the folder,
|
|
216
208
|
* which may be files, folders, or both.
|
|
217
209
|
*/
|
|
218
|
-
export declare const Tree:
|
|
219
|
-
as?: "div" | undefined;
|
|
220
|
-
} & Pick<React_2.DetailedHTMLProps<React_2.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React_2.HTMLAttributes<HTMLDivElement>> & {
|
|
221
|
-
ref?: ((instance: HTMLDivElement | null) => void) | React_2.RefObject<HTMLDivElement> | null | undefined;
|
|
222
|
-
} & {
|
|
223
|
-
children?: React_2.ReactNode | SlotRenderFunction<Pick<React_2.DetailedHTMLProps<React_2.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React_2.HTMLAttributes<HTMLDivElement>> & {
|
|
224
|
-
ref?: ((instance: HTMLDivElement | null) => void) | React_2.RefObject<HTMLDivElement> | null | undefined;
|
|
225
|
-
}>;
|
|
226
|
-
}, "ref"> & {
|
|
227
|
-
appearance?: "transparent" | "subtle" | "subtle-alpha" | undefined;
|
|
228
|
-
size?: "small" | "medium" | undefined;
|
|
229
|
-
openItems?: Iterable<string> | undefined;
|
|
230
|
-
defaultOpenItems?: Iterable<string> | undefined;
|
|
231
|
-
onOpenChange?(event: React_2.KeyboardEvent<HTMLElement> | React_2.MouseEvent<HTMLElement, MouseEvent>, data: TreeOpenChangeData<string>): void;
|
|
232
|
-
onNavigation_unstable?(event: React_2.KeyboardEvent<HTMLElement> | React_2.MouseEvent<HTMLElement, MouseEvent>, data: TreeNavigationData_unstable<string>): void;
|
|
233
|
-
} & React_2.RefAttributes<HTMLDivElement>> & (<Value = string>(props: TreeProps<Value>) => JSX.Element);
|
|
210
|
+
export declare const Tree: ForwardRefComponent<TreeProps>;
|
|
234
211
|
|
|
235
212
|
export declare const treeClassNames: SlotClassNames<TreeSlots>;
|
|
236
213
|
|
|
@@ -242,7 +219,7 @@ export declare type TreeContextValue = {
|
|
|
242
219
|
/**
|
|
243
220
|
* requests root Tree component to respond to some tree item event,
|
|
244
221
|
*/
|
|
245
|
-
requestTreeResponse(request: TreeItemRequest
|
|
222
|
+
requestTreeResponse(request: TreeItemRequest): void;
|
|
246
223
|
};
|
|
247
224
|
|
|
248
225
|
declare type TreeContextValues = {
|
|
@@ -261,58 +238,7 @@ declare type TreeContextValues = {
|
|
|
261
238
|
* When a TreeItem has nested child subtree, an expand/collapse control is displayed,
|
|
262
239
|
* allowing the user to show or hide the children.
|
|
263
240
|
*/
|
|
264
|
-
export declare const TreeItem:
|
|
265
|
-
as?: "div" | undefined;
|
|
266
|
-
} & Pick<React_2.DetailedHTMLProps<React_2.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React_2.HTMLAttributes<HTMLDivElement>> & {
|
|
267
|
-
ref?: ((instance: HTMLDivElement | null) => void) | React_2.RefObject<HTMLDivElement> | null | undefined;
|
|
268
|
-
} & {
|
|
269
|
-
children?: React_2.ReactNode | SlotRenderFunction<Pick<React_2.DetailedHTMLProps<React_2.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React_2.HTMLAttributes<HTMLDivElement>> & {
|
|
270
|
-
ref?: ((instance: HTMLDivElement | null) => void) | React_2.RefObject<HTMLDivElement> | null | undefined;
|
|
271
|
-
}>;
|
|
272
|
-
} & {
|
|
273
|
-
style?: TreeItemCSSProperties | undefined;
|
|
274
|
-
}, "ref"> & {
|
|
275
|
-
value?: string | undefined;
|
|
276
|
-
itemType: TreeItemType;
|
|
277
|
-
} & React_2.RefAttributes<HTMLDivElement>> & (<Value = string>(props: TreeItemProps<Value>) => JSX.Element);
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* TreeItemAside component - represents a custom set of actionable elements that will be visible when a certain
|
|
281
|
-
* `TreeItem` is currently "active".
|
|
282
|
-
*/
|
|
283
|
-
export declare const TreeItemAside: ForwardRefComponent<TreeItemAsideProps>;
|
|
284
|
-
|
|
285
|
-
export declare const treeItemAsideClassNames: SlotClassNames<TreeItemAsideSlots>;
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* TreeItemAside Props
|
|
289
|
-
*/
|
|
290
|
-
export declare type TreeItemAsideProps = ComponentProps<TreeItemAsideSlots> & {
|
|
291
|
-
/**
|
|
292
|
-
* boolean indicating if the aside content should behave as "actions"
|
|
293
|
-
*
|
|
294
|
-
* actionable elements are normally buttons, menus, or other focusable elements.
|
|
295
|
-
* Those elements are only visibly available if the given tree item is currently active.
|
|
296
|
-
*/
|
|
297
|
-
actions?: boolean;
|
|
298
|
-
/**
|
|
299
|
-
* Forces visibility of the aside content, even if they're actions
|
|
300
|
-
*/
|
|
301
|
-
visible?: true;
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
export declare type TreeItemAsideSlots = {
|
|
305
|
-
root: Slot<'div'>;
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* State used in rendering TreeItemAside
|
|
310
|
-
*/
|
|
311
|
-
export declare type TreeItemAsideState = ComponentState<TreeItemAsideSlots> & {
|
|
312
|
-
actions: boolean;
|
|
313
|
-
visible: boolean;
|
|
314
|
-
buttonContextValue: ButtonContextValue;
|
|
315
|
-
};
|
|
241
|
+
export declare const TreeItem: ForwardRefComponent<TreeItemProps>;
|
|
316
242
|
|
|
317
243
|
export declare const treeItemClassNames: SlotClassNames<TreeItemSlots>;
|
|
318
244
|
|
|
@@ -323,8 +249,8 @@ declare type TreeItemContextValue = {
|
|
|
323
249
|
expandIconRef: React_2.Ref<HTMLDivElement>;
|
|
324
250
|
layoutRef: React_2.Ref<HTMLDivElement>;
|
|
325
251
|
subtreeRef: React_2.Ref<HTMLDivElement>;
|
|
326
|
-
value: unknown;
|
|
327
252
|
itemType: TreeItemType;
|
|
253
|
+
value: string;
|
|
328
254
|
open: boolean;
|
|
329
255
|
};
|
|
330
256
|
|
|
@@ -353,10 +279,9 @@ export declare type TreeItemLayoutProps = ComponentProps<Partial<TreeItemLayoutS
|
|
|
353
279
|
export declare type TreeItemLayoutSlots = {
|
|
354
280
|
root: Slot<'div'>;
|
|
355
281
|
/**
|
|
356
|
-
*
|
|
357
|
-
* by default renders a chevron icon to indicate opening and closing
|
|
282
|
+
* Content. Children of the root slot are automatically rendered here
|
|
358
283
|
*/
|
|
359
|
-
|
|
284
|
+
content: NonNullable<Slot<'div'>>;
|
|
360
285
|
/**
|
|
361
286
|
* Icon slot that renders right before main content
|
|
362
287
|
*/
|
|
@@ -365,12 +290,30 @@ export declare type TreeItemLayoutSlots = {
|
|
|
365
290
|
* Icon slot that renders right after main content
|
|
366
291
|
*/
|
|
367
292
|
iconAfter?: Slot<'div'>;
|
|
293
|
+
/**
|
|
294
|
+
* Expand icon slot,
|
|
295
|
+
* by default renders a chevron icon to indicate opening and closing
|
|
296
|
+
*/
|
|
297
|
+
expandIcon?: Slot<'div'>;
|
|
298
|
+
aside?: Slot<'div'>;
|
|
299
|
+
/**
|
|
300
|
+
* actionable elements are normally buttons, menus, or other focusable elements.
|
|
301
|
+
* Those elements are only visibly available if the given tree item is currently active.
|
|
302
|
+
*/
|
|
303
|
+
actions?: Slot<ExtractSlotProps<Slot<'div'> & {
|
|
304
|
+
/**
|
|
305
|
+
* Forces visibility of the aside/action content
|
|
306
|
+
*/
|
|
307
|
+
visible?: boolean;
|
|
308
|
+
}>>;
|
|
368
309
|
};
|
|
369
310
|
|
|
370
311
|
/**
|
|
371
312
|
* State used in rendering TreeItemLayout
|
|
372
313
|
*/
|
|
373
|
-
export declare type TreeItemLayoutState = ComponentState<TreeItemLayoutSlots
|
|
314
|
+
export declare type TreeItemLayoutState = ComponentState<TreeItemLayoutSlots> & {
|
|
315
|
+
buttonContextValue: ButtonContextValue;
|
|
316
|
+
};
|
|
374
317
|
|
|
375
318
|
export declare const treeItemLevelToken: "--fluent-TreeItem--level";
|
|
376
319
|
|
|
@@ -392,29 +335,20 @@ declare type TreeItemPersonaLayoutContextValues = {
|
|
|
392
335
|
*/
|
|
393
336
|
export declare type TreeItemPersonaLayoutProps = ComponentProps<Partial<TreeItemPersonaLayoutSlots>>;
|
|
394
337
|
|
|
395
|
-
export declare type TreeItemPersonaLayoutSlots = {
|
|
338
|
+
export declare type TreeItemPersonaLayoutSlots = Pick<TreeItemLayoutSlots, 'actions' | 'aside' | 'expandIcon'> & {
|
|
396
339
|
root: NonNullable<Slot<'div'>>;
|
|
397
|
-
/**
|
|
398
|
-
* Expand icon slot,
|
|
399
|
-
* by default renders a chevron icon to indicate opening and closing
|
|
400
|
-
*/
|
|
401
|
-
expandIcon?: Slot<'div'>;
|
|
402
340
|
/**
|
|
403
341
|
* Avatar to display.
|
|
404
342
|
*/
|
|
405
343
|
media: NonNullable<Slot<'div'>>;
|
|
406
344
|
/**
|
|
407
|
-
*
|
|
345
|
+
* Content. Children of the root slot are automatically rendered here
|
|
408
346
|
*/
|
|
409
|
-
|
|
347
|
+
content: NonNullable<Slot<'div'>>;
|
|
410
348
|
/**
|
|
411
|
-
* Secondary text that describes or complements the
|
|
349
|
+
* Secondary text that describes or complements the content
|
|
412
350
|
*/
|
|
413
351
|
description?: Slot<'div'>;
|
|
414
|
-
/**
|
|
415
|
-
* A layout wrapper for the main and description slots
|
|
416
|
-
*/
|
|
417
|
-
content: NonNullable<Slot<'div'>>;
|
|
418
352
|
};
|
|
419
353
|
|
|
420
354
|
/**
|
|
@@ -422,21 +356,22 @@ export declare type TreeItemPersonaLayoutSlots = {
|
|
|
422
356
|
*/
|
|
423
357
|
export declare type TreeItemPersonaLayoutState = ComponentState<TreeItemPersonaLayoutSlots> & {
|
|
424
358
|
avatarSize: AvatarSize;
|
|
359
|
+
buttonContextValue: ButtonContextValue;
|
|
425
360
|
};
|
|
426
361
|
|
|
427
362
|
/**
|
|
428
363
|
* TreeItem Props
|
|
429
364
|
*/
|
|
430
|
-
export declare type TreeItemProps
|
|
431
|
-
value?: Value;
|
|
365
|
+
export declare type TreeItemProps = ComponentProps<Partial<TreeItemSlots>> & {
|
|
432
366
|
itemType: TreeItemType;
|
|
367
|
+
value?: TreeItemValue;
|
|
433
368
|
};
|
|
434
369
|
|
|
435
370
|
export declare const TreeItemProvider: React_2.Provider<TreeItemContextValue | undefined> & React_2.FC<React_2.ProviderProps<TreeItemContextValue | undefined>>;
|
|
436
371
|
|
|
437
|
-
declare type TreeItemRequest
|
|
372
|
+
declare type TreeItemRequest = {
|
|
438
373
|
itemType: TreeItemType;
|
|
439
|
-
} & (OmitWithoutExpanding<TreeOpenChangeData
|
|
374
|
+
} & (OmitWithoutExpanding<TreeOpenChangeData, 'open' | 'target'> | OmitWithoutExpanding<TreeNavigationData_unstable, 'target'>);
|
|
440
375
|
|
|
441
376
|
export declare type TreeItemSlots = {
|
|
442
377
|
root: Slot<ExtractSlotProps<Slot<'div'> & {
|
|
@@ -454,9 +389,11 @@ export declare type TreeItemState = ComponentState<TreeItemSlots> & TreeItemCont
|
|
|
454
389
|
|
|
455
390
|
declare type TreeItemType = 'leaf' | 'branch';
|
|
456
391
|
|
|
457
|
-
|
|
458
|
-
|
|
392
|
+
declare type TreeItemValue = string | number;
|
|
393
|
+
|
|
394
|
+
export declare type TreeNavigationData_unstable = {
|
|
459
395
|
target: HTMLElement;
|
|
396
|
+
value: string;
|
|
460
397
|
} & ({
|
|
461
398
|
event: React_2.MouseEvent<HTMLElement>;
|
|
462
399
|
type: 'Click';
|
|
@@ -485,9 +422,9 @@ export declare type TreeNavigationData_unstable<Value = string> = {
|
|
|
485
422
|
|
|
486
423
|
export declare type TreeNavigationEvent_unstable = TreeNavigationData_unstable['event'];
|
|
487
424
|
|
|
488
|
-
export declare type TreeOpenChangeData
|
|
425
|
+
export declare type TreeOpenChangeData = {
|
|
489
426
|
open: boolean;
|
|
490
|
-
value:
|
|
427
|
+
value: string;
|
|
491
428
|
} & ({
|
|
492
429
|
event: React_2.MouseEvent<HTMLElement>;
|
|
493
430
|
target: HTMLElement;
|
|
@@ -512,7 +449,7 @@ export declare type TreeOpenChangeData<Value = string> = {
|
|
|
512
449
|
|
|
513
450
|
export declare type TreeOpenChangeEvent = TreeOpenChangeData['event'];
|
|
514
451
|
|
|
515
|
-
export declare type TreeProps
|
|
452
|
+
export declare type TreeProps = ComponentProps<TreeSlots> & {
|
|
516
453
|
/**
|
|
517
454
|
* A tree item can have various appearances:
|
|
518
455
|
* - 'subtle' (default): The default tree item styles.
|
|
@@ -531,13 +468,13 @@ export declare type TreeProps<Value = string> = ComponentProps<TreeSlots> & {
|
|
|
531
468
|
* Controls the state of the open tree items.
|
|
532
469
|
* These property is ignored for subtrees.
|
|
533
470
|
*/
|
|
534
|
-
openItems?: Iterable<
|
|
471
|
+
openItems?: Iterable<string>;
|
|
535
472
|
/**
|
|
536
473
|
* This refers to a list of ids of opened tree items.
|
|
537
474
|
* Default value for the uncontrolled state of open tree items.
|
|
538
475
|
* These property is ignored for subtrees.
|
|
539
476
|
*/
|
|
540
|
-
defaultOpenItems?: Iterable<
|
|
477
|
+
defaultOpenItems?: Iterable<string>;
|
|
541
478
|
/**
|
|
542
479
|
* Callback fired when the component changes value from open state.
|
|
543
480
|
* These property is ignored for subtrees.
|
|
@@ -546,7 +483,7 @@ export declare type TreeProps<Value = string> = ComponentProps<TreeSlots> & {
|
|
|
546
483
|
* @param data - A data object with relevant information,
|
|
547
484
|
* such as open value and type of interaction that created the event.
|
|
548
485
|
*/
|
|
549
|
-
onOpenChange?(event: TreeOpenChangeEvent, data: TreeOpenChangeData
|
|
486
|
+
onOpenChange?(event: TreeOpenChangeEvent, data: TreeOpenChangeData): void;
|
|
550
487
|
/**
|
|
551
488
|
* Callback fired when navigation happens inside the component.
|
|
552
489
|
* These property is ignored for subtrees.
|
|
@@ -556,7 +493,7 @@ export declare type TreeProps<Value = string> = ComponentProps<TreeSlots> & {
|
|
|
556
493
|
* @param event - a React's Synthetic event
|
|
557
494
|
* @param data - A data object with relevant information,
|
|
558
495
|
*/
|
|
559
|
-
onNavigation_unstable?(event: TreeNavigationEvent_unstable, data: TreeNavigationData_unstable
|
|
496
|
+
onNavigation_unstable?(event: TreeNavigationEvent_unstable, data: TreeNavigationData_unstable): void;
|
|
560
497
|
};
|
|
561
498
|
|
|
562
499
|
export declare const TreeProvider: Provider<TreeContextValue | undefined> & FC<ProviderProps<TreeContextValue | undefined>>;
|
|
@@ -584,7 +521,7 @@ export declare type TreeState = ComponentState<TreeSlots> & TreeContextValue & {
|
|
|
584
521
|
* @param flatTreeItemProps - a list of tree items
|
|
585
522
|
* @param options - in case control over the internal openItems is required
|
|
586
523
|
*/
|
|
587
|
-
export declare function useFlatTree_unstable<Props extends FlatTreeItemProps
|
|
524
|
+
export declare function useFlatTree_unstable<Props extends FlatTreeItemProps = FlatTreeItemProps>(flatTreeItemProps: Props[], options?: FlatTreeOptions): FlatTree<Props>;
|
|
588
525
|
|
|
589
526
|
/**
|
|
590
527
|
* Create the state required to render Tree.
|
|
@@ -610,26 +547,12 @@ export declare function useTreeContextValues_unstable(state: TreeState): TreeCon
|
|
|
610
547
|
* @param props - props from this instance of TreeItem
|
|
611
548
|
* @param ref - reference to root HTMLElement of TreeItem
|
|
612
549
|
*/
|
|
613
|
-
export declare function useTreeItem_unstable
|
|
614
|
-
|
|
615
|
-
/**
|
|
616
|
-
* Create the state required to render TreeItemAside.
|
|
617
|
-
*
|
|
618
|
-
* The returned state can be modified with hooks such as useTreeItemAsideStyles_unstable,
|
|
619
|
-
* before being passed to renderTreeItemAside_unstable.
|
|
620
|
-
*
|
|
621
|
-
* @param props - props from this instance of TreeItemAside
|
|
622
|
-
* @param ref - reference to root HTMLElement of TreeItemAside
|
|
623
|
-
*/
|
|
624
|
-
export declare const useTreeItemAside_unstable: (props: TreeItemAsideProps, ref: React_2.Ref<HTMLElement>) => TreeItemAsideState;
|
|
625
|
-
|
|
626
|
-
/**
|
|
627
|
-
* Apply styling to the TreeItemAside slots based on the state
|
|
628
|
-
*/
|
|
629
|
-
export declare const useTreeItemAsideStyles_unstable: (state: TreeItemAsideState) => TreeItemAsideState;
|
|
550
|
+
export declare function useTreeItem_unstable(props: TreeItemProps, ref: React_2.Ref<HTMLDivElement>): TreeItemState;
|
|
630
551
|
|
|
631
552
|
export declare const useTreeItemContext_unstable: <T>(selector: ContextSelector<TreeItemContextValue, T>) => T;
|
|
632
553
|
|
|
554
|
+
export declare function useTreeItemContextValues_unstable(state: Pick<TreeItemState, keyof TreeItemContextValue>): TreeItemContextValues;
|
|
555
|
+
|
|
633
556
|
/**
|
|
634
557
|
* Create the state required to render TreeItemLayout.
|
|
635
558
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Tree.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useTree_unstable } from './useTree';\nimport { renderTree_unstable } from './renderTree';\nimport { useTreeStyles_unstable } from './useTreeStyles.styles';\nimport type { TreeProps } from './Tree.types';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\nimport { useTreeContextValues_unstable } from './useTreeContextValues';\n\n/**\n * A tree view widget presents a hierarchical list.\n * Any item in the hierarchy may have child items,\n * and items that have children may be expanded or collapsed to show or hide the children.\n * For example, in a file system navigator that uses a tree view to display folders and files,\n * an item representing a folder can be expanded to reveal the contents of the folder,\n * which may be files, folders, or both.\n */\nexport const Tree = React.forwardRef((props, ref) => {\n const state = useTree_unstable(props, ref);\n useTreeStyles_unstable(state);\n const contextValues = useTreeContextValues_unstable(state);\n return renderTree_unstable(state, contextValues);\n})
|
|
1
|
+
{"version":3,"sources":["Tree.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useTree_unstable } from './useTree';\nimport { renderTree_unstable } from './renderTree';\nimport { useTreeStyles_unstable } from './useTreeStyles.styles';\nimport type { TreeProps } from './Tree.types';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\nimport { useTreeContextValues_unstable } from './useTreeContextValues';\n\n/**\n * A tree view widget presents a hierarchical list.\n * Any item in the hierarchy may have child items,\n * and items that have children may be expanded or collapsed to show or hide the children.\n * For example, in a file system navigator that uses a tree view to display folders and files,\n * an item representing a folder can be expanded to reveal the contents of the folder,\n * which may be files, folders, or both.\n */\nexport const Tree: ForwardRefComponent<TreeProps> = React.forwardRef((props, ref) => {\n const state = useTree_unstable(props, ref);\n useTreeStyles_unstable(state);\n const contextValues = useTreeContextValues_unstable(state);\n return renderTree_unstable(state, contextValues);\n});\n\nTree.displayName = 'Tree';\n"],"names":["React","useTree_unstable","renderTree_unstable","useTreeStyles_unstable","useTreeContextValues_unstable","Tree","forwardRef","props","ref","state","contextValues","displayName"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,gBAAgB,QAAQ,YAAY;AAC7C,SAASC,mBAAmB,QAAQ,eAAe;AACnD,SAASC,sBAAsB,QAAQ,yBAAyB;AAGhE,SAASC,6BAA6B,QAAQ,yBAAyB;AAEvE;;;;;;;CAOC,GACD,OAAO,MAAMC,qBAAuCL,MAAMM,UAAU,CAAC,CAACC,OAAOC,MAAQ;IACnF,MAAMC,QAAQR,iBAAiBM,OAAOC;IACtCL,uBAAuBM;IACvB,MAAMC,gBAAgBN,8BAA8BK;IACpD,OAAOP,oBAAoBO,OAAOC;AACpC,GAAG;AAEHL,KAAKM,WAAW,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Tree.types.ts"],"sourcesContent":["import * as React from 'react';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport { TreeContextValue } from '../../contexts/treeContext';\nimport { ArrowDown, ArrowLeft, ArrowRight, ArrowUp, End, Enter, Home } from '@fluentui/keyboard-keys';\n\nexport type TreeSlots = {\n root: Slot<'div'>;\n};\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type TreeNavigationData_unstable
|
|
1
|
+
{"version":3,"sources":["Tree.types.ts"],"sourcesContent":["import * as React from 'react';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport { TreeContextValue } from '../../contexts/treeContext';\nimport { ArrowDown, ArrowLeft, ArrowRight, ArrowUp, End, Enter, Home } from '@fluentui/keyboard-keys';\n\nexport type TreeSlots = {\n root: Slot<'div'>;\n};\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type TreeNavigationData_unstable = { target: HTMLElement; value: string } & (\n | { event: React.MouseEvent<HTMLElement>; type: 'Click' }\n | { event: React.KeyboardEvent<HTMLElement>; type: 'TypeAhead' }\n | { event: React.KeyboardEvent<HTMLElement>; type: typeof ArrowRight }\n | { event: React.KeyboardEvent<HTMLElement>; type: typeof ArrowLeft }\n | { event: React.KeyboardEvent<HTMLElement>; type: typeof ArrowUp }\n | { event: React.KeyboardEvent<HTMLElement>; type: typeof ArrowDown }\n | { event: React.KeyboardEvent<HTMLElement>; type: typeof Home }\n | { event: React.KeyboardEvent<HTMLElement>; type: typeof End }\n);\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type TreeNavigationEvent_unstable = TreeNavigationData_unstable['event'];\n\nexport type TreeOpenChangeData = { open: boolean; value: string } & (\n | {\n event: React.MouseEvent<HTMLElement>;\n target: HTMLElement;\n type: 'ExpandIconClick';\n }\n | {\n event: React.MouseEvent<HTMLElement>;\n target: HTMLElement;\n type: 'Click';\n }\n | {\n event: React.KeyboardEvent<HTMLElement>;\n target: HTMLElement;\n type: typeof Enter;\n }\n | {\n event: React.KeyboardEvent<HTMLElement>;\n target: HTMLElement;\n type: typeof ArrowRight;\n }\n | {\n event: React.KeyboardEvent<HTMLElement>;\n target: HTMLElement;\n type: typeof ArrowLeft;\n }\n);\n\nexport type TreeOpenChangeEvent = TreeOpenChangeData['event'];\n\nexport type TreeContextValues = {\n tree: TreeContextValue;\n};\n\nexport type TreeProps = ComponentProps<TreeSlots> & {\n /**\n * A tree item can have various appearances:\n * - 'subtle' (default): The default tree item styles.\n * - 'subtle-alpha': Minimizes emphasis on hovered or focused states.\n * - 'transparent': Removes background color.\n * @default 'subtle'\n */\n appearance?: 'subtle' | 'subtle-alpha' | 'transparent';\n /**\n * Size of the tree item.\n * @default 'medium'\n */\n size?: 'small' | 'medium';\n /**\n * This refers to a list of ids of opened tree items.\n * Controls the state of the open tree items.\n * These property is ignored for subtrees.\n */\n openItems?: Iterable<string>;\n /**\n * This refers to a list of ids of opened tree items.\n * Default value for the uncontrolled state of open tree items.\n * These property is ignored for subtrees.\n */\n defaultOpenItems?: Iterable<string>;\n /**\n * Callback fired when the component changes value from open state.\n * These property is ignored for subtrees.\n *\n * @param event - a React's Synthetic event\n * @param data - A data object with relevant information,\n * such as open value and type of interaction that created the event.\n */\n onOpenChange?(event: TreeOpenChangeEvent, data: TreeOpenChangeData): void;\n\n /**\n * Callback fired when navigation happens inside the component.\n * These property is ignored for subtrees.\n *\n * FIXME: This method is not ideal, as navigation should be handled internally by tabster.\n *\n * @param event - a React's Synthetic event\n * @param data - A data object with relevant information,\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n onNavigation_unstable?(event: TreeNavigationEvent_unstable, data: TreeNavigationData_unstable): void;\n};\n\n/**\n * State used in rendering Tree\n */\nexport type TreeState = ComponentState<TreeSlots> &\n TreeContextValue & {\n open: boolean;\n };\n"],"names":["React"],"mappings":"AAAA,YAAYA,WAAW,QAAQ"}
|
|
@@ -49,7 +49,7 @@ import { treeDataTypes } from '../../utils/tokens';
|
|
|
49
49
|
});
|
|
50
50
|
});
|
|
51
51
|
};
|
|
52
|
-
const handleTreeItemKeyDown = ({ event ,
|
|
52
|
+
const handleTreeItemKeyDown = ({ event , type , value , itemType })=>{
|
|
53
53
|
const open = openItems.has(value);
|
|
54
54
|
switch(type){
|
|
55
55
|
case treeDataTypes.ArrowRight:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useRootTree.ts"],"sourcesContent":["import * as React from 'react';\nimport * as ReactDOM from 'react-dom';\nimport { getNativeElementProps, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport { TreeOpenChangeData, TreeProps, TreeState, TreeNavigationData_unstable } from './Tree.types';\nimport { useNestedTreeNavigation, useOpenItemsState } from '../../hooks';\nimport { treeDataTypes } from '../../utils/tokens';\nimport { TreeItemRequest } from '../../contexts/index';\n\n/**\n * Create the state required to render the root level Tree.\n *\n * @param props - props from this instance of Tree\n * @param ref - reference to root HTMLElement of Tree\n */\nexport function useRootTree
|
|
1
|
+
{"version":3,"sources":["useRootTree.ts"],"sourcesContent":["import * as React from 'react';\nimport * as ReactDOM from 'react-dom';\nimport { getNativeElementProps, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport { TreeOpenChangeData, TreeProps, TreeState, TreeNavigationData_unstable } from './Tree.types';\nimport { useNestedTreeNavigation, useOpenItemsState } from '../../hooks';\nimport { treeDataTypes } from '../../utils/tokens';\nimport { TreeItemRequest } from '../../contexts/index';\n\n/**\n * Create the state required to render the root level Tree.\n *\n * @param props - props from this instance of Tree\n * @param ref - reference to root HTMLElement of Tree\n */\nexport function useRootTree(props: TreeProps, ref: React.Ref<HTMLElement>): TreeState {\n warnIfNoProperPropsRootTree(props);\n\n const { appearance = 'subtle', size = 'medium' } = props;\n\n const [openItems, updateOpenItems] = useOpenItemsState(props);\n const [navigate, navigationRef] = useNestedTreeNavigation();\n\n const requestOpenChange = (data: TreeOpenChangeData) => {\n props.onOpenChange?.(data.event, data);\n if (data.event.isDefaultPrevented()) {\n return;\n }\n return updateOpenItems(data);\n };\n\n const requestNavigation = (data: TreeNavigationData_unstable) => {\n props.onNavigation_unstable?.(data.event, data);\n if (data.event.isDefaultPrevented()) {\n return;\n }\n navigate(data);\n if (data.type === treeDataTypes.ArrowDown || data.type === treeDataTypes.ArrowUp) {\n data.event.preventDefault();\n }\n };\n\n const handleTreeItemClick = ({\n event,\n value,\n itemType,\n type,\n }: Extract<TreeItemRequest, { type: 'Click' | 'ExpandIconClick' }>) => {\n ReactDOM.unstable_batchedUpdates(() => {\n requestOpenChange({\n event,\n value,\n open: itemType === 'branch' && !openItems.has(value),\n type,\n target: event.currentTarget,\n });\n requestNavigation({ event, value, target: event.currentTarget, type: treeDataTypes.Click });\n });\n };\n\n const handleTreeItemKeyDown = ({\n event,\n type,\n value,\n itemType,\n }: Exclude<TreeItemRequest, { type: 'Click' | 'ExpandIconClick' }>) => {\n const open = openItems.has(value);\n switch (type) {\n case treeDataTypes.ArrowRight:\n if (itemType === 'leaf') {\n return;\n }\n if (!open) {\n return requestOpenChange({\n event,\n value,\n open: true,\n type: treeDataTypes.ArrowRight,\n target: event.currentTarget,\n });\n }\n return requestNavigation({ event, value, type, target: event.currentTarget });\n case treeDataTypes.Enter:\n return requestOpenChange({\n event,\n value,\n open: itemType === 'branch' && !open,\n type: treeDataTypes.Enter,\n target: event.currentTarget,\n });\n case treeDataTypes.ArrowLeft:\n if (open && itemType === 'branch') {\n return requestOpenChange({\n event,\n value,\n open: false,\n type: treeDataTypes.ArrowLeft,\n target: event.currentTarget,\n });\n }\n return requestNavigation({ event, value, target: event.currentTarget, type: treeDataTypes.ArrowLeft });\n case treeDataTypes.End:\n case treeDataTypes.Home:\n case treeDataTypes.ArrowUp:\n case treeDataTypes.ArrowDown:\n case treeDataTypes.TypeAhead:\n return requestNavigation({ event, value, type, target: event.currentTarget });\n }\n };\n\n const requestTreeResponse = useEventCallback((request: TreeItemRequest) => {\n switch (request.event.type) {\n case 'click':\n // casting is required here as we're narrowing down the event to only click events\n return handleTreeItemClick(request as Extract<TreeItemRequest, { type: 'Click' | 'ExpandIconClick' }>);\n case 'keydown':\n // casting is required here as we're narrowing down the event to only keyboard events\n return handleTreeItemKeyDown(request as Exclude<TreeItemRequest, { type: 'Click' | 'ExpandIconClick' }>);\n }\n });\n\n return {\n components: {\n root: 'div',\n },\n open: true,\n appearance,\n size,\n level: 1,\n openItems,\n requestTreeResponse,\n root: getNativeElementProps('div', {\n ref: useMergedRefs(navigationRef, ref),\n role: 'tree',\n ...props,\n }),\n };\n}\n\nfunction warnIfNoProperPropsRootTree(props: Pick<TreeProps, 'aria-label' | 'aria-labelledby'>) {\n if (process.env.NODE_ENV === 'development') {\n if (!props['aria-label'] && !props['aria-labelledby']) {\n // eslint-disable-next-line no-console\n console.warn('Tree must have either a `aria-label` or `aria-labelledby` property defined');\n }\n }\n}\n"],"names":["React","ReactDOM","getNativeElementProps","useEventCallback","useMergedRefs","useNestedTreeNavigation","useOpenItemsState","treeDataTypes","useRootTree","props","ref","warnIfNoProperPropsRootTree","appearance","size","openItems","updateOpenItems","navigate","navigationRef","requestOpenChange","data","onOpenChange","event","isDefaultPrevented","requestNavigation","onNavigation_unstable","type","ArrowDown","ArrowUp","preventDefault","handleTreeItemClick","value","itemType","unstable_batchedUpdates","open","has","target","currentTarget","Click","handleTreeItemKeyDown","ArrowRight","Enter","ArrowLeft","End","Home","TypeAhead","requestTreeResponse","request","components","root","level","role","process","env","NODE_ENV","console","warn"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["TreeItem.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useTreeItem_unstable } from './useTreeItem';\nimport { renderTreeItem_unstable } from './renderTreeItem';\nimport { useTreeItemStyles_unstable } from './useTreeItemStyles.styles';\nimport type { TreeItemProps } from './TreeItem.types';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\nimport { useTreeItemContextValues_unstable } from './useTreeItemContextValues';\n\n/**\n * The `TreeItem` component represents a single item in a tree.\n * It expects a certain order of children to work properly: the first child should be the node itself,\n * and the second child should be a nested subtree in the form of another Tree component or a standalone TreeItem.\n * This order follows the same order as document traversal for the TreeWalker API in JavaScript:\n * https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker.\n * The content and layout of a TreeItem can be defined using the TreeItemLayout or TreeItemPersonaLayout component,\n * which should be used as a direct child of TreeItem.\n *\n * When a TreeItem has nested child subtree, an expand/collapse control is displayed,\n * allowing the user to show or hide the children.\n */\nexport const TreeItem = React.forwardRef((props, ref) => {\n const state = useTreeItem_unstable(props, ref);\n\n useTreeItemStyles_unstable(state);\n const contextValues = useTreeItemContextValues_unstable(state);\n return renderTreeItem_unstable(state, contextValues);\n})
|
|
1
|
+
{"version":3,"sources":["TreeItem.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useTreeItem_unstable } from './useTreeItem';\nimport { renderTreeItem_unstable } from './renderTreeItem';\nimport { useTreeItemStyles_unstable } from './useTreeItemStyles.styles';\nimport type { TreeItemProps } from './TreeItem.types';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\nimport { useTreeItemContextValues_unstable } from './useTreeItemContextValues';\n\n/**\n * The `TreeItem` component represents a single item in a tree.\n * It expects a certain order of children to work properly: the first child should be the node itself,\n * and the second child should be a nested subtree in the form of another Tree component or a standalone TreeItem.\n * This order follows the same order as document traversal for the TreeWalker API in JavaScript:\n * https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker.\n * The content and layout of a TreeItem can be defined using the TreeItemLayout or TreeItemPersonaLayout component,\n * which should be used as a direct child of TreeItem.\n *\n * When a TreeItem has nested child subtree, an expand/collapse control is displayed,\n * allowing the user to show or hide the children.\n */\nexport const TreeItem: ForwardRefComponent<TreeItemProps> = React.forwardRef((props, ref) => {\n const state = useTreeItem_unstable(props, ref);\n\n useTreeItemStyles_unstable(state);\n const contextValues = useTreeItemContextValues_unstable(state);\n return renderTreeItem_unstable(state, contextValues);\n});\n\nTreeItem.displayName = 'TreeItem';\n"],"names":["React","useTreeItem_unstable","renderTreeItem_unstable","useTreeItemStyles_unstable","useTreeItemContextValues_unstable","TreeItem","forwardRef","props","ref","state","contextValues","displayName"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,oBAAoB,QAAQ,gBAAgB;AACrD,SAASC,uBAAuB,QAAQ,mBAAmB;AAC3D,SAASC,0BAA0B,QAAQ,6BAA6B;AAGxE,SAASC,iCAAiC,QAAQ,6BAA6B;AAE/E;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,yBAA+CL,MAAMM,UAAU,CAAC,CAACC,OAAOC,MAAQ;IAC3F,MAAMC,QAAQR,qBAAqBM,OAAOC;IAE1CL,2BAA2BM;IAC3B,MAAMC,gBAAgBN,kCAAkCK;IACxD,OAAOP,wBAAwBO,OAAOC;AACxC,GAAG;AAEHL,SAASM,WAAW,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["TreeItem.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, ExtractSlotProps, Slot } from '@fluentui/react-utilities';\nimport type { TreeItemContextValue } from '../../contexts';\nimport { treeItemLevelToken } from '../../utils/tokens';\nimport * as React from 'react';\n\nexport type TreeItemCSSProperties = React.CSSProperties & { [treeItemLevelToken]?: string | number };\n\nexport type TreeItemType = 'leaf' | 'branch';\n\nexport type TreeItemSlots = {\n root: Slot<ExtractSlotProps<Slot<'div'> & { style?: TreeItemCSSProperties }>>;\n};\n\nexport type TreeItemContextValues = { treeItem: TreeItemContextValue };\n\n/**\n * TreeItem Props\n */\nexport type TreeItemProps
|
|
1
|
+
{"version":3,"sources":["TreeItem.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, ExtractSlotProps, Slot } from '@fluentui/react-utilities';\nimport type { TreeItemContextValue } from '../../contexts';\nimport { treeItemLevelToken } from '../../utils/tokens';\nimport * as React from 'react';\n\nexport type TreeItemCSSProperties = React.CSSProperties & { [treeItemLevelToken]?: string | number };\n\nexport type TreeItemType = 'leaf' | 'branch';\n\nexport type TreeItemSlots = {\n root: Slot<ExtractSlotProps<Slot<'div'> & { style?: TreeItemCSSProperties }>>;\n};\n\nexport type TreeItemValue = string | number;\n\nexport type TreeItemContextValues = { treeItem: TreeItemContextValue };\n\n/**\n * TreeItem Props\n */\nexport type TreeItemProps = ComponentProps<Partial<TreeItemSlots>> & {\n itemType: TreeItemType;\n value?: TreeItemValue;\n};\n\n/**\n * State used in rendering TreeItem\n */\nexport type TreeItemState = ComponentState<TreeItemSlots> &\n TreeItemContextValue & {\n level: number;\n itemType: TreeItemType;\n };\n"],"names":["React"],"mappings":"AAGA,YAAYA,WAAW,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"sourcesContent":["export * from './TreeItem';\nexport * from './TreeItem.types';\nexport * from './renderTreeItem';\nexport * from './useTreeItem';\nexport * from './useTreeItemStyles.styles';\n"],"names":[],"mappings":"AAAA,cAAc,aAAa;AAC3B,cAAc,mBAAmB;AACjC,cAAc,mBAAmB;AACjC,cAAc,gBAAgB;AAC9B,cAAc,6BAA6B"}
|
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":["export * from './TreeItem';\nexport * from './TreeItem.types';\nexport * from './renderTreeItem';\nexport * from './useTreeItem';\nexport * from './useTreeItemStyles.styles';\nexport * from './useTreeItemContextValues';\n"],"names":[],"mappings":"AAAA,cAAc,aAAa;AAC3B,cAAc,mBAAmB;AACjC,cAAc,mBAAmB;AACjC,cAAc,gBAAgB;AAC9B,cAAc,6BAA6B;AAC3C,cAAc,6BAA6B"}
|
|
@@ -4,6 +4,7 @@ import { useEventCallback } from '@fluentui/react-utilities';
|
|
|
4
4
|
import { elementContains } from '@fluentui/react-portal';
|
|
5
5
|
import { useTreeContext_unstable } from '../../contexts/index';
|
|
6
6
|
import { treeDataTypes } from '../../utils/tokens';
|
|
7
|
+
import { dataTreeItemValueAttrName } from '../../utils/getTreeItemValueFromElement';
|
|
7
8
|
/**
|
|
8
9
|
* Create the state required to render TreeItem.
|
|
9
10
|
*
|
|
@@ -13,9 +14,10 @@ import { treeDataTypes } from '../../utils/tokens';
|
|
|
13
14
|
* @param props - props from this instance of TreeItem
|
|
14
15
|
* @param ref - reference to root HTMLElement of TreeItem
|
|
15
16
|
*/ export function useTreeItem_unstable(props, ref) {
|
|
17
|
+
var _props_value;
|
|
16
18
|
const contextLevel = useTreeContext_unstable((ctx)=>ctx.level);
|
|
17
|
-
const
|
|
18
|
-
const { onClick , onKeyDown , as ='div' ,
|
|
19
|
+
const value = useId('fuiTreeItemValue-', (_props_value = props.value) === null || _props_value === void 0 ? void 0 : _props_value.toString());
|
|
20
|
+
const { onClick , onKeyDown , as ='div' , itemType ='leaf' , 'aria-level': level = contextLevel , ...rest } = props;
|
|
19
21
|
const requestTreeResponse = useTreeContext_unstable((ctx)=>ctx.requestTreeResponse);
|
|
20
22
|
const [isActionsVisible, setActionsVisible] = React.useState(false);
|
|
21
23
|
const [isAsideVisible, setAsideVisible] = React.useState(true);
|
|
@@ -66,8 +68,8 @@ import { treeDataTypes } from '../../utils/tokens';
|
|
|
66
68
|
case treeDataTypes.ArrowRight:
|
|
67
69
|
return requestTreeResponse({
|
|
68
70
|
event,
|
|
69
|
-
itemType,
|
|
70
71
|
value,
|
|
72
|
+
itemType,
|
|
71
73
|
type: event.key
|
|
72
74
|
});
|
|
73
75
|
}
|
|
@@ -75,8 +77,8 @@ import { treeDataTypes } from '../../utils/tokens';
|
|
|
75
77
|
if (isTypeAheadCharacter) {
|
|
76
78
|
requestTreeResponse({
|
|
77
79
|
event,
|
|
78
|
-
itemType,
|
|
79
80
|
value,
|
|
81
|
+
itemType,
|
|
80
82
|
type: treeDataTypes.TypeAhead
|
|
81
83
|
});
|
|
82
84
|
}
|
|
@@ -114,11 +116,11 @@ import { treeDataTypes } from '../../utils/tokens';
|
|
|
114
116
|
root: getNativeElementProps(as, {
|
|
115
117
|
tabIndex: -1,
|
|
116
118
|
...rest,
|
|
117
|
-
id,
|
|
118
119
|
ref,
|
|
120
|
+
role: 'treeitem',
|
|
119
121
|
'aria-level': level,
|
|
122
|
+
[dataTreeItemValueAttrName]: value,
|
|
120
123
|
'aria-expanded': itemType === 'branch' ? open : undefined,
|
|
121
|
-
role: 'treeitem',
|
|
122
124
|
onClick: handleClick,
|
|
123
125
|
onKeyDown: handleKeyDown,
|
|
124
126
|
onMouseOver: handleActionsVisible,
|