@fluentui/react-utilities 0.0.0-nightly946f57cad420220203.1 → 0.0.0-nightly96d9c9354420220210.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 (42) hide show
  1. package/CHANGELOG.json +30 -6
  2. package/CHANGELOG.md +10 -6
  3. package/dist/react-utilities.d.ts +101 -67
  4. package/lib/compose/getSlots.d.ts +3 -3
  5. package/lib/compose/getSlots.js +1 -2
  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 +7 -3
  11. package/lib/compose/resolveShorthand.js +2 -2
  12. package/lib/compose/resolveShorthand.js.map +1 -1
  13. package/lib/compose/types.d.ts +70 -40
  14. package/lib/compose/types.js.map +1 -1
  15. package/lib/utils/applyTriggerPropsToChildren.d.ts +1 -1
  16. package/lib/utils/applyTriggerPropsToChildren.js +5 -2
  17. package/lib/utils/applyTriggerPropsToChildren.js.map +1 -1
  18. package/lib/utils/getNativeElementProps.d.ts +4 -4
  19. package/lib/utils/getNativeElementProps.js.map +1 -1
  20. package/lib-commonjs/compose/getSlots.d.ts +3 -3
  21. package/lib-commonjs/compose/getSlots.js +1 -3
  22. package/lib-commonjs/compose/getSlots.js.map +1 -1
  23. package/lib-commonjs/compose/index.d.ts +0 -1
  24. package/lib-commonjs/compose/index.js +0 -2
  25. package/lib-commonjs/compose/index.js.map +1 -1
  26. package/lib-commonjs/compose/resolveShorthand.d.ts +7 -3
  27. package/lib-commonjs/compose/resolveShorthand.js +2 -2
  28. package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
  29. package/lib-commonjs/compose/types.d.ts +70 -40
  30. package/lib-commonjs/compose/types.js.map +1 -1
  31. package/lib-commonjs/utils/applyTriggerPropsToChildren.d.ts +1 -1
  32. package/lib-commonjs/utils/applyTriggerPropsToChildren.js +5 -2
  33. package/lib-commonjs/utils/applyTriggerPropsToChildren.js.map +1 -1
  34. package/lib-commonjs/utils/getNativeElementProps.d.ts +4 -4
  35. package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
  36. package/package.json +2 -2
  37. package/lib/compose/nullRender.d.ts +0 -4
  38. package/lib/compose/nullRender.js +0 -5
  39. package/lib/compose/nullRender.js.map +0 -1
  40. package/lib-commonjs/compose/nullRender.d.ts +0 -4
  41. package/lib-commonjs/compose/nullRender.js +0 -14
  42. package/lib-commonjs/compose/nullRender.js.map +0 -1
package/CHANGELOG.json CHANGED
@@ -2,15 +2,15 @@
2
2
  "name": "@fluentui/react-utilities",
3
3
  "entries": [
4
4
  {
5
- "date": "Thu, 03 Feb 2022 04:16:57 GMT",
6
- "tag": "@fluentui/react-utilities_v0.0.0-nightly946f57cad420220203.1",
7
- "version": "0.0.0-nightly946f57cad420220203.1",
5
+ "date": "Thu, 10 Feb 2022 04:16:37 GMT",
6
+ "tag": "@fluentui/react-utilities_v0.0.0-nightly96d9c9354420220210.1",
7
+ "version": "0.0.0-nightly96d9c9354420220210.1",
8
8
  "comments": {
9
9
  "prerelease": [
10
10
  {
11
11
  "author": "email not defined",
12
12
  "package": "@fluentui/react-utilities",
13
- "commit": "1d230926e10b3b722bd932be1ec39faaf340671c",
13
+ "commit": "df0f6db42df4395871de937d79a23fc5c3d82831",
14
14
  "comment": "Release nightly v9"
15
15
  },
16
16
  {
@@ -31,6 +31,24 @@
31
31
  "commit": "d2eb57808a403b70845a732a62b55aa64d66b2a0",
32
32
  "comment": "add useTriggerElement() hook"
33
33
  },
34
+ {
35
+ "author": "bsunderhus@microsoft.com",
36
+ "package": "@fluentui/react-utilities",
37
+ "commit": "c0d4e63ee58e60e2c6674efbacc0783cd520984e",
38
+ "comment": "Removes nullRender from react-utilities"
39
+ },
40
+ {
41
+ "author": "olfedias@microsoft.com",
42
+ "package": "@fluentui/react-utilities",
43
+ "commit": "aa6cfd8ac825b5a280206808101de549a91094fc",
44
+ "comment": "update applyTriggerPropsToChildren() to return React.ReactElement or null"
45
+ },
46
+ {
47
+ "author": "behowell@microsoft.com",
48
+ "package": "@fluentui/react-utilities",
49
+ "commit": "53b01d71e335715fda91b33e3d7bbd9d471d5ed3",
50
+ "comment": "Refactor component Slot typings"
51
+ },
34
52
  {
35
53
  "author": "Humberto.Morimoto@microsoft.com",
36
54
  "package": "@fluentui/react-utilities",
@@ -43,6 +61,12 @@
43
61
  "commit": "e0b8e1fa6980077e7b311fd1c72c28d3e4305db0",
44
62
  "comment": "Renaming most *Shorthand* composition types to *SlotProps* so they better reflect what the types do."
45
63
  },
64
+ {
65
+ "author": "lingfangao@hotmail.com",
66
+ "package": "@fluentui/react-utilities",
67
+ "commit": "c00913d50e2dd15bbfbb0757cefe43b192ff1d7f",
68
+ "comment": "Bump Fluent UI packages to 9.0.0-rc"
69
+ },
46
70
  {
47
71
  "author": "behowell@microsoft.com",
48
72
  "package": "@fluentui/react-utilities",
@@ -58,8 +82,8 @@
58
82
  {
59
83
  "author": "beachball",
60
84
  "package": "@fluentui/react-utilities",
61
- "comment": "Bump @fluentui/keyboard-keys to v0.0.0-nightly946f57cad420220203.1",
62
- "commit": "1d230926e10b3b722bd932be1ec39faaf340671c"
85
+ "comment": "Bump @fluentui/keyboard-keys to v0.0.0-nightly96d9c9354420220210.1",
86
+ "commit": "df0f6db42df4395871de937d79a23fc5c3d82831"
63
87
  }
64
88
  ],
65
89
  "none": [
package/CHANGELOG.md CHANGED
@@ -1,25 +1,29 @@
1
1
  # Change Log - @fluentui/react-utilities
2
2
 
3
- This log was last generated on Thu, 03 Feb 2022 04:16:57 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 10 Feb 2022 04:16:37 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## [0.0.0-nightly946f57cad420220203.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v0.0.0-nightly946f57cad420220203.1)
7
+ ## [0.0.0-nightly96d9c9354420220210.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v0.0.0-nightly96d9c9354420220210.1)
8
8
 
9
- Thu, 03 Feb 2022 04:16:57 GMT
10
- [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.0-beta.4..@fluentui/react-utilities_v0.0.0-nightly946f57cad420220203.1)
9
+ Thu, 10 Feb 2022 04:16:37 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.0-beta.4..@fluentui/react-utilities_v0.0.0-nightly96d9c9354420220210.1)
11
11
 
12
12
  ### Changes
13
13
 
14
- - Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/1d230926e10b3b722bd932be1ec39faaf340671c) by email not defined)
14
+ - Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/df0f6db42df4395871de937d79a23fc5c3d82831) by email not defined)
15
15
  - Rename component hooks add the suffix _unstable, as their API has not been finalized yet ([PR #21365](https://github.com/microsoft/fluentui/pull/21365) by behowell@microsoft.com)
16
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
17
  - add useTriggerElement() hook ([PR #21225](https://github.com/microsoft/fluentui/pull/21225) by olfedias@microsoft.com)
18
+ - Removes nullRender from react-utilities ([PR #21576](https://github.com/microsoft/fluentui/pull/21576) by bsunderhus@microsoft.com)
19
+ - update applyTriggerPropsToChildren() to return React.ReactElement or null ([PR #21609](https://github.com/microsoft/fluentui/pull/21609) by olfedias@microsoft.com)
20
+ - Refactor component Slot typings ([PR #21518](https://github.com/microsoft/fluentui/pull/21518) by behowell@microsoft.com)
18
21
  - Adding ComponentSlotProps to allow ref to be passed in composite components. ([PR #20890](https://github.com/microsoft/fluentui/pull/20890) by Humberto.Morimoto@microsoft.com)
19
22
  - Renaming most *Shorthand* composition types to *SlotProps* so they better reflect what the types do. ([PR #20891](https://github.com/microsoft/fluentui/pull/20891) by Humberto.Morimoto@microsoft.com)
23
+ - Bump Fluent UI packages to 9.0.0-rc ([PR #21623](https://github.com/microsoft/fluentui/pull/21623) by lingfangao@hotmail.com)
20
24
  - Update trigger utilities to handle nested triggers ([PR #21495](https://github.com/microsoft/fluentui/pull/21495) by behowell@microsoft.com)
21
25
  - [breaking] Remove useControllableValue hook (use useControllableState instead) ([PR #20865](https://github.com/microsoft/fluentui/pull/20865) by elcraig@microsoft.com)
22
- - Bump @fluentui/keyboard-keys to v0.0.0-nightly946f57cad420220203.1 ([commit](https://github.com/microsoft/fluentui/commit/1d230926e10b3b722bd932be1ec39faaf340671c) by beachball)
26
+ - Bump @fluentui/keyboard-keys to v0.0.0-nightly96d9c9354420220210.1 ([commit](https://github.com/microsoft/fluentui/commit/df0f6db42df4395871de937d79a23fc5c3d82831) by beachball)
23
27
 
24
28
  ## [9.0.0-beta.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.0.0-beta.4)
25
29
 
@@ -11,7 +11,7 @@ export declare const anchorProperties: Record<string, number>;
11
11
  /**
12
12
  * Apply the trigger props to the children, either by calling the render function, or cloning with the new props.
13
13
  */
14
- export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: React_2.ReactElement<any, string | React_2.JSXElementConstructor<any>> | ((props: TTriggerProps) => React_2.ReactNode) | null | undefined, triggerProps: TTriggerProps) => React_2.ReactNode;
14
+ export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: React_2.ReactElement<any, string | React_2.JSXElementConstructor<any>> | ((props: TTriggerProps) => React_2.ReactElement | null) | null | undefined, triggerProps: TTriggerProps) => React_2.ReactElement | null;
15
15
 
16
16
  /**
17
17
  * Helper type for inferring the type of the as prop from a Props type.
@@ -75,35 +75,18 @@ export declare const colProperties: Record<string, number>;
75
75
  * Defines the Props type for a component given its slots and the definition of which one is the primary slot,
76
76
  * defaulting to root if one is not provided.
77
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]>;
81
-
82
- /**
83
- * Defines the slot props for a slot that supports a Component type.
84
- *
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
- * ```
96
- */
97
- export declare type ComponentSlotProps<Component extends React_2.ComponentType> = Component extends React_2.ComponentType<infer Props> ? SlotProps<Props> : never;
78
+ export declare type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> = Omit<Slots, Primary & 'root'> & PropsWithoutRef<ExtractSlotProps<Slots[Primary]>>;
98
79
 
99
80
  /**
100
81
  * Defines the State object of a component given its slots.
101
82
  */
102
83
  export declare type ComponentState<Slots extends SlotPropsRecord> = {
103
84
  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);
85
+ [Key in keyof Slots]-?: React_2.ComponentType<ExtractSlotProps<Slots[Key]>> | (ExtractSlotProps<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
105
86
  };
106
- } & Slots;
87
+ } & {
88
+ [Key in keyof Slots]: ReplaceNullWithUndefined<Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>>;
89
+ };
107
90
 
108
91
  /**
109
92
  * Default context value to use in case there is no SSRProvider. This is fine for client-only apps.
@@ -119,6 +102,18 @@ export declare const defaultSSRContextValue: SSRContextValue;
119
102
  */
120
103
  export declare const divProperties: Record<string, number>;
121
104
 
105
+ /**
106
+ * HTML element types that are not allowed to have children.
107
+ *
108
+ * Reference: https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
109
+ */
110
+ declare type EmptyIntrisicElements = 'area' | 'base' | 'br' | 'col' | 'embed' | 'hr' | 'img' | 'input' | 'link' | 'meta' | 'param' | 'source' | 'track' | 'wbr';
111
+
112
+ /**
113
+ * Removes SlotShorthandValue and null from the slot type, extracting just the slot's Props object.
114
+ */
115
+ export declare type ExtractSlotProps<S> = Exclude<S, SlotShorthandValue | null | undefined>;
116
+
122
117
  /**
123
118
  * Allows a component to be tagged as a FluentUI trigger component.
124
119
  *
@@ -181,19 +176,19 @@ export declare function getNativeProps<T extends Record<string, any>>(props: Rec
181
176
  *
182
177
  * @returns An object containing the native props for the `root` and primary slots.
183
178
  */
184
- export declare const getPartitionedNativeProps: ({ primarySlotTagName, props, excludedPropNames, }: {
179
+ export declare const getPartitionedNativeProps: <Props extends Pick<React_2.HTMLAttributes<HTMLElement>, "style" | "className">, ExcludedPropKeys extends Extract<keyof Props, string> = never>({ primarySlotTagName, props, excludedPropNames, }: {
185
180
  /** The primary slot's element type (e.g. 'div') */
186
181
  primarySlotTagName: keyof JSX.IntrinsicElements;
187
182
  /** The component's props object */
188
- props: Pick<React_2.HTMLAttributes<HTMLElement>, 'style' | 'className'>;
183
+ props: Props;
189
184
  /** List of native props to exclude from the returned value */
190
- excludedPropNames?: string[] | undefined;
185
+ excludedPropNames?: ExcludedPropKeys[] | undefined;
191
186
  }) => {
192
187
  root: {
193
188
  style: React_2.CSSProperties | undefined;
194
189
  className: string | undefined;
195
190
  };
196
- primary: React_2.HTMLAttributes<any>;
191
+ primary: Omit<Props, ExcludedPropKeys>;
197
192
  };
198
193
 
199
194
  /**
@@ -279,25 +274,13 @@ export declare const imgProperties: Record<string, number>;
279
274
  export declare const inputProperties: Record<string, number>;
280
275
 
281
276
  /**
282
- * Define the slot arguments for a slot that supports one or more intrinsic element types, such as 'div'.
283
- * For slots that support custom components, use {@link ComponentSlotProps} instead.
284
- *
285
- * The first param is the slot's default type if no `as` prop is specified.
286
- * The second param is an optional union of alternative types that can be specified for the `as` prop.
287
- *
288
- * ```
289
- * IntrinsicSlotProps<'div'> // Slot is always div
290
- * IntrinsicSlotProps<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
291
- * IntrinsicSlotProps<'label', 'span' | 'div'>; // Defaults to label, but allows as="span" or as="div"
292
- * ```
277
+ * Helper type for {@link Slot}. Modifies `JSX.IntrinsicElements[Type]`:
278
+ * * Removes legacy string ref.
279
+ * * Disallows children for empty tags like 'img'.
293
280
  */
294
- 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' : ({
295
- as?: DefaultAs;
296
- } & SlotProps<React_2.PropsWithRef<JSX.IntrinsicElements[DefaultAs]>>) | {
297
- [As in AlternateAs]: {
298
- as: As;
299
- } & SlotProps<React_2.PropsWithRef<JSX.IntrinsicElements[As]>>;
300
- }[AlternateAs];
281
+ declare type IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = React_2.PropsWithRef<JSX.IntrinsicElements[Type]> & (Type extends EmptyIntrisicElements ? {
282
+ children?: never;
283
+ } : {});
301
284
 
302
285
  /**
303
286
  * Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).
@@ -331,13 +314,8 @@ export declare const labelProperties: Record<string, number>;
331
314
  */
332
315
  export declare const liProperties: Record<string, number>;
333
316
 
334
- /**
335
- * Simple constant function for returning null, used to render empty templates in JSX.
336
- */
337
- export declare const nullRender: () => null;
338
-
339
317
  declare type ObjectSlotProps<S extends SlotPropsRecord> = {
340
- [K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : NonNullable<S[K]> extends SlotProps<infer P> ? P : never;
318
+ [K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : ExtractSlotProps<S[K]> extends React_2.ComponentType<infer P> ? P : never;
341
319
  };
342
320
 
343
321
  /**
@@ -393,6 +371,11 @@ export declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unkn
393
371
  */
394
372
  export declare type RefObjectFunction<T> = React_2.RefObject<T> & ((value: T) => void);
395
373
 
374
+ /**
375
+ * If type T includes `null`, remove it and add `undefined` instead.
376
+ */
377
+ export declare type ReplaceNullWithUndefined<T> = T extends null ? Exclude<T, null> | undefined : T;
378
+
396
379
  /**
397
380
  * Resets generated IDs, should be used only in tests.
398
381
  *
@@ -406,9 +389,14 @@ export declare function resetIdsForTests(): void;
406
389
  * @param value - the base shorthand props
407
390
  * @param options - options to resolve shorthand props
408
391
  */
409
- export declare function resolveShorthand<Props extends UnknownSlotProps, Required extends boolean = false>(value: ShorthandProps<Props>, options?: ResolveShorthandOptions<Props, Required>): Required extends false ? Props | undefined : Props;
392
+ export declare const resolveShorthand: ResolveShorthandFunction;
410
393
 
411
- export declare type ResolveShorthandOptions<Props extends Record<string, any>, Required extends boolean = false> = {
394
+ export declare type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {
395
+ <P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, true>): ReplaceNullWithUndefined<P>;
396
+ <P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, boolean>): ReplaceNullWithUndefined<P> | undefined;
397
+ };
398
+
399
+ export declare type ResolveShorthandOptions<Props, Required extends boolean = false> = {
412
400
  required?: Required;
413
401
  defaultProps?: Props;
414
402
  };
@@ -420,8 +408,6 @@ export declare type ResolveShorthandOptions<Props extends Record<string, any>, R
420
408
  */
421
409
  export declare const selectProperties: Record<string, number>;
422
410
 
423
- export declare type ShorthandProps<Props extends UnknownSlotProps> = React_2.ReactChild | React_2.ReactNodeArray | React_2.ReactPortal | number | null | undefined | Props;
424
-
425
411
  /**
426
412
  * Checks if the keyboard event should preventDefault() for Enter and Spacebar keys
427
413
  *
@@ -430,23 +416,54 @@ export declare type ShorthandProps<Props extends UnknownSlotProps> = React_2.Rea
430
416
  export declare function shouldPreventDefaultOnKeyDown(e: KeyboardEvent | React_2.KeyboardEvent): boolean;
431
417
 
432
418
  /**
433
- * Takes the props we want to support for a slot and adds the ability for `children` to be a render function that takes
434
- * those props.
419
+ * The props type and shorthand value for a slot. Type is either a single intrinsic element like `'div'`,
420
+ * or a component like `typeof Button`.
421
+ *
422
+ * If a slot needs to support multiple intrinsic element types, use the `AlternateAs` param (see examples below).
423
+ *
424
+ * By default, slots can be set to `null` to prevent them from being rendered. If a slot must always be rendered,
425
+ * wrap with `NonNullable` (see examples below).
426
+ *
427
+ * @example
428
+ * ```
429
+ * // Intrinsic element examples:
430
+ * Slot<'div'> // Slot is always div
431
+ * Slot<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
432
+ * Slot<'span', 'div' | 'pre'> // Defaults to span, but allows as="div" or as="pre"
433
+ * NonNullable<Slot<'div'>> // Slot that will always be rendered (can't be set to null by the user)
434
+ *
435
+ * // Component examples:
436
+ * Slot<typeof Button> // Slot is always a Button, and accepts all of Button's Props
437
+ * NonNullable<Slot<typeof Label>> // Slot is a Label and will always be rendered (can't be set to null by the user)
438
+ * ```
435
439
  */
436
- export declare type SlotProps<Props extends {
437
- children?: React_2.ReactNode;
438
- } = {}> = Props & {
439
- children?: Props['children'] | SlotRenderFunction<Props>;
440
- };
440
+ export declare type Slot<Type extends keyof JSX.IntrinsicElements | React_2.ComponentType | UnknownSlotProps, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<Extract<Type, string>> extends true ? WithSlotShorthandValue<Type extends keyof JSX.IntrinsicElements ? {
441
+ as?: Type;
442
+ } & WithSlotRenderFunction<IntrisicElementProps<Type>> : Type extends React_2.ComponentType<infer Props> ? WithSlotRenderFunction<Props> : Type> | {
443
+ [As in AlternateAs]: {
444
+ as: As;
445
+ } & WithSlotRenderFunction<IntrisicElementProps<As>>;
446
+ }[AlternateAs] | null : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';
441
447
 
442
- export declare type SlotPropsRecord = Record<string, UnknownSlotProps | undefined>;
448
+ /**
449
+ * Matches any component's Slots type (such as ButtonSlots).
450
+ *
451
+ * This should ONLY be used in type templates as in `extends SlotPropsRecord`;
452
+ * it shouldn't be used as a component's Slots type.
453
+ */
454
+ export declare type SlotPropsRecord = Record<string, UnknownSlotProps | SlotShorthandValue | null | undefined>;
443
455
 
444
456
  export declare type SlotRenderFunction<Props> = (Component: React_2.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React_2.ReactNode;
445
457
 
446
458
  export declare type Slots<S extends SlotPropsRecord> = {
447
- [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]>>;
459
+ [K in keyof S]: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? As : ExtractSlotProps<S[K]> extends React_2.ComponentType<infer P> ? React_2.ElementType<NonNullable<P>> : React_2.ElementType<ExtractSlotProps<S[K]>>;
448
460
  };
449
461
 
462
+ /**
463
+ * The shorthand value of a slot allows specifying its child
464
+ */
465
+ export declare type SlotShorthandValue = React_2.ReactChild | React_2.ReactNodeArray | React_2.ReactPortal;
466
+
450
467
  export declare const SSRContext: React_2.Context<SSRContextValue>;
451
468
 
452
469
  /**
@@ -510,12 +527,12 @@ export declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U :
510
527
  /**
511
528
  * Matches any slot props type.
512
529
  *
513
- * This should ONLY be used in type templates as in `extends DefaultObjectSlotProps`;
530
+ * This should ONLY be used in type templates as in `extends UnknownSlotProps`;
514
531
  * it shouldn't be used as the type of a slot.
515
532
  */
516
- export declare type UnknownSlotProps = SlotProps<Pick<React_2.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
533
+ export declare type UnknownSlotProps = Pick<React_2.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
517
534
  as?: keyof JSX.IntrinsicElements;
518
- }>;
535
+ };
519
536
 
520
537
  /**
521
538
  * Hook to store a value and generate callbacks for setting the value to true or false.
@@ -738,4 +755,21 @@ export declare const useUnmount: (callback: () => void) => void;
738
755
  */
739
756
  export declare const videoProperties: Record<string, number>;
740
757
 
758
+ /**
759
+ * Helper type for {@link Slot}. Takes the props we want to support for a slot and adds the ability for `children`
760
+ * to be a render function that takes those props.
761
+ */
762
+ declare type WithSlotRenderFunction<Props extends {
763
+ children?: unknown;
764
+ }> = Props & {
765
+ children?: Props['children'] | SlotRenderFunction<Props>;
766
+ };
767
+
768
+ /**
769
+ * Helper type for {@link Slot}. Adds shorthand types that are assignable to the slot's `children`.
770
+ */
771
+ declare type WithSlotShorthandValue<Props extends {
772
+ children?: unknown;
773
+ }> = Props | Extract<SlotShorthandValue, Props['children']>;
774
+
741
775
  export { }
@@ -1,10 +1,10 @@
1
1
  import * as React from 'react';
2
- import type { AsIntrinsicElement, ComponentState, SlotProps, SlotPropsRecord, UnionToIntersection } from './types';
2
+ import type { AsIntrinsicElement, ComponentState, ExtractSlotProps, SlotPropsRecord, UnionToIntersection } from './types';
3
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]>>;
4
+ [K in keyof S]: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? As : ExtractSlotProps<S[K]> extends React.ComponentType<infer P> ? React.ElementType<NonNullable<P>> : React.ElementType<ExtractSlotProps<S[K]>>;
5
5
  };
6
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;
7
+ [K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : ExtractSlotProps<S[K]> extends React.ComponentType<infer P> ? P : never;
8
8
  };
9
9
  /**
10
10
  * Given the state and an array of slot names, will break out `slots` and `slotProps`
@@ -1,5 +1,4 @@
1
1
  import * as React from 'react';
2
- import { nullRender } from './nullRender';
3
2
  import { omit } from '../utils/omit';
4
3
  /**
5
4
  * Given the state and an array of slot names, will break out `slots` and `slotProps`
@@ -40,7 +39,7 @@ function getSlot(state, slotName) {
40
39
  var _a, _b, _c;
41
40
 
42
41
  if (state[slotName] === undefined) {
43
- return [nullRender, undefined];
42
+ return [null, undefined];
44
43
  }
45
44
 
46
45
  const {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/compose/getSlots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA,SAAS,UAAT,QAA2B,cAA3B;AACA,SAAS,IAAT,QAAqB,eAArB;AA6BA;;;;;;;;;;;;;;;;AAgBG;;AACH,OAAM,SAAU,QAAV,CACJ,KADI,EACoB;AAKxB,QAAM,KAAK,GAAG,EAAd;AACA,QAAM,SAAS,GAAG,EAAlB;AAEA,QAAM,SAAS,GAAgB,MAAM,CAAC,IAAP,CAAY,KAAK,CAAC,UAAlB,CAA/B;;AACA,OAAK,MAAM,QAAX,IAAuB,SAAvB,EAAkC;AAChC,UAAM,CAAC,IAAD,EAAO,KAAP,IAAgB,OAAO,CAAC,KAAD,EAAQ,QAAR,CAA7B;AACA,IAAA,KAAK,CAAC,QAAD,CAAL,GAAkB,IAAlB;AACA,IAAA,SAAS,CAAC,QAAD,CAAT,GAAsB,KAAtB;AACD;;AACD,SAAO;AAAE,IAAA,KAAF;AAAS,IAAA,SAAS,EAAG;AAArB,GAAP;AACD;;AAED,SAAS,OAAT,CACE,KADF,EAEE,QAFF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,CAAC,UAAN,MAAgB,IAAhB,IAAgB,EAAA,KAAA,KAAA,CAAhB,GAAgB,KAAA,CAAhB,GAAgB,EAAA,CAAG,QAAH,CAApB,CAAN,IAA0C,KADhC,GAEV,KAAK,CAAC,UAAN,CAAiB,QAAjB,CAFJ;;AAIA,MAAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;AAClC,UAAM,MAAM,GAAG,QAAf;AACA,WAAO,CACL,KAAK,CAAC,QADD,EAEJ;AACC,MAAA,QAAQ,EAAE,MAAM,CAAC,IAAD,EAAO,IAAP;AADjB,KAFI,CAAP;AAMD;;AAED,QAAM,gBAAgB,GAAG,OAAO,IAAP,KAAgB,QAAhB,KAA4B,CAAA,EAAA,GAAA,KAAK,CAAC,QAAD,CAAL,MAAe,IAAf,IAAe,EAAA,KAAA,KAAA,CAAf,GAAe,KAAA,CAAf,GAAe,EAAA,CAAE,EAA7C,CAAzB;AACA,QAAM,SAAS,GAAI,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,QAAD,CAAN,EAAmB,CAAC,IAAD,CAAnB,CAAP,GAAoC,KAAK,CAAC,QAAD,CAA5E;AAEA,SAAO,CAAC,IAAD,EAAO,SAAP,CAAP;AACD","sourceRoot":""}
@@ -1,4 +1,3 @@
1
1
  export * from './getSlots';
2
- export * from './nullRender';
3
2
  export * from './resolveShorthand';
4
3
  export * from './types';
@@ -1,5 +1,4 @@
1
1
  export * from './getSlots';
2
- export * from './nullRender';
3
2
  export * from './resolveShorthand';
4
3
  export * from './types';
5
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/compose/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/compose/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC"}
@@ -1,12 +1,16 @@
1
- import type { UnknownSlotProps, 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
11
  * Resolves shorthands into slot props, to ensure normalization of the signature
8
12
  * being passed down to getSlots method
9
13
  * @param value - the base shorthand props
10
14
  * @param options - options to resolve shorthand props
11
15
  */
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;
16
+ export declare const resolveShorthand: ResolveShorthandFunction;
@@ -6,7 +6,7 @@ import { isValidElement } from 'react';
6
6
  * @param options - options to resolve shorthand props
7
7
  */
8
8
 
9
- export function resolveShorthand(value, options) {
9
+ export const resolveShorthand = (value, options) => {
10
10
  const {
11
11
  required = false,
12
12
  defaultProps
@@ -27,5 +27,5 @@ export function resolveShorthand(value, options) {
27
27
  return defaultProps ? { ...defaultProps,
28
28
  ...resolvedShorthand
29
29
  } : resolvedShorthand;
30
- }
30
+ };
31
31
  //# sourceMappingURL=resolveShorthand.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/compose/resolveShorthand.ts"],"names":[],"mappings":"AAAA,SAAS,cAAT,QAA+B,OAA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F,cAAc,CAAC,KAAD,CAApG,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","sourceRoot":""}
@@ -1,61 +1,83 @@
1
1
  import * as React from 'react';
2
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;
3
+ /**
4
+ * Matches any component's Slots type (such as ButtonSlots).
5
+ *
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;
5
14
  /**
6
15
  * Matches any slot props type.
7
16
  *
8
- * This should ONLY be used in type templates as in `extends DefaultObjectSlotProps`;
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 UnknownSlotProps = SlotProps<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
- * 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.
24
+ * Helper type for {@link Slot}. Adds shorthand types that are assignable to the slot's `children`.
17
25
  */
18
- export declare type SlotProps<Props extends {
19
- children?: React.ReactNode;
20
- } = {}> = 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 & {
21
36
  children?: Props['children'] | SlotRenderFunction<Props>;
22
37
  };
23
38
  /**
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.
39
+ * HTML element types that are not allowed to have children.
27
40
  *
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
- * ```
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'.
37
48
  */
38
- export declare type ComponentSlotProps<Component extends React.ComponentType> = Component extends React.ComponentType<infer Props> ? SlotProps<Props> : never;
49
+ declare type IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = React.PropsWithRef<JSX.IntrinsicElements[Type]> & (Type extends EmptyIntrisicElements ? {
50
+ children?: never;
51
+ } : {});
39
52
  /**
40
- * Define the slot arguments for a slot that supports one or more intrinsic element types, such as 'div'.
41
- * For slots that support custom components, use {@link ComponentSlotProps} instead.
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`.
42
55
  *
43
- * The first param is the slot's default type if no `as` prop is specified.
44
- * The second param is an optional union of alternative types that can be specified for the `as` prop.
56
+ * If a slot needs to support multiple intrinsic element types, use the `AlternateAs` param (see examples below).
45
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
46
62
  * ```
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"
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)
50
72
  * ```
51
73
  */
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' : ({
53
- as?: DefaultAs;
54
- } & SlotProps<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> | {
55
77
  [As in AlternateAs]: {
56
78
  as: As;
57
- } & SlotProps<React.PropsWithRef<JSX.IntrinsicElements[As]>>;
58
- }[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.';
59
81
  /**
60
82
  * Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.
61
83
  *
@@ -90,21 +112,29 @@ export declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U :
90
112
  * types, to prevent unions from being expanded.
91
113
  */
92
114
  export declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;
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>;
93
119
  /**
94
120
  * Defines the Props type for a component given its slots and the definition of which one is the primary slot,
95
121
  * defaulting to root if one is not provided.
96
122
  */
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]>;
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;
100
128
  /**
101
129
  * Defines the State object of a component given its slots.
102
130
  */
103
131
  export declare type ComponentState<Slots extends SlotPropsRecord> = {
104
132
  components: {
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);
133
+ [Key in keyof Slots]-?: React.ComponentType<ExtractSlotProps<Slots[Key]>> | (ExtractSlotProps<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
106
134
  };
107
- } & Slots;
135
+ } & {
136
+ [Key in keyof Slots]: ReplaceNullWithUndefined<Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>>;
137
+ };
108
138
  /**
109
139
  * This is part of a hack to infer the element type from a native element *props* type.
110
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":"WAyKA;AACA;AACA;AACA;AACA","sourceRoot":""}
1
+ {"version":3,"sources":["../../src/compose/types.ts"],"names":[],"mappings":"WAqNA;AACA;AACA;AACA;AACA","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;
@@ -9,9 +9,12 @@ export const applyTriggerPropsToChildren = (children, triggerProps) => {
9
9
  return children(triggerProps);
10
10
  } else if (children) {
11
11
  return cloneTriggerTree(children, triggerProps);
12
- }
12
+ } // Components in React should return either JSX elements or "null", otherwise React will throw:
13
+ // Nothing was returned from render.
14
+ // This usually means a return statement is missing. Or, to render nothing, return null.
15
+
13
16
 
14
- return children;
17
+ return children || null;
15
18
  };
16
19
  /**
17
20
  * Clones a React element tree, and applies the given props to the first grandchild that is not
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/applyTriggerPropsToChildren.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,eAAT,QAAgC,mBAAhC;AAEA;;AAEG;;AACH,OAAO,MAAM,2BAA2B,GAAG,CACzC,QADyC,EAEzC,YAFyC,KAGtB;AACnB,MAAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;AAClC,WAAO,QAAQ,CAAC,YAAD,CAAf;AACD,GAFD,MAEO,IAAI,QAAJ,EAAc;AACnB,WAAO,gBAAgB,CAAC,QAAD,EAAW,YAAX,CAAvB;AACD;;AAED,SAAO,QAAP;AACD,CAXM;AAaP;;;AAGG;;AACH,MAAM,gBAAgB,GAAG,CAAgB,KAAhB,EAAwC,YAAxC,KAA2F;AAClH,MAAI,eAAC,KAAK,CAAC,cAAN,CAAqB,KAArB,CAAD,IAAgC,KAAK,CAAC,IAAN,KAAe,KAAK,CAAC,QAAzD,EAAmE;AACjE,UAAM,IAAI,KAAJ,CACJ,oEACE,sDAFE,CAAN;AAID;;AAED,MAAI,eAAe,CAAC,KAAD,CAAnB,EAA4B;AAC1B,UAAM,UAAU,GAAG,gBAAgB,CAAC,KAAK,CAAC,KAAN,CAAY,QAAb,EAAuB,YAAvB,CAAnC;AACA,wBAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,SAA1B,EAAqC,UAArC,CAAP;AACD,GAHD,MAGO;AACL,wBAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,YAA1B,CAAP;AACD;AACF,CAdD","sourceRoot":""}
1
+ {"version":3,"sources":["../../src/utils/applyTriggerPropsToChildren.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,eAAT,QAAgC,mBAAhC;AAEA;;AAEG;;AACH,OAAO,MAAM,2BAA2B,GAAG,CACzC,QADyC,EAEzC,YAFyC,KAGZ;AAC7B,MAAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;AAClC,WAAO,QAAQ,CAAC,YAAD,CAAf;AACD,GAFD,MAEO,IAAI,QAAJ,EAAc;AACnB,WAAO,gBAAgB,CAAC,QAAD,EAAW,YAAX,CAAvB;AACD,GAL4B,CAO7B;AACA;AACA;;;AACA,SAAO,QAAQ,IAAI,IAAnB;AACD,CAdM;AAgBP;;;AAGG;;AACH,MAAM,gBAAgB,GAAG,CAAgB,KAAhB,EAAwC,YAAxC,KAA2F;AAClH,MAAI,eAAC,KAAK,CAAC,cAAN,CAAqB,KAArB,CAAD,IAAgC,KAAK,CAAC,IAAN,KAAe,KAAK,CAAC,QAAzD,EAAmE;AACjE,UAAM,IAAI,KAAJ,CACJ,oEACE,sDAFE,CAAN;AAID;;AAED,MAAI,eAAe,CAAC,KAAD,CAAnB,EAA4B;AAC1B,UAAM,UAAU,GAAG,gBAAgB,CAAC,KAAK,CAAC,KAAN,CAAY,QAAb,EAAuB,YAAvB,CAAnC;AACA,wBAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,SAA1B,EAAqC,UAArC,CAAP;AACD,GAHD,MAGO;AACL,wBAAO,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,SACE,eADF,EAEE,eAFF,EAGE,eAHF,EAIE,YAJF,EAKE,YALF,EAME,gBANF,EAOE,gBAPF,EAQE,eARF,EASE,kBATF,EAUE,gBAVF,EAWE,gBAXF,EAYE,eAZF,EAaE,YAbF,EAcE,YAdF,EAeE,YAfF,EAgBE,kBAhBF,EAiBE,aAjBF,EAkBE,cAlBF,EAmBE,gBAnBF,EAoBE,aApBF,EAqBE,qBArBF,EAsBE,cAtBF,QAuBO,cAvBP;AAyBA,MAAM,gBAAgB,GAA2C;AAC/D,EAAA,KAAK,EAAE,eADwD;AAE/D,EAAA,KAAK,EAAE,eAFwD;AAG/D,EAAA,KAAK,EAAE,eAHwD;AAI/D,EAAA,EAAE,EAAE,YAJ2D;AAK/D,EAAA,EAAE,EAAE,YAL2D;AAM/D,EAAA,CAAC,EAAE,gBAN4D;AAO/D,EAAA,MAAM,EAAE,gBAPuD;AAQ/D,EAAA,KAAK,EAAE,eARwD;AAS/D,EAAA,QAAQ,EAAE,kBATqD;AAU/D,EAAA,MAAM,EAAE,gBAVuD;AAW/D,EAAA,MAAM,EAAE,gBAXuD;AAY/D,EAAA,KAAK,EAAE,eAZwD;AAa/D,EAAA,EAAE,EAAE,YAb2D;AAc/D,EAAA,EAAE,EAAE,YAd2D;AAe/D,EAAA,EAAE,EAAE,YAf2D;AAgB/D,EAAA,QAAQ,EAAE,kBAhBqD;AAiB/D,EAAA,GAAG,EAAE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A,OAAO,EAAE,qBAAqB,CAAgC,kBAAhC,EAAoD,KAApD,EAA2D,CACvF,IAAI,iBAAiB,IAAI,EAAzB,CADuF,EAEvF,OAFuF,EAGvF,WAHuF,CAA3D;AAFzB,GAAP;AAQD,CAzBM","sourceRoot":""}
@@ -1,10 +1,10 @@
1
1
  import * as React from 'react';
2
- import type { AsIntrinsicElement, ComponentState, SlotProps, SlotPropsRecord, UnionToIntersection } from './types';
2
+ import type { AsIntrinsicElement, ComponentState, ExtractSlotProps, SlotPropsRecord, UnionToIntersection } from './types';
3
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]>>;
4
+ [K in keyof S]: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? As : ExtractSlotProps<S[K]> extends React.ComponentType<infer P> ? React.ElementType<NonNullable<P>> : React.ElementType<ExtractSlotProps<S[K]>>;
5
5
  };
6
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;
7
+ [K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : ExtractSlotProps<S[K]> extends React.ComponentType<infer P> ? P : never;
8
8
  };
9
9
  /**
10
10
  * Given the state and an array of slot names, will break out `slots` and `slotProps`
@@ -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`
@@ -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;;AAEA,MAAA,YAAA,gBAAA,OAAA,CAAA,cAAA,CAAA;;AACA,MAAA,MAAA,gBAAA,OAAA,CAAA,eAAA,CAAA;AA6BA;;;;;;;;;;;;;;;;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,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,G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AAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;AAClC,UAAM,MAAM,GAAG,QAAf;AACA,WAAO,CACL,KAAK,CAAC,QADD,EAEJ;AACC,MAAA,QAAQ,EAAE,MAAM,CAAC,IAAD,EAAO,IAAP;AADjB,KAFI,CAAP;AAMD;;AAED,QAAM,gBAAgB,GAAG,OAAO,IAAP,KAAgB,QAAhB,KAA4B,CAAA,EAAA,GAAA,KAAK,CAAC,QAAD,CAAL,MAAe,IAAf,IAAe,EAAA,KAAA,KAAA,CAAf,GAAe,KAAA,CAAf,GAAe,EAAA,CAAE,EAA7C,CAAzB;AACA,QAAM,SAAS,GAAI,gBAAgB,GAAG,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 { UnknownSlotProps, 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
11
  * Resolves shorthands into slot props, to ensure normalization of the signature
8
12
  * being passed down to getSlots method
9
13
  * @param value - the base shorthand props
10
14
  * @param options - options to resolve shorthand props
11
15
  */
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;
16
+ export declare const resolveShorthand: ResolveShorthandFunction;
@@ -14,7 +14,7 @@ const react_1 = /*#__PURE__*/require("react");
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,61 +1,83 @@
1
1
  import * as React from 'react';
2
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;
3
+ /**
4
+ * Matches any component's Slots type (such as ButtonSlots).
5
+ *
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;
5
14
  /**
6
15
  * Matches any slot props type.
7
16
  *
8
- * This should ONLY be used in type templates as in `extends DefaultObjectSlotProps`;
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 UnknownSlotProps = SlotProps<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
- * 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.
24
+ * Helper type for {@link Slot}. Adds shorthand types that are assignable to the slot's `children`.
17
25
  */
18
- export declare type SlotProps<Props extends {
19
- children?: React.ReactNode;
20
- } = {}> = 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 & {
21
36
  children?: Props['children'] | SlotRenderFunction<Props>;
22
37
  };
23
38
  /**
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.
39
+ * HTML element types that are not allowed to have children.
27
40
  *
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
- * ```
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'.
37
48
  */
38
- export declare type ComponentSlotProps<Component extends React.ComponentType> = Component extends React.ComponentType<infer Props> ? SlotProps<Props> : never;
49
+ declare type IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = React.PropsWithRef<JSX.IntrinsicElements[Type]> & (Type extends EmptyIntrisicElements ? {
50
+ children?: never;
51
+ } : {});
39
52
  /**
40
- * Define the slot arguments for a slot that supports one or more intrinsic element types, such as 'div'.
41
- * For slots that support custom components, use {@link ComponentSlotProps} instead.
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`.
42
55
  *
43
- * The first param is the slot's default type if no `as` prop is specified.
44
- * The second param is an optional union of alternative types that can be specified for the `as` prop.
56
+ * If a slot needs to support multiple intrinsic element types, use the `AlternateAs` param (see examples below).
45
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
46
62
  * ```
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"
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)
50
72
  * ```
51
73
  */
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' : ({
53
- as?: DefaultAs;
54
- } & SlotProps<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> | {
55
77
  [As in AlternateAs]: {
56
78
  as: As;
57
- } & SlotProps<React.PropsWithRef<JSX.IntrinsicElements[As]>>;
58
- }[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.';
59
81
  /**
60
82
  * Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.
61
83
  *
@@ -90,21 +112,29 @@ export declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U :
90
112
  * types, to prevent unions from being expanded.
91
113
  */
92
114
  export declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;
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>;
93
119
  /**
94
120
  * Defines the Props type for a component given its slots and the definition of which one is the primary slot,
95
121
  * defaulting to root if one is not provided.
96
122
  */
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]>;
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;
100
128
  /**
101
129
  * Defines the State object of a component given its slots.
102
130
  */
103
131
  export declare type ComponentState<Slots extends SlotPropsRecord> = {
104
132
  components: {
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);
133
+ [Key in keyof Slots]-?: React.ComponentType<ExtractSlotProps<Slots[Key]>> | (ExtractSlotProps<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
106
134
  };
107
- } & Slots;
135
+ } & {
136
+ [Key in keyof Slots]: ReplaceNullWithUndefined<Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>>;
137
+ };
108
138
  /**
109
139
  * This is part of a hack to infer the element type from a native element *props* type.
110
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":";;;;IAyKA;AACA;AACA;AACA;AACA","sourceRoot":""}
1
+ {"version":3,"sources":["../../src/compose/types.ts"],"names":[],"mappings":";;;;IAqNA;AACA;AACA;AACA;AACA","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;
@@ -18,9 +18,12 @@ const applyTriggerPropsToChildren = (children, triggerProps) => {
18
18
  return children(triggerProps);
19
19
  } else if (children) {
20
20
  return cloneTriggerTree(children, triggerProps);
21
- }
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;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/applyTriggerPropsToChildren.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,mBAAA,CAAA;AAEA;;AAEG;;;AACI,MAAM,2BAA2B,GAAG,CACzC,QADyC,EAEzC,YAFyC,KAGtB;AACnB,MAAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;AAClC,WAAO,QAAQ,CAAC,YAAD,CAAf;AACD,GAFD,MAEO,IAAI,QAAJ,EAAc;AACnB,WAAO,gBAAgB,CAAC,QAAD,EAAW,YAAX,CAAvB;AACD;;AAED,SAAO,QAAP;AACD,CAXM;;AAAM,OAAA,CAAA,2BAAA,GAA2B,2BAA3B;AAab;;;AAGG;;AACH,MAAM,gBAAgB,GAAG,CAAgB,KAAhB,EAAwC,YAAxC,KAA2F;AAClH,MAAI,CAAC,KAAK,CAAC,cAAN,CAAqB,KAArB,CAAD,IAAgC,KAAK,CAAC,IAAN,KAAe,KAAK,CAAC,QAAzD,EAAmE;AACjE,UAAM,IAAI,KAAJ,CACJ,oEACE,sDAFE,CAAN;AAID;;AAED,MAAI,iBAAA,CAAA,eAAA,CAAgB,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,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,EAAA,KAAK,EAAE,YAAA,CAAA,eAFwD;AAG/D,EAAA,KAAK,EAAE,YAAA,CAAA,eAHwD;AAI/D,EAAA,EAAE,EAAE,YAAA,CAAA,YAJ2D;AAK/D,EAAA,EAAE,EAAE,YAAA,CAAA,YAL2D;AAM/D,EA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AmB/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":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-utilities",
3
- "version": "0.0.0-nightly946f57cad420220203.1",
3
+ "version": "0.0.0-nightly96d9c9354420220210.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-nightly946f57cad420220203.1",
36
+ "@fluentui/keyboard-keys": "0.0.0-nightly96d9c9354420220210.1",
37
37
  "tslib": "^2.1.0"
38
38
  },
39
39
  "peerDependencies": {
@@ -1,4 +0,0 @@
1
- /**
2
- * Simple constant function for returning null, used to render empty templates in JSX.
3
- */
4
- export declare const nullRender: () => null;
@@ -1,5 +0,0 @@
1
- /**
2
- * Simple constant function for returning null, used to render empty templates in JSX.
3
- */
4
- export const nullRender = () => null;
5
- //# sourceMappingURL=nullRender.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nullRender.js","sourceRoot":"","sources":["../../src/compose/nullRender.tsx"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC"}
@@ -1,4 +0,0 @@
1
- /**
2
- * Simple constant function for returning null, used to render empty templates in JSX.
3
- */
4
- export declare const nullRender: () => null;
@@ -1,14 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.nullRender = void 0;
7
- /**
8
- * Simple constant function for returning null, used to render empty templates in JSX.
9
- */
10
-
11
- const nullRender = () => null;
12
-
13
- exports.nullRender = nullRender;
14
- //# sourceMappingURL=nullRender.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/compose/nullRender.tsx"],"names":[],"mappings":";;;;;;AAAA;;AAEG;;AACI,MAAM,UAAU,GAAG,MAAM,IAAzB;;AAAM,OAAA,CAAA,UAAA,GAAU,UAAV","sourceRoot":""}