@fluentui/react-tree 9.0.0-beta.12 → 9.0.0-beta.14
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 +204 -4
- package/CHANGELOG.md +50 -5
- package/dist/index.d.ts +142 -81
- package/lib/TreeItemAside.js +2 -0
- package/lib/TreeItemAside.js.map +1 -0
- package/lib/components/Tree/Tree.js +1 -1
- package/lib/components/Tree/Tree.js.map +1 -1
- package/lib/components/Tree/Tree.types.js.map +1 -1
- package/lib/components/Tree/index.js +1 -1
- package/lib/components/Tree/index.js.map +1 -1
- package/lib/components/Tree/renderTree.js +1 -1
- package/lib/components/Tree/renderTree.js.map +1 -1
- package/lib/components/Tree/useRootTree.js +160 -0
- package/lib/components/Tree/useRootTree.js.map +1 -0
- package/lib/components/Tree/useSubtree.js +40 -0
- package/lib/components/Tree/useSubtree.js.map +1 -0
- package/lib/components/Tree/useTree.js +2 -95
- package/lib/components/Tree/useTree.js.map +1 -1
- package/lib/components/Tree/useTreeContextValues.js +2 -4
- package/lib/components/Tree/useTreeContextValues.js.map +1 -1
- package/lib/components/Tree/useTreeStyles.styles.js +30 -0
- package/lib/components/Tree/useTreeStyles.styles.js.map +1 -0
- package/lib/components/TreeItem/TreeItem.js +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 -1
- package/lib/components/TreeItem/index.js.map +1 -1
- package/lib/components/TreeItem/renderTreeItem.js +2 -5
- package/lib/components/TreeItem/renderTreeItem.js.map +1 -1
- package/lib/components/TreeItem/useTreeItem.js +58 -181
- package/lib/components/TreeItem/useTreeItem.js.map +1 -1
- package/lib/components/TreeItem/useTreeItemContextValues.js +25 -11
- package/lib/components/TreeItem/useTreeItemContextValues.js.map +1 -1
- package/lib/components/TreeItem/useTreeItemStyles.styles.js +102 -0
- package/lib/components/TreeItem/useTreeItemStyles.styles.js.map +1 -0
- package/lib/components/TreeItemAside/TreeItemAside.js +15 -0
- package/lib/components/TreeItemAside/TreeItemAside.js.map +1 -0
- package/lib/components/TreeItemAside/TreeItemAside.types.js +2 -0
- package/lib/components/TreeItemAside/TreeItemAside.types.js.map +1 -0
- package/lib/components/TreeItemAside/index.js +6 -0
- package/lib/components/TreeItemAside/index.js.map +1 -0
- package/lib/components/TreeItemAside/renderTreeItemAside.js +19 -0
- package/lib/components/TreeItemAside/renderTreeItemAside.js.map +1 -0
- package/lib/components/TreeItemAside/useTreeItemAside.js +35 -0
- package/lib/components/TreeItemAside/useTreeItemAside.js.map +1 -0
- package/lib/components/TreeItemAside/useTreeItemAsideStyles.styles.js +47 -0
- package/lib/components/TreeItemAside/useTreeItemAsideStyles.styles.js.map +1 -0
- package/lib/components/TreeItemChevron.js +27 -0
- package/lib/components/TreeItemChevron.js.map +1 -0
- package/lib/components/TreeItemLayout/TreeItemLayout.js +1 -1
- package/lib/components/TreeItemLayout/TreeItemLayout.js.map +1 -1
- package/lib/components/TreeItemLayout/TreeItemLayout.types.js.map +1 -1
- package/lib/components/TreeItemLayout/index.js +1 -1
- package/lib/components/TreeItemLayout/index.js.map +1 -1
- package/lib/components/TreeItemLayout/renderTreeItemLayout.js +1 -4
- package/lib/components/TreeItemLayout/renderTreeItemLayout.js.map +1 -1
- package/lib/components/TreeItemLayout/useTreeItemLayout.js +16 -11
- package/lib/components/TreeItemLayout/useTreeItemLayout.js.map +1 -1
- package/lib/components/TreeItemLayout/useTreeItemLayoutStyles.styles.js +138 -0
- package/lib/components/TreeItemLayout/useTreeItemLayoutStyles.styles.js.map +1 -0
- package/lib/components/TreeItemPersonaLayout/TreeItemPersonaLayout.js +1 -1
- package/lib/components/TreeItemPersonaLayout/TreeItemPersonaLayout.js.map +1 -1
- package/lib/components/TreeItemPersonaLayout/TreeItemPersonaLayout.types.js.map +1 -1
- package/lib/components/TreeItemPersonaLayout/index.js +1 -1
- package/lib/components/TreeItemPersonaLayout/index.js.map +1 -1
- package/lib/components/TreeItemPersonaLayout/renderTreeItemPersonaLayout.js +2 -5
- package/lib/components/TreeItemPersonaLayout/renderTreeItemPersonaLayout.js.map +1 -1
- package/lib/components/TreeItemPersonaLayout/useTreeItemPersonaLayout.js +16 -20
- package/lib/components/TreeItemPersonaLayout/useTreeItemPersonaLayout.js.map +1 -1
- package/lib/components/TreeItemPersonaLayout/{useTreeItemPersonaLayoutStyles.js → useTreeItemPersonaLayoutStyles.styles.js} +46 -18
- package/lib/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.styles.js.map +1 -0
- package/lib/contexts/treeContext.js +1 -2
- package/lib/contexts/treeContext.js.map +1 -1
- package/lib/contexts/treeItemContext.js +12 -4
- package/lib/contexts/treeItemContext.js.map +1 -1
- package/lib/hooks/useFlatTree.js +7 -7
- package/lib/hooks/useFlatTree.js.map +1 -1
- package/lib/hooks/useFlatTreeNavigation.js +8 -8
- package/lib/hooks/useFlatTreeNavigation.js.map +1 -1
- package/lib/hooks/useNestedTreeNavigation.js +8 -8
- package/lib/hooks/useNestedTreeNavigation.js.map +1 -1
- package/lib/hooks/useOpenItemsState.js +1 -1
- package/lib/hooks/useOpenItemsState.js.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/utils/createFlatTreeItems.js +12 -10
- package/lib/utils/createFlatTreeItems.js.map +1 -1
- package/lib/utils/flattenTree.js +0 -29
- package/lib/utils/flattenTree.js.map +1 -1
- package/lib/utils/tokens.js +11 -11
- package/lib/utils/tokens.js.map +1 -1
- package/lib-commonjs/TreeItemAside.js +9 -0
- package/lib-commonjs/TreeItemAside.js.map +1 -0
- package/lib-commonjs/components/Tree/Tree.js +2 -2
- package/lib-commonjs/components/Tree/Tree.js.map +1 -1
- package/lib-commonjs/components/Tree/index.js +1 -1
- package/lib-commonjs/components/Tree/index.js.map +1 -1
- package/lib-commonjs/components/Tree/renderTree.js +1 -1
- package/lib-commonjs/components/Tree/renderTree.js.map +1 -1
- package/lib-commonjs/components/Tree/useRootTree.js +151 -0
- package/lib-commonjs/components/Tree/useRootTree.js.map +1 -0
- package/lib-commonjs/components/Tree/useSubtree.js +41 -0
- package/lib-commonjs/components/Tree/useSubtree.js.map +1 -0
- package/lib-commonjs/components/Tree/useTree.js +4 -89
- package/lib-commonjs/components/Tree/useTree.js.map +1 -1
- package/lib-commonjs/components/Tree/useTreeContextValues.js +2 -3
- package/lib-commonjs/components/Tree/useTreeContextValues.js.map +1 -1
- package/lib-commonjs/components/Tree/{useTreeStyles.js → useTreeStyles.styles.js} +21 -4
- package/lib-commonjs/components/Tree/useTreeStyles.styles.js.map +1 -0
- package/lib-commonjs/components/TreeItem/TreeItem.js +2 -2
- package/lib-commonjs/components/TreeItem/TreeItem.js.map +1 -1
- package/lib-commonjs/components/TreeItem/index.js +1 -1
- package/lib-commonjs/components/TreeItem/index.js.map +1 -1
- package/lib-commonjs/components/TreeItem/renderTreeItem.js +2 -5
- package/lib-commonjs/components/TreeItem/renderTreeItem.js.map +1 -1
- package/lib-commonjs/components/TreeItem/useTreeItem.js +55 -172
- package/lib-commonjs/components/TreeItem/useTreeItem.js.map +1 -1
- package/lib-commonjs/components/TreeItem/useTreeItemContextValues.js +16 -15
- package/lib-commonjs/components/TreeItem/useTreeItemContextValues.js.map +1 -1
- package/lib-commonjs/components/TreeItem/useTreeItemStyles.styles.js +208 -0
- package/lib-commonjs/components/TreeItem/useTreeItemStyles.styles.js.map +1 -0
- package/lib-commonjs/components/TreeItemAside/TreeItemAside.js +21 -0
- package/lib-commonjs/components/TreeItemAside/TreeItemAside.js.map +1 -0
- package/lib-commonjs/components/TreeItemAside/TreeItemAside.types.js +7 -0
- package/lib-commonjs/components/TreeItemAside/TreeItemAside.types.js.map +1 -0
- package/lib-commonjs/components/TreeItemAside/index.js +13 -0
- package/lib-commonjs/components/TreeItemAside/index.js.map +1 -0
- package/lib-commonjs/components/TreeItemAside/renderTreeItemAside.js +22 -0
- package/lib-commonjs/components/TreeItemAside/renderTreeItemAside.js.map +1 -0
- package/lib-commonjs/components/TreeItemAside/useTreeItemAside.js +33 -0
- package/lib-commonjs/components/TreeItemAside/useTreeItemAside.js.map +1 -0
- package/lib-commonjs/components/TreeItemAside/useTreeItemAsideStyles.styles.js +92 -0
- package/lib-commonjs/components/TreeItemAside/useTreeItemAsideStyles.styles.js.map +1 -0
- package/lib-commonjs/components/TreeItemChevron.js +35 -0
- package/lib-commonjs/components/TreeItemChevron.js.map +1 -0
- package/lib-commonjs/components/TreeItemLayout/TreeItemLayout.js +2 -2
- package/lib-commonjs/components/TreeItemLayout/TreeItemLayout.js.map +1 -1
- package/lib-commonjs/components/TreeItemLayout/index.js +1 -1
- package/lib-commonjs/components/TreeItemLayout/index.js.map +1 -1
- package/lib-commonjs/components/TreeItemLayout/renderTreeItemLayout.js +1 -2
- package/lib-commonjs/components/TreeItemLayout/renderTreeItemLayout.js.map +1 -1
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayout.js +15 -10
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayout.js.map +1 -1
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayoutStyles.styles.js +223 -0
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayoutStyles.styles.js.map +1 -0
- package/lib-commonjs/components/TreeItemPersonaLayout/TreeItemPersonaLayout.js +2 -2
- package/lib-commonjs/components/TreeItemPersonaLayout/TreeItemPersonaLayout.js.map +1 -1
- package/lib-commonjs/components/TreeItemPersonaLayout/index.js +1 -1
- package/lib-commonjs/components/TreeItemPersonaLayout/index.js.map +1 -1
- package/lib-commonjs/components/TreeItemPersonaLayout/renderTreeItemPersonaLayout.js +2 -3
- package/lib-commonjs/components/TreeItemPersonaLayout/renderTreeItemPersonaLayout.js.map +1 -1
- package/lib-commonjs/components/TreeItemPersonaLayout/useTreeItemPersonaLayout.js +14 -14
- package/lib-commonjs/components/TreeItemPersonaLayout/useTreeItemPersonaLayout.js.map +1 -1
- package/lib-commonjs/components/TreeItemPersonaLayout/{useTreeItemPersonaLayoutStyles.js → useTreeItemPersonaLayoutStyles.styles.js} +82 -28
- package/lib-commonjs/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.styles.js.map +1 -0
- package/lib-commonjs/contexts/treeContext.js +1 -2
- package/lib-commonjs/contexts/treeContext.js.map +1 -1
- package/lib-commonjs/contexts/treeItemContext.js +12 -4
- package/lib-commonjs/contexts/treeItemContext.js.map +1 -1
- package/lib-commonjs/hooks/useFlatTree.js +7 -7
- package/lib-commonjs/hooks/useFlatTree.js.map +1 -1
- package/lib-commonjs/hooks/useFlatTreeNavigation.js +8 -8
- package/lib-commonjs/hooks/useFlatTreeNavigation.js.map +1 -1
- package/lib-commonjs/hooks/useNestedTreeNavigation.js +8 -8
- package/lib-commonjs/hooks/useNestedTreeNavigation.js.map +1 -1
- package/lib-commonjs/hooks/useOpenItemsState.js +1 -3
- package/lib-commonjs/hooks/useOpenItemsState.js.map +1 -1
- package/lib-commonjs/index.js +6 -0
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utils/createFlatTreeItems.js +12 -10
- package/lib-commonjs/utils/createFlatTreeItems.js.map +1 -1
- package/lib-commonjs/utils/flattenTree.js +4 -37
- package/lib-commonjs/utils/flattenTree.js.map +1 -1
- package/lib-commonjs/utils/tokens.js +10 -10
- package/lib-commonjs/utils/tokens.js.map +1 -1
- package/package.json +15 -14
- package/.swcrc +0 -30
- package/lib/components/Tree/useTreeStyles.js +0 -20
- package/lib/components/Tree/useTreeStyles.js.map +0 -1
- package/lib/components/TreeItem/useTreeItemStyles.js +0 -203
- package/lib/components/TreeItem/useTreeItemStyles.js.map +0 -1
- package/lib/components/TreeItemLayout/useTreeItemLayoutStyles.js +0 -98
- package/lib/components/TreeItemLayout/useTreeItemLayoutStyles.js.map +0 -1
- package/lib/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.js.map +0 -1
- package/lib-commonjs/components/Tree/useTreeStyles.js.map +0 -1
- package/lib-commonjs/components/TreeItem/useTreeItemStyles.js +0 -375
- package/lib-commonjs/components/TreeItem/useTreeItemStyles.js.map +0 -1
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayoutStyles.js +0 -143
- package/lib-commonjs/components/TreeItemLayout/useTreeItemLayoutStyles.js.map +0 -1
- package/lib-commonjs/components/TreeItemPersonaLayout/useTreeItemPersonaLayoutStyles.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { ArrowRight } from '@fluentui/keyboard-keys';
|
|
|
6
6
|
import { ArrowUp } from '@fluentui/keyboard-keys';
|
|
7
7
|
import type { AvatarContextValue } from '@fluentui/react-avatar';
|
|
8
8
|
import type { AvatarSize } from '@fluentui/react-avatar';
|
|
9
|
-
import
|
|
9
|
+
import { ButtonContextValue } from '@fluentui/react-button';
|
|
10
10
|
import type { ComponentProps } from '@fluentui/react-utilities';
|
|
11
11
|
import type { ComponentState } from '@fluentui/react-utilities';
|
|
12
12
|
import { ContextSelector } from '@fluentui/react-context-selector';
|
|
@@ -23,6 +23,8 @@ import type { Slot } from '@fluentui/react-utilities';
|
|
|
23
23
|
import type { SlotClassNames } from '@fluentui/react-utilities';
|
|
24
24
|
import { SlotRenderFunction } from '@fluentui/react-utilities';
|
|
25
25
|
|
|
26
|
+
declare type FlattenedTreeItem<Props extends TreeItemProps<unknown>> = FlatTreeItemProps<NonNullable<Props['value']>> & Props;
|
|
27
|
+
|
|
26
28
|
/**
|
|
27
29
|
* Converts a nested structure to a flat one which can be consumed by `useFlatTreeItems`
|
|
28
30
|
* @example
|
|
@@ -63,7 +65,7 @@ import { SlotRenderFunction } from '@fluentui/react-utilities';
|
|
|
63
65
|
* ]);
|
|
64
66
|
* ```
|
|
65
67
|
*/
|
|
66
|
-
export declare const flattenTree_unstable: <
|
|
68
|
+
export declare const flattenTree_unstable: <Props extends TreeItemProps<unknown>>(items: NestedTreeItem<Props>[]) => FlattenedTreeItem<Props>[];
|
|
67
69
|
|
|
68
70
|
/**
|
|
69
71
|
* FlatTree API to manage all required mechanisms to convert a list of items into renderable TreeItems
|
|
@@ -75,13 +77,13 @@ export declare const flattenTree_unstable: <Value = string>(items: NestedTreeIte
|
|
|
75
77
|
*
|
|
76
78
|
* On simple scenarios it is advised to simply use a nested structure instead.
|
|
77
79
|
*/
|
|
78
|
-
export declare type FlatTree<
|
|
80
|
+
export declare type FlatTree<Props extends FlatTreeItemProps<unknown> = FlatTreeItemProps> = {
|
|
79
81
|
/**
|
|
80
82
|
* returns the properties required for the Tree component to work properly.
|
|
81
83
|
* That includes:
|
|
82
84
|
* `openItems`, `onOpenChange`, `onNavigation_unstable` and `ref`
|
|
83
85
|
*/
|
|
84
|
-
getTreeProps(): FlatTreeProps<
|
|
86
|
+
getTreeProps(): FlatTreeProps<Props['value']>;
|
|
85
87
|
/**
|
|
86
88
|
* internal method used to react to an `onNavigation` event.
|
|
87
89
|
* This method ensures proper navigation on keyboard and mouse interaction.
|
|
@@ -105,7 +107,7 @@ export declare type FlatTree<Value = string> = {
|
|
|
105
107
|
* };
|
|
106
108
|
*```
|
|
107
109
|
*/
|
|
108
|
-
navigate(data: TreeNavigationData_unstable<
|
|
110
|
+
navigate(data: TreeNavigationData_unstable<Props['value']>): void;
|
|
109
111
|
/**
|
|
110
112
|
* returns next item to be focused on a navigation.
|
|
111
113
|
* This method is provided to decouple the element that needs to be focused from
|
|
@@ -113,23 +115,43 @@ export declare type FlatTree<Value = string> = {
|
|
|
113
115
|
*
|
|
114
116
|
* On the case of TypeAhead navigation this method returns the current item.
|
|
115
117
|
*/
|
|
116
|
-
getNextNavigableItem(visibleItems: FlatTreeItem<
|
|
118
|
+
getNextNavigableItem(visibleItems: FlatTreeItem<Props>[], data: TreeNavigationData_unstable<Props['value']>): FlatTreeItem<Props> | undefined;
|
|
117
119
|
/**
|
|
118
120
|
* an iterable containing all visually available flat tree items
|
|
119
121
|
*/
|
|
120
|
-
items(): IterableIterator<FlatTreeItem<
|
|
122
|
+
items(): IterableIterator<FlatTreeItem<Props>>;
|
|
121
123
|
};
|
|
122
124
|
|
|
123
|
-
|
|
125
|
+
/**
|
|
126
|
+
* The item that is returned by `useFlatTree`, it represents a wrapper around the properties provided to
|
|
127
|
+
* `useFlatTree` but with extra information that might be useful on flat tree scenarios
|
|
128
|
+
*/
|
|
129
|
+
export declare type FlatTreeItem<Props extends FlatTreeItemProps<unknown> = FlatTreeItemProps> = {
|
|
130
|
+
index: number;
|
|
131
|
+
level: number;
|
|
132
|
+
childrenSize: number;
|
|
133
|
+
value: Props['value'];
|
|
134
|
+
parentValue: Props['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'>;
|
|
142
|
+
};
|
|
124
143
|
|
|
125
|
-
export declare type FlatTreeItemProps<Value = string> = Omit<TreeItemProps
|
|
144
|
+
export declare type FlatTreeItemProps<Value = string> = Omit<TreeItemProps<Value>, 'itemType'> & Partial<Pick<TreeItemProps<Value>, 'itemType'>> & {
|
|
126
145
|
value: Value;
|
|
127
146
|
parentValue?: Value;
|
|
128
147
|
};
|
|
129
148
|
|
|
130
|
-
|
|
149
|
+
declare type FlatTreeOptions<Props extends FlatTreeItemProps<unknown> = FlatTreeItemProps> = Pick<TreeProps<Props['value']>, 'openItems' | 'defaultOpenItems' | 'onOpenChange' | 'onNavigation_unstable'>;
|
|
150
|
+
|
|
151
|
+
export declare type FlatTreeProps<Value = string> = Required<Pick<TreeProps<Value>, 'openItems' | 'onOpenChange' | 'onNavigation_unstable'>> & {
|
|
131
152
|
ref: React_2.Ref<HTMLDivElement>;
|
|
132
|
-
|
|
153
|
+
openItems: ImmutableSet<Value>;
|
|
154
|
+
};
|
|
133
155
|
|
|
134
156
|
declare interface ImmutableSet<Value> {
|
|
135
157
|
/**
|
|
@@ -157,24 +179,11 @@ declare interface ImmutableSet<Value> {
|
|
|
157
179
|
[Symbol.iterator](): IterableIterator<Value>;
|
|
158
180
|
}
|
|
159
181
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
* Used internally on createFlatTreeItems and VisibleFlatTreeItemGenerator
|
|
163
|
-
* to ensure required properties when building a FlatTreeITem
|
|
164
|
-
*/
|
|
165
|
-
declare type MutableFlatTreeItem<Value = string> = {
|
|
166
|
-
parentValue?: Value;
|
|
167
|
-
childrenSize: number;
|
|
168
|
-
index: number;
|
|
169
|
-
value: Value;
|
|
170
|
-
level: number;
|
|
171
|
-
ref: React_2.RefObject<HTMLDivElement>;
|
|
172
|
-
getTreeItemProps(): Required<Pick<TreeItemProps<Value>, 'value' | 'aria-setsize' | 'aria-level' | 'aria-posinset' | 'leaf'>> & TreeItemProps<Value>;
|
|
182
|
+
export declare type NestedTreeItem<Props extends TreeItemProps<unknown>> = Omit<Props, 'subtree' | 'itemType'> & {
|
|
183
|
+
subtree?: NestedTreeItem<Props>[];
|
|
173
184
|
};
|
|
174
185
|
|
|
175
|
-
|
|
176
|
-
subtree?: NestedTreeItem<Value>[];
|
|
177
|
-
};
|
|
186
|
+
declare type OmitWithoutExpanding<P, K extends string | number | symbol> = P extends unknown ? Omit<P, K> : P;
|
|
178
187
|
|
|
179
188
|
export declare const renderTree_unstable: (state: TreeState, contextValues: TreeContextValues) => JSX.Element;
|
|
180
189
|
|
|
@@ -183,6 +192,11 @@ export declare const renderTree_unstable: (state: TreeState, contextValues: Tree
|
|
|
183
192
|
*/
|
|
184
193
|
export declare const renderTreeItem_unstable: (state: TreeItemState, contextValues: TreeItemContextValues) => JSX.Element;
|
|
185
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Render the final JSX of TreeItemAside
|
|
197
|
+
*/
|
|
198
|
+
export declare const renderTreeItemAside_unstable: (state: TreeItemAsideState) => JSX.Element | null;
|
|
199
|
+
|
|
186
200
|
/**
|
|
187
201
|
* Render the final JSX of TreeItemLayout
|
|
188
202
|
*/
|
|
@@ -210,7 +224,7 @@ export declare const Tree: React_2.ForwardRefExoticComponent<Omit<TreeSlots, "ro
|
|
|
210
224
|
ref?: ((instance: HTMLDivElement | null) => void) | React_2.RefObject<HTMLDivElement> | null | undefined;
|
|
211
225
|
}>;
|
|
212
226
|
}, "ref"> & {
|
|
213
|
-
appearance?: "
|
|
227
|
+
appearance?: "transparent" | "subtle" | "subtle-alpha" | undefined;
|
|
214
228
|
size?: "small" | "medium" | undefined;
|
|
215
229
|
openItems?: Iterable<string> | undefined;
|
|
216
230
|
defaultOpenItems?: Iterable<string> | undefined;
|
|
@@ -226,10 +240,9 @@ export declare type TreeContextValue = {
|
|
|
226
240
|
size: 'small' | 'medium';
|
|
227
241
|
openItems: ImmutableSet<unknown>;
|
|
228
242
|
/**
|
|
229
|
-
*
|
|
243
|
+
* requests root Tree component to respond to some tree item event,
|
|
230
244
|
*/
|
|
231
|
-
|
|
232
|
-
requestNavigation(data: TreeNavigationData_unstable<unknown>): void;
|
|
245
|
+
requestTreeResponse(request: TreeItemRequest<unknown>): void;
|
|
233
246
|
};
|
|
234
247
|
|
|
235
248
|
declare type TreeContextValues = {
|
|
@@ -260,18 +273,63 @@ export declare const TreeItem: React_2.ForwardRefExoticComponent<Omit<Partial<Tr
|
|
|
260
273
|
style?: TreeItemCSSProperties | undefined;
|
|
261
274
|
}, "ref"> & {
|
|
262
275
|
value?: string | undefined;
|
|
263
|
-
|
|
276
|
+
itemType: TreeItemType;
|
|
264
277
|
} & React_2.RefAttributes<HTMLDivElement>> & (<Value = string>(props: TreeItemProps<Value>) => JSX.Element);
|
|
265
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
|
+
};
|
|
316
|
+
|
|
266
317
|
export declare const treeItemClassNames: SlotClassNames<TreeItemSlots>;
|
|
267
318
|
|
|
268
319
|
declare type TreeItemContextValue = {
|
|
269
320
|
isActionsVisible: boolean;
|
|
321
|
+
isAsideVisible: boolean;
|
|
322
|
+
actionsRef: React_2.Ref<HTMLDivElement>;
|
|
323
|
+
expandIconRef: React_2.Ref<HTMLDivElement>;
|
|
324
|
+
layoutRef: React_2.Ref<HTMLDivElement>;
|
|
325
|
+
subtreeRef: React_2.Ref<HTMLDivElement>;
|
|
326
|
+
value: unknown;
|
|
327
|
+
itemType: TreeItemType;
|
|
328
|
+
open: boolean;
|
|
270
329
|
};
|
|
271
330
|
|
|
272
331
|
declare type TreeItemContextValues = {
|
|
273
332
|
treeItem: TreeItemContextValue;
|
|
274
|
-
button: ButtonContextValue;
|
|
275
333
|
};
|
|
276
334
|
|
|
277
335
|
declare type TreeItemCSSProperties = React_2.CSSProperties & {
|
|
@@ -293,25 +351,26 @@ export declare const treeItemLayoutClassNames: SlotClassNames<TreeItemLayoutSlot
|
|
|
293
351
|
export declare type TreeItemLayoutProps = ComponentProps<Partial<TreeItemLayoutSlots>>;
|
|
294
352
|
|
|
295
353
|
export declare type TreeItemLayoutSlots = {
|
|
296
|
-
root: Slot<'
|
|
354
|
+
root: Slot<'div'>;
|
|
297
355
|
/**
|
|
298
|
-
*
|
|
356
|
+
* Expand icon slot,
|
|
357
|
+
* by default renders a chevron icon to indicate opening and closing
|
|
299
358
|
*/
|
|
300
|
-
|
|
359
|
+
expandIcon?: Slot<'div'>;
|
|
301
360
|
/**
|
|
302
|
-
* Icon slot that renders right
|
|
361
|
+
* Icon slot that renders right before main content
|
|
303
362
|
*/
|
|
304
|
-
|
|
363
|
+
iconBefore?: Slot<'div'>;
|
|
305
364
|
/**
|
|
306
|
-
* slot that
|
|
365
|
+
* Icon slot that renders right after main content
|
|
307
366
|
*/
|
|
308
|
-
|
|
367
|
+
iconAfter?: Slot<'div'>;
|
|
309
368
|
};
|
|
310
369
|
|
|
311
370
|
/**
|
|
312
371
|
* State used in rendering TreeItemLayout
|
|
313
372
|
*/
|
|
314
|
-
export declare type TreeItemLayoutState = ComponentState<TreeItemLayoutSlots
|
|
373
|
+
export declare type TreeItemLayoutState = ComponentState<TreeItemLayoutSlots>;
|
|
315
374
|
|
|
316
375
|
export declare const treeItemLevelToken: "--fluent-TreeItem--level";
|
|
317
376
|
|
|
@@ -334,33 +393,34 @@ declare type TreeItemPersonaLayoutContextValues = {
|
|
|
334
393
|
export declare type TreeItemPersonaLayoutProps = ComponentProps<Partial<TreeItemPersonaLayoutSlots>>;
|
|
335
394
|
|
|
336
395
|
export declare type TreeItemPersonaLayoutSlots = {
|
|
337
|
-
root: Slot<'
|
|
396
|
+
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'>;
|
|
338
402
|
/**
|
|
339
403
|
* Avatar to display.
|
|
340
404
|
*/
|
|
341
|
-
media: NonNullable<Slot<'
|
|
405
|
+
media: NonNullable<Slot<'div'>>;
|
|
342
406
|
/**
|
|
343
407
|
* Main text. Children of the root slot are automatically rendered here
|
|
344
408
|
*/
|
|
345
|
-
main: Slot<'
|
|
409
|
+
main: NonNullable<Slot<'div'>>;
|
|
346
410
|
/**
|
|
347
411
|
* Secondary text that describes or complements the main text
|
|
348
412
|
*/
|
|
349
|
-
description?: Slot<'
|
|
350
|
-
/**
|
|
351
|
-
* aside text that works as extra textual information
|
|
352
|
-
*/
|
|
353
|
-
aside?: Slot<'span'>;
|
|
413
|
+
description?: Slot<'div'>;
|
|
354
414
|
/**
|
|
355
415
|
* A layout wrapper for the main and description slots
|
|
356
416
|
*/
|
|
357
|
-
content: Slot<'div'
|
|
417
|
+
content: NonNullable<Slot<'div'>>;
|
|
358
418
|
};
|
|
359
419
|
|
|
360
420
|
/**
|
|
361
421
|
* State used in rendering TreeItemPersonaLayout
|
|
362
422
|
*/
|
|
363
|
-
export declare type TreeItemPersonaLayoutState = ComponentState<TreeItemPersonaLayoutSlots> &
|
|
423
|
+
export declare type TreeItemPersonaLayoutState = ComponentState<TreeItemPersonaLayoutSlots> & {
|
|
364
424
|
avatarSize: AvatarSize;
|
|
365
425
|
};
|
|
366
426
|
|
|
@@ -369,48 +429,31 @@ export declare type TreeItemPersonaLayoutState = ComponentState<TreeItemPersonaL
|
|
|
369
429
|
*/
|
|
370
430
|
export declare type TreeItemProps<Value = string> = ComponentProps<Partial<TreeItemSlots>> & {
|
|
371
431
|
value?: Value;
|
|
372
|
-
|
|
373
|
-
* If a TreeItem is a leaf, it'll not present the `expandIcon` slot by default.
|
|
374
|
-
* This attribute is used to force the decision if a TreeItem is a leaf or not. By not providing this property
|
|
375
|
-
* this will be inferred by the presence of a subtree as part of the TreeItem children.
|
|
376
|
-
*/
|
|
377
|
-
leaf?: boolean;
|
|
432
|
+
itemType: TreeItemType;
|
|
378
433
|
};
|
|
379
434
|
|
|
380
|
-
export declare const TreeItemProvider: React_2.Provider<TreeItemContextValue | undefined
|
|
435
|
+
export declare const TreeItemProvider: React_2.Provider<TreeItemContextValue | undefined> & React_2.FC<React_2.ProviderProps<TreeItemContextValue | undefined>>;
|
|
436
|
+
|
|
437
|
+
declare type TreeItemRequest<Value> = {
|
|
438
|
+
itemType: TreeItemType;
|
|
439
|
+
} & (OmitWithoutExpanding<TreeOpenChangeData<Value>, 'open' | 'target'> | OmitWithoutExpanding<TreeNavigationData_unstable<Value>, 'target'>);
|
|
381
440
|
|
|
382
441
|
export declare type TreeItemSlots = {
|
|
383
442
|
root: Slot<ExtractSlotProps<Slot<'div'> & {
|
|
384
443
|
style?: TreeItemCSSProperties;
|
|
385
444
|
}>>;
|
|
386
|
-
content: NonNullable<Slot<'div'>>;
|
|
387
|
-
subtree?: Slot<'span'>;
|
|
388
|
-
/**
|
|
389
|
-
* Expand icon slot,
|
|
390
|
-
* by default renders a chevron icon to indicate opening and closing
|
|
391
|
-
*/
|
|
392
|
-
expandIcon?: Slot<'span'>;
|
|
393
|
-
/**
|
|
394
|
-
* Actions slot that renders on the end of tree item
|
|
395
|
-
* when the item is hovered/focused
|
|
396
|
-
*/
|
|
397
|
-
actions?: Slot<'span'>;
|
|
398
445
|
};
|
|
399
446
|
|
|
400
447
|
/**
|
|
401
448
|
* State used in rendering TreeItem
|
|
402
449
|
*/
|
|
403
|
-
export declare type TreeItemState = ComponentState<TreeItemSlots> & {
|
|
404
|
-
open: boolean;
|
|
405
|
-
isLeaf: boolean;
|
|
450
|
+
export declare type TreeItemState = ComponentState<TreeItemSlots> & TreeItemContextValue & {
|
|
406
451
|
level: number;
|
|
407
|
-
|
|
408
|
-
* By design, a button included on the actions slot should be small
|
|
409
|
-
*/
|
|
410
|
-
buttonSize: 'small';
|
|
411
|
-
isActionsVisible: boolean;
|
|
452
|
+
itemType: TreeItemType;
|
|
412
453
|
};
|
|
413
454
|
|
|
455
|
+
declare type TreeItemType = 'leaf' | 'branch';
|
|
456
|
+
|
|
414
457
|
export declare type TreeNavigationData_unstable<Value = string> = {
|
|
415
458
|
value: Value;
|
|
416
459
|
target: HTMLElement;
|
|
@@ -525,7 +568,9 @@ export declare type TreeSlots = {
|
|
|
525
568
|
/**
|
|
526
569
|
* State used in rendering Tree
|
|
527
570
|
*/
|
|
528
|
-
export declare type TreeState = ComponentState<TreeSlots> & TreeContextValue
|
|
571
|
+
export declare type TreeState = ComponentState<TreeSlots> & TreeContextValue & {
|
|
572
|
+
open: boolean;
|
|
573
|
+
};
|
|
529
574
|
|
|
530
575
|
/**
|
|
531
576
|
* this hook provides FlatTree API to manage all required mechanisms to convert a list of items into renderable TreeItems
|
|
@@ -539,7 +584,7 @@ export declare type TreeState = ComponentState<TreeSlots> & TreeContextValue;
|
|
|
539
584
|
* @param flatTreeItemProps - a list of tree items
|
|
540
585
|
* @param options - in case control over the internal openItems is required
|
|
541
586
|
*/
|
|
542
|
-
export declare function useFlatTree_unstable<
|
|
587
|
+
export declare function useFlatTree_unstable<Props extends FlatTreeItemProps<unknown> = FlatTreeItemProps>(flatTreeItemProps: Props[], options?: FlatTreeOptions<Props>): FlatTree<Props>;
|
|
543
588
|
|
|
544
589
|
/**
|
|
545
590
|
* Create the state required to render Tree.
|
|
@@ -567,7 +612,23 @@ export declare function useTreeContextValues_unstable(state: TreeState): TreeCon
|
|
|
567
612
|
*/
|
|
568
613
|
export declare function useTreeItem_unstable<Value = string>(props: TreeItemProps<Value>, ref: React_2.Ref<HTMLDivElement>): TreeItemState;
|
|
569
614
|
|
|
570
|
-
|
|
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;
|
|
630
|
+
|
|
631
|
+
export declare const useTreeItemContext_unstable: <T>(selector: ContextSelector<TreeItemContextValue, T>) => T;
|
|
571
632
|
|
|
572
633
|
/**
|
|
573
634
|
* Create the state required to render TreeItemLayout.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../src/TreeItemAside.ts"],"sourcesContent":["export * from './components/TreeItemAside/index';\n"],"mappings":"AAAA,cAAc"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useTree_unstable } from './useTree';
|
|
3
3
|
import { renderTree_unstable } from './renderTree';
|
|
4
|
-
import { useTreeStyles_unstable } from './useTreeStyles';
|
|
4
|
+
import { useTreeStyles_unstable } from './useTreeStyles.styles';
|
|
5
5
|
import { useTreeContextValues_unstable } from './useTreeContextValues';
|
|
6
6
|
/**
|
|
7
7
|
* A tree view widget presents a hierarchical list.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useTree_unstable","renderTree_unstable","useTreeStyles_unstable","useTreeContextValues_unstable","Tree","forwardRef","props","ref","state","contextValues","displayName"],"sources":["../../../src/components/Tree/Tree.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useTree_unstable } from './useTree';\nimport { renderTree_unstable } from './renderTree';\nimport { useTreeStyles_unstable } from './useTreeStyles';\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}) as ForwardRefComponent<TreeProps> & (<Value = string>(props: TreeProps<Value>) => JSX.Element);\n\nTree.displayName = 'Tree';\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,gBAAgB,QAAQ;AACjC,SAASC,mBAAmB,QAAQ;AACpC,SAASC,sBAAsB,QAAQ;AAGvC,SAASC,6BAA6B,QAAQ;AAE9C;;;;;;;;AAQA,OAAO,MAAMC,IAAA,gBAAOL,KAAA,CAAMM,UAAU,CAAC,CAACC,KAAA,EAAOC,GAAA,KAAQ;EACnD,MAAMC,KAAA,GAAQR,gBAAA,CAAiBM,KAAA,EAAOC,GAAA;EACtCL,sBAAA,CAAuBM,KAAA;EACvB,MAAMC,aAAA,GAAgBN,6BAAA,CAA8BK,KAAA;EACpD,OAAOP,mBAAA,CAAoBO,KAAA,EAAOC,aAAA;AACpC;AAEAL,IAAA,CAAKM,WAAW,GAAG"}
|
|
1
|
+
{"version":3,"names":["React","useTree_unstable","renderTree_unstable","useTreeStyles_unstable","useTreeContextValues_unstable","Tree","forwardRef","props","ref","state","contextValues","displayName"],"sources":["../../../src/components/Tree/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}) as ForwardRefComponent<TreeProps> & (<Value = string>(props: TreeProps<Value>) => JSX.Element);\n\nTree.displayName = 'Tree';\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,gBAAgB,QAAQ;AACjC,SAASC,mBAAmB,QAAQ;AACpC,SAASC,sBAAsB,QAAQ;AAGvC,SAASC,6BAA6B,QAAQ;AAE9C;;;;;;;;AAQA,OAAO,MAAMC,IAAA,gBAAOL,KAAA,CAAMM,UAAU,CAAC,CAACC,KAAA,EAAOC,GAAA,KAAQ;EACnD,MAAMC,KAAA,GAAQR,gBAAA,CAAiBM,KAAA,EAAOC,GAAA;EACtCL,sBAAA,CAAuBM,KAAA;EACvB,MAAMC,aAAA,GAAgBN,6BAAA,CAA8BK,KAAA;EACpD,OAAOP,mBAAA,CAAoBO,KAAA,EAAOC,aAAA;AACpC;AAEAL,IAAA,CAAKM,WAAW,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React"],"sources":["../../../src/components/Tree/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<Value = string> = { value: Value; target: HTMLElement } & (\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<Value = string> = { open: boolean; value: Value } & (\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<Value = string> = 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<Value>;\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<Value>;\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<Value>): 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<Value>): void;\n};\n\n/**\n * State used in rendering Tree\n */\nexport type TreeState = ComponentState<TreeSlots> &
|
|
1
|
+
{"version":3,"names":["React"],"sources":["../../../src/components/Tree/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<Value = string> = { value: Value; target: HTMLElement } & (\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<Value = string> = { open: boolean; value: Value } & (\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<Value = string> = 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<Value>;\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<Value>;\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<Value>): 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<Value>): void;\n};\n\n/**\n * State used in rendering Tree\n */\nexport type TreeState = ComponentState<TreeSlots> &\n TreeContextValue & {\n open: boolean;\n };\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW"}
|
|
@@ -2,6 +2,6 @@ export * from './Tree';
|
|
|
2
2
|
export * from './Tree.types';
|
|
3
3
|
export * from './renderTree';
|
|
4
4
|
export * from './useTree';
|
|
5
|
-
export * from './useTreeStyles';
|
|
5
|
+
export * from './useTreeStyles.styles';
|
|
6
6
|
export * from './useTreeContextValues';
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../../src/components/Tree/index.ts"],"sourcesContent":["export * from './Tree';\nexport * from './Tree.types';\nexport * from './renderTree';\nexport * from './useTree';\nexport * from './useTreeStyles';\nexport * from './useTreeContextValues';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc"}
|
|
1
|
+
{"version":3,"names":[],"sources":["../../../src/components/Tree/index.ts"],"sourcesContent":["export * from './Tree';\nexport * from './Tree.types';\nexport * from './renderTree';\nexport * from './useTree';\nexport * from './useTreeStyles.styles';\nexport * from './useTreeContextValues';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc"}
|
|
@@ -8,6 +8,6 @@ export const renderTree_unstable = (state, contextValues) => {
|
|
|
8
8
|
} = getSlotsNext(state);
|
|
9
9
|
return /*#__PURE__*/createElement(TreeProvider, {
|
|
10
10
|
value: contextValues.tree
|
|
11
|
-
}, /*#__PURE__*/createElement(slots.root, slotProps.root, slotProps.root.children));
|
|
11
|
+
}, state.open && /*#__PURE__*/createElement(slots.root, slotProps.root, slotProps.root.children));
|
|
12
12
|
};
|
|
13
13
|
//# sourceMappingURL=renderTree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createElement","getSlotsNext","TreeProvider","renderTree_unstable","state","contextValues","slots","slotProps","value","tree","root","children"],"sources":["../../../src/components/Tree/renderTree.tsx"],"sourcesContent":["/** @jsxRuntime classic */\n/** @jsx createElement */\n\nimport { createElement } from '@fluentui/react-jsx-runtime';\nimport { getSlotsNext } from '@fluentui/react-utilities';\nimport type { TreeState, TreeSlots, TreeContextValues } from './Tree.types';\nimport { TreeProvider } from '../../contexts';\n\nexport const renderTree_unstable = (state: TreeState, contextValues: TreeContextValues) => {\n const { slots, slotProps } = getSlotsNext<TreeSlots>(state);\n
|
|
1
|
+
{"version":3,"names":["createElement","getSlotsNext","TreeProvider","renderTree_unstable","state","contextValues","slots","slotProps","value","tree","open","root","children"],"sources":["../../../src/components/Tree/renderTree.tsx"],"sourcesContent":["/** @jsxRuntime classic */\n/** @jsx createElement */\n\nimport { createElement } from '@fluentui/react-jsx-runtime';\nimport { getSlotsNext } from '@fluentui/react-utilities';\nimport type { TreeState, TreeSlots, TreeContextValues } from './Tree.types';\nimport { TreeProvider } from '../../contexts';\n\nexport const renderTree_unstable = (state: TreeState, contextValues: TreeContextValues) => {\n const { slots, slotProps } = getSlotsNext<TreeSlots>(state);\n return (\n <TreeProvider value={contextValues.tree}>\n {state.open && <slots.root {...slotProps.root}>{slotProps.root.children}</slots.root>}\n </TreeProvider>\n );\n};\n"],"mappings":"AAAA,2BACA,yBAEA,SAASA,aAAa,QAAQ;AAC9B,SAASC,YAAY,QAAQ;AAE7B,SAASC,YAAY,QAAQ;AAE7B,OAAO,MAAMC,mBAAA,GAAsBA,CAACC,KAAA,EAAkBC,aAAA,KAAqC;EACzF,MAAM;IAAEC,KAAA;IAAOC;EAAS,CAAE,GAAGN,YAAA,CAAwBG,KAAA;EACrD,oBACEJ,aAVJ,CAUKE,YAAA;IAAaM,KAAA,EAAOH,aAAA,CAAcI;KAChCL,KAAA,CAAMM,IAAI,iBAAIV,aAXrB,CAWsBM,KAAA,CAAMK,IAAI,EAAKJ,SAAA,CAAUI,IAAI,EAAGJ,SAAA,CAAUI,IAAI,CAACC,QAAQ;AAG7E"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as ReactDOM from 'react-dom';
|
|
3
|
+
import { getNativeElementProps, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';
|
|
4
|
+
import { useNestedTreeNavigation, useOpenItemsState } from '../../hooks';
|
|
5
|
+
import { treeDataTypes } from '../../utils/tokens';
|
|
6
|
+
/**
|
|
7
|
+
* Create the state required to render the root level Tree.
|
|
8
|
+
*
|
|
9
|
+
* @param props - props from this instance of Tree
|
|
10
|
+
* @param ref - reference to root HTMLElement of Tree
|
|
11
|
+
*/
|
|
12
|
+
export function useRootTree(props, ref) {
|
|
13
|
+
warnIfNoProperPropsRootTree(props);
|
|
14
|
+
const {
|
|
15
|
+
appearance = 'subtle',
|
|
16
|
+
size = 'medium'
|
|
17
|
+
} = props;
|
|
18
|
+
const [openItems, updateOpenItems] = useOpenItemsState(props);
|
|
19
|
+
const [navigate, navigationRef] = useNestedTreeNavigation();
|
|
20
|
+
const requestOpenChange = data => {
|
|
21
|
+
var _props_onOpenChange;
|
|
22
|
+
(_props_onOpenChange = props.onOpenChange) === null || _props_onOpenChange === void 0 ? void 0 : _props_onOpenChange.call(props, data.event, data);
|
|
23
|
+
if (data.event.isDefaultPrevented()) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
return updateOpenItems(data);
|
|
27
|
+
};
|
|
28
|
+
const requestNavigation = data => {
|
|
29
|
+
var _props_onNavigation_unstable;
|
|
30
|
+
(_props_onNavigation_unstable = props.onNavigation_unstable) === null || _props_onNavigation_unstable === void 0 ? void 0 : _props_onNavigation_unstable.call(props, data.event, data);
|
|
31
|
+
if (data.event.isDefaultPrevented()) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
navigate(data);
|
|
35
|
+
if (data.type === treeDataTypes.ArrowDown || data.type === treeDataTypes.ArrowUp) {
|
|
36
|
+
data.event.preventDefault();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const handleTreeItemClick = ({
|
|
40
|
+
event,
|
|
41
|
+
value,
|
|
42
|
+
itemType,
|
|
43
|
+
type
|
|
44
|
+
}) => {
|
|
45
|
+
ReactDOM.unstable_batchedUpdates(() => {
|
|
46
|
+
requestOpenChange({
|
|
47
|
+
event,
|
|
48
|
+
value,
|
|
49
|
+
open: itemType === 'branch' && !openItems.has(value),
|
|
50
|
+
type,
|
|
51
|
+
target: event.currentTarget
|
|
52
|
+
});
|
|
53
|
+
requestNavigation({
|
|
54
|
+
event,
|
|
55
|
+
value,
|
|
56
|
+
target: event.currentTarget,
|
|
57
|
+
type: treeDataTypes.Click
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
const handleTreeItemKeyDown = ({
|
|
62
|
+
event,
|
|
63
|
+
value,
|
|
64
|
+
type,
|
|
65
|
+
itemType
|
|
66
|
+
}) => {
|
|
67
|
+
const open = openItems.has(value);
|
|
68
|
+
switch (type) {
|
|
69
|
+
case treeDataTypes.ArrowRight:
|
|
70
|
+
if (itemType === 'leaf') {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (!open) {
|
|
74
|
+
return requestOpenChange({
|
|
75
|
+
event,
|
|
76
|
+
value,
|
|
77
|
+
open: true,
|
|
78
|
+
type: treeDataTypes.ArrowRight,
|
|
79
|
+
target: event.currentTarget
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return requestNavigation({
|
|
83
|
+
event,
|
|
84
|
+
value,
|
|
85
|
+
type,
|
|
86
|
+
target: event.currentTarget
|
|
87
|
+
});
|
|
88
|
+
case treeDataTypes.Enter:
|
|
89
|
+
return requestOpenChange({
|
|
90
|
+
event,
|
|
91
|
+
value,
|
|
92
|
+
open: itemType === 'branch' && !open,
|
|
93
|
+
type: treeDataTypes.Enter,
|
|
94
|
+
target: event.currentTarget
|
|
95
|
+
});
|
|
96
|
+
case treeDataTypes.ArrowLeft:
|
|
97
|
+
if (open && itemType === 'branch') {
|
|
98
|
+
return requestOpenChange({
|
|
99
|
+
event,
|
|
100
|
+
value,
|
|
101
|
+
open: false,
|
|
102
|
+
type: treeDataTypes.ArrowLeft,
|
|
103
|
+
target: event.currentTarget
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return requestNavigation({
|
|
107
|
+
event,
|
|
108
|
+
value,
|
|
109
|
+
target: event.currentTarget,
|
|
110
|
+
type: treeDataTypes.ArrowLeft
|
|
111
|
+
});
|
|
112
|
+
case treeDataTypes.End:
|
|
113
|
+
case treeDataTypes.Home:
|
|
114
|
+
case treeDataTypes.ArrowUp:
|
|
115
|
+
case treeDataTypes.ArrowDown:
|
|
116
|
+
case treeDataTypes.TypeAhead:
|
|
117
|
+
return requestNavigation({
|
|
118
|
+
event,
|
|
119
|
+
value,
|
|
120
|
+
type,
|
|
121
|
+
target: event.currentTarget
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const requestTreeResponse = useEventCallback(request => {
|
|
126
|
+
switch (request.event.type) {
|
|
127
|
+
case 'click':
|
|
128
|
+
// casting is required here as we're narrowing down the event to only click events
|
|
129
|
+
return handleTreeItemClick(request);
|
|
130
|
+
case 'keydown':
|
|
131
|
+
// casting is required here as we're narrowing down the event to only keyboard events
|
|
132
|
+
return handleTreeItemKeyDown(request);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
return {
|
|
136
|
+
components: {
|
|
137
|
+
root: 'div'
|
|
138
|
+
},
|
|
139
|
+
open: true,
|
|
140
|
+
appearance,
|
|
141
|
+
size,
|
|
142
|
+
level: 1,
|
|
143
|
+
openItems,
|
|
144
|
+
requestTreeResponse,
|
|
145
|
+
root: getNativeElementProps('div', {
|
|
146
|
+
ref: useMergedRefs(navigationRef, ref),
|
|
147
|
+
role: 'tree',
|
|
148
|
+
...props
|
|
149
|
+
})
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function warnIfNoProperPropsRootTree(props) {
|
|
153
|
+
if (process.env.NODE_ENV === 'development') {
|
|
154
|
+
if (!props['aria-label'] && !props['aria-labelledby']) {
|
|
155
|
+
// eslint-disable-next-line no-console
|
|
156
|
+
console.warn('Tree must have either a `aria-label` or `aria-labelledby` property defined');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=useRootTree.js.map
|