@fluentui/react-utilities 0.0.0-nightlycc44f3625c20211220.1 → 0.0.0-nightlyd80c90385320220216.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 (84) hide show
  1. package/CHANGELOG.json +93 -6
  2. package/CHANGELOG.md +25 -6
  3. package/dist/react-utilities.d.ts +193 -78
  4. package/lib/compose/getSlots.d.ts +7 -8
  5. package/lib/compose/getSlots.js +3 -4
  6. package/lib/compose/getSlots.js.map +1 -1
  7. package/lib/compose/index.d.ts +0 -1
  8. package/lib/compose/index.js +0 -1
  9. package/lib/compose/index.js.map +1 -1
  10. package/lib/compose/resolveShorthand.d.ts +10 -6
  11. package/lib/compose/resolveShorthand.js +5 -5
  12. package/lib/compose/resolveShorthand.js.map +1 -1
  13. package/lib/compose/types.d.ts +86 -34
  14. package/lib/compose/types.js.map +1 -1
  15. package/lib/hooks/index.d.ts +1 -0
  16. package/lib/hooks/index.js +1 -0
  17. package/lib/hooks/index.js.map +1 -1
  18. package/lib/hooks/useMergedEventCallbacks.d.ts +18 -0
  19. package/lib/hooks/useMergedEventCallbacks.js +26 -0
  20. package/lib/hooks/useMergedEventCallbacks.js.map +1 -0
  21. package/lib/utils/applyTriggerPropsToChildren.d.ts +1 -1
  22. package/lib/utils/applyTriggerPropsToChildren.js +23 -3
  23. package/lib/utils/applyTriggerPropsToChildren.js.map +1 -1
  24. package/lib/utils/getNativeElementProps.d.ts +4 -4
  25. package/lib/utils/getNativeElementProps.js.map +1 -1
  26. package/lib/utils/getReactCallbackName.d.ts +25 -0
  27. package/lib/utils/getReactCallbackName.js +26 -0
  28. package/lib/utils/getReactCallbackName.js.map +1 -0
  29. package/lib/utils/getTriggerChild.d.ts +22 -0
  30. package/lib/utils/getTriggerChild.js +26 -0
  31. package/lib/utils/getTriggerChild.js.map +1 -0
  32. package/lib/utils/index.d.ts +2 -1
  33. package/lib/utils/index.js +2 -1
  34. package/lib/utils/index.js.map +1 -1
  35. package/lib/utils/isFluentTrigger.d.ts +22 -0
  36. package/lib/utils/isFluentTrigger.js +8 -0
  37. package/lib/utils/isFluentTrigger.js.map +1 -0
  38. package/lib-commonjs/compose/getSlots.d.ts +7 -8
  39. package/lib-commonjs/compose/getSlots.js +3 -5
  40. package/lib-commonjs/compose/getSlots.js.map +1 -1
  41. package/lib-commonjs/compose/index.d.ts +0 -1
  42. package/lib-commonjs/compose/index.js +0 -2
  43. package/lib-commonjs/compose/index.js.map +1 -1
  44. package/lib-commonjs/compose/resolveShorthand.d.ts +10 -6
  45. package/lib-commonjs/compose/resolveShorthand.js +5 -5
  46. package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
  47. package/lib-commonjs/compose/types.d.ts +86 -34
  48. package/lib-commonjs/compose/types.js.map +1 -1
  49. package/lib-commonjs/hooks/index.d.ts +1 -0
  50. package/lib-commonjs/hooks/index.js +2 -0
  51. package/lib-commonjs/hooks/index.js.map +1 -1
  52. package/lib-commonjs/hooks/useMergedEventCallbacks.d.ts +18 -0
  53. package/lib-commonjs/hooks/useMergedEventCallbacks.js +36 -0
  54. package/lib-commonjs/hooks/useMergedEventCallbacks.js.map +1 -0
  55. package/lib-commonjs/utils/applyTriggerPropsToChildren.d.ts +1 -1
  56. package/lib-commonjs/utils/applyTriggerPropsToChildren.js +24 -4
  57. package/lib-commonjs/utils/applyTriggerPropsToChildren.js.map +1 -1
  58. package/lib-commonjs/utils/getNativeElementProps.d.ts +4 -4
  59. package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
  60. package/lib-commonjs/utils/getReactCallbackName.d.ts +25 -0
  61. package/lib-commonjs/utils/getReactCallbackName.js +35 -0
  62. package/lib-commonjs/utils/getReactCallbackName.js.map +1 -0
  63. package/lib-commonjs/utils/getTriggerChild.d.ts +22 -0
  64. package/lib-commonjs/utils/getTriggerChild.js +37 -0
  65. package/lib-commonjs/utils/getTriggerChild.js.map +1 -0
  66. package/lib-commonjs/utils/index.d.ts +2 -1
  67. package/lib-commonjs/utils/index.js +4 -2
  68. package/lib-commonjs/utils/index.js.map +1 -1
  69. package/lib-commonjs/utils/isFluentTrigger.d.ts +22 -0
  70. package/lib-commonjs/utils/isFluentTrigger.js +17 -0
  71. package/lib-commonjs/utils/isFluentTrigger.js.map +1 -0
  72. package/package.json +3 -3
  73. package/lib/compose/nullRender.d.ts +0 -4
  74. package/lib/compose/nullRender.js +0 -5
  75. package/lib/compose/nullRender.js.map +0 -1
  76. package/lib/utils/onlyChild.d.ts +0 -5
  77. package/lib/utils/onlyChild.js +0 -13
  78. package/lib/utils/onlyChild.js.map +0 -1
  79. package/lib-commonjs/compose/nullRender.d.ts +0 -4
  80. package/lib-commonjs/compose/nullRender.js +0 -14
  81. package/lib-commonjs/compose/nullRender.js.map +0 -1
  82. package/lib-commonjs/utils/onlyChild.d.ts +0 -5
  83. package/lib-commonjs/utils/onlyChild.js +0 -23
  84. package/lib-commonjs/utils/onlyChild.js.map +0 -1
@@ -7,8 +7,6 @@ exports.getSlots = void 0;
7
7
 
8
8
  const React = /*#__PURE__*/require("react");
9
9
 
10
- const nullRender_1 = /*#__PURE__*/require("./nullRender");
11
-
12
10
  const omit_1 = /*#__PURE__*/require("../utils/omit");
13
11
  /**
14
12
  * Given the state and an array of slot names, will break out `slots` and `slotProps`
@@ -25,14 +23,14 @@ const omit_1 = /*#__PURE__*/require("../utils/omit");
25
23
  * runtime code filtering props in this function.
26
24
  *
27
25
  * @param state - State including slot definitions
28
- * @param slotNames - Name of which props are slots
29
26
  * @returns An object containing the `slots` map and `slotProps` map.
30
27
  */
31
28
 
32
29
 
33
- function getSlots(state, slotNames = ['root']) {
30
+ function getSlots(state) {
34
31
  const slots = {};
35
32
  const slotProps = {};
33
+ const slotNames = Object.keys(state.components);
36
34
 
37
35
  for (const slotName of slotNames) {
38
36
  const [slot, props] = getSlot(state, slotName);
@@ -52,7 +50,7 @@ function getSlot(state, slotName) {
52
50
  var _a, _b, _c;
53
51
 
54
52
  if (state[slotName] === undefined) {
55
- return [nullRender_1.nullRender, undefined];
53
+ return [null, undefined];
56
54
  }
57
55
 
58
56
  const {
@@ -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;;;;;;;;;;;;;;;;;AAiBG;;;AACH,SAAgB,QAAhB,CACE,KADF,EAEE,SAAA,GAAyB,CAAC,MAAD,CAF3B,EAEmC;AAKjC,QAAM,KAAK,GAAG,EAAd;AACA,QAAM,SAAS,GAAG,EAAlB;;AAEA,OAAK,MAAM,QAAX,IAAuB,SAAvB,EAAkC;AAChC,UAAM,CAAC,IAAD,EAAO,KAAP,IAAgB,OAAO,CAAC,KAAD,EAAQ,QAAR,CAA7B;AACA,IAAA,KAAK,CAAC,QAAD,CAAL,GAAkB,IAAlB;AACA,IAAA,SAAS,CAAC,QAAD,CAAT,GAAsB,KAAtB;AACD;;AACD,SAAO;AAAE,IAAA,KAAF;AAAS,IAAA,SAAS,EAAG;AAArB,GAAP;AACD;;AAhBD,OAAA,CAAA,QAAA,GAAA,QAAA;;AAkBA,SAAS,OAAT,CACE,KADF,EAEE,QAFF,EAEa;;;AAEX,MAAI,KAAK,CAAC,QAAD,CAAL,KAAoB,SAAxB,EAAmC;AACjC,WAAO,CAAC,YAAA,CAAA,UAAD,EAAa,SAAb,CAAP;AACD;;AACD,QAAM;AAAE,IAAA,QAAF;AAAY,IAAA,EAAE,EAAE,MAAhB;AAAwB,OAAG;AAA3B,MAAoC,KAAK,CAAC,QAAD,CAA/C;AAEA,QAAM,IAAI,GAAI,CAAA,CAAA,EAAA,GAAA,KAAK,CAAC,UAAN,MAAgB,IAAhB,IAAgB,EAAA,KAAA,KAAA,CAAhB,GAAgB,KAAA,CAAhB,GAAgB,EAA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EAEJ;AACC,MAAA,QAAQ,EAAE,MAAM,CAAC,IAAD,EAAO,IAAP;AADjB,KAFI,CAAP;AAMD;;AAED,QAAM,gBAAgB,GAAG,OAAO,IAAP,KAAgB,QAAhB,KAA4B,CAAA,EAAA,GAAA,KAAK,CAAC,QAAD,CAAL,MAAe,IAAf,IAAe,EAAA,KAAA,KAAA,CAAf,GAAe,KAAA,CAAf,GAAe,EAAA,CAAE,EAA7C,CAAzB;AACA,QAAM,SAAS,GAAI,gBAAgB,GAAG,MAAA,CAAA,IAAA,CAAK,KAAK,CAAC,QAAD,CAAV,EAAuB,CAAC,IAAD,CAAvB,CAAH,GAAoC,KAAK,CAAC,QAAD,CAA5E;AAEA,SAAO,CAAC,IAAD,EAAO,SAAP,CAAP;AACD","sourceRoot":""}
@@ -1,4 +1,3 @@
1
1
  export * from './getSlots';
2
- export * from './nullRender';
3
2
  export * from './resolveShorthand';
4
3
  export * from './types';
@@ -8,8 +8,6 @@ const tslib_1 = /*#__PURE__*/require("tslib");
8
8
 
9
9
  tslib_1.__exportStar(require("./getSlots"), exports);
10
10
 
11
- tslib_1.__exportStar(require("./nullRender"), exports);
12
-
13
11
  tslib_1.__exportStar(require("./resolveShorthand"), exports);
14
12
 
15
13
  tslib_1.__exportStar(require("./types"), exports);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/compose/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,YAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,oBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,SAAA,CAAA,EAAA,OAAA","sourceRoot":""}
1
+ {"version":3,"sources":["../../src/compose/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,YAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,oBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,SAAA,CAAA,EAAA,OAAA","sourceRoot":""}
@@ -1,12 +1,16 @@
1
- import type { DefaultObjectShorthandProps, ShorthandProps } from './types';
2
- export declare type ResolveShorthandOptions<Props extends Record<string, any>, Required extends boolean = false> = {
1
+ import type { ReplaceNullWithUndefined, SlotShorthandValue, UnknownSlotProps } from './types';
2
+ export declare type ResolveShorthandOptions<Props, Required extends boolean = false> = {
3
3
  required?: Required;
4
4
  defaultProps?: Props;
5
5
  };
6
+ export declare type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {
7
+ <P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, true>): ReplaceNullWithUndefined<P>;
8
+ <P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, boolean>): ReplaceNullWithUndefined<P> | undefined;
9
+ };
6
10
  /**
7
- * Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
11
+ * Resolves shorthands into slot props, to ensure normalization of the signature
8
12
  * being passed down to getSlots method
9
- * @param value - the base ShorthandProps
10
- * @param options - options to resolve ShorthandProps
13
+ * @param value - the base shorthand props
14
+ * @param options - options to resolve shorthand props
11
15
  */
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;
16
+ export declare const resolveShorthand: ResolveShorthandFunction;
@@ -7,14 +7,14 @@ 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
 
17
- function resolveShorthand(value, options) {
17
+ const resolveShorthand = (value, options) => {
18
18
  const {
19
19
  required = false,
20
20
  defaultProps
@@ -35,7 +35,7 @@ function resolveShorthand(value, options) {
35
35
  return defaultProps ? { ...defaultProps,
36
36
  ...resolvedShorthand
37
37
  } : resolvedShorthand;
38
- }
38
+ };
39
39
 
40
40
  exports.resolveShorthand = resolveShorthand;
41
41
  //# sourceMappingURL=resolveShorthand.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/compose/resolveShorthand.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,OAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AASA;;;;;AAKG;;;AACH,SAAgB,gBAAhB,CACE,KADF,EAEE,OAFF,EAEoD;AAElD,QAAM;AAAE,IAAA,QAAQ,GAAG,KAAb;AAAoB,IAAA;AAApB,MAAqC,OAAO,IAAI,EAAtD;;AACA,MAAI,KAAK,KAAK,IAAV,IAAmB,KAAK,KAAK,SAAV,IAAuB,CAAC,QAA/C,EAA0D;AACxD,WAAO,SAAP;AACD;;AAED,MAAI,iBAAiB,GAAG,EAAxB;;AAEA,MAAI,OAAO,KAAP,KAAiB,QAAjB,IAA6B,OAAO,KAAP,KAAiB,QAA9C,IAA0D,KAAK,CAAC,OAAN,CAAc,KAAd,CAA1D,IAAkF,OAAA,CAAA,cAAA,CAAe,KAAf,CAAtF,EAA6G;AAC3G,IAAA,iBAAiB,CAAC,QAAlB,GAA6B,KAA7B;AACD,GAFD,MAEO,IAAI,OAAO,KAAP,KAAiB,QAArB,EAA+B;AACpC,IAAA,iBAAiB,GAAG,KAApB;AACD;;AAED,SAAQ,YAAY,GAAG,EAAE,GAAG,YAAL;AAAmB,OAAG;AAAtB,GAAH,GAA+C,iBAAnE;AAGD;;AApBD,OAAA,CAAA,gBAAA,GAAA,gBAAA","sourceRoot":""}
1
+ {"version":3,"sources":["../../src/compose/resolveShorthand.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,OAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAkBA;;;;;AAKG;;;AACI,MAAM,gBAAgB,GAA6B,CAAC,KAAD,EAAQ,OAAR,KAAmB;AAC3E,QAAM;AAAE,IAAA,QAAQ,GAAG,KAAb;AAAoB,IAAA;AAApB,MAAqC,OAAO,IAAI,EAAtD;;AACA,MAAI,KAAK,KAAK,IAAV,IAAmB,KAAK,KAAK,SAAV,IAAuB,CAAC,QAA/C,EAA0D;AACxD,WAAO,SAAP;AACD;;AAED,MAAI,iBAAiB,GAAG,EAAxB;;AAEA,MAAI,OAAO,KAAP,KAAiB,QAAjB,IAA6B,OAAO,KAAP,KAAiB,QAA9C,IAA0D,KAAK,CAAC,OAAN,CAAc,KAAd,CAA1D,IAAkF,OAAA,CAAA,cAAA,CAAe,KAAf,CAAtF,EAA6G;AAC3G,IAAA,iBAAiB,CAAC,QAAlB,GAA6B,KAA7B;AACD,GAFD,MAEO,IAAI,OAAO,KAAP,KAAiB,QAArB,EAA+B;AACpC,IAAA,iBAAiB,GAAG,KAApB;AACD;;AAED,SAAO,YAAY,GAAG,EAAE,GAAG,YAAL;AAAmB,OAAG;AAAtB,GAAH,GAA+C,iBAAlE;AACD,CAfM;;AAAM,OAAA,CAAA,gBAAA,GAAgB,gBAAhB","sourceRoot":""}
@@ -1,46 +1,83 @@
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;
5
3
  /**
6
- * Matches any shorthand props type.
4
+ * Matches any component's Slots type (such as ButtonSlots).
7
5
  *
8
- * This should ONLY be used in type templates as in `extends DefaultObjectShorthandProps`;
6
+ * This should ONLY be used in type templates as in `extends SlotPropsRecord`;
7
+ * it shouldn't be used as a component's Slots type.
8
+ */
9
+ export declare type SlotPropsRecord = Record<string, UnknownSlotProps | SlotShorthandValue | null | undefined>;
10
+ /**
11
+ * The shorthand value of a slot allows specifying its child
12
+ */
13
+ export declare type SlotShorthandValue = React.ReactChild | React.ReactNodeArray | React.ReactPortal;
14
+ /**
15
+ * Matches any slot props type.
16
+ *
17
+ * This should ONLY be used in type templates as in `extends UnknownSlotProps`;
9
18
  * it shouldn't be used as the type of a slot.
10
19
  */
11
- export declare type DefaultObjectShorthandProps = ObjectShorthandProps<Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
20
+ export declare type UnknownSlotProps = Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
12
21
  as?: keyof JSX.IntrinsicElements;
13
- }>;
22
+ };
14
23
  /**
15
- * Defines the slot props for a slot that supports a Component type.
16
- *
17
- * For intrinsic elements like 'div', use {@link IntrinsicShorthandProps} instead.
24
+ * Helper type for {@link Slot}. Adds shorthand types that are assignable to the slot's `children`.
18
25
  */
19
- export declare type ObjectShorthandProps<Props extends {
20
- children?: React.ReactNode;
21
- } = {}> = Props & {
22
- children?: Props['children'] | ShorthandRenderFunction<Props>;
26
+ declare type WithSlotShorthandValue<Props extends {
27
+ children?: unknown;
28
+ }> = Props | Extract<SlotShorthandValue, Props['children']>;
29
+ /**
30
+ * Helper type for {@link Slot}. Takes the props we want to support for a slot and adds the ability for `children`
31
+ * to be a render function that takes those props.
32
+ */
33
+ declare type WithSlotRenderFunction<Props extends {
34
+ children?: unknown;
35
+ }> = Props & {
36
+ children?: Props['children'] | SlotRenderFunction<Props>;
23
37
  };
24
38
  /**
25
- * 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.
39
+ * HTML element types that are not allowed to have children.
27
40
  *
28
- * The first param is the slot's default type if no `as` prop is specified.
29
- * The second param is an optional union of alternative types that can be specified for the `as` prop.
41
+ * Reference: https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
42
+ */
43
+ declare type EmptyIntrisicElements = 'area' | 'base' | 'br' | 'col' | 'embed' | 'hr' | 'img' | 'input' | 'link' | 'meta' | 'param' | 'source' | 'track' | 'wbr';
44
+ /**
45
+ * Helper type for {@link Slot}. Modifies `JSX.IntrinsicElements[Type]`:
46
+ * * Removes legacy string ref.
47
+ * * Disallows children for empty tags like 'img'.
48
+ */
49
+ declare type IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = React.PropsWithRef<JSX.IntrinsicElements[Type]> & (Type extends EmptyIntrisicElements ? {
50
+ children?: never;
51
+ } : {});
52
+ /**
53
+ * The props type and shorthand value for a slot. Type is either a single intrinsic element like `'div'`,
54
+ * or a component like `typeof Button`.
30
55
  *
56
+ * If a slot needs to support multiple intrinsic element types, use the `AlternateAs` param (see examples below).
57
+ *
58
+ * By default, slots can be set to `null` to prevent them from being rendered. If a slot must always be rendered,
59
+ * wrap with `NonNullable` (see examples below).
60
+ *
61
+ * @example
31
62
  * ```
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"
63
+ * // Intrinsic element examples:
64
+ * Slot<'div'> // Slot is always div
65
+ * Slot<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
66
+ * Slot<'span', 'div' | 'pre'> // Defaults to span, but allows as="div" or as="pre"
67
+ * NonNullable<Slot<'div'>> // Slot that will always be rendered (can't be set to null by the user)
68
+ *
69
+ * // Component examples:
70
+ * Slot<typeof Button> // Slot is always a Button, and accepts all of Button's Props
71
+ * NonNullable<Slot<typeof Label>> // Slot is a Label and will always be rendered (can't be set to null by the user)
35
72
  * ```
36
73
  */
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' : ({
38
- as?: DefaultAs;
39
- } & ObjectShorthandProps<React.PropsWithRef<JSX.IntrinsicElements[DefaultAs]>>) | {
74
+ export declare type Slot<Type extends keyof JSX.IntrinsicElements | React.ComponentType | UnknownSlotProps, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<Extract<Type, string>> extends true ? WithSlotShorthandValue<Type extends keyof JSX.IntrinsicElements ? {
75
+ as?: Type;
76
+ } & WithSlotRenderFunction<IntrisicElementProps<Type>> : Type extends React.ComponentType<infer Props> ? WithSlotRenderFunction<Props> : Type> | {
40
77
  [As in AlternateAs]: {
41
78
  as: As;
42
- } & ObjectShorthandProps<React.PropsWithRef<JSX.IntrinsicElements[As]>>;
43
- }[AlternateAs];
79
+ } & WithSlotRenderFunction<IntrisicElementProps<As>>;
80
+ }[AlternateAs] | null : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';
44
81
  /**
45
82
  * Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.
46
83
  *
@@ -69,20 +106,35 @@ export declare type AsIntrinsicElement<As extends keyof JSX.IntrinsicElements> =
69
106
  export declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;
70
107
  /**
71
108
  * 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.
109
+ * IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
73
110
  *
74
111
  * The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional
75
112
  * types, to prevent unions from being expanded.
76
113
  */
77
114
  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> = {
82
- 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);
115
+ /**
116
+ * Removes SlotShorthandValue and null from the slot type, extracting just the slot's Props object.
117
+ */
118
+ export declare type ExtractSlotProps<S> = Exclude<S, SlotShorthandValue | null | undefined>;
119
+ /**
120
+ * Defines the Props type for a component given its slots and the definition of which one is the primary slot,
121
+ * defaulting to root if one is not provided.
122
+ */
123
+ export declare type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> = Omit<Slots, Primary & 'root'> & PropsWithoutRef<ExtractSlotProps<Slots[Primary]>>;
124
+ /**
125
+ * If type T includes `null`, remove it and add `undefined` instead.
126
+ */
127
+ export declare type ReplaceNullWithUndefined<T> = T extends null ? Exclude<T, null> | undefined : T;
128
+ /**
129
+ * Defines the State object of a component given its slots.
130
+ */
131
+ export declare type ComponentState<Slots extends SlotPropsRecord> = {
132
+ components: {
133
+ [Key in keyof Slots]-?: React.ComponentType<ExtractSlotProps<Slots[Key]>> | (ExtractSlotProps<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
84
134
  };
85
- } & Shorthands;
135
+ } & {
136
+ [Key in keyof Slots]: ReplaceNullWithUndefined<Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>>;
137
+ };
86
138
  /**
87
139
  * This is part of a hack to infer the element type from a native element *props* type.
88
140
  * 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":";;;;IAqNA;AACA;AACA;AACA;AACA","sourceRoot":""}
@@ -5,6 +5,7 @@ export * from './useEventCallback';
5
5
  export * from './useFirstMount';
6
6
  export * from './useId';
7
7
  export * from './useIsomorphicLayoutEffect';
8
+ export * from './useMergedEventCallbacks';
8
9
  export * from './useMergedRefs';
9
10
  export * from './useMount';
10
11
  export * from './useOnClickOutside';
@@ -20,6 +20,8 @@ tslib_1.__exportStar(require("./useId"), exports);
20
20
 
21
21
  tslib_1.__exportStar(require("./useIsomorphicLayoutEffect"), exports);
22
22
 
23
+ tslib_1.__exportStar(require("./useMergedEventCallbacks"), exports);
24
+
23
25
  tslib_1.__exportStar(require("./useMergedRefs"), exports);
24
26
 
25
27
  tslib_1.__exportStar(require("./useMount"), 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,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,SAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,6BAAA,CAAA,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AA,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,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,kBAAA,CAAA,EAAA,OAAA","sourceRoot":""}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Combine two event callbacks into a single callback function that calls each one in order.
3
+ *
4
+ * This is useful to add an event listener to an existing element without overwriting the current listener, if any.
5
+ *
6
+ * For example:
7
+ * ```ts
8
+ * state.slot.onChange = useMergedCallbacks(state.slot.onChange, ev => {
9
+ * // Handle onChange
10
+ * });
11
+ * ```
12
+ *
13
+ * @param callback1 - The first callback to be called
14
+ * @param callback2 - The second callback to be called
15
+ *
16
+ * @returns An event callback that calls the callbacks in order, and is stable between renders
17
+ */
18
+ export declare function useMergedEventCallbacks<Args extends unknown[]>(callback1: ((...args: Args) => void) | undefined, callback2: ((...args: Args) => void) | undefined): (...args: Args) => void;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useMergedEventCallbacks = void 0;
7
+
8
+ const useEventCallback_1 = /*#__PURE__*/require("./useEventCallback");
9
+ /**
10
+ * Combine two event callbacks into a single callback function that calls each one in order.
11
+ *
12
+ * This is useful to add an event listener to an existing element without overwriting the current listener, if any.
13
+ *
14
+ * For example:
15
+ * ```ts
16
+ * state.slot.onChange = useMergedCallbacks(state.slot.onChange, ev => {
17
+ * // Handle onChange
18
+ * });
19
+ * ```
20
+ *
21
+ * @param callback1 - The first callback to be called
22
+ * @param callback2 - The second callback to be called
23
+ *
24
+ * @returns An event callback that calls the callbacks in order, and is stable between renders
25
+ */
26
+
27
+
28
+ function useMergedEventCallbacks(callback1, callback2) {
29
+ return useEventCallback_1.useEventCallback((...args) => {
30
+ callback1 === null || callback1 === void 0 ? void 0 : callback1(...args);
31
+ callback2 === null || callback2 === void 0 ? void 0 : callback2(...args);
32
+ });
33
+ }
34
+
35
+ exports.useMergedEventCallbacks = useMergedEventCallbacks;
36
+ //# sourceMappingURL=useMergedEventCallbacks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/useMergedEventCallbacks.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,kBAAA,gBAAA,OAAA,CAAA,oBAAA,CAAA;AAEA;;;;;;;;;;;;;;;;AAgBG;;;AACH,SAAgB,uBAAhB,CACE,SADF,EAEE,SAFF,EAEkD;AAEhD,SAAO,kBAAA,CAAA,gBAAA,CAAiB,CAAC,GAAG,IAAJ,KAAkB;AACxC,IAAA,SAAS,KAAA,IAAT,IAAA,SAAS,KAAA,KAAA,CAAT,GAAS,KAAA,CAAT,GAAA,SAAS,CAAG,GAAG,IAAN,CAAT;AACA,IAAA,SAAS,KAAA,IAAT,IAAA,SAAS,KAAA,KAAA,CAAT,GAAS,KAAA,CAAT,GAAA,SAAS,CAAG,GAAG,IAAN,CAAT;AACD,GAHM,CAAP;AAID;;AARD,OAAA,CAAA,uBAAA,GAAA,uBAAA","sourceRoot":""}
@@ -2,4 +2,4 @@ import * as React from 'react';
2
2
  /**
3
3
  * Apply the trigger props to the children, either by calling the render function, or cloning with the new props.
4
4
  */
5
- export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: React.ReactElement<any, string | React.JSXElementConstructor<any>> | ((props: TTriggerProps) => React.ReactNode) | null | undefined, triggerProps: TTriggerProps) => React.ReactNode;
5
+ export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: React.ReactElement<any, string | React.JSXElementConstructor<any>> | ((props: TTriggerProps) => React.ReactElement | null) | null | undefined, triggerProps: TTriggerProps) => React.ReactElement | null;
@@ -7,7 +7,7 @@ exports.applyTriggerPropsToChildren = void 0;
7
7
 
8
8
  const React = /*#__PURE__*/require("react");
9
9
 
10
- const onlyChild_1 = /*#__PURE__*/require("./onlyChild");
10
+ const isFluentTrigger_1 = /*#__PURE__*/require("./isFluentTrigger");
11
11
  /**
12
12
  * Apply the trigger props to the children, either by calling the render function, or cloning with the new props.
13
13
  */
@@ -17,11 +17,31 @@ const applyTriggerPropsToChildren = (children, triggerProps) => {
17
17
  if (typeof children === 'function') {
18
18
  return children(triggerProps);
19
19
  } else if (children) {
20
- return React.cloneElement(onlyChild_1.onlyChild(children), triggerProps);
21
- }
20
+ return cloneTriggerTree(children, triggerProps);
21
+ } // Components in React should return either JSX elements or "null", otherwise React will throw:
22
+ // Nothing was returned from render.
23
+ // This usually means a return statement is missing. Or, to render nothing, return null.
24
+
22
25
 
23
- return children;
26
+ return children || null;
24
27
  };
25
28
 
26
29
  exports.applyTriggerPropsToChildren = applyTriggerPropsToChildren;
30
+ /**
31
+ * Clones a React element tree, and applies the given props to the first grandchild that is not
32
+ * a FluentTriggerComponent or React Fragment (the same element returned by {@link getTriggerChild}).
33
+ */
34
+
35
+ const cloneTriggerTree = (child, triggerProps) => {
36
+ if (!React.isValidElement(child) || child.type === React.Fragment) {
37
+ throw new Error('A trigger element must be a single element for this component. ' + "Please ensure that you're not using React Fragments.");
38
+ }
39
+
40
+ if (isFluentTrigger_1.isFluentTrigger(child)) {
41
+ const grandchild = cloneTriggerTree(child.props.children, triggerProps);
42
+ return React.cloneElement(child, undefined, grandchild);
43
+ } else {
44
+ return React.cloneElement(child, triggerProps);
45
+ }
46
+ };
27
47
  //# sourceMappingURL=applyTriggerPropsToChildren.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/applyTriggerPropsToChildren.ts"],"names":[],"mappings":";;;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,oEACE,sDAFE,CAAN;AAID;;AAED,MAAI,iBAAA,CAAA,eAAA,CAAgB,KAAhB,CAAJ,EAA4B;AAC1B,UAAM,UAAU,GAAG,gBAAgB,CAAC,KAAK,CAAC,KAAN,CAAY,QAAb,EAAuB,YAAvB,CAAnC;AACA,WAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,SAA1B,EAAqC,UAArC,CAAP;AACD,GAHD,MAGO;AACL,WAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,YAA1B,CAAP;AACD;AACF,CAdD","sourceRoot":""}
@@ -15,17 +15,17 @@ export declare function getNativeElementProps<TAttributes extends React.HTMLAttr
15
15
  *
16
16
  * @returns An object containing the native props for the `root` and primary slots.
17
17
  */
18
- export declare const getPartitionedNativeProps: ({ primarySlotTagName, props, excludedPropNames, }: {
18
+ export declare const getPartitionedNativeProps: <Props extends Pick<React.HTMLAttributes<HTMLElement>, "style" | "className">, ExcludedPropKeys extends Extract<keyof Props, string> = never>({ primarySlotTagName, props, excludedPropNames, }: {
19
19
  /** The primary slot's element type (e.g. 'div') */
20
20
  primarySlotTagName: keyof JSX.IntrinsicElements;
21
21
  /** The component's props object */
22
- props: Pick<React.HTMLAttributes<HTMLElement>, 'style' | 'className'>;
22
+ props: Props;
23
23
  /** List of native props to exclude from the returned value */
24
- excludedPropNames?: string[] | undefined;
24
+ excludedPropNames?: ExcludedPropKeys[] | undefined;
25
25
  }) => {
26
26
  root: {
27
27
  style: React.CSSProperties | undefined;
28
28
  className: string | undefined;
29
29
  };
30
- primary: React.HTMLAttributes<any>;
30
+ primary: Omit<Props, ExcludedPropKeys>;
31
31
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/getNativeElementProps.ts"],"names":[],"mappings":";;;;;;;AACA,MAAA,YAAA,gBAAA,OAAA,CAAA,cAAA,CAAA;;AAyBA,MAAM,gBAAgB,GAA2C;AAC/D,EAAA,KAAK,EAAE,YAAA,CAAA,eADwD;AAE/D,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,EAAA,EAAE,EAAE,YAAA,CAAA,YAf2D;AAgB/D,EAAA,QAAQ,EAAE,YAAA,CAAA,kBAhBqD;AAiB/D,EAAA,GAAG,EAAE,YAAA,CAAA,aAjB0D;AAkB/D,EAAA,IAAI,EAAE,YAAA,CAAA,cAlByD;AAmB/D,EAAA,MAAM,EAAE,YAAA,CAAA,gBAnBuD;AAoB/D,EAAA,GAAG,EAAE,YAAA,CAAA;AApB0D,CAAjE;AAuBA;;;;;;AAMG;AACH;;AACA,SAAgB,qBAAhB,CACE,OADF,EAEE,KAFF,EAGE,iBAHF,EAG8B;AAE5B,QAAM,gBAAgB,GAAI,OAAO,IAAI,gBAAgB,CAAC,OAAD,CAA5B,IAA0C,YAAA,CAAA,qBAAnE;AACA,EAAA,gBAAgB,CAAC,EAAjB,GAAsB,CAAtB;AAEA,SAAO,YAAA,CAAA,cAAA,CAAe,KAAf,EAAsB,gBAAtB,EAAwC,iBAAxC,CAAP;AACD;;AATD,OAAA,CAAA,qBAAA,GAAA,qBAAA;AAWA;;;;;;;AAOG;;AACI,MAAM,yBAAyB,GAAG,CAGvC;AACA,EAAA,kBADA;AAEA,EAAA,KAFA;AAGA,EAAA;AAHA,CAHuC,KAgBpC;AACH,SAAO;AACL,IAAA,IAAI,EAAE;AAAE,MAAA,KAAK,EAAE,KAAK,CAAC,KAAf;AAAsB,MAAA,SAAS,EAAE,KAAK,CAAC;AAAvC,KADD;AAEL,IAAA,OAAO,EAAE,qBAAqB,CAAgC,kBAAhC,EAAoD,KAApD,EAA2D,CACvF,IAAI,iBAAiB,IAAI,EAAzB,CADuF,EAEvF,OAFuF,EAGvF,WAHuF,CAA3D;AAFzB,GAAP;AAQD,CAzBM;;AAAM,OAAA,CAAA,yBAAA,GAAyB,yBAAzB","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":""}
@@ -0,0 +1,22 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).
4
+ *
5
+ * In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,
6
+ * it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.
7
+ * This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.
8
+ *
9
+ * For example, the following returns `<div id="child" />`:
10
+ * ```jsx
11
+ * getTriggerChild(
12
+ * <Tooltip>
13
+ * <MenuTrigger>
14
+ * <div id="child" />
15
+ * </MenuTrigger>
16
+ * </Tooltip>
17
+ * );
18
+ * ```
19
+ */
20
+ export declare const getTriggerChild: (children: React.ReactNode) => React.ReactElement & {
21
+ ref?: React.Ref<unknown>;
22
+ };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getTriggerChild = void 0;
7
+
8
+ const React = /*#__PURE__*/require("react");
9
+
10
+ const isFluentTrigger_1 = /*#__PURE__*/require("./isFluentTrigger");
11
+ /**
12
+ * Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).
13
+ *
14
+ * In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,
15
+ * it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.
16
+ * This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.
17
+ *
18
+ * For example, the following returns `<div id="child" />`:
19
+ * ```jsx
20
+ * getTriggerChild(
21
+ * <Tooltip>
22
+ * <MenuTrigger>
23
+ * <div id="child" />
24
+ * </MenuTrigger>
25
+ * </Tooltip>
26
+ * );
27
+ * ```
28
+ */
29
+
30
+
31
+ const getTriggerChild = children => {
32
+ const child = React.Children.only(children);
33
+ return isFluentTrigger_1.isFluentTrigger(child) ? exports.getTriggerChild(child.props.children) : child;
34
+ };
35
+
36
+ exports.getTriggerChild = getTriggerChild;
37
+ //# sourceMappingURL=getTriggerChild.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/getTriggerChild.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,mBAAA,CAAA;AAEA;;;;;;;;;;;;;;;;;AAiBG;;;AACI,MAAM,eAAe,GAAI,QAAD,IAAiF;AAC9G,QAAM,KAAK,GAAG,KAAK,CAAC,QAAN,CAAe,IAAf,CAAoB,QAApB,CAAd;AACA,SAAO,iBAAA,CAAA,eAAA,CAAgB,KAAhB,IAAyB,OAAA,CAAA,eAAA,CAAgB,KAAK,CAAC,KAAN,CAAY,QAA5B,CAAzB,GAAiE,KAAxE;AACD,CAHM;;AAAM,OAAA,CAAA,eAAA,GAAe,eAAf","sourceRoot":""}
@@ -2,7 +2,8 @@ export * from './applyTriggerPropsToChildren';
2
2
  export * from './clamp';
3
3
  export * from './getNativeElementProps';
4
4
  export * from './getRTLSafeKey';
5
+ export * from './getTriggerChild';
6
+ export * from './isFluentTrigger';
5
7
  export * from './omit';
6
- export * from './onlyChild';
7
8
  export * from './properties';
8
9
  export * from './shouldPreventDefaultOnKeyDown';