@fluentui/react-utilities 9.1.0 → 9.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.json CHANGED
@@ -2,7 +2,22 @@
2
2
  "name": "@fluentui/react-utilities",
3
3
  "entries": [
4
4
  {
5
- "date": "Thu, 15 Sep 2022 09:44:18 GMT",
5
+ "date": "Thu, 13 Oct 2022 10:59:42 GMT",
6
+ "tag": "@fluentui/react-utilities_v9.1.1",
7
+ "version": "9.1.1",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "bernardo.sunderhus@gmail.com",
12
+ "package": "@fluentui/react-utilities",
13
+ "commit": "17c5fe742918bbc41ed22f492a289f53bffc5008",
14
+ "comment": "chore: restricts trigger API types"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Thu, 15 Sep 2022 09:48:57 GMT",
6
21
  "tag": "@fluentui/react-utilities_v9.1.0",
7
22
  "version": "9.1.0",
8
23
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,21 @@
1
1
  # Change Log - @fluentui/react-utilities
2
2
 
3
- This log was last generated on Thu, 15 Sep 2022 09:44:18 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 13 Oct 2022 10:59:42 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.1.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.1.1)
8
+
9
+ Thu, 13 Oct 2022 10:59:42 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.1.0..@fluentui/react-utilities_v9.1.1)
11
+
12
+ ### Patches
13
+
14
+ - chore: restricts trigger API types ([PR #25044](https://github.com/microsoft/fluentui/pull/25044) by bernardo.sunderhus@gmail.com)
15
+
7
16
  ## [9.1.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.1.0)
8
17
 
9
- Thu, 15 Sep 2022 09:44:18 GMT
18
+ Thu, 15 Sep 2022 09:48:57 GMT
10
19
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.2..@fluentui/react-utilities_v9.1.0)
11
20
 
12
21
  ### Minor changes
package/dist/index.d.ts CHANGED
@@ -3,9 +3,9 @@ import * as React_2 from 'react';
3
3
 
4
4
  /**
5
5
  * @internal
6
- * Apply the trigger props to the children, either by calling the render function, or cloning with the new props.
6
+ * resolve the trigger props to the children, either by calling the render function, or cloning with the new props.
7
7
  */
8
- export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: React_2.ReactElement<any, string | React_2.JSXElementConstructor<any>> | ((props: TTriggerProps) => React_2.ReactElement | null) | null | undefined, triggerProps: TTriggerProps) => React_2.ReactElement | null;
8
+ export declare function applyTriggerPropsToChildren<TriggerChildProps>(children: TriggerProps<TriggerChildProps>['children'], triggerChildProps: TriggerChildProps): React_2.ReactElement | null;
9
9
 
10
10
  /**
11
11
  * Helper type for inferring the type of the as prop from a Props type.
@@ -164,10 +164,13 @@ export declare function getSlots<R extends SlotPropsRecord>(state: ComponentStat
164
164
  * </Tooltip>
165
165
  * );
166
166
  * ```
167
+ *
168
+ * In the case where the immediate child is not a valid element,
169
+ * null is returned
167
170
  */
168
- export declare const getTriggerChild: <P = any>(children: React_2.ReactNode) => React_2.ReactElement<P, string | React_2.JSXElementConstructor<any>> & {
169
- ref?: React_2.Ref<unknown> | undefined;
170
- };
171
+ export declare function getTriggerChild<TriggerChildProps>(children: TriggerProps<TriggerChildProps>['children']): (React_2.ReactElement<Partial<TriggerChildProps>> & {
172
+ ref?: React_2.Ref<any>;
173
+ }) | null;
171
174
 
172
175
  /**
173
176
  * Helper type for {@link Slot}. Modifies `JSX.IntrinsicElements[Type]`:
@@ -178,6 +181,13 @@ declare type IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = Re
178
181
  children?: never;
179
182
  } : {});
180
183
 
184
+ /**
185
+ * @internal
186
+ * Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).
187
+ * See the {@link FluentTriggerComponent} type for more info.
188
+ */
189
+ export declare function isFluentTrigger(element: React_2.ReactElement): element is React_2.ReactElement<TriggerProps>;
190
+
181
191
  /**
182
192
  * Guard method that validates if a shorthand is a slot
183
193
  * can be used to extends properties provided by a slot
@@ -381,6 +391,17 @@ export declare type SlotShorthandValue = React_2.ReactChild | React_2.ReactNode[
381
391
  */
382
392
  export declare const SSRProvider: React_2.FC;
383
393
 
394
+ /**
395
+ * @internal
396
+ * A trigger may have a children that could be either:
397
+ * 1. A single element
398
+ * 2. A render function that will receive properties and must return a valid element or null
399
+ * 3. null or undefined
400
+ */
401
+ export declare type TriggerProps<TriggerChildProps = unknown> = {
402
+ children?: React_2.ReactElement | ((props: TriggerChildProps) => React_2.ReactElement | null) | null;
403
+ };
404
+
384
405
  /**
385
406
  * Converts a union type (`A | B | C`) to an intersection type (`A & B & C`)
386
407
  */
package/lib/index.js CHANGED
@@ -2,5 +2,5 @@ export { getSlots, resolveShorthand, isResolvedShorthand } from './compose/index
2
2
  export { resetIdsForTests, useControllableState, useEventCallback, useFirstMount, useForceUpdate, useId, useIsomorphicLayoutEffect, useMergedRefs, useOnClickOutside, useOnScrollOutside, usePrevious, useTimeout } from './hooks/index';
3
3
  export { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';
4
4
  export { clamp, getNativeElementProps, getPartitionedNativeProps, getRTLSafeKey, mergeCallbacks, shouldPreventDefaultOnKeyDown } from './utils/index';
5
- export { applyTriggerPropsToChildren, getTriggerChild } from './trigger/index';
5
+ export { applyTriggerPropsToChildren, getTriggerChild, isFluentTrigger } from './trigger/index';
6
6
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,SAAS,QAAT,EAAmB,gBAAnB,EAAqC,mBAArC,QAAgE,iBAAhE;AAgBA,SACE,gBADF,EAEE,oBAFF,EAGE,gBAHF,EAIE,aAJF,EAKE,cALF,EAME,KANF,EAOE,yBAPF,EAQE,aARF,EASE,iBATF,EAUE,kBAVF,EAWE,WAXF,EAYE,UAZF,QAaO,eAbP;AAgBA,SAAS,SAAT,EAAoB,QAApB,EAA8B,WAA9B,QAAiD,aAAjD;AAEA,SACE,KADF,EAEE,qBAFF,EAGE,yBAHF,EAIE,aAJF,EAKE,cALF,EAME,6BANF,QAOO,eAPP;AASA,SAAS,2BAAT,EAAsC,eAAtC,QAA6D,iBAA7D","sourcesContent":["export { getSlots, resolveShorthand, isResolvedShorthand } from './compose/index';\nexport type {\n ExtractSlotProps,\n ComponentProps,\n ComponentState,\n ForwardRefComponent,\n ResolveShorthandFunction,\n ResolveShorthandOptions,\n Slot,\n Slots,\n SlotClassNames,\n SlotPropsRecord,\n SlotRenderFunction,\n SlotShorthandValue,\n} from './compose/index';\n\nexport {\n resetIdsForTests,\n useControllableState,\n useEventCallback,\n useFirstMount,\n useForceUpdate,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n useOnClickOutside,\n useOnScrollOutside,\n usePrevious,\n useTimeout,\n} from './hooks/index';\nexport type { RefObjectFunction, UseControllableStateOptions, UseOnClickOrScrollOutsideOptions } from './hooks/index';\n\nexport { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';\n\nexport {\n clamp,\n getNativeElementProps,\n getPartitionedNativeProps,\n getRTLSafeKey,\n mergeCallbacks,\n shouldPreventDefaultOnKeyDown,\n} from './utils/index';\n\nexport { applyTriggerPropsToChildren, getTriggerChild } from './trigger/index';\n\nexport type { FluentTriggerComponent } from './trigger/index';\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,SAAS,QAAT,EAAmB,gBAAnB,EAAqC,mBAArC,QAAgE,iBAAhE;AAgBA,SACE,gBADF,EAEE,oBAFF,EAGE,gBAHF,EAIE,aAJF,EAKE,cALF,EAME,KANF,EAOE,yBAPF,EAQE,aARF,EASE,iBATF,EAUE,kBAVF,EAWE,WAXF,EAYE,UAZF,QAaO,eAbP;AAgBA,SAAS,SAAT,EAAoB,QAApB,EAA8B,WAA9B,QAAiD,aAAjD;AAEA,SACE,KADF,EAEE,qBAFF,EAGE,yBAHF,EAIE,aAJF,EAKE,cALF,EAME,6BANF,QAOO,eAPP;AASA,SAAS,2BAAT,EAAsC,eAAtC,EAAuD,eAAvD,QAA8E,iBAA9E","sourcesContent":["export { getSlots, resolveShorthand, isResolvedShorthand } from './compose/index';\nexport type {\n ExtractSlotProps,\n ComponentProps,\n ComponentState,\n ForwardRefComponent,\n ResolveShorthandFunction,\n ResolveShorthandOptions,\n Slot,\n Slots,\n SlotClassNames,\n SlotPropsRecord,\n SlotRenderFunction,\n SlotShorthandValue,\n} from './compose/index';\n\nexport {\n resetIdsForTests,\n useControllableState,\n useEventCallback,\n useFirstMount,\n useForceUpdate,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n useOnClickOutside,\n useOnScrollOutside,\n usePrevious,\n useTimeout,\n} from './hooks/index';\nexport type { RefObjectFunction, UseControllableStateOptions, UseOnClickOrScrollOutsideOptions } from './hooks/index';\n\nexport { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';\n\nexport {\n clamp,\n getNativeElementProps,\n getPartitionedNativeProps,\n getRTLSafeKey,\n mergeCallbacks,\n shouldPreventDefaultOnKeyDown,\n} from './utils/index';\n\nexport { applyTriggerPropsToChildren, getTriggerChild, isFluentTrigger } from './trigger/index';\n\nexport type { FluentTriggerComponent, TriggerProps } from './trigger/index';\n"],"sourceRoot":"../src/"}
@@ -2,27 +2,27 @@ import * as React from 'react';
2
2
  import { isFluentTrigger } from './isFluentTrigger';
3
3
  /**
4
4
  * @internal
5
- * Apply the trigger props to the children, either by calling the render function, or cloning with the new props.
5
+ * resolve the trigger props to the children, either by calling the render function, or cloning with the new props.
6
6
  */
7
7
 
8
- export const applyTriggerPropsToChildren = (children, triggerProps) => {
8
+ export function applyTriggerPropsToChildren(children, triggerChildProps) {
9
9
  if (typeof children === 'function') {
10
- return children(triggerProps);
10
+ return children(triggerChildProps);
11
11
  } else if (children) {
12
- return cloneTriggerTree(children, triggerProps);
12
+ return cloneTriggerTree(children, triggerChildProps);
13
13
  } // Components in React should return either JSX elements or "null", otherwise React will throw:
14
14
  // Nothing was returned from render.
15
15
  // This usually means a return statement is missing. Or, to render nothing, return null.
16
16
 
17
17
 
18
18
  return children || null;
19
- };
19
+ }
20
20
  /**
21
21
  * Clones a React element tree, and applies the given props to the first grandchild that is not
22
22
  * a FluentTriggerComponent or React Fragment (the same element returned by {@link getTriggerChild}).
23
23
  */
24
24
 
25
- const cloneTriggerTree = (child, triggerProps) => {
25
+ function cloneTriggerTree(child, triggerProps) {
26
26
  if (! /*#__PURE__*/React.isValidElement(child) || child.type === React.Fragment) {
27
27
  throw new Error('A trigger element must be a single element for this component. ' + "Please ensure that you're not using React Fragments.");
28
28
  }
@@ -33,5 +33,5 @@ const cloneTriggerTree = (child, triggerProps) => {
33
33
  } else {
34
34
  return /*#__PURE__*/React.cloneElement(child, triggerProps);
35
35
  }
36
- };
36
+ }
37
37
  //# sourceMappingURL=applyTriggerPropsToChildren.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["trigger/applyTriggerPropsToChildren.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,eAAT,QAAgC,mBAAhC;AAEA;;;AAGG;;AACH,OAAO,MAAM,2BAA2B,GAAG,CACzC,QADyC,EAEzC,YAFyC,KAGZ;EAC7B,IAAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;IAClC,OAAO,QAAQ,CAAC,YAAD,CAAf;EACD,CAFD,MAEO,IAAI,QAAJ,EAAc;IACnB,OAAO,gBAAgB,CAAC,QAAD,EAAW,YAAX,CAAvB;EACD,CAL4B,CAO7B;EACA;EACA;;;EACA,OAAO,QAAQ,IAAI,IAAnB;AACD,CAdM;AAgBP;;;AAGG;;AACH,MAAM,gBAAgB,GAAG,CAAgB,KAAhB,EAAwC,YAAxC,KAA2F;EAClH,IAAI,eAAC,KAAK,CAAC,cAAN,CAAqB,KAArB,CAAD,IAAgC,KAAK,CAAC,IAAN,KAAe,KAAK,CAAC,QAAzD,EAAmE;IACjE,MAAM,IAAI,KAAJ,CACJ,oEACE,sDAFE,CAAN;EAID;;EAED,IAAI,eAAe,CAAC,KAAD,CAAnB,EAA4B;IAC1B,MAAM,UAAU,GAAG,gBAAgB,CAAC,KAAK,CAAC,KAAN,CAAY,QAAb,EAAuB,YAAvB,CAAnC;IACA,oBAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,SAA1B,EAAqC,UAArC,CAAP;EACD,CAHD,MAGO;IACL,oBAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,YAA1B,CAAP;EACD;AACF,CAdD","sourcesContent":["import * as React from 'react';\nimport { isFluentTrigger } from './isFluentTrigger';\n\n/**\n * @internal\n * Apply the trigger props to the children, either by calling the render function, or cloning with the new props.\n */\nexport const applyTriggerPropsToChildren = <TTriggerProps>(\n children: React.ReactElement | ((props: TTriggerProps) => React.ReactElement | null) | null | undefined,\n triggerProps: TTriggerProps,\n): React.ReactElement | null => {\n if (typeof children === 'function') {\n return children(triggerProps);\n } else if (children) {\n return cloneTriggerTree(children, triggerProps);\n }\n\n // Components in React should return either JSX elements or \"null\", otherwise React will throw:\n // Nothing was returned from render.\n // This usually means a return statement is missing. Or, to render nothing, return null.\n return children || null;\n};\n\n/**\n * Clones a React element tree, and applies the given props to the first grandchild that is not\n * a FluentTriggerComponent or React Fragment (the same element returned by {@link getTriggerChild}).\n */\nconst cloneTriggerTree = <TTriggerProps>(child: React.ReactNode, triggerProps: TTriggerProps): React.ReactElement => {\n if (!React.isValidElement(child) || child.type === React.Fragment) {\n throw new Error(\n 'A trigger element must be a single element for this component. ' +\n \"Please ensure that you're not using React Fragments.\",\n );\n }\n\n if (isFluentTrigger(child)) {\n const grandchild = cloneTriggerTree(child.props.children, triggerProps);\n return React.cloneElement(child, undefined, grandchild);\n } else {\n return React.cloneElement(child, triggerProps);\n }\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["trigger/applyTriggerPropsToChildren.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,eAAT,QAAgC,mBAAhC;AAGA;;;AAGG;;AACH,OAAM,SAAU,2BAAV,CACJ,QADI,EAEJ,iBAFI,EAEgC;EAEpC,IAAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;IAClC,OAAO,QAAQ,CAAC,iBAAD,CAAf;EACD,CAFD,MAEO,IAAI,QAAJ,EAAc;IACnB,OAAO,gBAAgB,CAAC,QAAD,EAAW,iBAAX,CAAvB;EACD,CANmC,CAQpC;EACA;EACA;;;EACA,OAAO,QAAQ,IAAI,IAAnB;AACD;AAED;;;AAGG;;AACH,SAAS,gBAAT,CACE,KADF,EAEE,YAFF,EAEiC;EAE/B,IAAI,eAAC,KAAK,CAAC,cAAN,CAAqB,KAArB,CAAD,IAAgC,KAAK,CAAC,IAAN,KAAe,KAAK,CAAC,QAAzD,EAAmE;IACjE,MAAM,IAAI,KAAJ,CACJ,oEACE,sDAFE,CAAN;EAID;;EAED,IAAI,eAAe,CAAC,KAAD,CAAnB,EAA4B;IAC1B,MAAM,UAAU,GAAG,gBAAgB,CAAC,KAAK,CAAC,KAAN,CAAY,QAAb,EAAuB,YAAvB,CAAnC;IACA,oBAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,SAA1B,EAAqC,UAArC,CAAP;EACD,CAHD,MAGO;IACL,oBAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,YAA1B,CAAP;EACD;AACF","sourcesContent":["import * as React from 'react';\nimport { isFluentTrigger } from './isFluentTrigger';\nimport type { TriggerProps } from './types';\n\n/**\n * @internal\n * resolve the trigger props to the children, either by calling the render function, or cloning with the new props.\n */\nexport function applyTriggerPropsToChildren<TriggerChildProps>(\n children: TriggerProps<TriggerChildProps>['children'],\n triggerChildProps: TriggerChildProps,\n): React.ReactElement | null {\n if (typeof children === 'function') {\n return children(triggerChildProps);\n } else if (children) {\n return cloneTriggerTree(children, triggerChildProps);\n }\n\n // Components in React should return either JSX elements or \"null\", otherwise React will throw:\n // Nothing was returned from render.\n // This usually means a return statement is missing. Or, to render nothing, return null.\n return children || null;\n}\n\n/**\n * Clones a React element tree, and applies the given props to the first grandchild that is not\n * a FluentTriggerComponent or React Fragment (the same element returned by {@link getTriggerChild}).\n */\nfunction cloneTriggerTree<TriggerChildProps>(\n child: React.ReactNode,\n triggerProps: TriggerChildProps,\n): React.ReactElement {\n if (!React.isValidElement(child) || child.type === React.Fragment) {\n throw new Error(\n 'A trigger element must be a single element for this component. ' +\n \"Please ensure that you're not using React Fragments.\",\n );\n }\n\n if (isFluentTrigger(child)) {\n const grandchild = cloneTriggerTree(child.props.children, triggerProps);\n return React.cloneElement(child, undefined, grandchild);\n } else {\n return React.cloneElement(child, triggerProps as TriggerChildProps & React.Attributes);\n }\n}\n"],"sourceRoot":"../src/"}
@@ -18,11 +18,18 @@ import { isFluentTrigger } from './isFluentTrigger';
18
18
  * </Tooltip>
19
19
  * );
20
20
  * ```
21
+ *
22
+ * In the case where the immediate child is not a valid element,
23
+ * null is returned
21
24
  */
22
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
25
 
24
- export const getTriggerChild = children => {
25
- const child = React.Children.only(children);
26
- return isFluentTrigger(child) ? getTriggerChild(child.props.children) : child;
27
- };
26
+ export function getTriggerChild(children) {
27
+ if (! /*#__PURE__*/React.isValidElement(children)) {
28
+ return null;
29
+ }
30
+
31
+ return isFluentTrigger(children) ? getTriggerChild( // FIXME: This casting should be unnecessary as isFluentTrigger is a guard type method,
32
+ // but for some reason it's failing on build
33
+ children.props.children) : children;
34
+ }
28
35
  //# sourceMappingURL=getTriggerChild.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["trigger/getTriggerChild.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,eAAT,QAAgC,mBAAhC;AAEA;;;;;;;;;;;;;;;;;;AAkBG;AACH;;AACA,OAAO,MAAM,eAAe,GAC1B,QAD6B,IAE2B;EACxD,MAAM,KAAK,GAAG,KAAK,CAAC,QAAN,CAAe,IAAf,CAAoB,QAApB,CAAd;EACA,OAAO,eAAe,CAAC,KAAD,CAAf,GAAyB,eAAe,CAAC,KAAK,CAAC,KAAN,CAAY,QAAb,CAAxC,GAAiE,KAAxE;AACD,CALM","sourcesContent":["import * as React from 'react';\nimport { isFluentTrigger } from './isFluentTrigger';\n\n/**\n * @internal\n * Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).\n *\n * In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,\n * it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.\n * This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.\n *\n * For example, the following returns `<div id=\"child\" />`:\n * ```jsx\n * getTriggerChild(\n * <Tooltip>\n * <MenuTrigger>\n * <div id=\"child\" />\n * </MenuTrigger>\n * </Tooltip>\n * );\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const getTriggerChild = <P = any>(\n children: React.ReactNode,\n): React.ReactElement<P> & { ref?: React.Ref<unknown> } => {\n const child = React.Children.only(children) as React.ReactElement;\n return isFluentTrigger(child) ? getTriggerChild(child.props.children) : child;\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["trigger/getTriggerChild.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,eAAT,QAAgC,mBAAhC;AAGA;;;;;;;;;;;;;;;;;;;;;AAqBG;;AACH,OAAM,SAAU,eAAV,CACJ,QADI,EACiD;EAGrD,IAAI,eAAC,KAAK,CAAC,cAAN,CAAwC,QAAxC,CAAL,EAAwD;IACtD,OAAO,IAAP;EACD;;EACD,OAAO,eAAe,CAAC,QAAD,CAAf,GACH,eAAe,EACb;EACA;EACC,QAAQ,CAAC,KAAT,CAAgC,QAHpB,CADZ,GAMH,QANJ;AAOD","sourcesContent":["import * as React from 'react';\nimport { isFluentTrigger } from './isFluentTrigger';\nimport type { TriggerProps } from './types';\n\n/**\n * @internal\n * Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).\n *\n * In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,\n * it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.\n * This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.\n *\n * For example, the following returns `<div id=\"child\" />`:\n * ```jsx\n * getTriggerChild(\n * <Tooltip>\n * <MenuTrigger>\n * <div id=\"child\" />\n * </MenuTrigger>\n * </Tooltip>\n * );\n * ```\n *\n * In the case where the immediate child is not a valid element,\n * null is returned\n */\nexport function getTriggerChild<TriggerChildProps>(\n children: TriggerProps<TriggerChildProps>['children'],\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): (React.ReactElement<Partial<TriggerChildProps>> & { ref?: React.Ref<any> }) | null {\n if (!React.isValidElement<TriggerChildProps>(children)) {\n return null;\n }\n return isFluentTrigger(children)\n ? getTriggerChild(\n // FIXME: This casting should be unnecessary as isFluentTrigger is a guard type method,\n // but for some reason it's failing on build\n (children.props as TriggerProps).children,\n )\n : children;\n}\n"],"sourceRoot":"../src/"}
@@ -1,8 +1,9 @@
1
1
  /**
2
+ * @internal
2
3
  * Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).
3
4
  * See the {@link FluentTriggerComponent} type for more info.
4
5
  */
5
- export const isFluentTrigger = element => {
6
- return element.type.isFluentTriggerComponent;
7
- };
6
+ export function isFluentTrigger(element) {
7
+ return Boolean(element.type.isFluentTriggerComponent);
8
+ }
8
9
  //# sourceMappingURL=isFluentTrigger.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["trigger/isFluentTrigger.ts"],"names":[],"mappings":"AAGA;;;AAGG;AACH,OAAO,MAAM,eAAe,GAAI,OAAD,IAAgC;EAC7D,OAAQ,OAAO,CAAC,IAAR,CAAwC,wBAAhD;AACD,CAFM","sourcesContent":["import * as React from 'react';\nimport { FluentTriggerComponent } from './types';\n\n/**\n * Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).\n * See the {@link FluentTriggerComponent} type for more info.\n */\nexport const isFluentTrigger = (element: React.ReactElement) => {\n return (element.type as FluentTriggerComponent).isFluentTriggerComponent;\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["trigger/isFluentTrigger.ts"],"names":[],"mappings":"AAGA;;;;AAIG;AACH,OAAM,SAAU,eAAV,CAA0B,OAA1B,EAAqD;EACzD,OAAO,OAAO,CAAE,OAAO,CAAC,IAAR,CAAwC,wBAA1C,CAAd;AACD","sourcesContent":["import * as React from 'react';\nimport type { FluentTriggerComponent, TriggerProps } from './types';\n\n/**\n * @internal\n * Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).\n * See the {@link FluentTriggerComponent} type for more info.\n */\nexport function isFluentTrigger(element: React.ReactElement): element is React.ReactElement<TriggerProps> {\n return Boolean((element.type as FluentTriggerComponent).isFluentTriggerComponent);\n}\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"../src/","sources":["trigger/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * @internal\n * Allows a component to be tagged as a FluentUI trigger component.\n *\n * Triggers are special-case components: they attach event listeners and other props on their child,\n * and use them to trigger another component to show. Examples include `MenuTrigger` and `Tooltip`.\n *\n * A component can be tagged as a trigger as follows:\n * ```ts\n * const MyComponent: React.FC<MyComponentProps> & FluentTriggerComponent = ...;\n *\n * MyComponent.isFluentTriggerComponent = true; // MUST also set this to true\n * ```\n */\nexport type FluentTriggerComponent = {\n isFluentTriggerComponent?: boolean;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"../src/","sources":["trigger/types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n * Allows a component to be tagged as a FluentUI trigger component.\n *\n * Triggers are special-case components: they attach event listeners and other props on their child,\n * and use them to trigger another component to show. Examples include `MenuTrigger` and `Tooltip`.\n *\n * A component can be tagged as a trigger as follows:\n * ```ts\n * const MyComponent: React.FC<MyComponentProps> & FluentTriggerComponent = ...;\n *\n * MyComponent.isFluentTriggerComponent = true; // MUST also set this to true\n * ```\n */\nexport type FluentTriggerComponent = {\n isFluentTriggerComponent?: boolean;\n};\n\n/**\n * @internal\n * A trigger may have a children that could be either:\n * 1. A single element\n * 2. A render function that will receive properties and must return a valid element or null\n * 3. null or undefined\n */\nexport type TriggerProps<TriggerChildProps = unknown> = {\n children?: React.ReactElement | ((props: TriggerChildProps) => React.ReactElement | null) | null;\n};\n"]}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getTriggerChild = exports.applyTriggerPropsToChildren = exports.shouldPreventDefaultOnKeyDown = exports.mergeCallbacks = exports.getRTLSafeKey = exports.getPartitionedNativeProps = exports.getNativeElementProps = exports.clamp = exports.SSRProvider = exports.useIsSSR = exports.canUseDOM = exports.useTimeout = exports.usePrevious = exports.useOnScrollOutside = exports.useOnClickOutside = exports.useMergedRefs = exports.useIsomorphicLayoutEffect = exports.useId = exports.useForceUpdate = exports.useFirstMount = exports.useEventCallback = exports.useControllableState = exports.resetIdsForTests = exports.isResolvedShorthand = exports.resolveShorthand = exports.getSlots = void 0;
6
+ exports.isFluentTrigger = exports.getTriggerChild = exports.applyTriggerPropsToChildren = exports.shouldPreventDefaultOnKeyDown = exports.mergeCallbacks = exports.getRTLSafeKey = exports.getPartitionedNativeProps = exports.getNativeElementProps = exports.clamp = exports.SSRProvider = exports.useIsSSR = exports.canUseDOM = exports.useTimeout = exports.usePrevious = exports.useOnScrollOutside = exports.useOnClickOutside = exports.useMergedRefs = exports.useIsomorphicLayoutEffect = exports.useId = exports.useForceUpdate = exports.useFirstMount = exports.useEventCallback = exports.useControllableState = exports.resetIdsForTests = exports.isResolvedShorthand = exports.resolveShorthand = exports.getSlots = void 0;
7
7
 
8
8
  var index_1 = /*#__PURE__*/require("./compose/index");
9
9
 
@@ -175,4 +175,10 @@ Object.defineProperty(exports, "getTriggerChild", {
175
175
  return index_5.getTriggerChild;
176
176
  }
177
177
  });
178
+ Object.defineProperty(exports, "isFluentTrigger", {
179
+ enumerable: true,
180
+ get: function () {
181
+ return index_5.isFluentTrigger;
182
+ }
183
+ });
178
184
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,OAAA,gBAAA,OAAA,CAAA,iBAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,UAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,QAAA;EAAQ;AAAR,CAAA;AAAU,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,kBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,gBAAA;EAAgB;AAAhB,CAAA;AAAkB,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,qBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,mBAAA;EAAmB;AAAnB,CAAA;;AAgBrC,IAAA,OAAA,gBAAA,OAAA,CAAA,eAAA,CAAA;;AACE,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,kBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,gBAAA;EAAgB;AAAhB,CAAA;AACA,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,sBAAA,EAAA;E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AAA;AACA,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,2BAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,yBAAA;EAAyB;AAAzB,CAAA;AACA,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,eAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,aAAA;EAAa;AAAb,CAAA;AACA,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,gBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,cAAA;EAAc;AAAd,CAAA;AACA,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,+BAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,6BAAA;EAA6B;AAA7B,CAAA;;AAGF,IAAA,OAAA,gBAAA,OAAA,CAAA,iBAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,6BAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,2BAAA;EAA2B;AAA3B,CAAA;AAA6B,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,iBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,eAAA;EAAe;AAAf,CAAA","sourcesContent":["export { getSlots, resolveShorthand, isResolvedShorthand } from './compose/index';\nexport type {\n ExtractSlotProps,\n ComponentProps,\n ComponentState,\n ForwardRefComponent,\n ResolveShorthandFunction,\n ResolveShorthandOptions,\n Slot,\n Slots,\n SlotClassNames,\n SlotPropsRecord,\n SlotRenderFunction,\n SlotShorthandValue,\n} from './compose/index';\n\nexport {\n resetIdsForTests,\n useControllableState,\n useEventCallback,\n useFirstMount,\n useForceUpdate,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n useOnClickOutside,\n useOnScrollOutside,\n usePrevious,\n useTimeout,\n} from './hooks/index';\nexport type { RefObjectFunction, UseControllableStateOptions, UseOnClickOrScrollOutsideOptions } from './hooks/index';\n\nexport { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';\n\nexport {\n clamp,\n getNativeElementProps,\n getPartitionedNativeProps,\n getRTLSafeKey,\n mergeCallbacks,\n shouldPreventDefaultOnKeyDown,\n} from './utils/index';\n\nexport { applyTriggerPropsToChildren, getTriggerChild } from './trigger/index';\n\nexport type { FluentTriggerComponent } from './trigger/index';\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,OAAA,gBAAA,OAAA,CAAA,iBAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,UAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,QAAA;EAAQ;AAAR,CAAA;AAAU,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,kBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,gBAAA;EAAgB;AAAhB,CAAA;AAAkB,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,qBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,mBAAA;EAAmB;AAAnB,CAAA;;AAgBrC,IAAA,OAAA,gBAAA,OAAA,CAAA,eAAA,CAAA;;AACE,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,kBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,OAAA,CAAA,gBAAA;EAAgB;AAAhB,CAAA;AACA,MAAA,CAAA,cAAA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ComponentProps,\n ComponentState,\n ForwardRefComponent,\n ResolveShorthandFunction,\n ResolveShorthandOptions,\n Slot,\n Slots,\n SlotClassNames,\n SlotPropsRecord,\n SlotRenderFunction,\n SlotShorthandValue,\n} from './compose/index';\n\nexport {\n resetIdsForTests,\n useControllableState,\n useEventCallback,\n useFirstMount,\n useForceUpdate,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n useOnClickOutside,\n useOnScrollOutside,\n usePrevious,\n useTimeout,\n} from './hooks/index';\nexport type { RefObjectFunction, UseControllableStateOptions, UseOnClickOrScrollOutsideOptions } from './hooks/index';\n\nexport { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';\n\nexport {\n clamp,\n getNativeElementProps,\n getPartitionedNativeProps,\n getRTLSafeKey,\n mergeCallbacks,\n shouldPreventDefaultOnKeyDown,\n} from './utils/index';\n\nexport { applyTriggerPropsToChildren, getTriggerChild, isFluentTrigger } from './trigger/index';\n\nexport type { FluentTriggerComponent, TriggerProps } from './trigger/index';\n"],"sourceRoot":"../src/"}
@@ -10,22 +10,22 @@ const React = /*#__PURE__*/require("react");
10
10
  const isFluentTrigger_1 = /*#__PURE__*/require("./isFluentTrigger");
11
11
  /**
12
12
  * @internal
13
- * Apply the trigger props to the children, either by calling the render function, or cloning with the new props.
13
+ * resolve the trigger props to the children, either by calling the render function, or cloning with the new props.
14
14
  */
15
15
 
16
16
 
17
- const applyTriggerPropsToChildren = (children, triggerProps) => {
17
+ function applyTriggerPropsToChildren(children, triggerChildProps) {
18
18
  if (typeof children === 'function') {
19
- return children(triggerProps);
19
+ return children(triggerChildProps);
20
20
  } else if (children) {
21
- return cloneTriggerTree(children, triggerProps);
21
+ return cloneTriggerTree(children, triggerChildProps);
22
22
  } // Components in React should return either JSX elements or "null", otherwise React will throw:
23
23
  // Nothing was returned from render.
24
24
  // This usually means a return statement is missing. Or, to render nothing, return null.
25
25
 
26
26
 
27
27
  return children || null;
28
- };
28
+ }
29
29
 
30
30
  exports.applyTriggerPropsToChildren = applyTriggerPropsToChildren;
31
31
  /**
@@ -33,7 +33,7 @@ exports.applyTriggerPropsToChildren = applyTriggerPropsToChildren;
33
33
  * a FluentTriggerComponent or React Fragment (the same element returned by {@link getTriggerChild}).
34
34
  */
35
35
 
36
- const cloneTriggerTree = (child, triggerProps) => {
36
+ function cloneTriggerTree(child, triggerProps) {
37
37
  if (!React.isValidElement(child) || child.type === React.Fragment) {
38
38
  throw new Error('A trigger element must be a single element for this component. ' + "Please ensure that you're not using React Fragments.");
39
39
  }
@@ -44,5 +44,5 @@ const cloneTriggerTree = (child, triggerProps) => {
44
44
  } else {
45
45
  return React.cloneElement(child, triggerProps);
46
46
  }
47
- };
47
+ }
48
48
  //# sourceMappingURL=applyTriggerPropsToChildren.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["trigger/applyTriggerPropsToChildren.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,mBAAA,CAAA;AAEA;;;AAGG;;;AACI,MAAM,2BAA2B,GAAG,CACzC,QADyC,EAEzC,YAFyC,KAGZ;EAC7B,IAAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;IAClC,OAAO,QAAQ,CAAC,YAAD,CAAf;EACD,CAFD,MAEO,IAAI,QAAJ,EAAc;IACnB,OAAO,gBAAgB,CAAC,QAAD,EAAW,YAAX,CAAvB;EACD,CAL4B,CAO7B;EACA;EACA;;;EACA,OAAO,QAAQ,IAAI,IAAnB;AACD,CAdM;;AAAM,OAAA,CAAA,2BAAA,GAA2B,2BAA3B;AAgBb;;;AAGG;;AACH,MAAM,gBAAgB,GAAG,CAAgB,KAAhB,EAAwC,YAAxC,KAA2F;EAClH,IAAI,CAAC,KAAK,CAAC,cAAN,CAAqB,KAArB,CAAD,IAAgC,KAAK,CAAC,IAAN,KAAe,KAAK,CAAC,QAAzD,EAAmE;IACjE,MAAM,IAAI,KAAJ,CACJ,oEACE,sDAFE,CAAN;EAID;;EAED,IAAI,iBAAA,CAAA,eAAA,CAAgB,KAAhB,CAAJ,EAA4B;IAC1B,MAAM,UAAU,GAAG,gBAAgB,CAAC,KAAK,CAAC,KAAN,CAAY,QAAb,EAAuB,YAAvB,CAAnC;IACA,OAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,SAA1B,EAAqC,UAArC,CAAP;EACD,CAHD,MAGO;IACL,OAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,YAA1B,CAAP;EACD;AACF,CAdD","sourcesContent":["import * as React from 'react';\nimport { isFluentTrigger } from './isFluentTrigger';\n\n/**\n * @internal\n * Apply the trigger props to the children, either by calling the render function, or cloning with the new props.\n */\nexport const applyTriggerPropsToChildren = <TTriggerProps>(\n children: React.ReactElement | ((props: TTriggerProps) => React.ReactElement | null) | null | undefined,\n triggerProps: TTriggerProps,\n): React.ReactElement | null => {\n if (typeof children === 'function') {\n return children(triggerProps);\n } else if (children) {\n return cloneTriggerTree(children, triggerProps);\n }\n\n // Components in React should return either JSX elements or \"null\", otherwise React will throw:\n // Nothing was returned from render.\n // This usually means a return statement is missing. Or, to render nothing, return null.\n return children || null;\n};\n\n/**\n * Clones a React element tree, and applies the given props to the first grandchild that is not\n * a FluentTriggerComponent or React Fragment (the same element returned by {@link getTriggerChild}).\n */\nconst cloneTriggerTree = <TTriggerProps>(child: React.ReactNode, triggerProps: TTriggerProps): React.ReactElement => {\n if (!React.isValidElement(child) || child.type === React.Fragment) {\n throw new Error(\n 'A trigger element must be a single element for this component. ' +\n \"Please ensure that you're not using React Fragments.\",\n );\n }\n\n if (isFluentTrigger(child)) {\n const grandchild = cloneTriggerTree(child.props.children, triggerProps);\n return React.cloneElement(child, undefined, grandchild);\n } else {\n return React.cloneElement(child, triggerProps);\n }\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["trigger/applyTriggerPropsToChildren.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,mBAAA,CAAA;AAGA;;;AAGG;;;AACH,SAAgB,2BAAhB,CACE,QADF,EAEE,iBAFF,EAEsC;EAEpC,IAAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;IAClC,OAAO,QAAQ,CAAC,iBAAD,CAAf;EACD,CAFD,MAEO,IAAI,QAAJ,EAAc;IACnB,OAAO,gBAAgB,CAAC,QAAD,EAAW,iBAAX,CAAvB;EACD,CANmC,CAQpC;EACA;EACA;;;EACA,OAAO,QAAQ,IAAI,IAAnB;AACD;;AAdD,OAAA,CAAA,2BAAA,GAAA,2BAAA;AAgBA;;;AAGG;;AACH,SAAS,gBAAT,CACE,KADF,EAEE,YAFF,EAEiC;EAE/B,IAAI,CAAC,KAAK,CAAC,cAAN,CAAqB,KAArB,CAAD,IAAgC,KAAK,CAAC,IAAN,KAAe,KAAK,CAAC,QAAzD,EAAmE;IACjE,MAAM,IAAI,KAAJ,CACJ,oEACE,sDAFE,CAAN;EAID;;EAED,IAAI,iBAAA,CAAA,eAAA,CAAgB,KAAhB,CAAJ,EAA4B;IAC1B,MAAM,UAAU,GAAG,gBAAgB,CAAC,KAAK,CAAC,KAAN,CAAY,QAAb,EAAuB,YAAvB,CAAnC;IACA,OAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,SAA1B,EAAqC,UAArC,CAAP;EACD,CAHD,MAGO;IACL,OAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,YAA1B,CAAP;EACD;AACF","sourcesContent":["import * as React from 'react';\nimport { isFluentTrigger } from './isFluentTrigger';\nimport type { TriggerProps } from './types';\n\n/**\n * @internal\n * resolve the trigger props to the children, either by calling the render function, or cloning with the new props.\n */\nexport function applyTriggerPropsToChildren<TriggerChildProps>(\n children: TriggerProps<TriggerChildProps>['children'],\n triggerChildProps: TriggerChildProps,\n): React.ReactElement | null {\n if (typeof children === 'function') {\n return children(triggerChildProps);\n } else if (children) {\n return cloneTriggerTree(children, triggerChildProps);\n }\n\n // Components in React should return either JSX elements or \"null\", otherwise React will throw:\n // Nothing was returned from render.\n // This usually means a return statement is missing. Or, to render nothing, return null.\n return children || null;\n}\n\n/**\n * Clones a React element tree, and applies the given props to the first grandchild that is not\n * a FluentTriggerComponent or React Fragment (the same element returned by {@link getTriggerChild}).\n */\nfunction cloneTriggerTree<TriggerChildProps>(\n child: React.ReactNode,\n triggerProps: TriggerChildProps,\n): React.ReactElement {\n if (!React.isValidElement(child) || child.type === React.Fragment) {\n throw new Error(\n 'A trigger element must be a single element for this component. ' +\n \"Please ensure that you're not using React Fragments.\",\n );\n }\n\n if (isFluentTrigger(child)) {\n const grandchild = cloneTriggerTree(child.props.children, triggerProps);\n return React.cloneElement(child, undefined, grandchild);\n } else {\n return React.cloneElement(child, triggerProps as TriggerChildProps & React.Attributes);\n }\n}\n"],"sourceRoot":"../src/"}
@@ -26,14 +26,21 @@ const isFluentTrigger_1 = /*#__PURE__*/require("./isFluentTrigger");
26
26
  * </Tooltip>
27
27
  * );
28
28
  * ```
29
+ *
30
+ * In the case where the immediate child is not a valid element,
31
+ * null is returned
29
32
  */
30
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
33
 
32
34
 
33
- const getTriggerChild = children => {
34
- const child = React.Children.only(children);
35
- return isFluentTrigger_1.isFluentTrigger(child) ? exports.getTriggerChild(child.props.children) : child;
36
- };
35
+ function getTriggerChild(children) {
36
+ if (!React.isValidElement(children)) {
37
+ return null;
38
+ }
39
+
40
+ return isFluentTrigger_1.isFluentTrigger(children) ? getTriggerChild( // FIXME: This casting should be unnecessary as isFluentTrigger is a guard type method,
41
+ // but for some reason it's failing on build
42
+ children.props.children) : children;
43
+ }
37
44
 
38
45
  exports.getTriggerChild = getTriggerChild;
39
46
  //# sourceMappingURL=getTriggerChild.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["trigger/getTriggerChild.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,mBAAA,CAAA;AAEA;;;;;;;;;;;;;;;;;;AAkBG;AACH;;;AACO,MAAM,eAAe,GAC1B,QAD6B,IAE2B;EACxD,MAAM,KAAK,GAAG,KAAK,CAAC,QAAN,CAAe,IAAf,CAAoB,QAApB,CAAd;EACA,OAAO,iBAAA,CAAA,eAAA,CAAgB,KAAhB,IAAyB,OAAA,CAAA,eAAA,CAAgB,KAAK,CAAC,KAAN,CAAY,QAA5B,CAAzB,GAAiE,KAAxE;AACD,CALM;;AAAM,OAAA,CAAA,eAAA,GAAe,eAAf","sourcesContent":["import * as React from 'react';\nimport { isFluentTrigger } from './isFluentTrigger';\n\n/**\n * @internal\n * Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).\n *\n * In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,\n * it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.\n * This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.\n *\n * For example, the following returns `<div id=\"child\" />`:\n * ```jsx\n * getTriggerChild(\n * <Tooltip>\n * <MenuTrigger>\n * <div id=\"child\" />\n * </MenuTrigger>\n * </Tooltip>\n * );\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const getTriggerChild = <P = any>(\n children: React.ReactNode,\n): React.ReactElement<P> & { ref?: React.Ref<unknown> } => {\n const child = React.Children.only(children) as React.ReactElement;\n return isFluentTrigger(child) ? getTriggerChild(child.props.children) : child;\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["trigger/getTriggerChild.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,mBAAA,CAAA;AAGA;;;;;;;;;;;;;;;;;;;;;AAqBG;;;AACH,SAAgB,eAAhB,CACE,QADF,EACuD;EAGrD,IAAI,CAAC,KAAK,CAAC,cAAN,CAAwC,QAAxC,CAAL,EAAwD;IACtD,OAAO,IAAP;EACD;;EACD,OAAO,iBAAA,CAAA,eAAA,CAAgB,QAAhB,IACH,eAAe,EACb;EACA;EACC,QAAQ,CAAC,KAAT,CAAgC,QAHpB,CADZ,GAMH,QANJ;AAOD;;AAdD,OAAA,CAAA,eAAA,GAAA,eAAA","sourcesContent":["import * as React from 'react';\nimport { isFluentTrigger } from './isFluentTrigger';\nimport type { TriggerProps } from './types';\n\n/**\n * @internal\n * Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).\n *\n * In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,\n * it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.\n * This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.\n *\n * For example, the following returns `<div id=\"child\" />`:\n * ```jsx\n * getTriggerChild(\n * <Tooltip>\n * <MenuTrigger>\n * <div id=\"child\" />\n * </MenuTrigger>\n * </Tooltip>\n * );\n * ```\n *\n * In the case where the immediate child is not a valid element,\n * null is returned\n */\nexport function getTriggerChild<TriggerChildProps>(\n children: TriggerProps<TriggerChildProps>['children'],\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): (React.ReactElement<Partial<TriggerChildProps>> & { ref?: React.Ref<any> }) | null {\n if (!React.isValidElement<TriggerChildProps>(children)) {\n return null;\n }\n return isFluentTrigger(children)\n ? getTriggerChild(\n // FIXME: This casting should be unnecessary as isFluentTrigger is a guard type method,\n // but for some reason it's failing on build\n (children.props as TriggerProps).children,\n )\n : children;\n}\n"],"sourceRoot":"../src/"}
@@ -5,13 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.isFluentTrigger = void 0;
7
7
  /**
8
+ * @internal
8
9
  * Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).
9
10
  * See the {@link FluentTriggerComponent} type for more info.
10
11
  */
11
12
 
12
- const isFluentTrigger = element => {
13
- return element.type.isFluentTriggerComponent;
14
- };
13
+ function isFluentTrigger(element) {
14
+ return Boolean(element.type.isFluentTriggerComponent);
15
+ }
15
16
 
16
17
  exports.isFluentTrigger = isFluentTrigger;
17
18
  //# sourceMappingURL=isFluentTrigger.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["trigger/isFluentTrigger.ts"],"names":[],"mappings":";;;;;;AAGA;;;AAGG;;AACI,MAAM,eAAe,GAAI,OAAD,IAAgC;EAC7D,OAAQ,OAAO,CAAC,IAAR,CAAwC,wBAAhD;AACD,CAFM;;AAAM,OAAA,CAAA,eAAA,GAAe,eAAf","sourcesContent":["import * as React from 'react';\nimport { FluentTriggerComponent } from './types';\n\n/**\n * Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).\n * See the {@link FluentTriggerComponent} type for more info.\n */\nexport const isFluentTrigger = (element: React.ReactElement) => {\n return (element.type as FluentTriggerComponent).isFluentTriggerComponent;\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["trigger/isFluentTrigger.ts"],"names":[],"mappings":";;;;;;AAGA;;;;AAIG;;AACH,SAAgB,eAAhB,CAAgC,OAAhC,EAA2D;EACzD,OAAO,OAAO,CAAE,OAAO,CAAC,IAAR,CAAwC,wBAA1C,CAAd;AACD;;AAFD,OAAA,CAAA,eAAA,GAAA,eAAA","sourcesContent":["import * as React from 'react';\nimport type { FluentTriggerComponent, TriggerProps } from './types';\n\n/**\n * @internal\n * Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).\n * See the {@link FluentTriggerComponent} type for more info.\n */\nexport function isFluentTrigger(element: React.ReactElement): element is React.ReactElement<TriggerProps> {\n return Boolean((element.type as FluentTriggerComponent).isFluentTriggerComponent);\n}\n"],"sourceRoot":"../src/"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-utilities",
3
- "version": "9.1.0",
3
+ "version": "9.1.1",
4
4
  "description": "A set of general React-specific utilities.",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",