@fluentui/react-utilities 0.0.0-nightlyd3bf09bf8120211201.1 → 0.0.0-nightlyd45ba4664620220211.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 (102) hide show
  1. package/CHANGELOG.json +119 -6
  2. package/CHANGELOG.md +26 -6
  3. package/dist/react-utilities.d.ts +213 -108
  4. package/lib/compose/getSlots.d.ts +11 -10
  5. package/lib/compose/getSlots.js +7 -6
  6. package/lib/compose/getSlots.js.map +1 -1
  7. package/lib/compose/index.d.ts +0 -1
  8. package/lib/compose/index.js +0 -1
  9. package/lib/compose/index.js.map +1 -1
  10. package/lib/compose/resolveShorthand.d.ts +10 -6
  11. package/lib/compose/resolveShorthand.js +5 -5
  12. package/lib/compose/resolveShorthand.js.map +1 -1
  13. package/lib/compose/types.d.ts +86 -34
  14. package/lib/compose/types.js.map +1 -1
  15. package/lib/hooks/index.d.ts +1 -1
  16. package/lib/hooks/index.js +1 -1
  17. package/lib/hooks/index.js.map +1 -1
  18. package/lib/hooks/useControllableState.d.ts +16 -6
  19. package/lib/hooks/useControllableState.js +13 -8
  20. package/lib/hooks/useControllableState.js.map +1 -1
  21. package/lib/hooks/useMergedEventCallbacks.d.ts +18 -0
  22. package/lib/hooks/useMergedEventCallbacks.js +26 -0
  23. package/lib/hooks/useMergedEventCallbacks.js.map +1 -0
  24. package/lib/hooks/useOnClickOutside.js.map +1 -1
  25. package/lib/utils/applyTriggerPropsToChildren.d.ts +1 -1
  26. package/lib/utils/applyTriggerPropsToChildren.js +23 -3
  27. package/lib/utils/applyTriggerPropsToChildren.js.map +1 -1
  28. package/lib/utils/getNativeElementProps.d.ts +4 -4
  29. package/lib/utils/getNativeElementProps.js.map +1 -1
  30. package/lib/utils/getReactCallbackName.d.ts +25 -0
  31. package/lib/utils/getReactCallbackName.js +26 -0
  32. package/lib/utils/getReactCallbackName.js.map +1 -0
  33. package/lib/utils/getTriggerChild.d.ts +22 -0
  34. package/lib/utils/getTriggerChild.js +26 -0
  35. package/lib/utils/getTriggerChild.js.map +1 -0
  36. package/lib/utils/index.d.ts +2 -1
  37. package/lib/utils/index.js +2 -1
  38. package/lib/utils/index.js.map +1 -1
  39. package/lib/utils/isFluentTrigger.d.ts +22 -0
  40. package/lib/utils/isFluentTrigger.js +8 -0
  41. package/lib/utils/isFluentTrigger.js.map +1 -0
  42. package/lib/utils/properties.js +40 -20
  43. package/lib/utils/properties.js.map +1 -1
  44. package/lib-commonjs/compose/getSlots.d.ts +11 -10
  45. package/lib-commonjs/compose/getSlots.js +7 -7
  46. package/lib-commonjs/compose/getSlots.js.map +1 -1
  47. package/lib-commonjs/compose/index.d.ts +0 -1
  48. package/lib-commonjs/compose/index.js +0 -2
  49. package/lib-commonjs/compose/index.js.map +1 -1
  50. package/lib-commonjs/compose/resolveShorthand.d.ts +10 -6
  51. package/lib-commonjs/compose/resolveShorthand.js +5 -5
  52. package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
  53. package/lib-commonjs/compose/types.d.ts +86 -34
  54. package/lib-commonjs/compose/types.js.map +1 -1
  55. package/lib-commonjs/hooks/index.d.ts +1 -1
  56. package/lib-commonjs/hooks/index.js +2 -2
  57. package/lib-commonjs/hooks/index.js.map +1 -1
  58. package/lib-commonjs/hooks/useControllableState.d.ts +16 -6
  59. package/lib-commonjs/hooks/useControllableState.js +13 -8
  60. package/lib-commonjs/hooks/useControllableState.js.map +1 -1
  61. package/lib-commonjs/hooks/useMergedEventCallbacks.d.ts +18 -0
  62. package/lib-commonjs/hooks/useMergedEventCallbacks.js +36 -0
  63. package/lib-commonjs/hooks/useMergedEventCallbacks.js.map +1 -0
  64. package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
  65. package/lib-commonjs/utils/applyTriggerPropsToChildren.d.ts +1 -1
  66. package/lib-commonjs/utils/applyTriggerPropsToChildren.js +24 -4
  67. package/lib-commonjs/utils/applyTriggerPropsToChildren.js.map +1 -1
  68. package/lib-commonjs/utils/getNativeElementProps.d.ts +4 -4
  69. package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
  70. package/lib-commonjs/utils/getReactCallbackName.d.ts +25 -0
  71. package/lib-commonjs/utils/getReactCallbackName.js +35 -0
  72. package/lib-commonjs/utils/getReactCallbackName.js.map +1 -0
  73. package/lib-commonjs/utils/getTriggerChild.d.ts +22 -0
  74. package/lib-commonjs/utils/getTriggerChild.js +37 -0
  75. package/lib-commonjs/utils/getTriggerChild.js.map +1 -0
  76. package/lib-commonjs/utils/index.d.ts +2 -1
  77. package/lib-commonjs/utils/index.js +4 -2
  78. package/lib-commonjs/utils/index.js.map +1 -1
  79. package/lib-commonjs/utils/isFluentTrigger.d.ts +22 -0
  80. package/lib-commonjs/utils/isFluentTrigger.js +17 -0
  81. package/lib-commonjs/utils/isFluentTrigger.js.map +1 -0
  82. package/lib-commonjs/utils/properties.js +40 -20
  83. package/lib-commonjs/utils/properties.js.map +1 -1
  84. package/package.json +3 -7
  85. package/lib/compose/nullRender.d.ts +0 -4
  86. package/lib/compose/nullRender.js +0 -5
  87. package/lib/compose/nullRender.js.map +0 -1
  88. package/lib/hooks/useControllableValue.d.ts +0 -20
  89. package/lib/hooks/useControllableValue.js +0 -57
  90. package/lib/hooks/useControllableValue.js.map +0 -1
  91. package/lib/utils/onlyChild.d.ts +0 -5
  92. package/lib/utils/onlyChild.js +0 -13
  93. package/lib/utils/onlyChild.js.map +0 -1
  94. package/lib-commonjs/compose/nullRender.d.ts +0 -4
  95. package/lib-commonjs/compose/nullRender.js +0 -14
  96. package/lib-commonjs/compose/nullRender.js.map +0 -1
  97. package/lib-commonjs/hooks/useControllableValue.d.ts +0 -20
  98. package/lib-commonjs/hooks/useControllableValue.js +0 -68
  99. package/lib-commonjs/hooks/useControllableValue.js.map +0 -1
  100. package/lib-commonjs/utils/onlyChild.d.ts +0 -5
  101. package/lib-commonjs/utils/onlyChild.js +0 -23
  102. package/lib-commonjs/utils/onlyChild.js.map +0 -1
@@ -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 | ((props: any) => React_2.ReactElement<any, string | any | (new (props: any) => React_2.Component<any, any, any>)> | null) | (new (props: any) => React_2.Component<any, any, 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.
@@ -58,8 +58,6 @@ export declare const buttonProperties: Record<string, number>;
58
58
  */
59
59
  export declare function canUseDOM(): boolean;
60
60
 
61
- export declare type ChangeCallback<TElement extends HTMLElement, TValue, TEvent extends React_2.SyntheticEvent<TElement> | undefined> = (ev: TEvent, newValue: TValue | undefined) => void;
62
-
63
61
  /**
64
62
  * Clamps `value` to a number between the min and max.
65
63
  *
@@ -73,25 +71,22 @@ export declare const colGroupProperties: Record<string, number>;
73
71
 
74
72
  export declare const colProperties: Record<string, number>;
75
73
 
76
- export declare type ComponentProps<Shorthands extends ObjectShorthandPropsRecord, Primary extends keyof Shorthands = 'root'> = Omit<{
77
- [Key in keyof Shorthands]?: ShorthandProps<NonNullable<Shorthands[Key]>>;
78
- }, Primary & 'root'> & PropsWithoutRef<Shorthands[Primary]>;
79
-
80
- export declare type ComponentState<Shorthands extends ObjectShorthandPropsRecord> = {
81
- components?: {
82
- [Key in keyof Shorthands]-?: React_2.ComponentType<NonNullable<Shorthands[Key]> extends ObjectShorthandProps<infer P> ? P : NonNullable<Shorthands[Key]>> | (NonNullable<Shorthands[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
83
- };
84
- } & Shorthands;
74
+ /**
75
+ * Defines the Props type for a component given its slots and the definition of which one is the primary slot,
76
+ * defaulting to root if one is not provided.
77
+ */
78
+ export declare type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> = Omit<Slots, Primary & 'root'> & PropsWithoutRef<ExtractSlotProps<Slots[Primary]>>;
85
79
 
86
80
  /**
87
- * Matches any shorthand props type.
88
- *
89
- * This should ONLY be used in type templates as in `extends DefaultObjectShorthandProps`;
90
- * it shouldn't be used as the type of a slot.
81
+ * Defines the State object of a component given its slots.
91
82
  */
92
- export declare type DefaultObjectShorthandProps = ObjectShorthandProps<Pick<React_2.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
93
- as?: keyof JSX.IntrinsicElements;
94
- }>;
83
+ export declare type ComponentState<Slots extends SlotPropsRecord> = {
84
+ components: {
85
+ [Key in keyof Slots]-?: React_2.ComponentType<ExtractSlotProps<Slots[Key]>> | (ExtractSlotProps<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
86
+ };
87
+ } & {
88
+ [Key in keyof Slots]: ReplaceNullWithUndefined<Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>>;
89
+ };
95
90
 
96
91
  /**
97
92
  * Default context value to use in case there is no SSRProvider. This is fine for client-only apps.
@@ -100,11 +95,6 @@ export declare type DefaultObjectShorthandProps = ObjectShorthandProps<Pick<Reac
100
95
  */
101
96
  export declare const defaultSSRContextValue: SSRContextValue;
102
97
 
103
- /**
104
- * Default value can be a value or an initializer
105
- */
106
- declare type DefaultValue<TValue> = TValue | (() => TValue);
107
-
108
98
  /**
109
99
  * An array of DIV tag properties and events.
110
100
  *
@@ -112,6 +102,35 @@ declare type DefaultValue<TValue> = TValue | (() => TValue);
112
102
  */
113
103
  export declare const divProperties: Record<string, number>;
114
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
+
117
+ /**
118
+ * Allows a component to be tagged as a FluentUI trigger component.
119
+ *
120
+ * Triggers are special-case components: they attach event listeners and other props on their child,
121
+ * and use them to trigger another component to show. Examples include `MenuTrigger` and `Tooltip`.
122
+ *
123
+ * A component can be tagged as a trigger as follows:
124
+ * ```ts
125
+ * const MyComponent: React.FC<MyComponentProps> & FluentTriggerComponent = ...;
126
+ *
127
+ * MyComponent.isFluentTriggerComponent = true; // MUST also set this to true
128
+ * ```
129
+ */
130
+ export declare type FluentTriggerComponent = {
131
+ isFluentTriggerComponent?: boolean;
132
+ };
133
+
115
134
  /**
116
135
  * An array of FORM tag properties and events.
117
136
  *
@@ -157,19 +176,19 @@ export declare function getNativeProps<T extends Record<string, any>>(props: Rec
157
176
  *
158
177
  * @returns An object containing the native props for the `root` and primary slots.
159
178
  */
160
- 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, }: {
161
180
  /** The primary slot's element type (e.g. 'div') */
162
181
  primarySlotTagName: keyof JSX.IntrinsicElements;
163
182
  /** The component's props object */
164
- props: Pick<React_2.HTMLAttributes<HTMLElement>, 'style' | 'className'>;
183
+ props: Props;
165
184
  /** List of native props to exclude from the returned value */
166
- excludedPropNames?: string[] | undefined;
185
+ excludedPropNames?: ExcludedPropKeys[] | undefined;
167
186
  }) => {
168
187
  root: {
169
188
  style: React_2.CSSProperties | undefined;
170
189
  className: string | undefined;
171
190
  };
172
- primary: React_2.HTMLAttributes<any>;
191
+ primary: Omit<Props, ExcludedPropKeys>;
173
192
  };
174
193
 
175
194
  /**
@@ -186,16 +205,39 @@ export declare const getRTLSafeKey: (key: string, dir: 'ltr' | 'rtl') => string;
186
205
  * Slots will render as null if they are rendered as primitives with undefined children.
187
206
  *
188
207
  * The slotProps will always omit the `as` prop within them, and for slots that are string
189
- * primitives, the props will be filtered according the the slot type. For example, if the
190
- * slot is rendered `as: 'a'`, the props will be filtered for acceptable anchor props.
208
+ * primitives, the props will be filtered according to the slot type by the type system.
209
+ * For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable
210
+ * anchor props. Note that this is only enforced at build time by Typescript -- there is no
211
+ * runtime code filtering props in this function.
191
212
  *
192
213
  * @param state - State including slot definitions
193
- * @param slotNames - Name of which props are slots
194
214
  * @returns An object containing the `slots` map and `slotProps` map.
195
215
  */
196
- export declare function getSlots<R extends ObjectShorthandPropsRecord>(state: ComponentState<R>, slotNames?: (keyof R)[]): {
216
+ export declare function getSlots<R extends SlotPropsRecord>(state: ComponentState<R>): {
197
217
  slots: Slots<R>;
198
- slotProps: SlotProps<R>;
218
+ slotProps: ObjectSlotProps<R>;
219
+ };
220
+
221
+ /**
222
+ * Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).
223
+ *
224
+ * In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,
225
+ * it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.
226
+ * This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.
227
+ *
228
+ * For example, the following returns `<div id="child" />`:
229
+ * ```jsx
230
+ * getTriggerChild(
231
+ * <Tooltip>
232
+ * <MenuTrigger>
233
+ * <div id="child" />
234
+ * </MenuTrigger>
235
+ * </Tooltip>
236
+ * );
237
+ * ```
238
+ */
239
+ export declare const getTriggerChild: (children: React_2.ReactNode) => React_2.ReactElement & {
240
+ ref?: React_2.Ref<unknown>;
199
241
  };
200
242
 
201
243
  /**
@@ -232,25 +274,19 @@ export declare const imgProperties: Record<string, number>;
232
274
  export declare const inputProperties: Record<string, number>;
233
275
 
234
276
  /**
235
- * Define the slot arguments for a slot that supports one or more intrinsic element types, such as 'div'.
236
- * For slots that support custom components, use {@link ObjectShorthandProps} instead.
237
- *
238
- * The first param is the slot's default type if no `as` prop is specified.
239
- * The second param is an optional union of alternative types that can be specified for the `as` prop.
240
- *
241
- * ```
242
- * IntrinsicShorthandProps<'div'> // Slot is always div
243
- * IntrinsicShorthandProps<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
244
- * IntrinsicShorthandProps<'label', 'span' | 'div'>; // Defaults to label, but allows as="span" or as="div"
245
- * ```
277
+ * Helper type for {@link Slot}. Modifies `JSX.IntrinsicElements[Type]`:
278
+ * * Removes legacy string ref.
279
+ * * Disallows children for empty tags like 'img'.
246
280
  */
247
- export declare type IntrinsicShorthandProps<DefaultAs extends keyof JSX.IntrinsicElements, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<DefaultAs> extends false ? 'Error: first parameter to IntrinsicShorthandProps must be a single element type, not a union of types' : ({
248
- as?: DefaultAs;
249
- } & ObjectShorthandProps<React_2.PropsWithRef<JSX.IntrinsicElements[DefaultAs]>>) | {
250
- [As in AlternateAs]: {
251
- as: As;
252
- } & ObjectShorthandProps<React_2.PropsWithRef<JSX.IntrinsicElements[As]>>;
253
- }[AlternateAs];
281
+ declare type IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = React_2.PropsWithRef<JSX.IntrinsicElements[Type]> & (Type extends EmptyIntrisicElements ? {
282
+ children?: never;
283
+ } : {});
284
+
285
+ /**
286
+ * Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).
287
+ * See the {@link FluentTriggerComponent} type for more info.
288
+ */
289
+ export declare const isFluentTrigger: (element: React_2.ReactElement) => boolean | undefined;
254
290
 
255
291
  /**
256
292
  * Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.
@@ -278,24 +314,10 @@ export declare const labelProperties: Record<string, number>;
278
314
  */
279
315
  export declare const liProperties: Record<string, number>;
280
316
 
281
- /**
282
- * Simple constant function for returning null, used to render empty templates in JSX.
283
- */
284
- export declare const nullRender: () => null;
285
-
286
- /**
287
- * Defines the slot props for a slot that supports a Component type.
288
- *
289
- * For intrinsic elements like 'div', use {@link IntrinsicShorthandProps} instead.
290
- */
291
- export declare type ObjectShorthandProps<Props extends {
292
- children?: React_2.ReactNode;
293
- } = {}> = Props & {
294
- children?: Props['children'] | ShorthandRenderFunction<Props>;
317
+ declare type ObjectSlotProps<S extends SlotPropsRecord> = {
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;
295
319
  };
296
320
 
297
- export declare type ObjectShorthandPropsRecord = Record<string, DefaultObjectShorthandProps | undefined>;
298
-
299
321
  /**
300
322
  * This is part of a hack to infer the element type from a native element *props* type.
301
323
  * The only place the original element is found in a native props type (at least that's workable
@@ -332,16 +354,11 @@ export declare const olProperties: Record<string, number>;
332
354
  */
333
355
  export declare function omit<TObj extends Record<string, any>, Exclusions extends (keyof TObj)[]>(obj: TObj, exclusions: Exclusions): Omit<TObj, Exclusions[number]>;
334
356
 
335
- /**
336
- * Similar to React.Children.only, but drills into fragments rather than treating them as a single child
337
- */
338
- export declare const onlyChild: <P>(child: string | number | boolean | {} | React_2.ReactNodeArray | React_2.ReactPortal | React_2.ReactElement<P, string | ((props: any) => React_2.ReactElement<any, string | any | (new (props: any) => React_2.Component<any, any, any>)> | null) | (new (props: any) => React_2.Component<any, any, any>)> | null | undefined) => React_2.ReactElement<P, string | ((props: any) => React_2.ReactElement<any, string | any | (new (props: any) => React_2.Component<any, any, any>)> | null) | (new (props: any) => React_2.Component<any, any, any>)>;
339
-
340
357
  export declare const optionProperties: Record<string, number>;
341
358
 
342
359
  /**
343
360
  * Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
344
- * IntrinsicShorthandProps). This allows IntrinsicShorthandProps to be used with React.forwardRef.
361
+ * IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
345
362
  *
346
363
  * The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional
347
364
  * types, to prevent unions from being expanded.
@@ -354,6 +371,11 @@ export declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unkn
354
371
  */
355
372
  export declare type RefObjectFunction<T> = React_2.RefObject<T> & ((value: T) => void);
356
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
+
357
379
  /**
358
380
  * Resets generated IDs, should be used only in tests.
359
381
  *
@@ -362,14 +384,19 @@ export declare type RefObjectFunction<T> = React_2.RefObject<T> & ((value: T) =>
362
384
  export declare function resetIdsForTests(): void;
363
385
 
364
386
  /**
365
- * Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
387
+ * Resolves shorthands into slot props, to ensure normalization of the signature
366
388
  * being passed down to getSlots method
367
- * @param value - the base ShorthandProps
368
- * @param options - options to resolve ShorthandProps
389
+ * @param value - the base shorthand props
390
+ * @param options - options to resolve shorthand props
369
391
  */
370
- export declare function resolveShorthand<Props extends DefaultObjectShorthandProps, Required extends boolean = false>(value: ShorthandProps<Props>, options?: ResolveShorthandOptions<Props, Required>): Required extends false ? Props | undefined : Props;
392
+ export declare const resolveShorthand: ResolveShorthandFunction;
393
+
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
+ };
371
398
 
372
- export declare type ResolveShorthandOptions<Props extends Record<string, any>, Required extends boolean = false> = {
399
+ export declare type ResolveShorthandOptions<Props, Required extends boolean = false> = {
373
400
  required?: Required;
374
401
  defaultProps?: Props;
375
402
  };
@@ -381,10 +408,6 @@ export declare type ResolveShorthandOptions<Props extends Record<string, any>, R
381
408
  */
382
409
  export declare const selectProperties: Record<string, number>;
383
410
 
384
- export declare type ShorthandProps<Props extends DefaultObjectShorthandProps> = React_2.ReactChild | React_2.ReactNodeArray | React_2.ReactPortal | number | null | undefined | Props;
385
-
386
- export declare type ShorthandRenderFunction<Props> = (Component: React_2.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React_2.ReactNode;
387
-
388
411
  /**
389
412
  * Checks if the keyboard event should preventDefault() for Enter and Spacebar keys
390
413
  *
@@ -392,14 +415,55 @@ export declare type ShorthandRenderFunction<Props> = (Component: React_2.Element
392
415
  */
393
416
  export declare function shouldPreventDefaultOnKeyDown(e: KeyboardEvent | React_2.KeyboardEvent): boolean;
394
417
 
395
- declare type SlotProps<S extends ObjectShorthandPropsRecord> = {
396
- [K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : NonNullable<S[K]> extends ObjectShorthandProps<infer P> ? P : never;
397
- };
418
+ /**
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
+ * ```
439
+ */
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.';
447
+
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>;
455
+
456
+ export declare type SlotRenderFunction<Props> = (Component: React_2.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React_2.ReactNode;
398
457
 
399
- export declare type Slots<S extends ObjectShorthandPropsRecord> = {
400
- [K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? As : S[K] extends ObjectShorthandProps<infer P> ? React_2.ElementType<NonNullable<P>> : React_2.ElementType<NonNullable<S[K]>>;
458
+ export declare type Slots<S extends SlotPropsRecord> = {
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]>>;
401
460
  };
402
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
+
403
467
  export declare const SSRContext: React_2.Context<SSRContextValue>;
404
468
 
405
469
  /**
@@ -460,6 +524,16 @@ export declare const trProperties: Record<string, number>;
460
524
  */
461
525
  export declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;
462
526
 
527
+ /**
528
+ * Matches any slot props type.
529
+ *
530
+ * This should ONLY be used in type templates as in `extends UnknownSlotProps`;
531
+ * it shouldn't be used as the type of a slot.
532
+ */
533
+ export declare type UnknownSlotProps = Pick<React_2.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
534
+ as?: keyof JSX.IntrinsicElements;
535
+ };
536
+
463
537
  /**
464
538
  * Hook to store a value and generate callbacks for setting the value to true or false.
465
539
  * The identity of the callbacks will always stay the same.
@@ -493,42 +567,37 @@ export declare type UseBooleanCallbacks = {
493
567
  export declare function useConst<T>(initialValue: T | (() => T)): T;
494
568
 
495
569
  /**
496
- * A useState 'like' hook that allows optional user control
497
- * Useful for components which allow uncontrolled and controlled behaviour for users
498
- * @returns - https://reactjs.org/docs/hooks-state.html
570
+ * A `useState`-like hook to manage a value that could be either controlled or uncontrolled,
571
+ * such as a checked state or text input string.
572
+ *
573
+ * Unlike `setState`, it's okay to call the returned updater (dispatch) function for either a
574
+ * controlled or uncontrolled component. Calls will only be respected if the component is uncontrolled.
575
+ *
576
+ * @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array
577
+ * of the current value and an updater (dispatch) function. The updater function is referentially
578
+ * stable (won't change during the component's lifecycle). It can take either a new value, or a
579
+ * function which is passed the previous value and returns the new value. Unlike `setState`, calls
580
+ * to the updater function will only be respected if the component is uncontrolled.
581
+ * @see https://reactjs.org/docs/uncontrolled-components.html
499
582
  */
500
583
  export declare const useControllableState: <State>(options: UseControllableStateOptions<State>) => [State, React_2.Dispatch<React_2.SetStateAction<State>>];
501
584
 
502
585
  export declare type UseControllableStateOptions<State> = {
503
586
  /**
504
- * User provided default state or factory initializer
587
+ * User-provided default state or initializer, for uncontrolled usage.
505
588
  */
506
589
  defaultState?: State | (() => State);
507
590
  /**
508
- * User provided controllable state, undefined state means internal state will be used
591
+ * User-provided controlled state. `undefined` means internal state will be used.
509
592
  */
510
593
  state: State | undefined;
511
594
  /**
512
- * Used to initialize state if all user provided states are undefined
595
+ * Used as the initial state if `state` and `defaultState` are both `undefined`.
596
+ * If `undefined` is the correct initial state, pass that here.
513
597
  */
514
598
  initialState: State;
515
599
  };
516
600
 
517
- /**
518
- * Hook to manage a value that could be either controlled or uncontrolled, such as a checked state or
519
- * text box string.
520
- * @param controlledValue - The controlled value passed in the props. This value will always be used if provided,
521
- * and the internal state will be updated to reflect it.
522
- * @param defaultUncontrolledValue - Initial value for the internal state in the uncontrolled case.
523
- * @returns An array of the current value and an updater callback. Like `React.useState`, the updater
524
- * callback always has the same identity, and it can take either a new value, or a function which
525
- * is passed the previous value and returns the new value.
526
- * @see https://reactjs.org/docs/uncontrolled-components.html
527
- */
528
- export declare function useControllableValue<TValue, TElement extends HTMLElement>(controlledValue: TValue, defaultUncontrolledValue: DefaultValue<TValue>): Readonly<[TValue, (update: React_2.SetStateAction<TValue>) => void]>;
529
-
530
- export declare function useControllableValue<TValue, TElement extends HTMLElement, TEvent extends React_2.SyntheticEvent<TElement> | undefined>(controlledValue: TValue, defaultUncontrolledValue: DefaultValue<TValue>, onChange: ChangeCallback<TElement, TValue, TEvent>): Readonly<[TValue, (update: React_2.SetStateAction<TValue>, ev?: React_2.FormEvent<TElement>) => void]>;
531
-
532
601
  /**
533
602
  * https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
534
603
  *
@@ -587,6 +656,25 @@ export declare const useIsomorphicLayoutEffect: typeof React_2.useEffect;
587
656
  */
588
657
  export declare function useIsSSR(): boolean;
589
658
 
659
+ /**
660
+ * Combine two event callbacks into a single callback function that calls each one in order.
661
+ *
662
+ * This is useful to add an event listener to an existing element without overwriting the current listener, if any.
663
+ *
664
+ * For example:
665
+ * ```ts
666
+ * state.slot.onChange = useMergedCallbacks(state.slot.onChange, ev => {
667
+ * // Handle onChange
668
+ * });
669
+ * ```
670
+ *
671
+ * @param callback1 - The first callback to be called
672
+ * @param callback2 - The second callback to be called
673
+ *
674
+ * @returns An event callback that calls the callbacks in order, and is stable between renders
675
+ */
676
+ export declare function useMergedEventCallbacks<Args extends unknown[]>(callback1: ((...args: Args) => void) | undefined, callback2: ((...args: Args) => void) | undefined): (...args: Args) => void;
677
+
590
678
  /**
591
679
  * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that
592
680
  * updates all provided refs
@@ -667,4 +755,21 @@ export declare const useUnmount: (callback: () => void) => void;
667
755
  */
668
756
  export declare const videoProperties: Record<string, number>;
669
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
+
670
775
  export { }
@@ -1,10 +1,10 @@
1
1
  import * as React from 'react';
2
- import { AsIntrinsicElement, ComponentState, ObjectShorthandPropsRecord, ObjectShorthandProps, UnionToIntersection } from './types';
3
- export declare type Slots<S extends ObjectShorthandPropsRecord> = {
4
- [K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? As : S[K] extends ObjectShorthandProps<infer P> ? React.ElementType<NonNullable<P>> : React.ElementType<NonNullable<S[K]>>;
2
+ import type { AsIntrinsicElement, ComponentState, ExtractSlotProps, SlotPropsRecord, UnionToIntersection } from './types';
3
+ export declare type Slots<S extends SlotPropsRecord> = {
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
- declare type SlotProps<S extends ObjectShorthandPropsRecord> = {
7
- [K in keyof S]-?: NonNullable<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : NonNullable<S[K]> extends ObjectShorthandProps<infer P> ? P : never;
6
+ declare type ObjectSlotProps<S extends SlotPropsRecord> = {
7
+ [K in keyof S]-?: 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`
@@ -15,15 +15,16 @@ declare type SlotProps<S extends ObjectShorthandPropsRecord> = {
15
15
  * Slots will render as null if they are rendered as primitives with undefined children.
16
16
  *
17
17
  * The slotProps will always omit the `as` prop within them, and for slots that are string
18
- * primitives, the props will be filtered according the the slot type. For example, if the
19
- * slot is rendered `as: 'a'`, the props will be filtered for acceptable anchor props.
18
+ * primitives, the props will be filtered according to the slot type by the type system.
19
+ * For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable
20
+ * anchor props. Note that this is only enforced at build time by Typescript -- there is no
21
+ * runtime code filtering props in this function.
20
22
  *
21
23
  * @param state - State including slot definitions
22
- * @param slotNames - Name of which props are slots
23
24
  * @returns An object containing the `slots` map and `slotProps` map.
24
25
  */
25
- export declare function getSlots<R extends ObjectShorthandPropsRecord>(state: ComponentState<R>, slotNames?: (keyof R)[]): {
26
+ export declare function getSlots<R extends SlotPropsRecord>(state: ComponentState<R>): {
26
27
  slots: Slots<R>;
27
- slotProps: SlotProps<R>;
28
+ slotProps: ObjectSlotProps<R>;
28
29
  };
29
30
  export {};
@@ -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`
@@ -10,17 +9,19 @@ import { omit } from '../utils/omit';
10
9
  * Slots will render as null if they are rendered as primitives with undefined children.
11
10
  *
12
11
  * The slotProps will always omit the `as` prop within them, and for slots that are string
13
- * primitives, the props will be filtered according the the slot type. For example, if the
14
- * slot is rendered `as: 'a'`, the props will be filtered for acceptable anchor props.
12
+ * primitives, the props will be filtered according to the slot type by the type system.
13
+ * For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable
14
+ * anchor props. Note that this is only enforced at build time by Typescript -- there is no
15
+ * runtime code filtering props in this function.
15
16
  *
16
17
  * @param state - State including slot definitions
17
- * @param slotNames - Name of which props are slots
18
18
  * @returns An object containing the `slots` map and `slotProps` map.
19
19
  */
20
20
 
21
- export function getSlots(state, slotNames = ['root']) {
21
+ export function getSlots(state) {
22
22
  const slots = {};
23
23
  const slotProps = {};
24
+ const slotNames = Object.keys(state.components);
24
25
 
25
26
  for (const slotName of slotNames) {
26
27
  const [slot, props] = getSlot(state, slotName);
@@ -38,7 +39,7 @@ function getSlot(state, slotName) {
38
39
  var _a, _b, _c;
39
40
 
40
41
  if (state[slotName] === undefined) {
41
- return [nullRender, undefined];
42
+ return [null, undefined];
42
43
  }
43
44
 
44
45
  const {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/compose/getSlots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAUA,SAAS,UAAT,QAA2B,cAA3B;AACA,SAAS,IAAT,QAAqB,eAArB;AAqBA;;;;;;;;;;;;;;;AAeG;;AACH,OAAM,SAAU,QAAV,CACJ,KADI,EAEJ,SAAA,GAAyB,CAAC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
- 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 { DefaultObjectShorthandProps, ShorthandProps } from './types';
2
- export declare type ResolveShorthandOptions<Props extends Record<string, any>, Required extends boolean = false> = {
1
+ import type { ReplaceNullWithUndefined, SlotShorthandValue, UnknownSlotProps } from './types';
2
+ export declare type ResolveShorthandOptions<Props, Required extends boolean = false> = {
3
3
  required?: Required;
4
4
  defaultProps?: Props;
5
5
  };
6
+ export declare type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {
7
+ <P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, true>): ReplaceNullWithUndefined<P>;
8
+ <P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, boolean>): ReplaceNullWithUndefined<P> | undefined;
9
+ };
6
10
  /**
7
- * Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
11
+ * Resolves shorthands into slot props, to ensure normalization of the signature
8
12
  * being passed down to getSlots method
9
- * @param value - the base ShorthandProps
10
- * @param options - options to resolve ShorthandProps
13
+ * @param value - the base shorthand props
14
+ * @param options - options to resolve shorthand props
11
15
  */
12
- export declare function resolveShorthand<Props extends DefaultObjectShorthandProps, Required extends boolean = false>(value: ShorthandProps<Props>, options?: ResolveShorthandOptions<Props, Required>): Required extends false ? Props | undefined : Props;
16
+ export declare const resolveShorthand: ResolveShorthandFunction;
@@ -1,12 +1,12 @@
1
1
  import { isValidElement } from 'react';
2
2
  /**
3
- * Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
3
+ * Resolves shorthands into slot props, to ensure normalization of the signature
4
4
  * being passed down to getSlots method
5
- * @param value - the base ShorthandProps
6
- * @param options - options to resolve ShorthandProps
5
+ * @param value - the base shorthand props
6
+ * @param options - options to resolve shorthand props
7
7
  */
8
8
 
9
- 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