@fluentui/react-utilities 0.0.0-nightly8dfa71215620220118.1 → 0.0.0-nightly940de09b9520220131.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.
Files changed (34) hide show
  1. package/CHANGELOG.json +36 -6
  2. package/CHANGELOG.md +10 -6
  3. package/dist/react-utilities.d.ts +89 -47
  4. package/lib/compose/getSlots.d.ts +7 -7
  5. package/lib/compose/getSlots.js.map +1 -1
  6. package/lib/compose/resolveShorthand.d.ts +5 -5
  7. package/lib/compose/resolveShorthand.js +3 -3
  8. package/lib/compose/types.d.ts +47 -25
  9. package/lib/compose/types.js.map +1 -1
  10. package/lib/hooks/index.d.ts +1 -0
  11. package/lib/hooks/index.js +1 -0
  12. package/lib/hooks/index.js.map +1 -1
  13. package/lib/hooks/useTriggerElement.d.ts +18 -0
  14. package/lib/hooks/useTriggerElement.js +90 -0
  15. package/lib/hooks/useTriggerElement.js.map +1 -0
  16. package/lib/utils/getReactCallbackName.d.ts +25 -0
  17. package/lib/utils/getReactCallbackName.js +26 -0
  18. package/lib/utils/getReactCallbackName.js.map +1 -0
  19. package/lib-commonjs/compose/getSlots.d.ts +7 -7
  20. package/lib-commonjs/compose/getSlots.js.map +1 -1
  21. package/lib-commonjs/compose/resolveShorthand.d.ts +5 -5
  22. package/lib-commonjs/compose/resolveShorthand.js +3 -3
  23. package/lib-commonjs/compose/types.d.ts +47 -25
  24. package/lib-commonjs/compose/types.js.map +1 -1
  25. package/lib-commonjs/hooks/index.d.ts +1 -0
  26. package/lib-commonjs/hooks/index.js +2 -0
  27. package/lib-commonjs/hooks/index.js.map +1 -1
  28. package/lib-commonjs/hooks/useTriggerElement.d.ts +18 -0
  29. package/lib-commonjs/hooks/useTriggerElement.js +105 -0
  30. package/lib-commonjs/hooks/useTriggerElement.js.map +1 -0
  31. package/lib-commonjs/utils/getReactCallbackName.d.ts +25 -0
  32. package/lib-commonjs/utils/getReactCallbackName.js +35 -0
  33. package/lib-commonjs/utils/getReactCallbackName.js.map +1 -0
  34. package/package.json +2 -2
package/CHANGELOG.json CHANGED
@@ -2,23 +2,47 @@
2
2
  "name": "@fluentui/react-utilities",
3
3
  "entries": [
4
4
  {
5
- "date": "Tue, 18 Jan 2022 04:14:43 GMT",
6
- "tag": "@fluentui/react-utilities_v0.0.0-nightly8dfa71215620220118.1",
7
- "version": "0.0.0-nightly8dfa71215620220118.1",
5
+ "date": "Mon, 31 Jan 2022 04:16:03 GMT",
6
+ "tag": "@fluentui/react-utilities_v0.0.0-nightly940de09b9520220131.1",
7
+ "version": "0.0.0-nightly940de09b9520220131.1",
8
8
  "comments": {
9
9
  "prerelease": [
10
10
  {
11
11
  "author": "email not defined",
12
12
  "package": "@fluentui/react-utilities",
13
- "commit": "88cddfc0c80b8e37df557740279661f628c46698",
13
+ "commit": "7343cc2ca2eaca5e933abf6a8b8b57f910107cc4",
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
+ },
16
22
  {
17
23
  "author": "behowell@microsoft.com",
18
24
  "package": "@fluentui/react-utilities",
19
25
  "commit": "7cc28ed8320b00f42d91c63882f10316db2205c5",
20
26
  "comment": "getSlots: remove slotNames param, and infer from state.components instead"
21
27
  },
28
+ {
29
+ "author": "olfedias@microsoft.com",
30
+ "package": "@fluentui/react-utilities",
31
+ "commit": "d2eb57808a403b70845a732a62b55aa64d66b2a0",
32
+ "comment": "add useTriggerElement() hook"
33
+ },
34
+ {
35
+ "author": "Humberto.Morimoto@microsoft.com",
36
+ "package": "@fluentui/react-utilities",
37
+ "commit": "0bc161458eae5ae8d387172430496ce9829b1bb1",
38
+ "comment": "Adding ComponentSlotProps to allow ref to be passed in composite components."
39
+ },
40
+ {
41
+ "author": "Humberto.Morimoto@microsoft.com",
42
+ "package": "@fluentui/react-utilities",
43
+ "commit": "e0b8e1fa6980077e7b311fd1c72c28d3e4305db0",
44
+ "comment": "Renaming most *Shorthand* composition types to *SlotProps* so they better reflect what the types do."
45
+ },
22
46
  {
23
47
  "author": "elcraig@microsoft.com",
24
48
  "package": "@fluentui/react-utilities",
@@ -28,8 +52,8 @@
28
52
  {
29
53
  "author": "beachball",
30
54
  "package": "@fluentui/react-utilities",
31
- "comment": "Bump @fluentui/keyboard-keys to v0.0.0-nightly8dfa71215620220118.1",
32
- "commit": "88cddfc0c80b8e37df557740279661f628c46698"
55
+ "comment": "Bump @fluentui/keyboard-keys to v0.0.0-nightly940de09b9520220131.1",
56
+ "commit": "7343cc2ca2eaca5e933abf6a8b8b57f910107cc4"
33
57
  }
34
58
  ],
35
59
  "none": [
@@ -39,6 +63,12 @@
39
63
  "commit": "3360b45ec159250b1346c91afad7dce138e6bc20",
40
64
  "comment": "Update API file to version generated by typescript 4.3"
41
65
  },
66
+ {
67
+ "author": "olfedias@microsoft.com",
68
+ "package": "@fluentui/react-utilities",
69
+ "commit": "c061e98be4b4a718c72a144a1f60bb5515824612",
70
+ "comment": "remove inline-style-expand-shorthand from tsconfigs"
71
+ },
42
72
  {
43
73
  "author": "martinhochel@microsoft.com",
44
74
  "package": "@fluentui/react-utilities",
package/CHANGELOG.md CHANGED
@@ -1,20 +1,24 @@
1
1
  # Change Log - @fluentui/react-utilities
2
2
 
3
- This log was last generated on Tue, 18 Jan 2022 04:14:43 GMT and should not be manually modified.
3
+ This log was last generated on Mon, 31 Jan 2022 04:16:03 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## [0.0.0-nightly8dfa71215620220118.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v0.0.0-nightly8dfa71215620220118.1)
7
+ ## [0.0.0-nightly940de09b9520220131.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v0.0.0-nightly940de09b9520220131.1)
8
8
 
9
- Tue, 18 Jan 2022 04:14:43 GMT
10
- [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.0-beta.4..@fluentui/react-utilities_v0.0.0-nightly8dfa71215620220118.1)
9
+ Mon, 31 Jan 2022 04:16:03 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.0-beta.4..@fluentui/react-utilities_v0.0.0-nightly940de09b9520220131.1)
11
11
 
12
12
  ### Changes
13
13
 
14
- - Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/88cddfc0c80b8e37df557740279661f628c46698) by email not defined)
14
+ - Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/7343cc2ca2eaca5e933abf6a8b8b57f910107cc4) 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)
15
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
+ - 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)
19
+ - 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)
16
20
  - [breaking] Remove useControllableValue hook (use useControllableState instead) ([PR #20865](https://github.com/microsoft/fluentui/pull/20865) by elcraig@microsoft.com)
17
- - Bump @fluentui/keyboard-keys to v0.0.0-nightly8dfa71215620220118.1 ([commit](https://github.com/microsoft/fluentui/commit/88cddfc0c80b8e37df557740279661f628c46698) by beachball)
21
+ - Bump @fluentui/keyboard-keys to v0.0.0-nightly940de09b9520220131.1 ([commit](https://github.com/microsoft/fluentui/commit/7343cc2ca2eaca5e933abf6a8b8b57f910107cc4) by beachball)
18
22
 
19
23
  ## [9.0.0-beta.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.0.0-beta.4)
20
24
 
@@ -71,25 +71,39 @@ export declare const colGroupProperties: Record<string, number>;
71
71
 
72
72
  export declare const colProperties: Record<string, number>;
73
73
 
74
- export declare type ComponentProps<Shorthands extends ObjectShorthandPropsRecord, Primary extends keyof Shorthands = 'root'> = Omit<{
75
- [Key in keyof Shorthands]?: ShorthandProps<NonNullable<Shorthands[Key]>>;
76
- }, Primary & 'root'> & PropsWithoutRef<Shorthands[Primary]>;
77
-
78
- export declare type ComponentState<Shorthands extends ObjectShorthandPropsRecord> = {
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<{
79
+ [Key in keyof Slots]?: ShorthandProps<NonNullable<Slots[Key]>>;
80
+ }, Primary & 'root'> & PropsWithoutRef<Slots[Primary]>;
83
81
 
84
82
  /**
85
- * Matches any shorthand props type.
83
+ * Defines the slot props for a slot that supports a Component type.
86
84
  *
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.
85
+ * For intrinsic/native elements like 'div', use {@link IntrinsicSlotProps} instead.
86
+ *
87
+ * The generic param is the type of a control, i.e. a React component. For example:
88
+ *
89
+ * @example
90
+ * ```
91
+ * type Props = {...}
92
+ * const Button: React.FC<Props> = () => {...}
93
+ * // $ExpectType ...
94
+ * type SlotProps = ComponentSlotProps<typeof Button>
95
+ * ```
89
96
  */
90
- export declare type DefaultObjectShorthandProps = ObjectShorthandProps<Pick<React_2.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
91
- as?: keyof JSX.IntrinsicElements;
92
- }>;
97
+ export declare type ComponentSlotProps<Component extends React_2.ComponentType> = Component extends React_2.ComponentType<infer Props> ? SlotProps<Props> : never;
98
+
99
+ /**
100
+ * Defines the State object of a component given its slots.
101
+ */
102
+ export declare type ComponentState<Slots extends SlotPropsRecord> = {
103
+ components: {
104
+ [Key in keyof Slots]-?: React_2.ComponentType<NonNullable<Slots[Key]> extends SlotProps<infer P> ? P : NonNullable<Slots[Key]>> | (NonNullable<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
105
+ };
106
+ } & Slots;
93
107
 
94
108
  /**
95
109
  * Default context value to use in case there is no SSRProvider. This is fine for client-only apps.
@@ -187,9 +201,9 @@ export declare const getRTLSafeKey: (key: string, dir: 'ltr' | 'rtl') => string;
187
201
  * @param state - State including slot definitions
188
202
  * @returns An object containing the `slots` map and `slotProps` map.
189
203
  */
190
- export declare function getSlots<R extends ObjectShorthandPropsRecord>(state: ComponentState<R>): {
204
+ export declare function getSlots<R extends SlotPropsRecord>(state: ComponentState<R>): {
191
205
  slots: Slots<R>;
192
- slotProps: SlotProps<R>;
206
+ slotProps: ObjectSlotProps<R>;
193
207
  };
194
208
 
195
209
  /**
@@ -227,23 +241,23 @@ export declare const inputProperties: Record<string, number>;
227
241
 
228
242
  /**
229
243
  * Define the slot arguments for a slot that supports one or more intrinsic element types, such as 'div'.
230
- * For slots that support custom components, use {@link ObjectShorthandProps} instead.
244
+ * For slots that support custom components, use {@link ComponentSlotProps} instead.
231
245
  *
232
246
  * The first param is the slot's default type if no `as` prop is specified.
233
247
  * The second param is an optional union of alternative types that can be specified for the `as` prop.
234
248
  *
235
249
  * ```
236
- * IntrinsicShorthandProps<'div'> // Slot is always div
237
- * IntrinsicShorthandProps<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
238
- * IntrinsicShorthandProps<'label', 'span' | 'div'>; // Defaults to label, but allows as="span" or as="div"
250
+ * IntrinsicSlotProps<'div'> // Slot is always div
251
+ * IntrinsicSlotProps<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
252
+ * IntrinsicSlotProps<'label', 'span' | 'div'>; // Defaults to label, but allows as="span" or as="div"
239
253
  * ```
240
254
  */
241
- export declare type IntrinsicShorthandProps<DefaultAs extends keyof JSX.IntrinsicElements, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<DefaultAs> extends false ? 'Error: first parameter to IntrinsicShorthandProps must be a single element type, not a union of types' : ({
255
+ export declare type IntrinsicSlotProps<DefaultAs extends keyof JSX.IntrinsicElements, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<DefaultAs> extends false ? 'Error: first parameter to IntrinsicSlotProps must be a single element type, not a union of types' : ({
242
256
  as?: DefaultAs;
243
- } & ObjectShorthandProps<React_2.PropsWithRef<JSX.IntrinsicElements[DefaultAs]>>) | {
257
+ } & SlotProps<React_2.PropsWithRef<JSX.IntrinsicElements[DefaultAs]>>) | {
244
258
  [As in AlternateAs]: {
245
259
  as: As;
246
- } & ObjectShorthandProps<React_2.PropsWithRef<JSX.IntrinsicElements[As]>>;
260
+ } & SlotProps<React_2.PropsWithRef<JSX.IntrinsicElements[As]>>;
247
261
  }[AlternateAs];
248
262
 
249
263
  /**
@@ -277,19 +291,10 @@ export declare const liProperties: Record<string, number>;
277
291
  */
278
292
  export declare const nullRender: () => null;
279
293
 
280
- /**
281
- * Defines the slot props for a slot that supports a Component type.
282
- *
283
- * For intrinsic elements like 'div', use {@link IntrinsicShorthandProps} instead.
284
- */
285
- export declare type ObjectShorthandProps<Props extends {
286
- children?: React_2.ReactNode;
287
- } = {}> = Props & {
288
- children?: Props['children'] | ShorthandRenderFunction<Props>;
294
+ declare type ObjectSlotProps<S extends SlotPropsRecord> = {
295
+ [K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : NonNullable<S[K]> extends SlotProps<infer P> ? P : never;
289
296
  };
290
297
 
291
- export declare type ObjectShorthandPropsRecord = Record<string, DefaultObjectShorthandProps | undefined>;
292
-
293
298
  /**
294
299
  * This is part of a hack to infer the element type from a native element *props* type.
295
300
  * The only place the original element is found in a native props type (at least that's workable
@@ -335,7 +340,7 @@ export declare const optionProperties: Record<string, number>;
335
340
 
336
341
  /**
337
342
  * Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
338
- * IntrinsicShorthandProps). This allows IntrinsicShorthandProps to be used with React.forwardRef.
343
+ * IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
339
344
  *
340
345
  * The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional
341
346
  * types, to prevent unions from being expanded.
@@ -356,12 +361,12 @@ export declare type RefObjectFunction<T> = React_2.RefObject<T> & ((value: T) =>
356
361
  export declare function resetIdsForTests(): void;
357
362
 
358
363
  /**
359
- * Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
364
+ * Resolves shorthands into slot props, to ensure normalization of the signature
360
365
  * being passed down to getSlots method
361
- * @param value - the base ShorthandProps
362
- * @param options - options to resolve ShorthandProps
366
+ * @param value - the base shorthand props
367
+ * @param options - options to resolve shorthand props
363
368
  */
364
- export declare function resolveShorthand<Props extends DefaultObjectShorthandProps, Required extends boolean = false>(value: ShorthandProps<Props>, options?: ResolveShorthandOptions<Props, Required>): Required extends false ? Props | undefined : Props;
369
+ export declare function resolveShorthand<Props extends UnknownSlotProps, Required extends boolean = false>(value: ShorthandProps<Props>, options?: ResolveShorthandOptions<Props, Required>): Required extends false ? Props | undefined : Props;
365
370
 
366
371
  export declare type ResolveShorthandOptions<Props extends Record<string, any>, Required extends boolean = false> = {
367
372
  required?: Required;
@@ -375,9 +380,7 @@ export declare type ResolveShorthandOptions<Props extends Record<string, any>, R
375
380
  */
376
381
  export declare const selectProperties: Record<string, number>;
377
382
 
378
- export declare type ShorthandProps<Props extends DefaultObjectShorthandProps> = React_2.ReactChild | React_2.ReactNodeArray | React_2.ReactPortal | number | null | undefined | Props;
379
-
380
- export declare type ShorthandRenderFunction<Props> = (Component: React_2.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React_2.ReactNode;
383
+ export declare type ShorthandProps<Props extends UnknownSlotProps> = React_2.ReactChild | React_2.ReactNodeArray | React_2.ReactPortal | number | null | undefined | Props;
381
384
 
382
385
  /**
383
386
  * Checks if the keyboard event should preventDefault() for Enter and Spacebar keys
@@ -386,12 +389,22 @@ export declare type ShorthandRenderFunction<Props> = (Component: React_2.Element
386
389
  */
387
390
  export declare function shouldPreventDefaultOnKeyDown(e: KeyboardEvent | React_2.KeyboardEvent): boolean;
388
391
 
389
- declare type SlotProps<S extends ObjectShorthandPropsRecord> = {
390
- [K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : NonNullable<S[K]> extends ObjectShorthandProps<infer P> ? P : never;
392
+ /**
393
+ * Takes the props we want to support for a slot and adds the ability for `children` to be a render function that takes
394
+ * those props.
395
+ */
396
+ export declare type SlotProps<Props extends {
397
+ children?: React_2.ReactNode;
398
+ } = {}> = Props & {
399
+ children?: Props['children'] | SlotRenderFunction<Props>;
391
400
  };
392
401
 
393
- export declare type Slots<S extends ObjectShorthandPropsRecord> = {
394
- [K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? As : S[K] extends ObjectShorthandProps<infer P> ? React_2.ElementType<NonNullable<P>> : React_2.ElementType<NonNullable<S[K]>>;
402
+ export declare type SlotPropsRecord = Record<string, UnknownSlotProps | undefined>;
403
+
404
+ export declare type SlotRenderFunction<Props> = (Component: React_2.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React_2.ReactNode;
405
+
406
+ export declare type Slots<S extends SlotPropsRecord> = {
407
+ [K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? As : S[K] extends SlotProps<infer P> ? React_2.ElementType<NonNullable<P>> : React_2.ElementType<NonNullable<S[K]>>;
395
408
  };
396
409
 
397
410
  export declare const SSRContext: React_2.Context<SSRContextValue>;
@@ -454,6 +467,16 @@ export declare const trProperties: Record<string, number>;
454
467
  */
455
468
  export declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;
456
469
 
470
+ /**
471
+ * Matches any slot props type.
472
+ *
473
+ * This should ONLY be used in type templates as in `extends DefaultObjectSlotProps`;
474
+ * it shouldn't be used as the type of a slot.
475
+ */
476
+ export declare type UnknownSlotProps = SlotProps<Pick<React_2.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
477
+ as?: keyof JSX.IntrinsicElements;
478
+ }>;
479
+
457
480
  /**
458
481
  * Hook to store a value and generate callbacks for setting the value to true or false.
459
482
  * The identity of the callbacks will always stay the same.
@@ -642,6 +665,25 @@ export declare function useSSRContext(): SSRContextValue;
642
665
  */
643
666
  export declare function useTimeout(): readonly [(fn: () => void, delay: number) => void, () => void];
644
667
 
668
+ /**
669
+ * A hook that handles "trigger" pattern.
670
+ *
671
+ * Clones a passed element or calls render props. Merges props including refs and callbacks, callbacks are kept stable
672
+ * by reference.
673
+ */
674
+ export declare function useTriggerElement<TriggerProps extends React_2.HTMLProps<unknown>>(options: UseTriggerElementOptions<TriggerProps>): React_2.ReactNode;
675
+
676
+ export declare type UseTriggerElementOptions<TriggerProps> = {
677
+ /** An actual trigger element or render props function. */
678
+ children: React_2.ReactElement | ((props: TriggerProps) => React_2.ReactNode) | null | undefined;
679
+ /** A ref to trigger element. */
680
+ ref: React_2.Ref<unknown> | undefined;
681
+ /** Props that are passed to a parent component and should be forwarded down. */
682
+ outerProps: React_2.HTMLProps<unknown>;
683
+ /** Custom props including callbacks. */
684
+ overrideProps: TriggerProps;
685
+ };
686
+
645
687
  /**
646
688
  * Hook which synchronously executes a callback when the component is about to unmount.
647
689
  *
@@ -1,10 +1,10 @@
1
1
  import * as React from 'react';
2
- import { AsIntrinsicElement, ComponentState, ObjectShorthandPropsRecord, ObjectShorthandProps, UnionToIntersection } from './types';
3
- export declare type Slots<S extends ObjectShorthandPropsRecord> = {
4
- [K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? As : S[K] extends ObjectShorthandProps<infer P> ? React.ElementType<NonNullable<P>> : React.ElementType<NonNullable<S[K]>>;
2
+ import type { AsIntrinsicElement, ComponentState, SlotProps, SlotPropsRecord, UnionToIntersection } from './types';
3
+ export declare type Slots<S extends SlotPropsRecord> = {
4
+ [K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? As : S[K] extends SlotProps<infer P> ? React.ElementType<NonNullable<P>> : React.ElementType<NonNullable<S[K]>>;
5
5
  };
6
- declare type SlotProps<S extends ObjectShorthandPropsRecord> = {
7
- [K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : NonNullable<S[K]> extends ObjectShorthandProps<infer P> ? P : never;
6
+ declare type ObjectSlotProps<S extends SlotPropsRecord> = {
7
+ [K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : NonNullable<S[K]> extends SlotProps<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`
@@ -23,8 +23,8 @@ declare type SlotProps<S extends ObjectShorthandPropsRecord> = {
23
23
  * @param state - State including slot definitions
24
24
  * @returns An object containing the `slots` map and `slotProps` map.
25
25
  */
26
- export declare function getSlots<R extends ObjectShorthandPropsRecord>(state: ComponentState<R>): {
26
+ export declare function getSlots<R extends SlotPropsRecord>(state: ComponentState<R>): {
27
27
  slots: Slots<R>;
28
- slotProps: SlotProps<R>;
28
+ slotProps: ObjectSlotProps<R>;
29
29
  };
30
30
  export {};
@@ -1 +1 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AA,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":""}
@@ -1,12 +1,12 @@
1
- import type { DefaultObjectShorthandProps, ShorthandProps } from './types';
1
+ import type { UnknownSlotProps, ShorthandProps } from './types';
2
2
  export declare type ResolveShorthandOptions<Props extends Record<string, any>, Required extends boolean = false> = {
3
3
  required?: Required;
4
4
  defaultProps?: Props;
5
5
  };
6
6
  /**
7
- * Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
7
+ * Resolves shorthands into slot props, to ensure normalization of the signature
8
8
  * being passed down to getSlots method
9
- * @param value - the base ShorthandProps
10
- * @param options - options to resolve ShorthandProps
9
+ * @param value - the base shorthand props
10
+ * @param options - options to resolve shorthand props
11
11
  */
12
- export declare function resolveShorthand<Props extends DefaultObjectShorthandProps, Required extends boolean = false>(value: ShorthandProps<Props>, options?: ResolveShorthandOptions<Props, Required>): Required extends false ? Props | undefined : Props;
12
+ export declare function resolveShorthand<Props extends UnknownSlotProps, Required extends boolean = false>(value: ShorthandProps<Props>, options?: ResolveShorthandOptions<Props, Required>): Required extends false ? Props | undefined : Props;
@@ -1,9 +1,9 @@
1
1
  import { isValidElement } from 'react';
2
2
  /**
3
- * Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
3
+ * Resolves shorthands into slot props, to ensure normalization of the signature
4
4
  * being passed down to getSlots method
5
- * @param value - the base ShorthandProps
6
- * @param options - options to resolve ShorthandProps
5
+ * @param value - the base shorthand props
6
+ * @param options - options to resolve shorthand props
7
7
  */
8
8
 
9
9
  export function resolveShorthand(value, options) {
@@ -1,45 +1,60 @@
1
1
  import * as React from 'react';
2
- export declare type ShorthandRenderFunction<Props> = (Component: React.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React.ReactNode;
3
- export declare type ObjectShorthandPropsRecord = Record<string, DefaultObjectShorthandProps | undefined>;
4
- export declare type ShorthandProps<Props extends DefaultObjectShorthandProps> = React.ReactChild | React.ReactNodeArray | React.ReactPortal | number | null | undefined | Props;
2
+ export declare type SlotRenderFunction<Props> = (Component: React.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React.ReactNode;
3
+ export declare type SlotPropsRecord = Record<string, UnknownSlotProps | undefined>;
4
+ export declare type ShorthandProps<Props extends UnknownSlotProps> = React.ReactChild | React.ReactNodeArray | React.ReactPortal | number | null | undefined | Props;
5
5
  /**
6
- * Matches any shorthand props type.
6
+ * Matches any slot props type.
7
7
  *
8
- * This should ONLY be used in type templates as in `extends DefaultObjectShorthandProps`;
8
+ * This should ONLY be used in type templates as in `extends DefaultObjectSlotProps`;
9
9
  * it shouldn't be used as the type of a slot.
10
10
  */
11
- export declare type DefaultObjectShorthandProps = ObjectShorthandProps<Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
11
+ export declare type UnknownSlotProps = SlotProps<Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
12
12
  as?: keyof JSX.IntrinsicElements;
13
13
  }>;
14
14
  /**
15
- * Defines the slot props for a slot that supports a Component type.
16
- *
17
- * For intrinsic elements like 'div', use {@link IntrinsicShorthandProps} instead.
15
+ * Takes the props we want to support for a slot and adds the ability for `children` to be a render function that takes
16
+ * those props.
18
17
  */
19
- export declare type ObjectShorthandProps<Props extends {
18
+ export declare type SlotProps<Props extends {
20
19
  children?: React.ReactNode;
21
20
  } = {}> = Props & {
22
- children?: Props['children'] | ShorthandRenderFunction<Props>;
21
+ children?: Props['children'] | SlotRenderFunction<Props>;
23
22
  };
23
+ /**
24
+ * Defines the slot props for a slot that supports a Component type.
25
+ *
26
+ * For intrinsic/native elements like 'div', use {@link IntrinsicSlotProps} instead.
27
+ *
28
+ * The generic param is the type of a control, i.e. a React component. For example:
29
+ *
30
+ * @example
31
+ * ```
32
+ * type Props = {...}
33
+ * const Button: React.FC<Props> = () => {...}
34
+ * // $ExpectType ...
35
+ * type SlotProps = ComponentSlotProps<typeof Button>
36
+ * ```
37
+ */
38
+ export declare type ComponentSlotProps<Component extends React.ComponentType> = Component extends React.ComponentType<infer Props> ? SlotProps<Props> : never;
24
39
  /**
25
40
  * Define the slot arguments for a slot that supports one or more intrinsic element types, such as 'div'.
26
- * For slots that support custom components, use {@link ObjectShorthandProps} instead.
41
+ * For slots that support custom components, use {@link ComponentSlotProps} instead.
27
42
  *
28
43
  * The first param is the slot's default type if no `as` prop is specified.
29
44
  * The second param is an optional union of alternative types that can be specified for the `as` prop.
30
45
  *
31
46
  * ```
32
- * IntrinsicShorthandProps<'div'> // Slot is always div
33
- * IntrinsicShorthandProps<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
34
- * IntrinsicShorthandProps<'label', 'span' | 'div'>; // Defaults to label, but allows as="span" or as="div"
47
+ * IntrinsicSlotProps<'div'> // Slot is always div
48
+ * IntrinsicSlotProps<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
49
+ * IntrinsicSlotProps<'label', 'span' | 'div'>; // Defaults to label, but allows as="span" or as="div"
35
50
  * ```
36
51
  */
37
- export declare type IntrinsicShorthandProps<DefaultAs extends keyof JSX.IntrinsicElements, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<DefaultAs> extends false ? 'Error: first parameter to IntrinsicShorthandProps must be a single element type, not a union of types' : ({
52
+ export declare type IntrinsicSlotProps<DefaultAs extends keyof JSX.IntrinsicElements, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<DefaultAs> extends false ? 'Error: first parameter to IntrinsicSlotProps must be a single element type, not a union of types' : ({
38
53
  as?: DefaultAs;
39
- } & ObjectShorthandProps<React.PropsWithRef<JSX.IntrinsicElements[DefaultAs]>>) | {
54
+ } & SlotProps<React.PropsWithRef<JSX.IntrinsicElements[DefaultAs]>>) | {
40
55
  [As in AlternateAs]: {
41
56
  as: As;
42
- } & ObjectShorthandProps<React.PropsWithRef<JSX.IntrinsicElements[As]>>;
57
+ } & SlotProps<React.PropsWithRef<JSX.IntrinsicElements[As]>>;
43
58
  }[AlternateAs];
44
59
  /**
45
60
  * Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.
@@ -69,20 +84,27 @@ export declare type AsIntrinsicElement<As extends keyof JSX.IntrinsicElements> =
69
84
  export declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;
70
85
  /**
71
86
  * Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
72
- * IntrinsicShorthandProps). This allows IntrinsicShorthandProps to be used with React.forwardRef.
87
+ * IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
73
88
  *
74
89
  * The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional
75
90
  * types, to prevent unions from being expanded.
76
91
  */
77
92
  export declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;
78
- export declare type ComponentProps<Shorthands extends ObjectShorthandPropsRecord, Primary extends keyof Shorthands = 'root'> = Omit<{
79
- [Key in keyof Shorthands]?: ShorthandProps<NonNullable<Shorthands[Key]>>;
80
- }, Primary & 'root'> & PropsWithoutRef<Shorthands[Primary]>;
81
- export declare type ComponentState<Shorthands extends ObjectShorthandPropsRecord> = {
93
+ /**
94
+ * Defines the Props type for a component given its slots and the definition of which one is the primary slot,
95
+ * defaulting to root if one is not provided.
96
+ */
97
+ export declare type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> = Omit<{
98
+ [Key in keyof Slots]?: ShorthandProps<NonNullable<Slots[Key]>>;
99
+ }, Primary & 'root'> & PropsWithoutRef<Slots[Primary]>;
100
+ /**
101
+ * Defines the State object of a component given its slots.
102
+ */
103
+ export declare type ComponentState<Slots extends SlotPropsRecord> = {
82
104
  components: {
83
- [Key in keyof Shorthands]-?: React.ComponentType<NonNullable<Shorthands[Key]> extends ObjectShorthandProps<infer P> ? P : NonNullable<Shorthands[Key]>> | (NonNullable<Shorthands[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
105
+ [Key in keyof Slots]-?: React.ComponentType<NonNullable<Slots[Key]> extends SlotProps<infer P> ? P : NonNullable<Slots[Key]>> | (NonNullable<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
84
106
  };
85
- } & Shorthands;
107
+ } & Slots;
86
108
  /**
87
109
  * This is part of a hack to infer the element type from a native element *props* type.
88
110
  * The only place the original element is found in a native props type (at least that's workable
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/compose/types.ts"],"names":[],"mappings":"WAgJA;AACA;AACA;AACA;AACA","sourceRoot":""}
1
+ {"version":3,"sources":["../../src/compose/types.ts"],"names":[],"mappings":"WAyKA;AACA;AACA;AACA;AACA","sourceRoot":""}
@@ -11,5 +11,6 @@ export * from './useOnClickOutside';
11
11
  export * from './useOnScrollOutside';
12
12
  export * from './usePrevious';
13
13
  export * from './useTimeout';
14
+ export * from './useTriggerElement';
14
15
  export * from './useUnmount';
15
16
  export * from './useForceUpdate';
@@ -11,6 +11,7 @@ export * from './useOnClickOutside';
11
11
  export * from './useOnScrollOutside';
12
12
  export * from './usePrevious';
13
13
  export * from './useTimeout';
14
+ export * from './useTriggerElement';
14
15
  export * from './useUnmount';
15
16
  export * from './useForceUpdate';
16
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,18 @@
1
+ import * as React from 'react';
2
+ export declare type UseTriggerElementOptions<TriggerProps> = {
3
+ /** An actual trigger element or render props function. */
4
+ children: React.ReactElement | ((props: TriggerProps) => React.ReactNode) | null | undefined;
5
+ /** A ref to trigger element. */
6
+ ref: React.Ref<unknown> | undefined;
7
+ /** Props that are passed to a parent component and should be forwarded down. */
8
+ outerProps: React.HTMLProps<unknown>;
9
+ /** Custom props including callbacks. */
10
+ overrideProps: TriggerProps;
11
+ };
12
+ /**
13
+ * A hook that handles "trigger" pattern.
14
+ *
15
+ * Clones a passed element or calls render props. Merges props including refs and callbacks, callbacks are kept stable
16
+ * by reference.
17
+ */
18
+ export declare function useTriggerElement<TriggerProps extends React.HTMLProps<unknown>>(options: UseTriggerElementOptions<TriggerProps>): React.ReactNode;
@@ -0,0 +1,90 @@
1
+ import * as React from 'react';
2
+ import { applyTriggerPropsToChildren } from '../utils/applyTriggerPropsToChildren';
3
+ import { getReactCallbackName } from '../utils/getReactCallbackName';
4
+ import { onlyChild } from '../utils/onlyChild';
5
+ import { useEventCallback } from './useEventCallback';
6
+ import { useMergedRefs } from './useMergedRefs';
7
+ const CAPTURE_CALLBACK_REGEX = /on[A-Z].+Capture$/;
8
+ const CALLBACK_REGEX = /on[A-Z].+/;
9
+ /**
10
+ * A hook that handles "trigger" pattern.
11
+ *
12
+ * Clones a passed element or calls render props. Merges props including refs and callbacks, callbacks are kept stable
13
+ * by reference.
14
+ */
15
+
16
+ export function useTriggerElement(options) {
17
+ const {
18
+ children,
19
+ ref,
20
+ outerProps,
21
+ overrideProps
22
+ } = options;
23
+ let childProps = {};
24
+ let childRef = null; // child can be a render func, `applyTriggerPropsToChildren`does the same check again
25
+ // TODO figure out a way to only do this check once
26
+
27
+ if ( /*#__PURE__*/React.isValidElement(children)) {
28
+ const child = onlyChild(children);
29
+ childProps = child.props;
30
+ childRef = child.ref;
31
+ } // Two separate callbacks are needed to handle properly bubble and capture callbacks
32
+ // "getReactCallbackName()" could return proper callback name, but it's possible only with React 17
33
+
34
+
35
+ const handleBubbleEvent = useEventCallback(ev => {
36
+ var _a, _b, _c;
37
+
38
+ const callbackName = getReactCallbackName(ev);
39
+
40
+ if (callbackName) {
41
+ // Typecast is required as "ev" is "React.SyntheticEvent" while callbacks have stricter typings and accept
42
+ // "FocusEvent", "ClipboardEvent" and etc.
43
+
44
+ /* eslint-disable @typescript-eslint/no-explicit-any */
45
+ (_a = childProps[callbackName]) === null || _a === void 0 ? void 0 : _a.call(childProps, ev);
46
+ (_b = overrideProps[callbackName]) === null || _b === void 0 ? void 0 : _b.call(overrideProps, ev);
47
+ (_c = outerProps[callbackName]) === null || _c === void 0 ? void 0 : _c.call(outerProps, ev);
48
+ /* eslint-enable @typescript-eslint/no-explicit-any */
49
+ }
50
+ });
51
+ const handleCaptureEvent = useEventCallback(ev => {
52
+ var _a, _b, _c;
53
+
54
+ const callbackName = getReactCallbackName(ev) + 'Capture';
55
+
56
+ if (callbackName) {
57
+ // Typecast is required as "ev" is "React.SyntheticEvent" while callbacks have stricter typings and accept
58
+ // "FocusEvent", "ClipboardEvent" and etc.
59
+
60
+ /* eslint-disable @typescript-eslint/no-explicit-any */
61
+ (_a = childProps[callbackName]) === null || _a === void 0 ? void 0 : _a.call(childProps, ev);
62
+ (_b = overrideProps[callbackName]) === null || _b === void 0 ? void 0 : _b.call(overrideProps, ev);
63
+ (_c = outerProps[callbackName]) === null || _c === void 0 ? void 0 : _c.call(outerProps, ev);
64
+ /* eslint-enable @typescript-eslint/no-explicit-any */
65
+ }
66
+ });
67
+ const mergedPropEntries = Object.entries({ ...outerProps,
68
+ ...overrideProps,
69
+ ...childProps,
70
+ // Undocumented, but React supports ref cloning through props
71
+ ref: useMergedRefs(childRef, ref)
72
+ }); // TODO: fix me after https://github.com/microsoft/fluentui/issues/21229
73
+ // Causes TS error:
74
+ // "Property 'fromEntries' does not exist on type 'ObjectConstructor'"
75
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
+
77
+ const triggerProps = Object.fromEntries(mergedPropEntries.map(([propName, propValue]) => {
78
+ if (propName.match(CAPTURE_CALLBACK_REGEX)) {
79
+ return [propName, handleCaptureEvent];
80
+ }
81
+
82
+ if (propName.match(CALLBACK_REGEX)) {
83
+ return [propName, handleBubbleEvent];
84
+ }
85
+
86
+ return [propName, propValue];
87
+ }));
88
+ return applyTriggerPropsToChildren(children, triggerProps);
89
+ }
90
+ //# sourceMappingURL=useTriggerElement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/useTriggerElement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA,SAAS,2BAAT,QAA4C,sCAA5C;AACA,SAAS,oBAAT,QAAqC,+BAArC;AACA,SAAS,SAAT,QAA0B,oB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X,CAAP;AACD;;AAED,QAAI,QAAQ,CAAC,KAAT,CAAe,cAAf,CAAJ,EAAoC;AAClC,aAAO,CAAC,QAAD,EAAW,iBAAX,CAAP;AACD;;AAED,WAAO,CAAC,QAAD,EAAW,SAAX,CAAP;AACD,GAVD,CADoB,CAAtB;AAcA,SAAO,2BAA2B,CAAC,QAAD,EAAW,YAAX,CAAlC;AACD","sourceRoot":""}
@@ -0,0 +1,25 @@
1
+ import * as React from 'react';
2
+ interface ReactSyntheticEvent extends React.SyntheticEvent<unknown> {
3
+ _reactName?: string;
4
+ dispatchConfig?: {
5
+ registrationName: string;
6
+ phasedRegistrationNames: {
7
+ bubbled: string;
8
+ captured: string;
9
+ };
10
+ };
11
+ }
12
+ declare type NonUndefined<A> = A extends undefined ? never : A;
13
+ declare type FunctionKeys<T extends object> = {
14
+ [K in keyof T]-?: NonUndefined<T[K]> extends Function ? K : never;
15
+ }[keyof T];
16
+ export declare type ReactCallbackName = FunctionKeys<React.DOMAttributes<unknown>>;
17
+ /**
18
+ * React.SyntheticEvent contains name of a callback that should be fired, this function returns it.
19
+ *
20
+ * Ideally, it should also distinguish regular and "capture" callbacks, but it's possible only with React 17 as
21
+ * ".eventPhase" there has proper value, see https://github.com/facebook/react/pull/19244. In React 16 all events
22
+ * are handled in bubble phase.
23
+ */
24
+ export declare function getReactCallbackName(event: ReactSyntheticEvent): ReactCallbackName | undefined;
25
+ export {};
@@ -0,0 +1,26 @@
1
+ /**
2
+ * React.SyntheticEvent contains name of a callback that should be fired, this function returns it.
3
+ *
4
+ * Ideally, it should also distinguish regular and "capture" callbacks, but it's possible only with React 17 as
5
+ * ".eventPhase" there has proper value, see https://github.com/facebook/react/pull/19244. In React 16 all events
6
+ * are handled in bubble phase.
7
+ */
8
+ export function getReactCallbackName(event) {
9
+ if (event._reactName) {
10
+ return event._reactName;
11
+ }
12
+
13
+ if (event.dispatchConfig) {
14
+ if (event.dispatchConfig.registrationName) {
15
+ return event.dispatchConfig.registrationName;
16
+ }
17
+
18
+ return event.dispatchConfig.phasedRegistrationNames.bubbled;
19
+ }
20
+
21
+ if (process.env.NODE_ENV !== 'production') {
22
+ // eslint-disable-next-line no-console
23
+ console.error(['Passed React.SyntheticEvent does not contain ".dispatchConfig" or "._reactName".', 'This should not happen, please report it to https://github.com/microsoft/fluentui']);
24
+ }
25
+ }
26
+ //# sourceMappingURL=getReactCallbackName.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/getReactCallbackName.ts"],"names":[],"mappings":"AAwBA;;;;;;AAMG;AACH,OAAM,SAAU,oBAAV,CAA+B,KAA/B,EAAyD;AAC7D,MAAI,KAAK,CAAC,UAAV,EAAsB;AACpB,WAAO,KAAK,CAAC,UAAb;AACD;;AAED,MAAI,KAAK,CAAC,cAAV,EAA0B;AACxB,QAAI,KAAK,CAAC,cAAN,CAAqB,gBAAzB,EAA2C;AACzC,aAAO,KAAK,CAAC,cAAN,CAAqB,gBAA5B;AACD;;AAED,WAAO,KAAK,CAAC,cAAN,CAAqB,uBAArB,CAA6C,OAApD;AACD;;AAED,MAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;AACA,IAAA,OAAO,CAAC,KAAR,CAAc,CACZ,kFADY,EAEZ,mFAFY,CAAd;AAID;AACF","sourceRoot":""}
@@ -1,10 +1,10 @@
1
1
  import * as React from 'react';
2
- import { AsIntrinsicElement, ComponentState, ObjectShorthandPropsRecord, ObjectShorthandProps, UnionToIntersection } from './types';
3
- export declare type Slots<S extends ObjectShorthandPropsRecord> = {
4
- [K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? As : S[K] extends ObjectShorthandProps<infer P> ? React.ElementType<NonNullable<P>> : React.ElementType<NonNullable<S[K]>>;
2
+ import type { AsIntrinsicElement, ComponentState, SlotProps, SlotPropsRecord, UnionToIntersection } from './types';
3
+ export declare type Slots<S extends SlotPropsRecord> = {
4
+ [K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? As : S[K] extends SlotProps<infer P> ? React.ElementType<NonNullable<P>> : React.ElementType<NonNullable<S[K]>>;
5
5
  };
6
- declare type SlotProps<S extends ObjectShorthandPropsRecord> = {
7
- [K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : NonNullable<S[K]> extends ObjectShorthandProps<infer P> ? P : never;
6
+ declare type ObjectSlotProps<S extends SlotPropsRecord> = {
7
+ [K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : NonNullable<S[K]> extends SlotProps<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`
@@ -23,8 +23,8 @@ declare type SlotProps<S extends ObjectShorthandPropsRecord> = {
23
23
  * @param state - State including slot definitions
24
24
  * @returns An object containing the `slots` map and `slotProps` map.
25
25
  */
26
- export declare function getSlots<R extends ObjectShorthandPropsRecord>(state: ComponentState<R>): {
26
+ export declare function getSlots<R extends SlotPropsRecord>(state: ComponentState<R>): {
27
27
  slots: Slots<R>;
28
- slotProps: SlotProps<R>;
28
+ slotProps: ObjectSlotProps<R>;
29
29
  };
30
30
  export {};
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/compose/getSlots.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AAUA,MAAA,YAAA,gBAAA,OAAA,CAAA,cAAA,CAAA;;AACA,MAAA,MAAA,gBAAA,OAAA,CAAA,eAAA,CAAA;AAqBA;;;;;;;;;;;;;;;;AAgBG;;;AACH,SAAgB,QAAhB,CACE,KADF,EAC0B;AAKxB,QAAM,KAAK,GAAG,EAAd;AACA,QAAM,SAAS,GAAG,EAAlB;AAEA,QAAM,SAAS,GAAgB,MAAM,CAAC,IAAP,CAAY,KAAK,CAAC,UAAlB,CAA/B;;AACA,OA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AAC,QAAD,CAA5E;AAEA,SAAO,CAAC,IAAD,EAAO,SAAP,CAAP;AACD","sourceRoot":""}
@@ -1,12 +1,12 @@
1
- import type { DefaultObjectShorthandProps, ShorthandProps } from './types';
1
+ import type { UnknownSlotProps, ShorthandProps } from './types';
2
2
  export declare type ResolveShorthandOptions<Props extends Record<string, any>, Required extends boolean = false> = {
3
3
  required?: Required;
4
4
  defaultProps?: Props;
5
5
  };
6
6
  /**
7
- * Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
7
+ * Resolves shorthands into slot props, to ensure normalization of the signature
8
8
  * being passed down to getSlots method
9
- * @param value - the base ShorthandProps
10
- * @param options - options to resolve ShorthandProps
9
+ * @param value - the base shorthand props
10
+ * @param options - options to resolve shorthand props
11
11
  */
12
- export declare function resolveShorthand<Props extends DefaultObjectShorthandProps, Required extends boolean = false>(value: ShorthandProps<Props>, options?: ResolveShorthandOptions<Props, Required>): Required extends false ? Props | undefined : Props;
12
+ export declare function resolveShorthand<Props extends UnknownSlotProps, Required extends boolean = false>(value: ShorthandProps<Props>, options?: ResolveShorthandOptions<Props, Required>): Required extends false ? Props | undefined : Props;
@@ -7,10 +7,10 @@ exports.resolveShorthand = void 0;
7
7
 
8
8
  const react_1 = /*#__PURE__*/require("react");
9
9
  /**
10
- * Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
10
+ * Resolves shorthands into slot props, to ensure normalization of the signature
11
11
  * being passed down to getSlots method
12
- * @param value - the base ShorthandProps
13
- * @param options - options to resolve ShorthandProps
12
+ * @param value - the base shorthand props
13
+ * @param options - options to resolve shorthand props
14
14
  */
15
15
 
16
16
 
@@ -1,45 +1,60 @@
1
1
  import * as React from 'react';
2
- export declare type ShorthandRenderFunction<Props> = (Component: React.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React.ReactNode;
3
- export declare type ObjectShorthandPropsRecord = Record<string, DefaultObjectShorthandProps | undefined>;
4
- export declare type ShorthandProps<Props extends DefaultObjectShorthandProps> = React.ReactChild | React.ReactNodeArray | React.ReactPortal | number | null | undefined | Props;
2
+ export declare type SlotRenderFunction<Props> = (Component: React.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React.ReactNode;
3
+ export declare type SlotPropsRecord = Record<string, UnknownSlotProps | undefined>;
4
+ export declare type ShorthandProps<Props extends UnknownSlotProps> = React.ReactChild | React.ReactNodeArray | React.ReactPortal | number | null | undefined | Props;
5
5
  /**
6
- * Matches any shorthand props type.
6
+ * Matches any slot props type.
7
7
  *
8
- * This should ONLY be used in type templates as in `extends DefaultObjectShorthandProps`;
8
+ * This should ONLY be used in type templates as in `extends DefaultObjectSlotProps`;
9
9
  * it shouldn't be used as the type of a slot.
10
10
  */
11
- export declare type DefaultObjectShorthandProps = ObjectShorthandProps<Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
11
+ export declare type UnknownSlotProps = SlotProps<Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
12
12
  as?: keyof JSX.IntrinsicElements;
13
13
  }>;
14
14
  /**
15
- * Defines the slot props for a slot that supports a Component type.
16
- *
17
- * For intrinsic elements like 'div', use {@link IntrinsicShorthandProps} instead.
15
+ * Takes the props we want to support for a slot and adds the ability for `children` to be a render function that takes
16
+ * those props.
18
17
  */
19
- export declare type ObjectShorthandProps<Props extends {
18
+ export declare type SlotProps<Props extends {
20
19
  children?: React.ReactNode;
21
20
  } = {}> = Props & {
22
- children?: Props['children'] | ShorthandRenderFunction<Props>;
21
+ children?: Props['children'] | SlotRenderFunction<Props>;
23
22
  };
23
+ /**
24
+ * Defines the slot props for a slot that supports a Component type.
25
+ *
26
+ * For intrinsic/native elements like 'div', use {@link IntrinsicSlotProps} instead.
27
+ *
28
+ * The generic param is the type of a control, i.e. a React component. For example:
29
+ *
30
+ * @example
31
+ * ```
32
+ * type Props = {...}
33
+ * const Button: React.FC<Props> = () => {...}
34
+ * // $ExpectType ...
35
+ * type SlotProps = ComponentSlotProps<typeof Button>
36
+ * ```
37
+ */
38
+ export declare type ComponentSlotProps<Component extends React.ComponentType> = Component extends React.ComponentType<infer Props> ? SlotProps<Props> : never;
24
39
  /**
25
40
  * Define the slot arguments for a slot that supports one or more intrinsic element types, such as 'div'.
26
- * For slots that support custom components, use {@link ObjectShorthandProps} instead.
41
+ * For slots that support custom components, use {@link ComponentSlotProps} instead.
27
42
  *
28
43
  * The first param is the slot's default type if no `as` prop is specified.
29
44
  * The second param is an optional union of alternative types that can be specified for the `as` prop.
30
45
  *
31
46
  * ```
32
- * IntrinsicShorthandProps<'div'> // Slot is always div
33
- * IntrinsicShorthandProps<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
34
- * IntrinsicShorthandProps<'label', 'span' | 'div'>; // Defaults to label, but allows as="span" or as="div"
47
+ * IntrinsicSlotProps<'div'> // Slot is always div
48
+ * IntrinsicSlotProps<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
49
+ * IntrinsicSlotProps<'label', 'span' | 'div'>; // Defaults to label, but allows as="span" or as="div"
35
50
  * ```
36
51
  */
37
- export declare type IntrinsicShorthandProps<DefaultAs extends keyof JSX.IntrinsicElements, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<DefaultAs> extends false ? 'Error: first parameter to IntrinsicShorthandProps must be a single element type, not a union of types' : ({
52
+ export declare type IntrinsicSlotProps<DefaultAs extends keyof JSX.IntrinsicElements, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<DefaultAs> extends false ? 'Error: first parameter to IntrinsicSlotProps must be a single element type, not a union of types' : ({
38
53
  as?: DefaultAs;
39
- } & ObjectShorthandProps<React.PropsWithRef<JSX.IntrinsicElements[DefaultAs]>>) | {
54
+ } & SlotProps<React.PropsWithRef<JSX.IntrinsicElements[DefaultAs]>>) | {
40
55
  [As in AlternateAs]: {
41
56
  as: As;
42
- } & ObjectShorthandProps<React.PropsWithRef<JSX.IntrinsicElements[As]>>;
57
+ } & SlotProps<React.PropsWithRef<JSX.IntrinsicElements[As]>>;
43
58
  }[AlternateAs];
44
59
  /**
45
60
  * Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.
@@ -69,20 +84,27 @@ export declare type AsIntrinsicElement<As extends keyof JSX.IntrinsicElements> =
69
84
  export declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;
70
85
  /**
71
86
  * Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
72
- * IntrinsicShorthandProps). This allows IntrinsicShorthandProps to be used with React.forwardRef.
87
+ * IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
73
88
  *
74
89
  * The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional
75
90
  * types, to prevent unions from being expanded.
76
91
  */
77
92
  export declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;
78
- export declare type ComponentProps<Shorthands extends ObjectShorthandPropsRecord, Primary extends keyof Shorthands = 'root'> = Omit<{
79
- [Key in keyof Shorthands]?: ShorthandProps<NonNullable<Shorthands[Key]>>;
80
- }, Primary & 'root'> & PropsWithoutRef<Shorthands[Primary]>;
81
- export declare type ComponentState<Shorthands extends ObjectShorthandPropsRecord> = {
93
+ /**
94
+ * Defines the Props type for a component given its slots and the definition of which one is the primary slot,
95
+ * defaulting to root if one is not provided.
96
+ */
97
+ export declare type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> = Omit<{
98
+ [Key in keyof Slots]?: ShorthandProps<NonNullable<Slots[Key]>>;
99
+ }, Primary & 'root'> & PropsWithoutRef<Slots[Primary]>;
100
+ /**
101
+ * Defines the State object of a component given its slots.
102
+ */
103
+ export declare type ComponentState<Slots extends SlotPropsRecord> = {
82
104
  components: {
83
- [Key in keyof Shorthands]-?: React.ComponentType<NonNullable<Shorthands[Key]> extends ObjectShorthandProps<infer P> ? P : NonNullable<Shorthands[Key]>> | (NonNullable<Shorthands[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
105
+ [Key in keyof Slots]-?: React.ComponentType<NonNullable<Slots[Key]> extends SlotProps<infer P> ? P : NonNullable<Slots[Key]>> | (NonNullable<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
84
106
  };
85
- } & Shorthands;
107
+ } & Slots;
86
108
  /**
87
109
  * This is part of a hack to infer the element type from a native element *props* type.
88
110
  * The only place the original element is found in a native props type (at least that's workable
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/compose/types.ts"],"names":[],"mappings":";;;;IAgJA;AACA;AACA;AACA;AACA","sourceRoot":""}
1
+ {"version":3,"sources":["../../src/compose/types.ts"],"names":[],"mappings":";;;;IAyKA;AACA;AACA;AACA;AACA","sourceRoot":""}
@@ -11,5 +11,6 @@ export * from './useOnClickOutside';
11
11
  export * from './useOnScrollOutside';
12
12
  export * from './usePrevious';
13
13
  export * from './useTimeout';
14
+ export * from './useTriggerElement';
14
15
  export * from './useUnmount';
15
16
  export * from './useForceUpdate';
@@ -32,6 +32,8 @@ tslib_1.__exportStar(require("./usePrevious"), exports);
32
32
 
33
33
  tslib_1.__exportStar(require("./useTimeout"), exports);
34
34
 
35
+ tslib_1.__exportStar(require("./useTriggerElement"), exports);
36
+
35
37
  tslib_1.__exportStar(require("./useUnmount"), exports);
36
38
 
37
39
  tslib_1.__exportStar(require("./useForceUpdate"), exports);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,wBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,YAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,oBAAA,CAAA,EAAA,OAAA;;AACA,OA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CAAA,6BAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,YAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,qBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,sBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,eAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,qBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,kBAAA,CAAA,EAAA,OAAA","sourceRoot":""}
@@ -0,0 +1,18 @@
1
+ import * as React from 'react';
2
+ export declare type UseTriggerElementOptions<TriggerProps> = {
3
+ /** An actual trigger element or render props function. */
4
+ children: React.ReactElement | ((props: TriggerProps) => React.ReactNode) | null | undefined;
5
+ /** A ref to trigger element. */
6
+ ref: React.Ref<unknown> | undefined;
7
+ /** Props that are passed to a parent component and should be forwarded down. */
8
+ outerProps: React.HTMLProps<unknown>;
9
+ /** Custom props including callbacks. */
10
+ overrideProps: TriggerProps;
11
+ };
12
+ /**
13
+ * A hook that handles "trigger" pattern.
14
+ *
15
+ * Clones a passed element or calls render props. Merges props including refs and callbacks, callbacks are kept stable
16
+ * by reference.
17
+ */
18
+ export declare function useTriggerElement<TriggerProps extends React.HTMLProps<unknown>>(options: UseTriggerElementOptions<TriggerProps>): React.ReactNode;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useTriggerElement = void 0;
7
+
8
+ const React = /*#__PURE__*/require("react");
9
+
10
+ const applyTriggerPropsToChildren_1 = /*#__PURE__*/require("../utils/applyTriggerPropsToChildren");
11
+
12
+ const getReactCallbackName_1 = /*#__PURE__*/require("../utils/getReactCallbackName");
13
+
14
+ const onlyChild_1 = /*#__PURE__*/require("../utils/onlyChild");
15
+
16
+ const useEventCallback_1 = /*#__PURE__*/require("./useEventCallback");
17
+
18
+ const useMergedRefs_1 = /*#__PURE__*/require("./useMergedRefs");
19
+
20
+ const CAPTURE_CALLBACK_REGEX = /on[A-Z].+Capture$/;
21
+ const CALLBACK_REGEX = /on[A-Z].+/;
22
+ /**
23
+ * A hook that handles "trigger" pattern.
24
+ *
25
+ * Clones a passed element or calls render props. Merges props including refs and callbacks, callbacks are kept stable
26
+ * by reference.
27
+ */
28
+
29
+ function useTriggerElement(options) {
30
+ const {
31
+ children,
32
+ ref,
33
+ outerProps,
34
+ overrideProps
35
+ } = options;
36
+ let childProps = {};
37
+ let childRef = null; // child can be a render func, `applyTriggerPropsToChildren`does the same check again
38
+ // TODO figure out a way to only do this check once
39
+
40
+ if (React.isValidElement(children)) {
41
+ const child = onlyChild_1.onlyChild(children);
42
+ childProps = child.props;
43
+ childRef = child.ref;
44
+ } // Two separate callbacks are needed to handle properly bubble and capture callbacks
45
+ // "getReactCallbackName()" could return proper callback name, but it's possible only with React 17
46
+
47
+
48
+ const handleBubbleEvent = useEventCallback_1.useEventCallback(ev => {
49
+ var _a, _b, _c;
50
+
51
+ const callbackName = getReactCallbackName_1.getReactCallbackName(ev);
52
+
53
+ if (callbackName) {
54
+ // Typecast is required as "ev" is "React.SyntheticEvent" while callbacks have stricter typings and accept
55
+ // "FocusEvent", "ClipboardEvent" and etc.
56
+
57
+ /* eslint-disable @typescript-eslint/no-explicit-any */
58
+ (_a = childProps[callbackName]) === null || _a === void 0 ? void 0 : _a.call(childProps, ev);
59
+ (_b = overrideProps[callbackName]) === null || _b === void 0 ? void 0 : _b.call(overrideProps, ev);
60
+ (_c = outerProps[callbackName]) === null || _c === void 0 ? void 0 : _c.call(outerProps, ev);
61
+ /* eslint-enable @typescript-eslint/no-explicit-any */
62
+ }
63
+ });
64
+ const handleCaptureEvent = useEventCallback_1.useEventCallback(ev => {
65
+ var _a, _b, _c;
66
+
67
+ const callbackName = getReactCallbackName_1.getReactCallbackName(ev) + 'Capture';
68
+
69
+ if (callbackName) {
70
+ // Typecast is required as "ev" is "React.SyntheticEvent" while callbacks have stricter typings and accept
71
+ // "FocusEvent", "ClipboardEvent" and etc.
72
+
73
+ /* eslint-disable @typescript-eslint/no-explicit-any */
74
+ (_a = childProps[callbackName]) === null || _a === void 0 ? void 0 : _a.call(childProps, ev);
75
+ (_b = overrideProps[callbackName]) === null || _b === void 0 ? void 0 : _b.call(overrideProps, ev);
76
+ (_c = outerProps[callbackName]) === null || _c === void 0 ? void 0 : _c.call(outerProps, ev);
77
+ /* eslint-enable @typescript-eslint/no-explicit-any */
78
+ }
79
+ });
80
+ const mergedPropEntries = Object.entries({ ...outerProps,
81
+ ...overrideProps,
82
+ ...childProps,
83
+ // Undocumented, but React supports ref cloning through props
84
+ ref: useMergedRefs_1.useMergedRefs(childRef, ref)
85
+ }); // TODO: fix me after https://github.com/microsoft/fluentui/issues/21229
86
+ // Causes TS error:
87
+ // "Property 'fromEntries' does not exist on type 'ObjectConstructor'"
88
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
+
90
+ const triggerProps = Object.fromEntries(mergedPropEntries.map(([propName, propValue]) => {
91
+ if (propName.match(CAPTURE_CALLBACK_REGEX)) {
92
+ return [propName, handleCaptureEvent];
93
+ }
94
+
95
+ if (propName.match(CALLBACK_REGEX)) {
96
+ return [propName, handleBubbleEvent];
97
+ }
98
+
99
+ return [propName, propValue];
100
+ }));
101
+ return applyTriggerPropsToChildren_1.applyTriggerPropsToChildren(children, triggerProps);
102
+ }
103
+
104
+ exports.useTriggerElement = useTriggerElement;
105
+ //# sourceMappingURL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GAAG,UADoC;AAEvC,OAAG,aAFoC;AAGvC,OAAG,UAHoC;AAIvC;AACA,IAAA,GAAG,EAAE,eAAA,CAAA,aAAA,CAAc,QAAd,EAAwB,GAAxB;AALkC,GAAf,CAA1B,CA9C+C,CAsD/C;AACA;AACA;AACA;;AACA,QAAM,YAAY,GAAI,MAAc,CAAC,WAAf,CACpB,iBAAiB,CAAC,GAAlB,CAAsB,CAAC,CAAC,QAAD,EAAW,SAAX,CAAD,KAA0B;AAC9C,QAAI,QAAQ,CAAC,KAAT,CAAe,sBAAf,CAAJ,EAA4C;AAC1C,aAAO,CAAC,QAAD,EAAW,kBAAX,CAAP;AACD;;AAED,QAAI,QAAQ,CAAC,KAAT,CAAe,cAAf,CAAJ,EAAoC;AAClC,aAAO,CAAC,QAAD,EAAW,iBAAX,CAAP;AACD;;AAED,WAAO,CAAC,QAAD,EAAW,SAAX,CAAP;AACD,GAVD,CADoB,CAAtB;AAcA,SAAO,6BAAA,CAAA,2BAAA,CAA4B,QAA5B,EAAsC,YAAtC,CAAP;AACD;;AA1ED,OAAA,CAAA,iBAAA,GAAA,iBAAA","sourceRoot":""}
@@ -0,0 +1,25 @@
1
+ import * as React from 'react';
2
+ interface ReactSyntheticEvent extends React.SyntheticEvent<unknown> {
3
+ _reactName?: string;
4
+ dispatchConfig?: {
5
+ registrationName: string;
6
+ phasedRegistrationNames: {
7
+ bubbled: string;
8
+ captured: string;
9
+ };
10
+ };
11
+ }
12
+ declare type NonUndefined<A> = A extends undefined ? never : A;
13
+ declare type FunctionKeys<T extends object> = {
14
+ [K in keyof T]-?: NonUndefined<T[K]> extends Function ? K : never;
15
+ }[keyof T];
16
+ export declare type ReactCallbackName = FunctionKeys<React.DOMAttributes<unknown>>;
17
+ /**
18
+ * React.SyntheticEvent contains name of a callback that should be fired, this function returns it.
19
+ *
20
+ * Ideally, it should also distinguish regular and "capture" callbacks, but it's possible only with React 17 as
21
+ * ".eventPhase" there has proper value, see https://github.com/facebook/react/pull/19244. In React 16 all events
22
+ * are handled in bubble phase.
23
+ */
24
+ export declare function getReactCallbackName(event: ReactSyntheticEvent): ReactCallbackName | undefined;
25
+ export {};
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getReactCallbackName = void 0;
7
+ /**
8
+ * React.SyntheticEvent contains name of a callback that should be fired, this function returns it.
9
+ *
10
+ * Ideally, it should also distinguish regular and "capture" callbacks, but it's possible only with React 17 as
11
+ * ".eventPhase" there has proper value, see https://github.com/facebook/react/pull/19244. In React 16 all events
12
+ * are handled in bubble phase.
13
+ */
14
+
15
+ function getReactCallbackName(event) {
16
+ if (event._reactName) {
17
+ return event._reactName;
18
+ }
19
+
20
+ if (event.dispatchConfig) {
21
+ if (event.dispatchConfig.registrationName) {
22
+ return event.dispatchConfig.registrationName;
23
+ }
24
+
25
+ return event.dispatchConfig.phasedRegistrationNames.bubbled;
26
+ }
27
+
28
+ if (process.env.NODE_ENV !== 'production') {
29
+ // eslint-disable-next-line no-console
30
+ console.error(['Passed React.SyntheticEvent does not contain ".dispatchConfig" or "._reactName".', 'This should not happen, please report it to https://github.com/microsoft/fluentui']);
31
+ }
32
+ }
33
+
34
+ exports.getReactCallbackName = getReactCallbackName;
35
+ //# sourceMappingURL=getReactCallbackName.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/getReactCallbackName.ts"],"names":[],"mappings":";;;;;;AAwBA;;;;;;AAMG;;AACH,SAAgB,oBAAhB,CAAqC,KAArC,EAA+D;AAC7D,MAAI,KAAK,CAAC,UAAV,EAAsB;AACpB,WAAO,KAAK,CAAC,UAAb;AACD;;AAED,MAAI,KAAK,CAAC,cAAV,EAA0B;AACxB,QAAI,KAAK,CAAC,cAAN,CAAqB,gBAAzB,EAA2C;AACzC,aAAO,KAAK,CAAC,cAAN,CAAqB,gBAA5B;AACD;;AAED,WAAO,KAAK,CAAC,cAAN,CAAqB,uBAArB,CAA6C,OAApD;AACD;;AAED,MAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;AACA,IAAA,OAAO,CAAC,KAAR,CAAc,CACZ,kFADY,EAEZ,mFAFY,CAAd;AAID;AACF;;AApBD,OAAA,CAAA,oBAAA,GAAA,oBAAA","sourceRoot":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-utilities",
3
- "version": "0.0.0-nightly8dfa71215620220118.1",
3
+ "version": "0.0.0-nightly940de09b9520220131.1",
4
4
  "description": "A set of general React-specific utilities.",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -33,7 +33,7 @@
33
33
  "react-test-renderer": "^16.3.0"
34
34
  },
35
35
  "dependencies": {
36
- "@fluentui/keyboard-keys": "0.0.0-nightly8dfa71215620220118.1",
36
+ "@fluentui/keyboard-keys": "0.0.0-nightly940de09b9520220131.1",
37
37
  "tslib": "^2.1.0"
38
38
  },
39
39
  "peerDependencies": {