@fluentui/react-utilities 0.0.0-nightlya0ab3454ed20211208.1 → 0.0.0-nightlyb2b3ec1da320220209.1
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 +84 -6
- package/CHANGELOG.md +15 -6
- package/dist/react-utilities.d.ts +193 -78
- package/lib/compose/getSlots.d.ts +7 -8
- package/lib/compose/getSlots.js +3 -4
- package/lib/compose/getSlots.js.map +1 -1
- package/lib/compose/index.d.ts +0 -1
- package/lib/compose/index.js +0 -1
- package/lib/compose/index.js.map +1 -1
- package/lib/compose/resolveShorthand.d.ts +10 -6
- package/lib/compose/resolveShorthand.js +5 -5
- package/lib/compose/resolveShorthand.js.map +1 -1
- package/lib/compose/types.d.ts +86 -34
- package/lib/compose/types.js.map +1 -1
- package/lib/hooks/index.d.ts +1 -0
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useMergedEventCallbacks.d.ts +18 -0
- package/lib/hooks/useMergedEventCallbacks.js +26 -0
- package/lib/hooks/useMergedEventCallbacks.js.map +1 -0
- package/lib/hooks/useOnClickOutside.js.map +1 -1
- package/lib/utils/applyTriggerPropsToChildren.d.ts +1 -1
- package/lib/utils/applyTriggerPropsToChildren.js +23 -3
- package/lib/utils/applyTriggerPropsToChildren.js.map +1 -1
- package/lib/utils/getNativeElementProps.d.ts +4 -4
- package/lib/utils/getNativeElementProps.js.map +1 -1
- package/lib/utils/getReactCallbackName.d.ts +25 -0
- package/lib/utils/getReactCallbackName.js +26 -0
- package/lib/utils/getReactCallbackName.js.map +1 -0
- package/lib/utils/getTriggerChild.d.ts +22 -0
- package/lib/utils/getTriggerChild.js +26 -0
- package/lib/utils/getTriggerChild.js.map +1 -0
- package/lib/utils/index.d.ts +2 -1
- package/lib/utils/index.js +2 -1
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/isFluentTrigger.d.ts +22 -0
- package/lib/utils/isFluentTrigger.js +8 -0
- package/lib/utils/isFluentTrigger.js.map +1 -0
- package/lib/utils/properties.js +40 -20
- package/lib/utils/properties.js.map +1 -1
- package/lib-commonjs/compose/getSlots.d.ts +7 -8
- package/lib-commonjs/compose/getSlots.js +3 -5
- package/lib-commonjs/compose/getSlots.js.map +1 -1
- package/lib-commonjs/compose/index.d.ts +0 -1
- package/lib-commonjs/compose/index.js +0 -2
- package/lib-commonjs/compose/index.js.map +1 -1
- package/lib-commonjs/compose/resolveShorthand.d.ts +10 -6
- package/lib-commonjs/compose/resolveShorthand.js +5 -5
- package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
- package/lib-commonjs/compose/types.d.ts +86 -34
- package/lib-commonjs/compose/types.js.map +1 -1
- package/lib-commonjs/hooks/index.d.ts +1 -0
- package/lib-commonjs/hooks/index.js +2 -0
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useMergedEventCallbacks.d.ts +18 -0
- package/lib-commonjs/hooks/useMergedEventCallbacks.js +36 -0
- package/lib-commonjs/hooks/useMergedEventCallbacks.js.map +1 -0
- package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
- package/lib-commonjs/utils/applyTriggerPropsToChildren.d.ts +1 -1
- package/lib-commonjs/utils/applyTriggerPropsToChildren.js +24 -4
- package/lib-commonjs/utils/applyTriggerPropsToChildren.js.map +1 -1
- package/lib-commonjs/utils/getNativeElementProps.d.ts +4 -4
- package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
- package/lib-commonjs/utils/getReactCallbackName.d.ts +25 -0
- package/lib-commonjs/utils/getReactCallbackName.js +35 -0
- package/lib-commonjs/utils/getReactCallbackName.js.map +1 -0
- package/lib-commonjs/utils/getTriggerChild.d.ts +22 -0
- package/lib-commonjs/utils/getTriggerChild.js +37 -0
- package/lib-commonjs/utils/getTriggerChild.js.map +1 -0
- package/lib-commonjs/utils/index.d.ts +2 -1
- package/lib-commonjs/utils/index.js +4 -2
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/isFluentTrigger.d.ts +22 -0
- package/lib-commonjs/utils/isFluentTrigger.js +17 -0
- package/lib-commonjs/utils/isFluentTrigger.js.map +1 -0
- package/lib-commonjs/utils/properties.js +40 -20
- package/lib-commonjs/utils/properties.js.map +1 -1
- package/package.json +3 -7
- package/lib/compose/nullRender.d.ts +0 -4
- package/lib/compose/nullRender.js +0 -5
- package/lib/compose/nullRender.js.map +0 -1
- package/lib/utils/onlyChild.d.ts +0 -5
- package/lib/utils/onlyChild.js +0 -13
- package/lib/utils/onlyChild.js.map +0 -1
- package/lib-commonjs/compose/nullRender.d.ts +0 -4
- package/lib-commonjs/compose/nullRender.js +0 -14
- package/lib-commonjs/compose/nullRender.js.map +0 -1
- package/lib-commonjs/utils/onlyChild.d.ts +0 -5
- package/lib-commonjs/utils/onlyChild.js +0 -23
- package/lib-commonjs/utils/onlyChild.js.map +0 -1
package/CHANGELOG.json
CHANGED
@@ -2,17 +2,71 @@
|
|
2
2
|
"name": "@fluentui/react-utilities",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "Wed,
|
6
|
-
"tag": "@fluentui/react-utilities_v0.0.0-
|
7
|
-
"version": "0.0.0-
|
5
|
+
"date": "Wed, 09 Feb 2022 04:13:04 GMT",
|
6
|
+
"tag": "@fluentui/react-utilities_v0.0.0-nightlyb2b3ec1da320220209.1",
|
7
|
+
"version": "0.0.0-nightlyb2b3ec1da320220209.1",
|
8
8
|
"comments": {
|
9
9
|
"prerelease": [
|
10
10
|
{
|
11
11
|
"author": "email not defined",
|
12
12
|
"package": "@fluentui/react-utilities",
|
13
|
-
"commit": "
|
13
|
+
"commit": "066f84c7bef7f4df47448557396199d8b7f26480",
|
14
14
|
"comment": "Release nightly v9"
|
15
15
|
},
|
16
|
+
{
|
17
|
+
"author": "behowell@microsoft.com",
|
18
|
+
"package": "@fluentui/react-utilities",
|
19
|
+
"commit": "317209bb5cd57c40f35bc42060acb7e3cce5ec95",
|
20
|
+
"comment": "Rename component hooks add the suffix _unstable, as their API has not been finalized yet"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"author": "behowell@microsoft.com",
|
24
|
+
"package": "@fluentui/react-utilities",
|
25
|
+
"commit": "7cc28ed8320b00f42d91c63882f10316db2205c5",
|
26
|
+
"comment": "getSlots: remove slotNames param, and infer from state.components instead"
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"author": "olfedias@microsoft.com",
|
30
|
+
"package": "@fluentui/react-utilities",
|
31
|
+
"commit": "d2eb57808a403b70845a732a62b55aa64d66b2a0",
|
32
|
+
"comment": "add useTriggerElement() hook"
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"author": "bsunderhus@microsoft.com",
|
36
|
+
"package": "@fluentui/react-utilities",
|
37
|
+
"commit": "c0d4e63ee58e60e2c6674efbacc0783cd520984e",
|
38
|
+
"comment": "Removes nullRender from react-utilities"
|
39
|
+
},
|
40
|
+
{
|
41
|
+
"author": "olfedias@microsoft.com",
|
42
|
+
"package": "@fluentui/react-utilities",
|
43
|
+
"commit": "aa6cfd8ac825b5a280206808101de549a91094fc",
|
44
|
+
"comment": "update applyTriggerPropsToChildren() to return React.ReactElement or null"
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"author": "behowell@microsoft.com",
|
48
|
+
"package": "@fluentui/react-utilities",
|
49
|
+
"commit": "53b01d71e335715fda91b33e3d7bbd9d471d5ed3",
|
50
|
+
"comment": "Refactor component Slot typings"
|
51
|
+
},
|
52
|
+
{
|
53
|
+
"author": "Humberto.Morimoto@microsoft.com",
|
54
|
+
"package": "@fluentui/react-utilities",
|
55
|
+
"commit": "0bc161458eae5ae8d387172430496ce9829b1bb1",
|
56
|
+
"comment": "Adding ComponentSlotProps to allow ref to be passed in composite components."
|
57
|
+
},
|
58
|
+
{
|
59
|
+
"author": "Humberto.Morimoto@microsoft.com",
|
60
|
+
"package": "@fluentui/react-utilities",
|
61
|
+
"commit": "e0b8e1fa6980077e7b311fd1c72c28d3e4305db0",
|
62
|
+
"comment": "Renaming most *Shorthand* composition types to *SlotProps* so they better reflect what the types do."
|
63
|
+
},
|
64
|
+
{
|
65
|
+
"author": "behowell@microsoft.com",
|
66
|
+
"package": "@fluentui/react-utilities",
|
67
|
+
"commit": "f30e7585a8d2abd9db06c4076f39a779008b0eca",
|
68
|
+
"comment": "Update trigger utilities to handle nested triggers"
|
69
|
+
},
|
16
70
|
{
|
17
71
|
"author": "elcraig@microsoft.com",
|
18
72
|
"package": "@fluentui/react-utilities",
|
@@ -22,16 +76,40 @@
|
|
22
76
|
{
|
23
77
|
"author": "beachball",
|
24
78
|
"package": "@fluentui/react-utilities",
|
25
|
-
"comment": "Bump @fluentui/keyboard-keys to v0.0.0-
|
26
|
-
"commit": "
|
79
|
+
"comment": "Bump @fluentui/keyboard-keys to v0.0.0-nightlyb2b3ec1da320220209.1",
|
80
|
+
"commit": "066f84c7bef7f4df47448557396199d8b7f26480"
|
27
81
|
}
|
28
82
|
],
|
29
83
|
"none": [
|
84
|
+
{
|
85
|
+
"author": "elcraig@microsoft.com",
|
86
|
+
"package": "@fluentui/react-utilities",
|
87
|
+
"commit": "3360b45ec159250b1346c91afad7dce138e6bc20",
|
88
|
+
"comment": "Update API file to version generated by typescript 4.3"
|
89
|
+
},
|
90
|
+
{
|
91
|
+
"author": "olfedias@microsoft.com",
|
92
|
+
"package": "@fluentui/react-utilities",
|
93
|
+
"commit": "c061e98be4b4a718c72a144a1f60bb5515824612",
|
94
|
+
"comment": "remove inline-style-expand-shorthand from tsconfigs"
|
95
|
+
},
|
96
|
+
{
|
97
|
+
"author": "martinhochel@microsoft.com",
|
98
|
+
"package": "@fluentui/react-utilities",
|
99
|
+
"commit": "8dfa712156b70414205b87b5b6d099367b0c297d",
|
100
|
+
"comment": "chore: use storybook runner for all vNext packages"
|
101
|
+
},
|
30
102
|
{
|
31
103
|
"author": "seanmonahan@microsoft.com",
|
32
104
|
"package": "@fluentui/react-utilities",
|
33
105
|
"commit": "6404bef16cebf1f67b9b80a9f6d5f605f9873df1",
|
34
106
|
"comment": "Update getSlots() docs."
|
107
|
+
},
|
108
|
+
{
|
109
|
+
"author": "lingfangao@hotmail.com",
|
110
|
+
"package": "@fluentui/react-utilities",
|
111
|
+
"commit": "a4e048a0e03ddd676670da516e3a6612b26ea500",
|
112
|
+
"comment": "chore: Remove enzyme from react-utilities tests"
|
35
113
|
}
|
36
114
|
]
|
37
115
|
}
|
package/CHANGELOG.md
CHANGED
@@ -1,19 +1,28 @@
|
|
1
1
|
# Change Log - @fluentui/react-utilities
|
2
2
|
|
3
|
-
This log was last generated on Wed,
|
3
|
+
This log was last generated on Wed, 09 Feb 2022 04:13:04 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
-
## [0.0.0-
|
7
|
+
## [0.0.0-nightlyb2b3ec1da320220209.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v0.0.0-nightlyb2b3ec1da320220209.1)
|
8
8
|
|
9
|
-
Wed,
|
10
|
-
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.0-beta.4..@fluentui/react-utilities_v0.0.0-
|
9
|
+
Wed, 09 Feb 2022 04:13:04 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.0-beta.4..@fluentui/react-utilities_v0.0.0-nightlyb2b3ec1da320220209.1)
|
11
11
|
|
12
12
|
### Changes
|
13
13
|
|
14
|
-
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/
|
14
|
+
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/066f84c7bef7f4df47448557396199d8b7f26480) by email not defined)
|
15
|
+
- Rename component hooks add the suffix _unstable, as their API has not been finalized yet ([PR #21365](https://github.com/microsoft/fluentui/pull/21365) by behowell@microsoft.com)
|
16
|
+
- getSlots: remove slotNames param, and infer from state.components instead ([PR #21134](https://github.com/microsoft/fluentui/pull/21134) by behowell@microsoft.com)
|
17
|
+
- add useTriggerElement() hook ([PR #21225](https://github.com/microsoft/fluentui/pull/21225) by olfedias@microsoft.com)
|
18
|
+
- Removes nullRender from react-utilities ([PR #21576](https://github.com/microsoft/fluentui/pull/21576) by bsunderhus@microsoft.com)
|
19
|
+
- update applyTriggerPropsToChildren() to return React.ReactElement or null ([PR #21609](https://github.com/microsoft/fluentui/pull/21609) by olfedias@microsoft.com)
|
20
|
+
- Refactor component Slot typings ([PR #21518](https://github.com/microsoft/fluentui/pull/21518) by behowell@microsoft.com)
|
21
|
+
- Adding ComponentSlotProps to allow ref to be passed in composite components. ([PR #20890](https://github.com/microsoft/fluentui/pull/20890) by Humberto.Morimoto@microsoft.com)
|
22
|
+
- Renaming most *Shorthand* composition types to *SlotProps* so they better reflect what the types do. ([PR #20891](https://github.com/microsoft/fluentui/pull/20891) by Humberto.Morimoto@microsoft.com)
|
23
|
+
- Update trigger utilities to handle nested triggers ([PR #21495](https://github.com/microsoft/fluentui/pull/21495) by behowell@microsoft.com)
|
15
24
|
- [breaking] Remove useControllableValue hook (use useControllableState instead) ([PR #20865](https://github.com/microsoft/fluentui/pull/20865) by elcraig@microsoft.com)
|
16
|
-
- Bump @fluentui/keyboard-keys to v0.0.0-
|
25
|
+
- Bump @fluentui/keyboard-keys to v0.0.0-nightlyb2b3ec1da320220209.1 ([commit](https://github.com/microsoft/fluentui/commit/066f84c7bef7f4df47448557396199d8b7f26480) by beachball)
|
17
26
|
|
18
27
|
## [9.0.0-beta.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.0.0-beta.4)
|
19
28
|
|
@@ -11,7 +11,7 @@ export declare const anchorProperties: Record<string, number>;
|
|
11
11
|
/**
|
12
12
|
* Apply the trigger props to the children, either by calling the render function, or cloning with the new props.
|
13
13
|
*/
|
14
|
-
export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: React_2.ReactElement<any, string |
|
14
|
+
export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: React_2.ReactElement<any, string | React_2.JSXElementConstructor<any>> | ((props: TTriggerProps) => React_2.ReactElement | null) | null | undefined, triggerProps: TTriggerProps) => React_2.ReactElement | null;
|
15
15
|
|
16
16
|
/**
|
17
17
|
* Helper type for inferring the type of the as prop from a Props type.
|
@@ -71,25 +71,22 @@ export declare const colGroupProperties: Record<string, number>;
|
|
71
71
|
|
72
72
|
export declare const colProperties: Record<string, number>;
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
export declare type
|
79
|
-
components?: {
|
80
|
-
[Key in keyof Shorthands]-?: React_2.ComponentType<NonNullable<Shorthands[Key]> extends ObjectShorthandProps<infer P> ? P : NonNullable<Shorthands[Key]>> | (NonNullable<Shorthands[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
|
81
|
-
};
|
82
|
-
} & Shorthands;
|
74
|
+
/**
|
75
|
+
* Defines the Props type for a component given its slots and the definition of which one is the primary slot,
|
76
|
+
* defaulting to root if one is not provided.
|
77
|
+
*/
|
78
|
+
export declare type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> = Omit<Slots, Primary & 'root'> & PropsWithoutRef<ExtractSlotProps<Slots[Primary]>>;
|
83
79
|
|
84
80
|
/**
|
85
|
-
*
|
86
|
-
*
|
87
|
-
* This should ONLY be used in type templates as in `extends DefaultObjectShorthandProps`;
|
88
|
-
* it shouldn't be used as the type of a slot.
|
81
|
+
* Defines the State object of a component given its slots.
|
89
82
|
*/
|
90
|
-
export declare type
|
91
|
-
|
92
|
-
|
83
|
+
export declare type ComponentState<Slots extends SlotPropsRecord> = {
|
84
|
+
components: {
|
85
|
+
[Key in keyof Slots]-?: React_2.ComponentType<ExtractSlotProps<Slots[Key]>> | (ExtractSlotProps<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
|
86
|
+
};
|
87
|
+
} & {
|
88
|
+
[Key in keyof Slots]: ReplaceNullWithUndefined<Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>>;
|
89
|
+
};
|
93
90
|
|
94
91
|
/**
|
95
92
|
* Default context value to use in case there is no SSRProvider. This is fine for client-only apps.
|
@@ -105,6 +102,35 @@ export declare const defaultSSRContextValue: SSRContextValue;
|
|
105
102
|
*/
|
106
103
|
export declare const divProperties: Record<string, number>;
|
107
104
|
|
105
|
+
/**
|
106
|
+
* HTML element types that are not allowed to have children.
|
107
|
+
*
|
108
|
+
* Reference: https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
|
109
|
+
*/
|
110
|
+
declare type EmptyIntrisicElements = 'area' | 'base' | 'br' | 'col' | 'embed' | 'hr' | 'img' | 'input' | 'link' | 'meta' | 'param' | 'source' | 'track' | 'wbr';
|
111
|
+
|
112
|
+
/**
|
113
|
+
* Removes SlotShorthandValue and null from the slot type, extracting just the slot's Props object.
|
114
|
+
*/
|
115
|
+
export declare type ExtractSlotProps<S> = Exclude<S, SlotShorthandValue | null | undefined>;
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Allows a component to be tagged as a FluentUI trigger component.
|
119
|
+
*
|
120
|
+
* Triggers are special-case components: they attach event listeners and other props on their child,
|
121
|
+
* and use them to trigger another component to show. Examples include `MenuTrigger` and `Tooltip`.
|
122
|
+
*
|
123
|
+
* A component can be tagged as a trigger as follows:
|
124
|
+
* ```ts
|
125
|
+
* const MyComponent: React.FC<MyComponentProps> & FluentTriggerComponent = ...;
|
126
|
+
*
|
127
|
+
* MyComponent.isFluentTriggerComponent = true; // MUST also set this to true
|
128
|
+
* ```
|
129
|
+
*/
|
130
|
+
export declare type FluentTriggerComponent = {
|
131
|
+
isFluentTriggerComponent?: boolean;
|
132
|
+
};
|
133
|
+
|
108
134
|
/**
|
109
135
|
* An array of FORM tag properties and events.
|
110
136
|
*
|
@@ -150,19 +176,19 @@ export declare function getNativeProps<T extends Record<string, any>>(props: Rec
|
|
150
176
|
*
|
151
177
|
* @returns An object containing the native props for the `root` and primary slots.
|
152
178
|
*/
|
153
|
-
export declare const getPartitionedNativeProps: ({ primarySlotTagName, props, excludedPropNames, }: {
|
179
|
+
export declare const getPartitionedNativeProps: <Props extends Pick<React_2.HTMLAttributes<HTMLElement>, "style" | "className">, ExcludedPropKeys extends Extract<keyof Props, string> = never>({ primarySlotTagName, props, excludedPropNames, }: {
|
154
180
|
/** The primary slot's element type (e.g. 'div') */
|
155
181
|
primarySlotTagName: keyof JSX.IntrinsicElements;
|
156
182
|
/** The component's props object */
|
157
|
-
props:
|
183
|
+
props: Props;
|
158
184
|
/** List of native props to exclude from the returned value */
|
159
|
-
excludedPropNames?:
|
185
|
+
excludedPropNames?: ExcludedPropKeys[] | undefined;
|
160
186
|
}) => {
|
161
187
|
root: {
|
162
188
|
style: React_2.CSSProperties | undefined;
|
163
189
|
className: string | undefined;
|
164
190
|
};
|
165
|
-
primary:
|
191
|
+
primary: Omit<Props, ExcludedPropKeys>;
|
166
192
|
};
|
167
193
|
|
168
194
|
/**
|
@@ -185,12 +211,33 @@ export declare const getRTLSafeKey: (key: string, dir: 'ltr' | 'rtl') => string;
|
|
185
211
|
* runtime code filtering props in this function.
|
186
212
|
*
|
187
213
|
* @param state - State including slot definitions
|
188
|
-
* @param slotNames - Name of which props are slots
|
189
214
|
* @returns An object containing the `slots` map and `slotProps` map.
|
190
215
|
*/
|
191
|
-
export declare function getSlots<R extends
|
216
|
+
export declare function getSlots<R extends SlotPropsRecord>(state: ComponentState<R>): {
|
192
217
|
slots: Slots<R>;
|
193
|
-
slotProps:
|
218
|
+
slotProps: ObjectSlotProps<R>;
|
219
|
+
};
|
220
|
+
|
221
|
+
/**
|
222
|
+
* Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).
|
223
|
+
*
|
224
|
+
* In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,
|
225
|
+
* it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.
|
226
|
+
* This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.
|
227
|
+
*
|
228
|
+
* For example, the following returns `<div id="child" />`:
|
229
|
+
* ```jsx
|
230
|
+
* getTriggerChild(
|
231
|
+
* <Tooltip>
|
232
|
+
* <MenuTrigger>
|
233
|
+
* <div id="child" />
|
234
|
+
* </MenuTrigger>
|
235
|
+
* </Tooltip>
|
236
|
+
* );
|
237
|
+
* ```
|
238
|
+
*/
|
239
|
+
export declare const getTriggerChild: (children: React_2.ReactNode) => React_2.ReactElement & {
|
240
|
+
ref?: React_2.Ref<unknown>;
|
194
241
|
};
|
195
242
|
|
196
243
|
/**
|
@@ -227,25 +274,19 @@ export declare const imgProperties: Record<string, number>;
|
|
227
274
|
export declare const inputProperties: Record<string, number>;
|
228
275
|
|
229
276
|
/**
|
230
|
-
*
|
231
|
-
*
|
232
|
-
*
|
233
|
-
* The first param is the slot's default type if no `as` prop is specified.
|
234
|
-
* The second param is an optional union of alternative types that can be specified for the `as` prop.
|
235
|
-
*
|
236
|
-
* ```
|
237
|
-
* IntrinsicShorthandProps<'div'> // Slot is always div
|
238
|
-
* IntrinsicShorthandProps<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
|
239
|
-
* IntrinsicShorthandProps<'label', 'span' | 'div'>; // Defaults to label, but allows as="span" or as="div"
|
240
|
-
* ```
|
277
|
+
* Helper type for {@link Slot}. Modifies `JSX.IntrinsicElements[Type]`:
|
278
|
+
* * Removes legacy string ref.
|
279
|
+
* * Disallows children for empty tags like 'img'.
|
241
280
|
*/
|
242
|
-
|
243
|
-
|
244
|
-
}
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
}
|
281
|
+
declare type IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = React_2.PropsWithRef<JSX.IntrinsicElements[Type]> & (Type extends EmptyIntrisicElements ? {
|
282
|
+
children?: never;
|
283
|
+
} : {});
|
284
|
+
|
285
|
+
/**
|
286
|
+
* Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).
|
287
|
+
* See the {@link FluentTriggerComponent} type for more info.
|
288
|
+
*/
|
289
|
+
export declare const isFluentTrigger: (element: React_2.ReactElement) => boolean | undefined;
|
249
290
|
|
250
291
|
/**
|
251
292
|
* Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.
|
@@ -273,24 +314,10 @@ export declare const labelProperties: Record<string, number>;
|
|
273
314
|
*/
|
274
315
|
export declare const liProperties: Record<string, number>;
|
275
316
|
|
276
|
-
|
277
|
-
|
278
|
-
*/
|
279
|
-
export declare const nullRender: () => null;
|
280
|
-
|
281
|
-
/**
|
282
|
-
* Defines the slot props for a slot that supports a Component type.
|
283
|
-
*
|
284
|
-
* For intrinsic elements like 'div', use {@link IntrinsicShorthandProps} instead.
|
285
|
-
*/
|
286
|
-
export declare type ObjectShorthandProps<Props extends {
|
287
|
-
children?: React_2.ReactNode;
|
288
|
-
} = {}> = Props & {
|
289
|
-
children?: Props['children'] | ShorthandRenderFunction<Props>;
|
317
|
+
declare type ObjectSlotProps<S extends SlotPropsRecord> = {
|
318
|
+
[K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : ExtractSlotProps<S[K]> extends React_2.ComponentType<infer P> ? P : never;
|
290
319
|
};
|
291
320
|
|
292
|
-
export declare type ObjectShorthandPropsRecord = Record<string, DefaultObjectShorthandProps | undefined>;
|
293
|
-
|
294
321
|
/**
|
295
322
|
* This is part of a hack to infer the element type from a native element *props* type.
|
296
323
|
* The only place the original element is found in a native props type (at least that's workable
|
@@ -327,16 +354,11 @@ export declare const olProperties: Record<string, number>;
|
|
327
354
|
*/
|
328
355
|
export declare function omit<TObj extends Record<string, any>, Exclusions extends (keyof TObj)[]>(obj: TObj, exclusions: Exclusions): Omit<TObj, Exclusions[number]>;
|
329
356
|
|
330
|
-
/**
|
331
|
-
* Similar to React.Children.only, but drills into fragments rather than treating them as a single child
|
332
|
-
*/
|
333
|
-
export declare const onlyChild: <P>(child: string | number | boolean | {} | React_2.ReactNodeArray | React_2.ReactPortal | React_2.ReactElement<P, string | ((props: any) => React_2.ReactElement<any, string | any | (new (props: any) => React_2.Component<any, any, any>)> | null) | (new (props: any) => React_2.Component<any, any, any>)> | null | undefined) => React_2.ReactElement<P, string | ((props: any) => React_2.ReactElement<any, string | any | (new (props: any) => React_2.Component<any, any, any>)> | null) | (new (props: any) => React_2.Component<any, any, any>)>;
|
334
|
-
|
335
357
|
export declare const optionProperties: Record<string, number>;
|
336
358
|
|
337
359
|
/**
|
338
360
|
* Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
|
339
|
-
*
|
361
|
+
* IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
|
340
362
|
*
|
341
363
|
* The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional
|
342
364
|
* types, to prevent unions from being expanded.
|
@@ -349,6 +371,11 @@ export declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unkn
|
|
349
371
|
*/
|
350
372
|
export declare type RefObjectFunction<T> = React_2.RefObject<T> & ((value: T) => void);
|
351
373
|
|
374
|
+
/**
|
375
|
+
* If type T includes `null`, remove it and add `undefined` instead.
|
376
|
+
*/
|
377
|
+
export declare type ReplaceNullWithUndefined<T> = T extends null ? Exclude<T, null> | undefined : T;
|
378
|
+
|
352
379
|
/**
|
353
380
|
* Resets generated IDs, should be used only in tests.
|
354
381
|
*
|
@@ -357,14 +384,19 @@ export declare type RefObjectFunction<T> = React_2.RefObject<T> & ((value: T) =>
|
|
357
384
|
export declare function resetIdsForTests(): void;
|
358
385
|
|
359
386
|
/**
|
360
|
-
* Resolves
|
387
|
+
* Resolves shorthands into slot props, to ensure normalization of the signature
|
361
388
|
* being passed down to getSlots method
|
362
|
-
* @param value - the base
|
363
|
-
* @param options - options to resolve
|
389
|
+
* @param value - the base shorthand props
|
390
|
+
* @param options - options to resolve shorthand props
|
364
391
|
*/
|
365
|
-
export declare
|
392
|
+
export declare const resolveShorthand: ResolveShorthandFunction;
|
366
393
|
|
367
|
-
export declare type
|
394
|
+
export declare type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {
|
395
|
+
<P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, true>): ReplaceNullWithUndefined<P>;
|
396
|
+
<P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, boolean>): ReplaceNullWithUndefined<P> | undefined;
|
397
|
+
};
|
398
|
+
|
399
|
+
export declare type ResolveShorthandOptions<Props, Required extends boolean = false> = {
|
368
400
|
required?: Required;
|
369
401
|
defaultProps?: Props;
|
370
402
|
};
|
@@ -376,10 +408,6 @@ export declare type ResolveShorthandOptions<Props extends Record<string, any>, R
|
|
376
408
|
*/
|
377
409
|
export declare const selectProperties: Record<string, number>;
|
378
410
|
|
379
|
-
export declare type ShorthandProps<Props extends DefaultObjectShorthandProps> = React_2.ReactChild | React_2.ReactNodeArray | React_2.ReactPortal | number | null | undefined | Props;
|
380
|
-
|
381
|
-
export declare type ShorthandRenderFunction<Props> = (Component: React_2.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React_2.ReactNode;
|
382
|
-
|
383
411
|
/**
|
384
412
|
* Checks if the keyboard event should preventDefault() for Enter and Spacebar keys
|
385
413
|
*
|
@@ -387,14 +415,55 @@ export declare type ShorthandRenderFunction<Props> = (Component: React_2.Element
|
|
387
415
|
*/
|
388
416
|
export declare function shouldPreventDefaultOnKeyDown(e: KeyboardEvent | React_2.KeyboardEvent): boolean;
|
389
417
|
|
390
|
-
|
391
|
-
|
392
|
-
|
418
|
+
/**
|
419
|
+
* The props type and shorthand value for a slot. Type is either a single intrinsic element like `'div'`,
|
420
|
+
* or a component like `typeof Button`.
|
421
|
+
*
|
422
|
+
* If a slot needs to support multiple intrinsic element types, use the `AlternateAs` param (see examples below).
|
423
|
+
*
|
424
|
+
* By default, slots can be set to `null` to prevent them from being rendered. If a slot must always be rendered,
|
425
|
+
* wrap with `NonNullable` (see examples below).
|
426
|
+
*
|
427
|
+
* @example
|
428
|
+
* ```
|
429
|
+
* // Intrinsic element examples:
|
430
|
+
* Slot<'div'> // Slot is always div
|
431
|
+
* Slot<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
|
432
|
+
* Slot<'span', 'div' | 'pre'> // Defaults to span, but allows as="div" or as="pre"
|
433
|
+
* NonNullable<Slot<'div'>> // Slot that will always be rendered (can't be set to null by the user)
|
434
|
+
*
|
435
|
+
* // Component examples:
|
436
|
+
* Slot<typeof Button> // Slot is always a Button, and accepts all of Button's Props
|
437
|
+
* NonNullable<Slot<typeof Label>> // Slot is a Label and will always be rendered (can't be set to null by the user)
|
438
|
+
* ```
|
439
|
+
*/
|
440
|
+
export declare type Slot<Type extends keyof JSX.IntrinsicElements | React_2.ComponentType | UnknownSlotProps, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<Extract<Type, string>> extends true ? WithSlotShorthandValue<Type extends keyof JSX.IntrinsicElements ? {
|
441
|
+
as?: Type;
|
442
|
+
} & WithSlotRenderFunction<IntrisicElementProps<Type>> : Type extends React_2.ComponentType<infer Props> ? WithSlotRenderFunction<Props> : Type> | {
|
443
|
+
[As in AlternateAs]: {
|
444
|
+
as: As;
|
445
|
+
} & WithSlotRenderFunction<IntrisicElementProps<As>>;
|
446
|
+
}[AlternateAs] | null : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';
|
447
|
+
|
448
|
+
/**
|
449
|
+
* Matches any component's Slots type (such as ButtonSlots).
|
450
|
+
*
|
451
|
+
* This should ONLY be used in type templates as in `extends SlotPropsRecord`;
|
452
|
+
* it shouldn't be used as a component's Slots type.
|
453
|
+
*/
|
454
|
+
export declare type SlotPropsRecord = Record<string, UnknownSlotProps | SlotShorthandValue | null | undefined>;
|
393
455
|
|
394
|
-
export declare type
|
395
|
-
|
456
|
+
export declare type SlotRenderFunction<Props> = (Component: React_2.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React_2.ReactNode;
|
457
|
+
|
458
|
+
export declare type Slots<S extends SlotPropsRecord> = {
|
459
|
+
[K in keyof S]: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? As : ExtractSlotProps<S[K]> extends React_2.ComponentType<infer P> ? React_2.ElementType<NonNullable<P>> : React_2.ElementType<ExtractSlotProps<S[K]>>;
|
396
460
|
};
|
397
461
|
|
462
|
+
/**
|
463
|
+
* The shorthand value of a slot allows specifying its child
|
464
|
+
*/
|
465
|
+
export declare type SlotShorthandValue = React_2.ReactChild | React_2.ReactNodeArray | React_2.ReactPortal;
|
466
|
+
|
398
467
|
export declare const SSRContext: React_2.Context<SSRContextValue>;
|
399
468
|
|
400
469
|
/**
|
@@ -455,6 +524,16 @@ export declare const trProperties: Record<string, number>;
|
|
455
524
|
*/
|
456
525
|
export declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;
|
457
526
|
|
527
|
+
/**
|
528
|
+
* Matches any slot props type.
|
529
|
+
*
|
530
|
+
* This should ONLY be used in type templates as in `extends UnknownSlotProps`;
|
531
|
+
* it shouldn't be used as the type of a slot.
|
532
|
+
*/
|
533
|
+
export declare type UnknownSlotProps = Pick<React_2.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
|
534
|
+
as?: keyof JSX.IntrinsicElements;
|
535
|
+
};
|
536
|
+
|
458
537
|
/**
|
459
538
|
* Hook to store a value and generate callbacks for setting the value to true or false.
|
460
539
|
* The identity of the callbacks will always stay the same.
|
@@ -577,6 +656,25 @@ export declare const useIsomorphicLayoutEffect: typeof React_2.useEffect;
|
|
577
656
|
*/
|
578
657
|
export declare function useIsSSR(): boolean;
|
579
658
|
|
659
|
+
/**
|
660
|
+
* Combine two event callbacks into a single callback function that calls each one in order.
|
661
|
+
*
|
662
|
+
* This is useful to add an event listener to an existing element without overwriting the current listener, if any.
|
663
|
+
*
|
664
|
+
* For example:
|
665
|
+
* ```ts
|
666
|
+
* state.slot.onChange = useMergedCallbacks(state.slot.onChange, ev => {
|
667
|
+
* // Handle onChange
|
668
|
+
* });
|
669
|
+
* ```
|
670
|
+
*
|
671
|
+
* @param callback1 - The first callback to be called
|
672
|
+
* @param callback2 - The second callback to be called
|
673
|
+
*
|
674
|
+
* @returns An event callback that calls the callbacks in order, and is stable between renders
|
675
|
+
*/
|
676
|
+
export declare function useMergedEventCallbacks<Args extends unknown[]>(callback1: ((...args: Args) => void) | undefined, callback2: ((...args: Args) => void) | undefined): (...args: Args) => void;
|
677
|
+
|
580
678
|
/**
|
581
679
|
* React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that
|
582
680
|
* updates all provided refs
|
@@ -657,4 +755,21 @@ export declare const useUnmount: (callback: () => void) => void;
|
|
657
755
|
*/
|
658
756
|
export declare const videoProperties: Record<string, number>;
|
659
757
|
|
758
|
+
/**
|
759
|
+
* Helper type for {@link Slot}. Takes the props we want to support for a slot and adds the ability for `children`
|
760
|
+
* to be a render function that takes those props.
|
761
|
+
*/
|
762
|
+
declare type WithSlotRenderFunction<Props extends {
|
763
|
+
children?: unknown;
|
764
|
+
}> = Props & {
|
765
|
+
children?: Props['children'] | SlotRenderFunction<Props>;
|
766
|
+
};
|
767
|
+
|
768
|
+
/**
|
769
|
+
* Helper type for {@link Slot}. Adds shorthand types that are assignable to the slot's `children`.
|
770
|
+
*/
|
771
|
+
declare type WithSlotShorthandValue<Props extends {
|
772
|
+
children?: unknown;
|
773
|
+
}> = Props | Extract<SlotShorthandValue, Props['children']>;
|
774
|
+
|
660
775
|
export { }
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
import { AsIntrinsicElement, ComponentState,
|
3
|
-
export declare type Slots<S extends
|
4
|
-
[K in keyof S]
|
2
|
+
import type { AsIntrinsicElement, ComponentState, ExtractSlotProps, SlotPropsRecord, UnionToIntersection } from './types';
|
3
|
+
export declare type Slots<S extends SlotPropsRecord> = {
|
4
|
+
[K in keyof S]: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? As : ExtractSlotProps<S[K]> extends React.ComponentType<infer P> ? React.ElementType<NonNullable<P>> : React.ElementType<ExtractSlotProps<S[K]>>;
|
5
5
|
};
|
6
|
-
declare type
|
7
|
-
[K in keyof S]-?:
|
6
|
+
declare type ObjectSlotProps<S extends SlotPropsRecord> = {
|
7
|
+
[K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : ExtractSlotProps<S[K]> extends React.ComponentType<infer P> ? P : never;
|
8
8
|
};
|
9
9
|
/**
|
10
10
|
* Given the state and an array of slot names, will break out `slots` and `slotProps`
|
@@ -21,11 +21,10 @@ declare type SlotProps<S extends ObjectShorthandPropsRecord> = {
|
|
21
21
|
* runtime code filtering props in this function.
|
22
22
|
*
|
23
23
|
* @param state - State including slot definitions
|
24
|
-
* @param slotNames - Name of which props are slots
|
25
24
|
* @returns An object containing the `slots` map and `slotProps` map.
|
26
25
|
*/
|
27
|
-
export declare function getSlots<R extends
|
26
|
+
export declare function getSlots<R extends SlotPropsRecord>(state: ComponentState<R>): {
|
28
27
|
slots: Slots<R>;
|
29
|
-
slotProps:
|
28
|
+
slotProps: ObjectSlotProps<R>;
|
30
29
|
};
|
31
30
|
export {};
|
package/lib/compose/getSlots.js
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
import { nullRender } from './nullRender';
|
3
2
|
import { omit } from '../utils/omit';
|
4
3
|
/**
|
5
4
|
* Given the state and an array of slot names, will break out `slots` and `slotProps`
|
@@ -16,13 +15,13 @@ import { omit } from '../utils/omit';
|
|
16
15
|
* runtime code filtering props in this function.
|
17
16
|
*
|
18
17
|
* @param state - State including slot definitions
|
19
|
-
* @param slotNames - Name of which props are slots
|
20
18
|
* @returns An object containing the `slots` map and `slotProps` map.
|
21
19
|
*/
|
22
20
|
|
23
|
-
export function getSlots(state
|
21
|
+
export function getSlots(state) {
|
24
22
|
const slots = {};
|
25
23
|
const slotProps = {};
|
24
|
+
const slotNames = Object.keys(state.components);
|
26
25
|
|
27
26
|
for (const slotName of slotNames) {
|
28
27
|
const [slot, props] = getSlot(state, slotName);
|
@@ -40,7 +39,7 @@ function getSlot(state, slotName) {
|
|
40
39
|
var _a, _b, _c;
|
41
40
|
|
42
41
|
if (state[slotName] === undefined) {
|
43
|
-
return [
|
42
|
+
return [null, undefined];
|
44
43
|
}
|
45
44
|
|
46
45
|
const {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/compose/getSlots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;
|
1
|
+
{"version":3,"sources":["../../src/compose/getSlots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA,SAAS,IAAT,QAAqB,eAArB;AA6BA;;;;;;;;;;;;;;;;AAgBG;;AACH,OAAM,SAAU,QAAV,CACJ,KADI,EACoB;AAKxB,QAAM,KAAK,GAAG,EAAd;AACA,QAAM,SAAS,GAAG,EAAlB;AAEA,QAAM,SAAS,GAAgB,MAAM,CAAC,IAAP,CAAY,KAAK,CAAC,UAAlB,CAA/B;;AACA,OAAK,MAAM,QAAX,IAAuB,SAAvB,EAAkC;AAChC,UAAM,CAAC,IAAD,EAAO,KAAP,IAAgB,OAAO,CAAC,KAAD,EAAQ,QAAR,CAA7B;AACA,IAAA,KAAK,CAAC,QAAD,CAAL,GAAkB,IAAlB;AACA,IAAA,SAAS,CAAC,QAAD,CAAT,GAAsB,KAAtB;AACD;;AACD,SAAO;AAAE,IAAA,KAAF;AAAS,IAAA,SAAS,EAAG;AAArB,GAAP;AACD;;AAED,SAAS,OAAT,CACE,KADF,EAEE,QAFF,EAEa;;;AAEX,MAAI,KAAK,CAAC,QAAD,CAAL,KAAoB,SAAxB,EAAmC;AACjC,WAAO,CAAC,IAAD,EAAO,SAAP,CAAP;AACD;;AACD,QAAM;AAAE,IAAA,QAAF;AAAY,IAAA,EAAE,EAAE,MAAhB;AAAwB,OAAG;AAA3B,MAAoC,KAAK,CAAC,QAAD,CAA/C;AAEA,QAAM,IAAI,GAAI,CAAA,CAAA,EAAA,GAAA,KAAK,CAAC,UAAN,MAAgB,IAAhB,IAAgB,EAAA,KAAA,KAAA,CAAhB,GAAgB,KAAA,CAAhB,GAAgB,EAAA,CAAG,QAAH,CAAhB,MAAiC,SAAjC,IAA8C,OAAO,KAAK,CAAC,UAAN,CAAiB,QAAjB,CAAP,KAAsC,QAApF,GACV,MAAM,KAAI,CAAA,EAAA,GAAA,KAAK,CAAC,UAAN,MAAgB,IAAhB,IAAgB,EAAA,KAAA,KAAA,CAAhB,GAAgB,KAAA,CAAhB,GAAgB,EAAA,CAAG,QAAH,CAApB,CAAN,IAA0C,KADhC,GAEV,KAAK,CAAC,UAAN,CAAiB,QAAjB,CAFJ;;AAIA,MAAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;AAClC,UAAM,MAAM,GAAG,QAAf;AACA,WAAO,CACL,KAAK,CAAC,QADD,EAEJ;AACC,MAAA,QAAQ,EAAE,MAAM,CAAC,IAAD,EAAO,IAAP;AADjB,KAFI,CAAP;AAMD;;AAED,QAAM,gBAAgB,GAAG,OAAO,IAAP,KAAgB,QAAhB,KAA4B,CAAA,EAAA,GAAA,KAAK,CAAC,QAAD,CAAL,MAAe,IAAf,IAAe,EAAA,KAAA,KAAA,CAAf,GAAe,KAAA,CAAf,GAAe,EAAA,CAAE,EAA7C,CAAzB;AACA,QAAM,SAAS,GAAI,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,QAAD,CAAN,EAAmB,CAAC,IAAD,CAAnB,CAAP,GAAoC,KAAK,CAAC,QAAD,CAA5E;AAEA,SAAO,CAAC,IAAD,EAAO,SAAP,CAAP;AACD","sourceRoot":""}
|
package/lib/compose/index.d.ts
CHANGED