@fluentui/react-utilities 0.0.0-nightly-20230501-0418.1 → 0.0.0-nightly-20230503-0419.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 +5 -5
- package/CHANGELOG.md +5 -5
- package/dist/index.d.ts +710 -0
- package/lib/compose/constants.js +5 -0
- package/lib/compose/constants.js.map +1 -0
- package/lib/compose/getSlots.js +58 -0
- package/lib/compose/getSlots.js.map +1 -0
- package/lib/compose/getSlotsNext.js +34 -0
- package/lib/compose/getSlotsNext.js.map +1 -0
- package/lib/compose/index.js +7 -0
- package/lib/compose/index.js.map +1 -0
- package/lib/compose/isResolvedShorthand.js +35 -0
- package/lib/compose/isResolvedShorthand.js.map +1 -0
- package/lib/compose/resolveShorthand.js +34 -0
- package/lib/compose/resolveShorthand.js.map +1 -0
- package/lib/compose/types.js +2 -0
- package/lib/compose/types.js.map +1 -0
- package/lib/events/index.js +2 -0
- package/lib/events/index.js.map +1 -0
- package/lib/events/mouseTouchHelpers.js +39 -0
- package/lib/events/mouseTouchHelpers.js.map +1 -0
- package/lib/hooks/index.js +13 -0
- package/lib/hooks/index.js.map +1 -0
- package/lib/hooks/useControllableState.js +49 -0
- package/lib/hooks/useControllableState.js.map +1 -0
- package/lib/hooks/useEventCallback.js +28 -0
- package/lib/hooks/useEventCallback.js.map +1 -0
- package/lib/hooks/useFirstMount.js +21 -0
- package/lib/hooks/useFirstMount.js.map +1 -0
- package/lib/hooks/useForceUpdate.js +9 -0
- package/lib/hooks/useForceUpdate.js.map +1 -0
- package/lib/hooks/useId.js +48 -0
- package/lib/hooks/useId.js.map +1 -0
- package/lib/hooks/useIsomorphicLayoutEffect.js +13 -0
- package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -0
- package/lib/hooks/useMergedRefs.js +25 -0
- package/lib/hooks/useMergedRefs.js.map +1 -0
- package/lib/hooks/useOnClickOutside.js +135 -0
- package/lib/hooks/useOnClickOutside.js.map +1 -0
- package/lib/hooks/useOnScrollOutside.js +36 -0
- package/lib/hooks/useOnScrollOutside.js.map +1 -0
- package/lib/hooks/usePrevious.js +12 -0
- package/lib/hooks/usePrevious.js.map +1 -0
- package/lib/hooks/useScrollbarWidth.js +30 -0
- package/lib/hooks/useScrollbarWidth.js.map +1 -0
- package/lib/hooks/useTimeout.js +28 -0
- package/lib/hooks/useTimeout.js.map +1 -0
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -0
- package/lib/ssr/SSRContext.js +60 -0
- package/lib/ssr/SSRContext.js.map +1 -0
- package/lib/ssr/canUseDOM.js +8 -0
- package/lib/ssr/canUseDOM.js.map +1 -0
- package/lib/ssr/index.js +3 -0
- package/lib/ssr/index.js.map +1 -0
- package/lib/trigger/applyTriggerPropsToChildren.js +33 -0
- package/lib/trigger/applyTriggerPropsToChildren.js.map +1 -0
- package/lib/trigger/getTriggerChild.js +34 -0
- package/lib/trigger/getTriggerChild.js.map +1 -0
- package/lib/trigger/index.js +5 -0
- package/lib/trigger/index.js.map +1 -0
- package/lib/trigger/isFluentTrigger.js +10 -0
- package/lib/trigger/isFluentTrigger.js.map +1 -0
- package/lib/trigger/types.js +2 -0
- package/lib/trigger/types.js.map +1 -0
- package/lib/utils/clamp.js +9 -0
- package/lib/utils/clamp.js.map +1 -0
- package/lib/utils/getNativeElementProps.js +61 -0
- package/lib/utils/getNativeElementProps.js.map +1 -0
- package/lib/utils/getRTLSafeKey.js +19 -0
- package/lib/utils/getRTLSafeKey.js.map +1 -0
- package/lib/utils/getReactCallbackName.js +24 -0
- package/lib/utils/getReactCallbackName.js.map +1 -0
- package/lib/utils/index.js +9 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/isHTMLElement.js +20 -0
- package/lib/utils/isHTMLElement.js.map +1 -0
- package/lib/utils/isInteractiveHTMLElement.js +22 -0
- package/lib/utils/isInteractiveHTMLElement.js.map +1 -0
- package/lib/utils/mergeCallbacks.js +29 -0
- package/lib/utils/mergeCallbacks.js.map +1 -0
- package/lib/utils/omit.js +24 -0
- package/lib/utils/omit.js.map +1 -0
- package/lib/utils/properties.js +200 -0
- package/lib/utils/properties.js.map +1 -0
- package/package.json +2 -2
package/dist/index.d.ts
ADDED
@@ -0,0 +1,710 @@
|
|
1
|
+
import { DispatchWithoutAction } from 'react';
|
2
|
+
import * as React_2 from 'react';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* @internal
|
6
|
+
* resolve the trigger props to the children, either by calling the render function, or cloning with the new props.
|
7
|
+
*/
|
8
|
+
export declare function applyTriggerPropsToChildren<TriggerChildProps>(children: TriggerProps<TriggerChildProps>['children'], triggerChildProps: TriggerChildProps): React_2.ReactElement | null;
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Helper type for inferring the type of the as prop from a Props type.
|
12
|
+
*
|
13
|
+
* For example:
|
14
|
+
* ```
|
15
|
+
* type Example<T> = T extends AsIntrinsicElement<infer As> ? As : never;
|
16
|
+
* ```
|
17
|
+
*/
|
18
|
+
declare type AsIntrinsicElement<As extends keyof JSX.IntrinsicElements> = {
|
19
|
+
as?: As;
|
20
|
+
};
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Verifies if an application can use DOM.
|
24
|
+
*/
|
25
|
+
export declare function canUseDOM(): boolean;
|
26
|
+
|
27
|
+
/**
|
28
|
+
* @internal
|
29
|
+
* Clamps `value` to a number between the min and max.
|
30
|
+
*
|
31
|
+
* @param value - the value to be clamped
|
32
|
+
* @param min - the lowest valid value
|
33
|
+
* @param max - the highest valid value
|
34
|
+
*/
|
35
|
+
export declare const clamp: (value: number, min: number, max: number) => number;
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Defines the Props type for a component given its slots and the definition of which one is the primary slot,
|
39
|
+
* defaulting to root if one is not provided.
|
40
|
+
*/
|
41
|
+
export declare type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> = Omit<Slots, Primary & 'root'> & PropsWithoutRef<ExtractSlotProps<Slots[Primary]>>;
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Defines the State object of a component given its slots.
|
45
|
+
*/
|
46
|
+
export declare type ComponentState<Slots extends SlotPropsRecord> = {
|
47
|
+
components: {
|
48
|
+
[Key in keyof Slots]-?: React_2.ComponentType<ExtractSlotProps<Slots[Key]>> | (ExtractSlotProps<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
|
49
|
+
};
|
50
|
+
} & {
|
51
|
+
[Key in keyof Slots]: ReplaceNullWithUndefined<Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>>;
|
52
|
+
};
|
53
|
+
|
54
|
+
/**
|
55
|
+
* HTML element types that are not allowed to have children.
|
56
|
+
*
|
57
|
+
* Reference: https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
|
58
|
+
*/
|
59
|
+
declare type EmptyIntrinsicElements = 'area' | 'base' | 'br' | 'col' | 'embed' | 'hr' | 'img' | 'input' | 'link' | 'meta' | 'param' | 'source' | 'track' | 'wbr';
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Removes SlotShorthandValue and null from the slot type, extracting just the slot's Props object.
|
63
|
+
*/
|
64
|
+
export declare type ExtractSlotProps<S> = Exclude<S, SlotShorthandValue | null | undefined>;
|
65
|
+
|
66
|
+
/**
|
67
|
+
* @internal
|
68
|
+
* Allows a component to be tagged as a FluentUI trigger component.
|
69
|
+
*
|
70
|
+
* Triggers are special-case components: they attach event listeners and other props on their child,
|
71
|
+
* and use them to trigger another component to show. Examples include `MenuTrigger` and `Tooltip`.
|
72
|
+
*
|
73
|
+
* A component can be tagged as a trigger as follows:
|
74
|
+
* ```ts
|
75
|
+
* const MyComponent: React.FC<MyComponentProps> & FluentTriggerComponent = ...;
|
76
|
+
*
|
77
|
+
* MyComponent.isFluentTriggerComponent = true; // MUST also set this to true
|
78
|
+
* ```
|
79
|
+
*/
|
80
|
+
export declare type FluentTriggerComponent = {
|
81
|
+
isFluentTriggerComponent?: boolean;
|
82
|
+
};
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Return type for `React.forwardRef`, including inference of the proper typing for the ref.
|
86
|
+
*/
|
87
|
+
export declare type ForwardRefComponent<Props> = ObscureEventName extends keyof Props ? Required<Props>[ObscureEventName] extends React_2.PointerEventHandler<infer Element> ? React_2.ForwardRefExoticComponent<Props & React_2.RefAttributes<Element>> : never : never;
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Returns an object with clientX, clientY for TouchOrMouseEvent.
|
91
|
+
* Returns zeros in case the event is not a mouse or a touch event.
|
92
|
+
*/
|
93
|
+
export declare function getEventClientCoords(event: TouchOrMouseEvent): {
|
94
|
+
clientX: number;
|
95
|
+
clientY: number;
|
96
|
+
};
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Given an element tagname and user props, filters the props to only allowed props for the given
|
100
|
+
* element type.
|
101
|
+
* @param tagName - Tag name (e.g. "div")
|
102
|
+
* @param props - Props object
|
103
|
+
* @param excludedPropNames - List of props to disallow
|
104
|
+
*/
|
105
|
+
export declare function getNativeElementProps<TAttributes extends React_2.HTMLAttributes<any>>(tagName: string, props: {}, excludedPropNames?: string[]): TAttributes;
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.
|
109
|
+
*
|
110
|
+
* This function is only for use with components that have a primary slot other than `root`.
|
111
|
+
* Most components should use {@link getNativeElementProps} for their root slot if it is the primary slot.
|
112
|
+
*
|
113
|
+
* @returns An object containing the native props for the `root` and primary slots.
|
114
|
+
*/
|
115
|
+
export declare const getPartitionedNativeProps: <Props extends Pick<React_2.HTMLAttributes<HTMLElement>, "style" | "className">, ExcludedPropKeys extends Extract<keyof Props, string> = never>({ primarySlotTagName, props, excludedPropNames, }: {
|
116
|
+
/** The primary slot's element type (e.g. 'div') */
|
117
|
+
primarySlotTagName: keyof JSX.IntrinsicElements;
|
118
|
+
/** The component's props object */
|
119
|
+
props: Props;
|
120
|
+
/** List of native props to exclude from the returned value */
|
121
|
+
excludedPropNames?: ExcludedPropKeys[] | undefined;
|
122
|
+
}) => {
|
123
|
+
root: {
|
124
|
+
style: React_2.CSSProperties | undefined;
|
125
|
+
className: string | undefined;
|
126
|
+
};
|
127
|
+
primary: Omit<Props, ExcludedPropKeys>;
|
128
|
+
};
|
129
|
+
|
130
|
+
/**
|
131
|
+
* @internal
|
132
|
+
* Finds and swaps a provided key for it's right to left format.
|
133
|
+
*/
|
134
|
+
export declare const getRTLSafeKey: (key: string, dir: 'ltr' | 'rtl') => string;
|
135
|
+
|
136
|
+
/**
|
137
|
+
* Given the state and an array of slot names, will break out `slots` and `slotProps`
|
138
|
+
* collections.
|
139
|
+
*
|
140
|
+
* The root is derived from a mix of `components` props and `as` prop.
|
141
|
+
*
|
142
|
+
* Slots will render as null if they are rendered as primitives with undefined children.
|
143
|
+
*
|
144
|
+
* The slotProps will always omit the `as` prop within them, and for slots that are string
|
145
|
+
* primitives, the props will be filtered according to the slot type by the type system.
|
146
|
+
* For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable
|
147
|
+
* anchor props. Note that this is only enforced at build time by Typescript -- there is no
|
148
|
+
* runtime code filtering props in this function.
|
149
|
+
*
|
150
|
+
* @param state - State including slot definitions
|
151
|
+
* @returns An object containing the `slots` map and `slotProps` map.
|
152
|
+
*/
|
153
|
+
export declare function getSlots<R extends SlotPropsRecord>(state: ComponentState<R>): {
|
154
|
+
slots: Slots<R>;
|
155
|
+
slotProps: ObjectSlotProps<R>;
|
156
|
+
};
|
157
|
+
|
158
|
+
/**
|
159
|
+
* Similar to `getSlots`, main difference is that it's compatible with new custom jsx pragma
|
160
|
+
*/
|
161
|
+
export declare function getSlotsNext<R extends SlotPropsRecord>(state: ComponentState<R>): {
|
162
|
+
slots: Slots<R>;
|
163
|
+
slotProps: ObjectSlotProps<R>;
|
164
|
+
};
|
165
|
+
|
166
|
+
/**
|
167
|
+
* @internal
|
168
|
+
* Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).
|
169
|
+
*
|
170
|
+
* In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,
|
171
|
+
* it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.
|
172
|
+
* This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.
|
173
|
+
*
|
174
|
+
* For example, the following returns `<div id="child" />`:
|
175
|
+
* ```jsx
|
176
|
+
* getTriggerChild(
|
177
|
+
* <Tooltip>
|
178
|
+
* <MenuTrigger>
|
179
|
+
* <div id="child" />
|
180
|
+
* </MenuTrigger>
|
181
|
+
* </Tooltip>
|
182
|
+
* );
|
183
|
+
* ```
|
184
|
+
*
|
185
|
+
* In the case where the immediate child is not a valid element,
|
186
|
+
* null is returned
|
187
|
+
*/
|
188
|
+
export declare function getTriggerChild<TriggerChildProps>(children: TriggerProps<TriggerChildProps>['children']): (React_2.ReactElement<Partial<TriggerChildProps>> & {
|
189
|
+
ref?: React_2.Ref<any>;
|
190
|
+
}) | null;
|
191
|
+
|
192
|
+
/**
|
193
|
+
* @internal
|
194
|
+
*/
|
195
|
+
declare type HTMLElementConstructorName = 'HTMLElement' | 'HTMLAnchorElement' | 'HTMLAreaElement' | 'HTMLAudioElement' | 'HTMLBaseElement' | 'HTMLBodyElement' | 'HTMLBRElement' | 'HTMLButtonElement' | 'HTMLCanvasElement' | 'HTMLDataElement' | 'HTMLDataListElement' | 'HTMLDetailsElement' | 'HTMLDialogElement' | 'HTMLDivElement' | 'HTMLDListElement' | 'HTMLEmbedElement' | 'HTMLFieldSetElement' | 'HTMLFormElement' | 'HTMLHeadingElement' | 'HTMLHeadElement' | 'HTMLHRElement' | 'HTMLHtmlElement' | 'HTMLIFrameElement' | 'HTMLImageElement' | 'HTMLInputElement' | 'HTMLModElement' | 'HTMLLabelElement' | 'HTMLLegendElement' | 'HTMLLIElement' | 'HTMLLinkElement' | 'HTMLMapElement' | 'HTMLMetaElement' | 'HTMLMeterElement' | 'HTMLObjectElement' | 'HTMLOListElement' | 'HTMLOptGroupElement' | 'HTMLOptionElement' | 'HTMLOutputElement' | 'HTMLParagraphElement' | 'HTMLParamElement' | 'HTMLPreElement' | 'HTMLProgressElement' | 'HTMLQuoteElement' | 'HTMLSlotElement' | 'HTMLScriptElement' | 'HTMLSelectElement' | 'HTMLSourceElement' | 'HTMLSpanElement' | 'HTMLStyleElement' | 'HTMLTableElement' | 'HTMLTableColElement' | 'HTMLTableRowElement' | 'HTMLTableSectionElement' | 'HTMLTemplateElement' | 'HTMLTextAreaElement' | 'HTMLTimeElement' | 'HTMLTitleElement' | 'HTMLTrackElement' | 'HTMLUListElement' | 'HTMLVideoElement';
|
196
|
+
|
197
|
+
/**
|
198
|
+
* Allows to define a prefix that will be used for all IDs generated by useId() hook. It's useful to avoid collisions
|
199
|
+
* between different bundles.
|
200
|
+
*/
|
201
|
+
export declare const IdPrefixProvider: React_2.Provider<string | undefined>;
|
202
|
+
|
203
|
+
/**
|
204
|
+
* Helper type for {@link Slot}. Modifies `JSX.IntrinsicElements[Type]`:
|
205
|
+
* * Removes legacy string ref.
|
206
|
+
* * Disallows children for empty tags like 'img'.
|
207
|
+
*/
|
208
|
+
declare type IntrinsicElementProps<Type extends keyof JSX.IntrinsicElements> = Type extends EmptyIntrinsicElements ? PropsWithoutChildren<React_2.PropsWithRef<JSX.IntrinsicElements[Type]>> : React_2.PropsWithRef<JSX.IntrinsicElements[Type]>;
|
209
|
+
|
210
|
+
/**
|
211
|
+
* @internal
|
212
|
+
* Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).
|
213
|
+
* See the {@link FluentTriggerComponent} type for more info.
|
214
|
+
*/
|
215
|
+
export declare function isFluentTrigger(element: React_2.ReactElement): element is React_2.ReactElement<TriggerProps>;
|
216
|
+
|
217
|
+
/**
|
218
|
+
* Verifies if a given node is an HTMLElement,
|
219
|
+
* this method works seamlessly with frames and elements from different documents
|
220
|
+
*
|
221
|
+
* This is preferred over simply using `instanceof`.
|
222
|
+
* Since `instanceof` might be problematic while operating with [multiple realms](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof#instanceof_and_multiple_realms)
|
223
|
+
*
|
224
|
+
* @example
|
225
|
+
* ```ts
|
226
|
+
* isHTMLElement(event.target) && event.target.focus()
|
227
|
+
* isHTMLElement(event.target, {constructorName: 'HTMLInputElement'}) && event.target.value // some value
|
228
|
+
* ```
|
229
|
+
*
|
230
|
+
*/
|
231
|
+
export declare function isHTMLElement<ConstructorName extends HTMLElementConstructorName = 'HTMLElement'>(element?: unknown, options?: {
|
232
|
+
/**
|
233
|
+
* Can be used to provide a custom constructor instead of `HTMLElement`,
|
234
|
+
* Like `HTMLInputElement` for example.
|
235
|
+
*/
|
236
|
+
constructorName?: ConstructorName;
|
237
|
+
}): element is InstanceType<(typeof globalThis)[ConstructorName]>;
|
238
|
+
|
239
|
+
/**
|
240
|
+
* @internal
|
241
|
+
* Checks that the element has default behaviour from user input on click or 'Enter'/'Space' keys
|
242
|
+
*/
|
243
|
+
export declare function isInteractiveHTMLElement(element: unknown): boolean;
|
244
|
+
|
245
|
+
/**
|
246
|
+
* Returns true if event is a mouse event. Useful when sharing logic between touch and mouse interactions.
|
247
|
+
*/
|
248
|
+
export declare function isMouseEvent(event: TouchOrMouseEvent): event is MouseEvent | React_2.MouseEvent;
|
249
|
+
|
250
|
+
/**
|
251
|
+
* Guard method that validates if a shorthand is a slot
|
252
|
+
* can be used to extends properties provided by a slot
|
253
|
+
*
|
254
|
+
* @example
|
255
|
+
* ```
|
256
|
+
* const backdropSlot = resolveShorthand(backdrop, {
|
257
|
+
* defaultProps: {
|
258
|
+
* onClick: useEventCallback(event => {
|
259
|
+
* if (isResolvedShorthand(backdrop)) {
|
260
|
+
* backdrop.onClick?.(event)
|
261
|
+
* }
|
262
|
+
* // do something after passing click down the line
|
263
|
+
* }),
|
264
|
+
* },
|
265
|
+
* })
|
266
|
+
* ```
|
267
|
+
* @example
|
268
|
+
* ```
|
269
|
+
* const handleBackDropClick = (event) => {
|
270
|
+
* // do your thing
|
271
|
+
* }
|
272
|
+
* const backdropSlot = resolveShorthand(backdrop, {
|
273
|
+
* defaultProps: {
|
274
|
+
* onClick: useEventCallback(
|
275
|
+
* mergeCallbacks(isResolvedShorthand(backdrop) ? backdrop.onClick : undefined, handleBackdropClick)
|
276
|
+
* )
|
277
|
+
* })
|
278
|
+
* ```
|
279
|
+
*/
|
280
|
+
export declare function isResolvedShorthand<Shorthand extends Slot<UnknownSlotProps>>(shorthand?: Shorthand): shorthand is ExtractSlotProps<Shorthand>;
|
281
|
+
|
282
|
+
/**
|
283
|
+
* Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.
|
284
|
+
*
|
285
|
+
* ```
|
286
|
+
* IsSingleton<'a'> // true
|
287
|
+
* IsSingleton<'a' | 'b' | 'c'> // false
|
288
|
+
* ```
|
289
|
+
*/
|
290
|
+
declare type IsSingleton<T extends string> = {
|
291
|
+
[K in T]: Exclude<T, K> extends never ? true : false;
|
292
|
+
}[T];
|
293
|
+
|
294
|
+
/**
|
295
|
+
* Returns true if event is a touch event. Useful when sharing logic between touch and mouse interactions.
|
296
|
+
*/
|
297
|
+
export declare function isTouchEvent(event: TouchOrMouseEvent): event is TouchEvent | React_2.TouchEvent;
|
298
|
+
|
299
|
+
/**
|
300
|
+
* @internal
|
301
|
+
* Combine two event callbacks into a single callback function that calls each one in order.
|
302
|
+
*
|
303
|
+
* Usage example:
|
304
|
+
* ```ts
|
305
|
+
* state.slot.onChange = mergeCallbacks(state.slot.onChange, ev => {
|
306
|
+
* // Handle onChange
|
307
|
+
* });
|
308
|
+
* ```
|
309
|
+
*
|
310
|
+
* The primary use is to avoid the need to capture an existing callback (`state.slot.onChange` in the example) to a
|
311
|
+
* local variable before replacing with a new listener that calls the existing one. This helps avoid bugs like:
|
312
|
+
* * Infinite recursion by calling the re-assigned state.slot.onChange if it's not captured to a local variable.
|
313
|
+
* * Missing a call to the original onChange due to an early return or other conditional.
|
314
|
+
*
|
315
|
+
* If you need a callback that is stable between renders, wrap the result in {@link useEventCallback}.
|
316
|
+
*
|
317
|
+
* @param callback1 - The first callback to be called, or undefined
|
318
|
+
* @param callback2 - The second callback to be called, or undefined
|
319
|
+
*
|
320
|
+
* @returns A function that that calls the provided functions in order
|
321
|
+
*/
|
322
|
+
export declare function mergeCallbacks<Args extends unknown[]>(callback1: ((...args: Args) => void) | undefined, callback2: ((...args: Args) => void) | undefined): (...args: Args) => void;
|
323
|
+
|
324
|
+
export declare type NativeTouchOrMouseEvent = MouseEvent | TouchEvent;
|
325
|
+
|
326
|
+
declare type ObjectSlotProps<S extends SlotPropsRecord> = {
|
327
|
+
[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 : ExtractSlotProps<S[K]>;
|
328
|
+
};
|
329
|
+
|
330
|
+
/**
|
331
|
+
* This is part of a hack to infer the element type from a native element *props* type.
|
332
|
+
* The only place the original element is found in a native props type (at least that's workable
|
333
|
+
* for inference) is in the event handlers, so some of the helper types use this event handler
|
334
|
+
* name to infer the original element type.
|
335
|
+
*
|
336
|
+
* Notes:
|
337
|
+
* - Using an extremely obscure event handler reduces the likelihood that its signature will be
|
338
|
+
* modified in any component's props.
|
339
|
+
* - Inferring based on a single prop name instead of a larger type like `DOMAttributes<T>` should be
|
340
|
+
* less expensive for typescript to evaluate and is less likely to result in type expansion in .d.ts.
|
341
|
+
*/
|
342
|
+
declare type ObscureEventName = 'onLostPointerCaptureCapture';
|
343
|
+
|
344
|
+
/**
|
345
|
+
* Tiny helper to do the minimal amount of work in duplicating an object but omitting some
|
346
|
+
* props. This ends up faster than using object ...rest or reduce to filter.
|
347
|
+
*
|
348
|
+
* This behaves very much like filteredAssign, but does not merge many objects together,
|
349
|
+
* uses an exclusion object map, and avoids spreads all for optimal performance.
|
350
|
+
*
|
351
|
+
* See perf test for background:
|
352
|
+
* https://jsperf.com/omit-vs-rest-vs-reduce/1
|
353
|
+
*
|
354
|
+
* @param obj - The object to clone
|
355
|
+
* @param exclusions - The array of keys to exclude
|
356
|
+
*/
|
357
|
+
export declare function omit<TObj extends Record<string, any>, Exclusions extends (keyof TObj)[]>(obj: TObj, exclusions: Exclusions): Omit<TObj, Exclusions[number]>;
|
358
|
+
|
359
|
+
/**
|
360
|
+
* Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
|
361
|
+
* IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
|
362
|
+
*
|
363
|
+
* The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional
|
364
|
+
* types, to prevent unions from being expanded.
|
365
|
+
*/
|
366
|
+
declare type PropsWithoutChildren<P> = 'children' extends keyof P ? (P extends unknown ? Omit<P, 'children'> : P) : P;
|
367
|
+
|
368
|
+
/**
|
369
|
+
* Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
|
370
|
+
* IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
|
371
|
+
*
|
372
|
+
* The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional
|
373
|
+
* types, to prevent unions from being expanded.
|
374
|
+
*/
|
375
|
+
declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;
|
376
|
+
|
377
|
+
export declare type ReactTouchOrMouseEvent = React_2.MouseEvent | React_2.TouchEvent;
|
378
|
+
|
379
|
+
/**
|
380
|
+
* A Ref function which can be treated like a ref object in that it has an attached
|
381
|
+
* current property, which will be updated as the ref is evaluated.
|
382
|
+
*/
|
383
|
+
export declare type RefObjectFunction<T> = React_2.RefObject<T> & ((value: T) => void);
|
384
|
+
|
385
|
+
/**
|
386
|
+
* If type T includes `null`, remove it and add `undefined` instead.
|
387
|
+
*/
|
388
|
+
declare type ReplaceNullWithUndefined<T> = T extends null ? Exclude<T, null> | undefined : T;
|
389
|
+
|
390
|
+
/**
|
391
|
+
* Resets generated IDs, should be used only in tests.
|
392
|
+
*/
|
393
|
+
export declare function resetIdsForTests(): void;
|
394
|
+
|
395
|
+
/**
|
396
|
+
* Resolves shorthands into slot props, to ensure normalization of the signature
|
397
|
+
* being passed down to getSlots method
|
398
|
+
* @param value - the base shorthand props
|
399
|
+
* @param options - options to resolve shorthand props
|
400
|
+
*/
|
401
|
+
export declare const resolveShorthand: ResolveShorthandFunction;
|
402
|
+
|
403
|
+
export declare type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {
|
404
|
+
<P extends Props>(value: P | SlotShorthandValue | undefined, options: ResolveShorthandOptions<P, true>): P;
|
405
|
+
<P extends Props>(value: P | SlotShorthandValue | null | undefined, options?: ResolveShorthandOptions<P, boolean>): P | undefined;
|
406
|
+
};
|
407
|
+
|
408
|
+
export declare type ResolveShorthandOptions<Props, Required extends boolean = false> = Required extends true ? {
|
409
|
+
required: true;
|
410
|
+
defaultProps?: Props;
|
411
|
+
} : {
|
412
|
+
required?: Required;
|
413
|
+
defaultProps?: Props;
|
414
|
+
};
|
415
|
+
|
416
|
+
/**
|
417
|
+
* The props type and shorthand value for a slot. Type is either a single intrinsic element like `'div'`,
|
418
|
+
* or a component like `typeof Button`.
|
419
|
+
*
|
420
|
+
* If a slot needs to support multiple intrinsic element types, use the `AlternateAs` param (see examples below).
|
421
|
+
*
|
422
|
+
* By default, slots can be set to `null` to prevent them from being rendered. If a slot must always be rendered,
|
423
|
+
* wrap with `NonNullable` (see examples below).
|
424
|
+
*
|
425
|
+
* @example
|
426
|
+
* ```
|
427
|
+
* // Intrinsic element examples:
|
428
|
+
* Slot<'div'> // Slot is always div
|
429
|
+
* Slot<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
|
430
|
+
* Slot<'span', 'div' | 'pre'> // Defaults to span, but allows as="div" or as="pre"
|
431
|
+
* NonNullable<Slot<'div'>> // Slot that will always be rendered (can't be set to null by the user)
|
432
|
+
*
|
433
|
+
* // Component examples:
|
434
|
+
* Slot<typeof Button> // Slot is always a Button, and accepts all of Button's Props
|
435
|
+
* NonNullable<Slot<typeof Label>> // Slot is a Label and will always be rendered (can't be set to null by the user)
|
436
|
+
* ```
|
437
|
+
*/
|
438
|
+
export declare type Slot<Type extends keyof JSX.IntrinsicElements | React_2.ComponentType | React_2.VoidFunctionComponent | UnknownSlotProps, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<Extract<Type, string>> extends true ? WithSlotShorthandValue<Type extends keyof JSX.IntrinsicElements ? {
|
439
|
+
as?: Type;
|
440
|
+
} & WithSlotRenderFunction<IntrinsicElementProps<Type>> : Type extends React_2.ComponentType<infer Props> ? WithSlotRenderFunction<Props> : Type> | {
|
441
|
+
[As in AlternateAs]: {
|
442
|
+
as: As;
|
443
|
+
} & WithSlotRenderFunction<IntrinsicElementProps<As>>;
|
444
|
+
}[AlternateAs] | null : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';
|
445
|
+
|
446
|
+
/**
|
447
|
+
* @internal
|
448
|
+
* Internal reference for the render function
|
449
|
+
*/
|
450
|
+
export declare const SLOT_RENDER_FUNCTION_SYMBOL: unique symbol;
|
451
|
+
|
452
|
+
/**
|
453
|
+
* Helper type to correctly define the slot class names object.
|
454
|
+
*/
|
455
|
+
export declare type SlotClassNames<Slots> = {
|
456
|
+
[SlotName in keyof Slots]-?: string;
|
457
|
+
};
|
458
|
+
|
459
|
+
/**
|
460
|
+
* Matches any component's Slots type (such as ButtonSlots).
|
461
|
+
*
|
462
|
+
* This should ONLY be used in type templates as in `extends SlotPropsRecord`;
|
463
|
+
* it shouldn't be used as a component's Slots type.
|
464
|
+
*/
|
465
|
+
export declare type SlotPropsRecord = Record<string, UnknownSlotProps | SlotShorthandValue | null | undefined>;
|
466
|
+
|
467
|
+
export declare type SlotRenderFunction<Props> = (Component: React_2.ElementType<Props>, props: Omit<Props, 'as'>) => React_2.ReactNode;
|
468
|
+
|
469
|
+
export declare type Slots<S extends SlotPropsRecord> = {
|
470
|
+
[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]>>;
|
471
|
+
};
|
472
|
+
|
473
|
+
/**
|
474
|
+
* The shorthand value of a slot allows specifying its child
|
475
|
+
*/
|
476
|
+
export declare type SlotShorthandValue = React_2.ReactChild | React_2.ReactNode[] | React_2.ReactPortal;
|
477
|
+
|
478
|
+
/**
|
479
|
+
* When using SSR with Fluent UI, applications must be wrapped in an SSRProvider. This ensures that auto generated ids
|
480
|
+
* are consistent between the client and server.
|
481
|
+
*
|
482
|
+
* @public
|
483
|
+
*/
|
484
|
+
export declare const SSRProvider: React_2.FC<{
|
485
|
+
children: React_2.ReactNode;
|
486
|
+
}>;
|
487
|
+
|
488
|
+
export declare type TouchOrMouseEvent = NativeTouchOrMouseEvent | ReactTouchOrMouseEvent;
|
489
|
+
|
490
|
+
/**
|
491
|
+
* A trigger may have a children that could be either:
|
492
|
+
* 1. A single element
|
493
|
+
* 2. A render function that will receive properties and must return a valid element or null
|
494
|
+
* 3. null or undefined
|
495
|
+
*/
|
496
|
+
export declare type TriggerProps<TriggerChildProps = unknown> = {
|
497
|
+
children?: React_2.ReactElement | ((props: TriggerChildProps) => React_2.ReactElement | null) | null;
|
498
|
+
};
|
499
|
+
|
500
|
+
/**
|
501
|
+
* Converts a union type (`A | B | C`) to an intersection type (`A & B & C`)
|
502
|
+
*/
|
503
|
+
declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;
|
504
|
+
|
505
|
+
/**
|
506
|
+
* Matches any slot props type.
|
507
|
+
*
|
508
|
+
* This should ONLY be used in type templates as in `extends UnknownSlotProps`;
|
509
|
+
* it shouldn't be used as the type of a slot.
|
510
|
+
*/
|
511
|
+
export declare type UnknownSlotProps = Pick<React_2.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
|
512
|
+
as?: keyof JSX.IntrinsicElements;
|
513
|
+
};
|
514
|
+
|
515
|
+
/**
|
516
|
+
* @internal
|
517
|
+
*
|
518
|
+
* A `useState`-like hook to manage a value that could be either controlled or uncontrolled,
|
519
|
+
* such as a checked state or text input string.
|
520
|
+
*
|
521
|
+
* Unlike `setState`, it's okay to call the returned updater (dispatch) function for either a
|
522
|
+
* controlled or uncontrolled component. Calls will only be respected if the component is uncontrolled.
|
523
|
+
*
|
524
|
+
* @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array
|
525
|
+
* of the current value and an updater (dispatch) function. The updater function is referentially
|
526
|
+
* stable (won't change during the component's lifecycle). It can take either a new value, or a
|
527
|
+
* function which is passed the previous value and returns the new value. Unlike `setState`, calls
|
528
|
+
* to the updater function will only be respected if the component is uncontrolled.
|
529
|
+
* @see https://reactjs.org/docs/uncontrolled-components.html
|
530
|
+
*/
|
531
|
+
export declare const useControllableState: <State>(options: UseControllableStateOptions<State>) => [State, React_2.Dispatch<React_2.SetStateAction<State>>];
|
532
|
+
|
533
|
+
/**
|
534
|
+
* @internal
|
535
|
+
*/
|
536
|
+
export declare type UseControllableStateOptions<State> = {
|
537
|
+
/**
|
538
|
+
* User-provided default state or initializer, for uncontrolled usage.
|
539
|
+
*/
|
540
|
+
defaultState?: State | (() => State);
|
541
|
+
/**
|
542
|
+
* User-provided controlled state. `undefined` means internal state will be used.
|
543
|
+
*/
|
544
|
+
state: State | undefined;
|
545
|
+
/**
|
546
|
+
* Used as the initial state if `state` and `defaultState` are both `undefined`.
|
547
|
+
* If `undefined` is the correct initial state, pass that here.
|
548
|
+
*/
|
549
|
+
initialState: State;
|
550
|
+
};
|
551
|
+
|
552
|
+
/**
|
553
|
+
* @internal
|
554
|
+
* https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
|
555
|
+
*
|
556
|
+
* Modified `useCallback` that can be used when dependencies change too frequently. Can occur when
|
557
|
+
* e.g. user props are dependencies which could change on every render
|
558
|
+
* e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently
|
559
|
+
*
|
560
|
+
* This should not be used often, but can be a useful re-render optimization since the callback is a ref and
|
561
|
+
* will not be invalidated between re-renders
|
562
|
+
*
|
563
|
+
* @param fn - The callback function that will be used
|
564
|
+
*/
|
565
|
+
export declare const useEventCallback: <Args extends unknown[], Return>(fn: (...args: Args) => Return) => (...args: Args) => Return;
|
566
|
+
|
567
|
+
/**
|
568
|
+
* @internal
|
569
|
+
* Checks if components was mounted the first time.
|
570
|
+
* Since concurrent mode will be released in the future this needs to be verified
|
571
|
+
* Currently (React 17) will always render the initial mount once
|
572
|
+
* https://codesandbox.io/s/heuristic-brook-s4w0q?file=/src/App.jsx
|
573
|
+
* https://codesandbox.io/s/holy-grass-8nieu?file=/src/App.jsx
|
574
|
+
*
|
575
|
+
* @example
|
576
|
+
* const isFirstMount = useFirstMount();
|
577
|
+
*/
|
578
|
+
export declare function useFirstMount(): boolean;
|
579
|
+
|
580
|
+
/**
|
581
|
+
* @internal
|
582
|
+
* Forces a re-render, similar to `forceUpdate` in class components.
|
583
|
+
*/
|
584
|
+
export declare function useForceUpdate(): DispatchWithoutAction;
|
585
|
+
|
586
|
+
/**
|
587
|
+
* Hook to generate a unique ID.
|
588
|
+
*
|
589
|
+
* @param prefix - Optional prefix for the ID. Defaults to 'fui-'.
|
590
|
+
* @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,
|
591
|
+
* without conditioning the hook call
|
592
|
+
* @returns The ID
|
593
|
+
*/
|
594
|
+
export declare function useId(prefix?: string, providedId?: string): string;
|
595
|
+
|
596
|
+
/**
|
597
|
+
* React currently throws a warning when using useLayoutEffect on the server. To get around it, we can conditionally
|
598
|
+
* useEffect on the server (no-op) and useLayoutEffect in the browser. We occasionally need useLayoutEffect to
|
599
|
+
* ensure we don't get a render flash for certain operations, but we may also need affected components to render on
|
600
|
+
* the server.
|
601
|
+
*
|
602
|
+
* https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
|
603
|
+
* https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js
|
604
|
+
*/
|
605
|
+
export declare const useIsomorphicLayoutEffect: typeof React_2.useEffect;
|
606
|
+
|
607
|
+
/**
|
608
|
+
* Returns whether the component is currently being server side rendered or hydrated on the client. Can be used to delay
|
609
|
+
* browser-specific rendering until after hydration. May cause re-renders on a client when is used within SSRProvider.
|
610
|
+
*/
|
611
|
+
export declare function useIsSSR(): boolean;
|
612
|
+
|
613
|
+
/**
|
614
|
+
* React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that
|
615
|
+
* updates all provided refs
|
616
|
+
* @param refs - Refs to collectively update with one ref value.
|
617
|
+
* @returns A function with an attached "current" prop, so that it can be treated like a RefObject.
|
618
|
+
*/
|
619
|
+
export declare function useMergedRefs<T>(...refs: (React_2.Ref<T> | undefined)[]): RefObjectFunction<T>;
|
620
|
+
|
621
|
+
/**
|
622
|
+
* @internal
|
623
|
+
*/
|
624
|
+
export declare type UseOnClickOrScrollOutsideOptions = {
|
625
|
+
/**
|
626
|
+
* The element to listen for the click event
|
627
|
+
*/
|
628
|
+
element: Document | undefined;
|
629
|
+
/**
|
630
|
+
* Refs to elements that check if the click is outside
|
631
|
+
*/
|
632
|
+
refs: React_2.MutableRefObject<HTMLElement | undefined | null>[];
|
633
|
+
/**
|
634
|
+
* By default uses element.contains, but custom contain function can be provided
|
635
|
+
*
|
636
|
+
* @param parent - provided parent element
|
637
|
+
* @param child - event target element
|
638
|
+
*/
|
639
|
+
contains?(parent: HTMLElement | null, child: HTMLElement): boolean;
|
640
|
+
/**
|
641
|
+
* Disables event listeners
|
642
|
+
*/
|
643
|
+
disabled?: boolean;
|
644
|
+
/**
|
645
|
+
* Called if the click is outside the element refs
|
646
|
+
*/
|
647
|
+
callback: (ev: MouseEvent | TouchEvent) => void;
|
648
|
+
};
|
649
|
+
|
650
|
+
/**
|
651
|
+
* @internal
|
652
|
+
* Utility to perform checks where a click/touch event was made outside a component
|
653
|
+
*/
|
654
|
+
export declare const useOnClickOutside: (options: UseOnClickOrScrollOutsideOptions) => void;
|
655
|
+
|
656
|
+
/**
|
657
|
+
* @internal
|
658
|
+
* Utility to perform checks where a click/touch event was made outside a component
|
659
|
+
*/
|
660
|
+
export declare const useOnScrollOutside: (options: UseOnClickOrScrollOutsideOptions) => void;
|
661
|
+
|
662
|
+
/**
|
663
|
+
* @internal
|
664
|
+
*/
|
665
|
+
export declare const usePrevious: <ValueType = unknown>(value: ValueType) => ValueType | null;
|
666
|
+
|
667
|
+
/**
|
668
|
+
* @returns The width in pixels of the scrollbar in the user agent
|
669
|
+
*/
|
670
|
+
export declare function useScrollbarWidth(options: UseScrollbarWidthOptions): number | undefined;
|
671
|
+
|
672
|
+
declare interface UseScrollbarWidthOptions {
|
673
|
+
/**
|
674
|
+
* Reference document to measure the scrollbar width
|
675
|
+
*/
|
676
|
+
targetDocument: Document | null | undefined;
|
677
|
+
/**
|
678
|
+
* Does not use the cache and recalculates the scrollbar width
|
679
|
+
*/
|
680
|
+
force?: boolean;
|
681
|
+
}
|
682
|
+
|
683
|
+
/**
|
684
|
+
* @internal
|
685
|
+
* Helper to manage a browser timeout.
|
686
|
+
* Ensures that the timeout isn't set multiple times at once,
|
687
|
+
* and is cleaned up when the component is unloaded.
|
688
|
+
*
|
689
|
+
* @returns A pair of [setTimeout, clearTimeout] that are stable between renders.
|
690
|
+
*/
|
691
|
+
export declare function useTimeout(): readonly [(fn: () => void, delay: number) => void, () => void];
|
692
|
+
|
693
|
+
/**
|
694
|
+
* Helper type for {@link Slot}. Takes the props we want to support for a slot and adds the ability for `children`
|
695
|
+
* to be a render function that takes those props.
|
696
|
+
*/
|
697
|
+
declare type WithSlotRenderFunction<Props> = Props & {
|
698
|
+
children?: (Props extends {
|
699
|
+
children?: unknown;
|
700
|
+
} ? Props['children'] : never) | SlotRenderFunction<Props>;
|
701
|
+
};
|
702
|
+
|
703
|
+
/**
|
704
|
+
* Helper type for {@link Slot}. Adds shorthand types that are assignable to the slot's `children`.
|
705
|
+
*/
|
706
|
+
declare type WithSlotShorthandValue<Props extends {
|
707
|
+
children?: unknown;
|
708
|
+
}> = Props | Extract<SlotShorthandValue, Props['children']>;
|
709
|
+
|
710
|
+
export { }
|