@fluentui/react-utilities 9.0.0-nightly.d730088d7f.0 → 9.0.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +355 -9
- package/CHANGELOG.md +185 -70
- package/dist/index.d.ts +517 -0
- package/{lib → dist}/tsdoc-metadata.json +0 -0
- package/lib/compose/getSlots.js +21 -30
- package/lib/compose/getSlots.js.map +1 -1
- package/lib/compose/index.js +0 -1
- package/lib/compose/index.js.map +1 -1
- package/lib/compose/resolveShorthand.js +13 -12
- package/lib/compose/resolveShorthand.js.map +1 -1
- package/lib/compose/types.js +1 -5
- package/lib/compose/types.js.map +1 -1
- package/lib/hooks/index.js +2 -6
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useControllableState.js +26 -26
- package/lib/hooks/useControllableState.js.map +1 -1
- package/lib/hooks/useEventCallback.js +6 -12
- package/lib/hooks/useEventCallback.js.map +1 -1
- package/lib/hooks/useFirstMount.js +1 -1
- package/lib/hooks/useFirstMount.js.map +1 -1
- package/lib/hooks/useForceUpdate.js +1 -3
- package/lib/hooks/useForceUpdate.js.map +1 -1
- package/lib/hooks/useId.js +9 -5
- package/lib/hooks/useId.js.map +1 -1
- package/lib/hooks/useIsomorphicLayoutEffect.js +1 -1
- package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -1
- package/lib/hooks/useMergedEventCallbacks.js +26 -0
- package/lib/hooks/useMergedEventCallbacks.js.map +1 -0
- package/lib/hooks/useMergedRefs.js +5 -13
- package/lib/hooks/useMergedRefs.js.map +1 -1
- package/lib/hooks/useOnClickOutside.js +30 -36
- package/lib/hooks/useOnClickOutside.js.map +1 -1
- package/lib/hooks/useOnScrollOutside.js +13 -15
- package/lib/hooks/useOnScrollOutside.js.map +1 -1
- package/lib/hooks/usePrevious.js +3 -3
- package/lib/hooks/usePrevious.js.map +1 -1
- package/lib/hooks/useTimeout.js +13 -18
- package/lib/hooks/useTimeout.js.map +1 -1
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/ssr/SSRContext.js +9 -15
- package/lib/ssr/SSRContext.js.map +1 -1
- package/lib/ssr/canUseDOM.js.map +1 -1
- package/lib/ssr/index.js.map +1 -1
- package/lib/utils/applyTriggerPropsToChildren.js +24 -4
- package/lib/utils/applyTriggerPropsToChildren.js.map +1 -1
- package/lib/utils/clamp.js +1 -3
- package/lib/utils/clamp.js.map +1 -1
- package/lib/utils/getNativeElementProps.js +28 -4
- package/lib/utils/getNativeElementProps.js.map +1 -1
- package/lib/utils/getRTLSafeKey.js +1 -1
- package/lib/utils/getRTLSafeKey.js.map +1 -1
- package/lib/utils/getReactCallbackName.js +26 -0
- package/lib/utils/getReactCallbackName.js.map +1 -0
- package/lib/utils/getTriggerChild.js +26 -0
- package/lib/utils/getTriggerChild.js.map +1 -0
- package/lib/utils/index.js +2 -1
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/isFluentTrigger.js +8 -0
- package/lib/utils/isFluentTrigger.js.map +1 -0
- package/lib/utils/omit.js +2 -2
- package/lib/utils/omit.js.map +1 -1
- package/lib/utils/properties.js +72 -49
- package/lib/utils/properties.js.map +1 -1
- package/lib/utils/shouldPreventDefaultOnKeyDown.js +8 -4
- package/lib/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
- package/lib-commonjs/compose/getSlots.js +23 -34
- package/lib-commonjs/compose/getSlots.js.map +1 -1
- package/lib-commonjs/compose/index.js +1 -3
- package/lib-commonjs/compose/index.js.map +1 -1
- package/lib-commonjs/compose/resolveShorthand.js +14 -14
- package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
- package/lib-commonjs/compose/types.js +1 -5
- package/lib-commonjs/compose/types.js.map +1 -1
- package/lib-commonjs/hooks/index.js +5 -13
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useControllableState.js +27 -28
- package/lib-commonjs/hooks/useControllableState.js.map +1 -1
- package/lib-commonjs/hooks/useEventCallback.js +8 -14
- package/lib-commonjs/hooks/useEventCallback.js.map +1 -1
- package/lib-commonjs/hooks/useFirstMount.js +2 -2
- package/lib-commonjs/hooks/useFirstMount.js.map +1 -1
- package/lib-commonjs/hooks/useForceUpdate.js +2 -4
- package/lib-commonjs/hooks/useForceUpdate.js.map +1 -1
- package/lib-commonjs/hooks/useId.js +11 -7
- package/lib-commonjs/hooks/useId.js.map +1 -1
- package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js +2 -2
- package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -1
- package/lib-commonjs/hooks/useMergedEventCallbacks.js +36 -0
- package/lib-commonjs/hooks/useMergedEventCallbacks.js.map +1 -0
- package/lib-commonjs/hooks/useMergedRefs.js +6 -15
- package/lib-commonjs/hooks/useMergedRefs.js.map +1 -1
- package/lib-commonjs/hooks/useOnClickOutside.js +32 -38
- package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
- package/lib-commonjs/hooks/useOnScrollOutside.js +15 -17
- package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -1
- package/lib-commonjs/hooks/usePrevious.js +4 -4
- package/lib-commonjs/hooks/usePrevious.js.map +1 -1
- package/lib-commonjs/hooks/useTimeout.js +14 -20
- package/lib-commonjs/hooks/useTimeout.js.map +1 -1
- package/lib-commonjs/index.js +158 -5
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/ssr/SSRContext.js +9 -15
- package/lib-commonjs/ssr/SSRContext.js.map +1 -1
- package/lib-commonjs/ssr/canUseDOM.js.map +1 -1
- package/lib-commonjs/ssr/index.js +1 -1
- package/lib-commonjs/ssr/index.js.map +1 -1
- package/lib-commonjs/utils/applyTriggerPropsToChildren.js +26 -6
- package/lib-commonjs/utils/applyTriggerPropsToChildren.js.map +1 -1
- package/lib-commonjs/utils/clamp.js +1 -3
- package/lib-commonjs/utils/clamp.js.map +1 -1
- package/lib-commonjs/utils/getNativeElementProps.js +31 -5
- package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
- package/lib-commonjs/utils/getRTLSafeKey.js +1 -1
- package/lib-commonjs/utils/getRTLSafeKey.js.map +1 -1
- package/lib-commonjs/utils/getReactCallbackName.js +35 -0
- package/lib-commonjs/utils/getReactCallbackName.js.map +1 -0
- package/lib-commonjs/utils/getTriggerChild.js +37 -0
- package/lib-commonjs/utils/getTriggerChild.js.map +1 -0
- package/lib-commonjs/utils/index.js +5 -3
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/isFluentTrigger.js +17 -0
- package/lib-commonjs/utils/isFluentTrigger.js.map +1 -0
- package/lib-commonjs/utils/omit.js +2 -2
- package/lib-commonjs/utils/omit.js.map +1 -1
- package/lib-commonjs/utils/properties.js +70 -47
- package/lib-commonjs/utils/properties.js.map +1 -1
- package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js +9 -5
- package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
- package/package.json +14 -17
- package/dist/react-utilities.d.ts +0 -648
- package/lib/compose/getSlots.d.ts +0 -29
- package/lib/compose/index.d.ts +0 -4
- package/lib/compose/nullRender.d.ts +0 -4
- package/lib/compose/nullRender.js +0 -7
- package/lib/compose/nullRender.js.map +0 -1
- package/lib/compose/resolveShorthand.d.ts +0 -12
- package/lib/compose/types.d.ts +0 -104
- package/lib/hooks/index.d.ts +0 -16
- package/lib/hooks/useBoolean.d.ts +0 -17
- package/lib/hooks/useBoolean.js +0 -39
- package/lib/hooks/useBoolean.js.map +0 -1
- package/lib/hooks/useConst.d.ts +0 -12
- package/lib/hooks/useConst.js +0 -30
- package/lib/hooks/useConst.js.map +0 -1
- package/lib/hooks/useControllableState.d.ts +0 -21
- package/lib/hooks/useControllableValue.d.ts +0 -20
- package/lib/hooks/useControllableValue.js +0 -62
- package/lib/hooks/useControllableValue.js.map +0 -1
- package/lib/hooks/useEventCallback.d.ts +0 -13
- package/lib/hooks/useFirstMount.d.ts +0 -11
- package/lib/hooks/useForceUpdate.d.ts +0 -4
- package/lib/hooks/useId.d.ts +0 -15
- package/lib/hooks/useIsomorphicLayoutEffect.d.ts +0 -11
- package/lib/hooks/useMergedRefs.d.ts +0 -13
- package/lib/hooks/useMount.d.ts +0 -6
- package/lib/hooks/useMount.js +0 -17
- package/lib/hooks/useMount.js.map +0 -1
- package/lib/hooks/useOnClickOutside.d.ts +0 -29
- package/lib/hooks/useOnScrollOutside.d.ts +0 -5
- package/lib/hooks/usePrevious.d.ts +0 -1
- package/lib/hooks/useTimeout.d.ts +0 -8
- package/lib/hooks/useUnmount.d.ts +0 -6
- package/lib/hooks/useUnmount.js +0 -19
- package/lib/hooks/useUnmount.js.map +0 -1
- package/lib/index.d.ts +0 -4
- package/lib/ssr/SSRContext.d.ts +0 -33
- package/lib/ssr/canUseDOM.d.ts +0 -4
- package/lib/ssr/index.d.ts +0 -2
- package/lib/utils/applyTriggerPropsToChildren.d.ts +0 -5
- package/lib/utils/clamp.d.ts +0 -8
- package/lib/utils/getNativeElementProps.d.ts +0 -9
- package/lib/utils/getRTLSafeKey.d.ts +0 -4
- package/lib/utils/index.d.ts +0 -8
- package/lib/utils/omit.d.ts +0 -14
- package/lib/utils/onlyChild.d.ts +0 -5
- package/lib/utils/onlyChild.js +0 -13
- package/lib/utils/onlyChild.js.map +0 -1
- package/lib/utils/properties.d.ts +0 -148
- package/lib/utils/shouldPreventDefaultOnKeyDown.d.ts +0 -7
- package/lib-commonjs/compose/getSlots.d.ts +0 -29
- package/lib-commonjs/compose/index.d.ts +0 -4
- package/lib-commonjs/compose/nullRender.d.ts +0 -4
- package/lib-commonjs/compose/nullRender.js +0 -16
- package/lib-commonjs/compose/nullRender.js.map +0 -1
- package/lib-commonjs/compose/resolveShorthand.d.ts +0 -12
- package/lib-commonjs/compose/types.d.ts +0 -104
- package/lib-commonjs/hooks/index.d.ts +0 -16
- package/lib-commonjs/hooks/useBoolean.d.ts +0 -17
- package/lib-commonjs/hooks/useBoolean.js +0 -50
- package/lib-commonjs/hooks/useBoolean.js.map +0 -1
- package/lib-commonjs/hooks/useConst.d.ts +0 -12
- package/lib-commonjs/hooks/useConst.js +0 -40
- package/lib-commonjs/hooks/useConst.js.map +0 -1
- package/lib-commonjs/hooks/useControllableState.d.ts +0 -21
- package/lib-commonjs/hooks/useControllableValue.d.ts +0 -20
- package/lib-commonjs/hooks/useControllableValue.js +0 -73
- package/lib-commonjs/hooks/useControllableValue.js.map +0 -1
- package/lib-commonjs/hooks/useEventCallback.d.ts +0 -13
- package/lib-commonjs/hooks/useFirstMount.d.ts +0 -11
- package/lib-commonjs/hooks/useForceUpdate.d.ts +0 -4
- package/lib-commonjs/hooks/useId.d.ts +0 -15
- package/lib-commonjs/hooks/useIsomorphicLayoutEffect.d.ts +0 -11
- package/lib-commonjs/hooks/useMergedRefs.d.ts +0 -13
- package/lib-commonjs/hooks/useMount.d.ts +0 -6
- package/lib-commonjs/hooks/useMount.js +0 -27
- package/lib-commonjs/hooks/useMount.js.map +0 -1
- package/lib-commonjs/hooks/useOnClickOutside.d.ts +0 -29
- package/lib-commonjs/hooks/useOnScrollOutside.d.ts +0 -5
- package/lib-commonjs/hooks/usePrevious.d.ts +0 -1
- package/lib-commonjs/hooks/useTimeout.d.ts +0 -8
- package/lib-commonjs/hooks/useUnmount.d.ts +0 -6
- package/lib-commonjs/hooks/useUnmount.js +0 -29
- package/lib-commonjs/hooks/useUnmount.js.map +0 -1
- package/lib-commonjs/index.d.ts +0 -4
- package/lib-commonjs/ssr/SSRContext.d.ts +0 -33
- package/lib-commonjs/ssr/canUseDOM.d.ts +0 -4
- package/lib-commonjs/ssr/index.d.ts +0 -2
- package/lib-commonjs/utils/applyTriggerPropsToChildren.d.ts +0 -5
- package/lib-commonjs/utils/clamp.d.ts +0 -8
- package/lib-commonjs/utils/getNativeElementProps.d.ts +0 -9
- package/lib-commonjs/utils/getRTLSafeKey.d.ts +0 -4
- package/lib-commonjs/utils/index.d.ts +0 -8
- package/lib-commonjs/utils/omit.d.ts +0 -14
- package/lib-commonjs/utils/onlyChild.d.ts +0 -5
- package/lib-commonjs/utils/onlyChild.js +0 -23
- package/lib-commonjs/utils/onlyChild.js.map +0 -1
- package/lib-commonjs/utils/properties.d.ts +0 -148
- package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.d.ts +0 -7
package/dist/index.d.ts
ADDED
@@ -0,0 +1,517 @@
|
|
1
|
+
import { DispatchWithoutAction } from 'react';
|
2
|
+
import * as React_2 from 'react';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Apply the trigger props to the children, either by calling the render function, or cloning with the new props.
|
6
|
+
*/
|
7
|
+
export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: React_2.ReactElement<any, string | React_2.JSXElementConstructor<any>> | ((props: TTriggerProps) => React_2.ReactElement | null) | null | undefined, triggerProps: TTriggerProps) => React_2.ReactElement | null;
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Helper type for inferring the type of the as prop from a Props type.
|
11
|
+
*
|
12
|
+
* For example:
|
13
|
+
* ```
|
14
|
+
* type Example<T> = T extends AsIntrinsicElement<infer As> ? As : never;
|
15
|
+
* ```
|
16
|
+
*/
|
17
|
+
declare type AsIntrinsicElement<As extends keyof JSX.IntrinsicElements> = {
|
18
|
+
as?: As;
|
19
|
+
};
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Verifies if an application can use DOM.
|
23
|
+
*/
|
24
|
+
export declare function canUseDOM(): boolean;
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Clamps `value` to a number between the min and max.
|
28
|
+
*
|
29
|
+
* @param value - the value to be clamped
|
30
|
+
* @param min - the lowest valid value
|
31
|
+
* @param max - the highest valid value
|
32
|
+
*/
|
33
|
+
export declare const clamp: (value: number, min: number, max: number) => number;
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Defines the Props type for a component given its slots and the definition of which one is the primary slot,
|
37
|
+
* defaulting to root if one is not provided.
|
38
|
+
*/
|
39
|
+
export declare type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> = Omit<Slots, Primary & 'root'> & PropsWithoutRef<ExtractSlotProps<Slots[Primary]>>;
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Defines the State object of a component given its slots.
|
43
|
+
*/
|
44
|
+
export declare type ComponentState<Slots extends SlotPropsRecord> = {
|
45
|
+
components: {
|
46
|
+
[Key in keyof Slots]-?: React_2.ComponentType<ExtractSlotProps<Slots[Key]>> | (ExtractSlotProps<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
|
47
|
+
};
|
48
|
+
} & {
|
49
|
+
[Key in keyof Slots]: ReplaceNullWithUndefined<Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>>;
|
50
|
+
};
|
51
|
+
|
52
|
+
/**
|
53
|
+
* HTML element types that are not allowed to have children.
|
54
|
+
*
|
55
|
+
* Reference: https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
|
56
|
+
*/
|
57
|
+
declare type EmptyIntrisicElements = 'area' | 'base' | 'br' | 'col' | 'embed' | 'hr' | 'img' | 'input' | 'link' | 'meta' | 'param' | 'source' | 'track' | 'wbr';
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Removes SlotShorthandValue and null from the slot type, extracting just the slot's Props object.
|
61
|
+
*/
|
62
|
+
export declare type ExtractSlotProps<S> = Exclude<S, SlotShorthandValue | null | undefined>;
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Allows a component to be tagged as a FluentUI trigger component.
|
66
|
+
*
|
67
|
+
* Triggers are special-case components: they attach event listeners and other props on their child,
|
68
|
+
* and use them to trigger another component to show. Examples include `MenuTrigger` and `Tooltip`.
|
69
|
+
*
|
70
|
+
* A component can be tagged as a trigger as follows:
|
71
|
+
* ```ts
|
72
|
+
* const MyComponent: React.FC<MyComponentProps> & FluentTriggerComponent = ...;
|
73
|
+
*
|
74
|
+
* MyComponent.isFluentTriggerComponent = true; // MUST also set this to true
|
75
|
+
* ```
|
76
|
+
*/
|
77
|
+
export declare type FluentTriggerComponent = {
|
78
|
+
isFluentTriggerComponent?: boolean;
|
79
|
+
};
|
80
|
+
|
81
|
+
/**
|
82
|
+
* Return type for `React.forwardRef`, including inference of the proper typing for the ref.
|
83
|
+
*/
|
84
|
+
export declare type ForwardRefComponent<Props> = ObscureEventName extends keyof Props ? Required<Props>[ObscureEventName] extends React_2.PointerEventHandler<infer Element> ? React_2.ForwardRefExoticComponent<Props & React_2.RefAttributes<Element>> : never : never;
|
85
|
+
|
86
|
+
/**
|
87
|
+
* Given an element tagname and user props, filters the props to only allowed props for the given
|
88
|
+
* element type.
|
89
|
+
* @param tagName - Tag name (e.g. "div")
|
90
|
+
* @param props - Props object
|
91
|
+
* @param excludedPropNames - List of props to disallow
|
92
|
+
*/
|
93
|
+
export declare function getNativeElementProps<TAttributes extends React_2.HTMLAttributes<any>>(tagName: string, props: {}, excludedPropNames?: string[]): TAttributes;
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.
|
97
|
+
*
|
98
|
+
* This function is only for use with components that have a primary slot other than `root`.
|
99
|
+
* Most components should use {@link getNativeElementProps} for their root slot if it is the primary slot.
|
100
|
+
*
|
101
|
+
* @returns An object containing the native props for the `root` and primary slots.
|
102
|
+
*/
|
103
|
+
export declare const getPartitionedNativeProps: <Props extends Pick<React_2.HTMLAttributes<HTMLElement>, "style" | "className">, ExcludedPropKeys extends Extract<keyof Props, string> = never>({ primarySlotTagName, props, excludedPropNames, }: {
|
104
|
+
/** The primary slot's element type (e.g. 'div') */
|
105
|
+
primarySlotTagName: keyof JSX.IntrinsicElements;
|
106
|
+
/** The component's props object */
|
107
|
+
props: Props;
|
108
|
+
/** List of native props to exclude from the returned value */
|
109
|
+
excludedPropNames?: ExcludedPropKeys[] | undefined;
|
110
|
+
}) => {
|
111
|
+
root: {
|
112
|
+
style: React_2.CSSProperties | undefined;
|
113
|
+
className: string | undefined;
|
114
|
+
};
|
115
|
+
primary: Omit<Props, ExcludedPropKeys>;
|
116
|
+
};
|
117
|
+
|
118
|
+
/**
|
119
|
+
* Finds and swaps a provided key for it's right to left format.
|
120
|
+
*/
|
121
|
+
export declare const getRTLSafeKey: (key: string, dir: 'ltr' | 'rtl') => string;
|
122
|
+
|
123
|
+
/**
|
124
|
+
* Given the state and an array of slot names, will break out `slots` and `slotProps`
|
125
|
+
* collections.
|
126
|
+
*
|
127
|
+
* The root is derived from a mix of `components` props and `as` prop.
|
128
|
+
*
|
129
|
+
* Slots will render as null if they are rendered as primitives with undefined children.
|
130
|
+
*
|
131
|
+
* The slotProps will always omit the `as` prop within them, and for slots that are string
|
132
|
+
* primitives, the props will be filtered according to the slot type by the type system.
|
133
|
+
* For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable
|
134
|
+
* anchor props. Note that this is only enforced at build time by Typescript -- there is no
|
135
|
+
* runtime code filtering props in this function.
|
136
|
+
*
|
137
|
+
* @param state - State including slot definitions
|
138
|
+
* @returns An object containing the `slots` map and `slotProps` map.
|
139
|
+
*/
|
140
|
+
export declare function getSlots<R extends SlotPropsRecord>(state: ComponentState<R>): {
|
141
|
+
slots: Slots<R>;
|
142
|
+
slotProps: ObjectSlotProps<R>;
|
143
|
+
};
|
144
|
+
|
145
|
+
/**
|
146
|
+
* Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).
|
147
|
+
*
|
148
|
+
* In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,
|
149
|
+
* it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.
|
150
|
+
* This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.
|
151
|
+
*
|
152
|
+
* For example, the following returns `<div id="child" />`:
|
153
|
+
* ```jsx
|
154
|
+
* getTriggerChild(
|
155
|
+
* <Tooltip>
|
156
|
+
* <MenuTrigger>
|
157
|
+
* <div id="child" />
|
158
|
+
* </MenuTrigger>
|
159
|
+
* </Tooltip>
|
160
|
+
* );
|
161
|
+
* ```
|
162
|
+
*/
|
163
|
+
export declare const getTriggerChild: (children: React_2.ReactNode) => React_2.ReactElement & {
|
164
|
+
ref?: React_2.Ref<unknown>;
|
165
|
+
};
|
166
|
+
|
167
|
+
/**
|
168
|
+
* Helper type for {@link Slot}. Modifies `JSX.IntrinsicElements[Type]`:
|
169
|
+
* * Removes legacy string ref.
|
170
|
+
* * Disallows children for empty tags like 'img'.
|
171
|
+
*/
|
172
|
+
declare type IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = React_2.PropsWithRef<JSX.IntrinsicElements[Type]> & (Type extends EmptyIntrisicElements ? {
|
173
|
+
children?: never;
|
174
|
+
} : {});
|
175
|
+
|
176
|
+
/**
|
177
|
+
* Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.
|
178
|
+
*
|
179
|
+
* ```
|
180
|
+
* IsSingleton<'a'> // true
|
181
|
+
* IsSingleton<'a' | 'b' | 'c'> // false
|
182
|
+
* ```
|
183
|
+
*/
|
184
|
+
declare type IsSingleton<T extends string> = {
|
185
|
+
[K in T]: Exclude<T, K> extends never ? true : false;
|
186
|
+
}[T];
|
187
|
+
|
188
|
+
declare type ObjectSlotProps<S extends SlotPropsRecord> = {
|
189
|
+
[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;
|
190
|
+
};
|
191
|
+
|
192
|
+
/**
|
193
|
+
* This is part of a hack to infer the element type from a native element *props* type.
|
194
|
+
* The only place the original element is found in a native props type (at least that's workable
|
195
|
+
* for inference) is in the event handlers, so some of the helper types use this event handler
|
196
|
+
* name to infer the original element type.
|
197
|
+
*
|
198
|
+
* Notes:
|
199
|
+
* - Using an extremely obscure event handler reduces the likelihood that its signature will be
|
200
|
+
* modified in any component's props.
|
201
|
+
* - Inferring based on a single prop name instead of a larger type like `DOMAttributes<T>` should be
|
202
|
+
* less expensive for typescript to evaluate and is less likely to result in type expansion in .d.ts.
|
203
|
+
*/
|
204
|
+
declare type ObscureEventName = 'onLostPointerCaptureCapture';
|
205
|
+
|
206
|
+
/**
|
207
|
+
* Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
|
208
|
+
* IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
|
209
|
+
*
|
210
|
+
* The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional
|
211
|
+
* types, to prevent unions from being expanded.
|
212
|
+
*/
|
213
|
+
declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;
|
214
|
+
|
215
|
+
/**
|
216
|
+
* A Ref function which can be treated like a ref object in that it has an attached
|
217
|
+
* current property, which will be updated as the ref is evaluated.
|
218
|
+
*/
|
219
|
+
export declare type RefObjectFunction<T> = React_2.RefObject<T> & ((value: T) => void);
|
220
|
+
|
221
|
+
/**
|
222
|
+
* If type T includes `null`, remove it and add `undefined` instead.
|
223
|
+
*/
|
224
|
+
declare type ReplaceNullWithUndefined<T> = T extends null ? Exclude<T, null> | undefined : T;
|
225
|
+
|
226
|
+
/**
|
227
|
+
* Resets generated IDs, should be used only in tests.
|
228
|
+
*
|
229
|
+
* @private
|
230
|
+
*/
|
231
|
+
export declare function resetIdsForTests(): void;
|
232
|
+
|
233
|
+
/**
|
234
|
+
* Resolves shorthands into slot props, to ensure normalization of the signature
|
235
|
+
* being passed down to getSlots method
|
236
|
+
* @param value - the base shorthand props
|
237
|
+
* @param options - options to resolve shorthand props
|
238
|
+
*/
|
239
|
+
export declare const resolveShorthand: ResolveShorthandFunction;
|
240
|
+
|
241
|
+
export declare type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {
|
242
|
+
<P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, true>): ReplaceNullWithUndefined<P>;
|
243
|
+
<P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, boolean>): ReplaceNullWithUndefined<P> | undefined;
|
244
|
+
};
|
245
|
+
|
246
|
+
export declare type ResolveShorthandOptions<Props, Required extends boolean = false> = {
|
247
|
+
required?: Required;
|
248
|
+
defaultProps?: Props;
|
249
|
+
};
|
250
|
+
|
251
|
+
/**
|
252
|
+
* Checks if the keyboard event should preventDefault() for Enter and Spacebar keys
|
253
|
+
*
|
254
|
+
* Useful for situations where a keydown needs to be transformed to a click event
|
255
|
+
*/
|
256
|
+
export declare function shouldPreventDefaultOnKeyDown(e: KeyboardEvent | React_2.KeyboardEvent): boolean;
|
257
|
+
|
258
|
+
/**
|
259
|
+
* The props type and shorthand value for a slot. Type is either a single intrinsic element like `'div'`,
|
260
|
+
* or a component like `typeof Button`.
|
261
|
+
*
|
262
|
+
* If a slot needs to support multiple intrinsic element types, use the `AlternateAs` param (see examples below).
|
263
|
+
*
|
264
|
+
* By default, slots can be set to `null` to prevent them from being rendered. If a slot must always be rendered,
|
265
|
+
* wrap with `NonNullable` (see examples below).
|
266
|
+
*
|
267
|
+
* @example
|
268
|
+
* ```
|
269
|
+
* // Intrinsic element examples:
|
270
|
+
* Slot<'div'> // Slot is always div
|
271
|
+
* Slot<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
|
272
|
+
* Slot<'span', 'div' | 'pre'> // Defaults to span, but allows as="div" or as="pre"
|
273
|
+
* NonNullable<Slot<'div'>> // Slot that will always be rendered (can't be set to null by the user)
|
274
|
+
*
|
275
|
+
* // Component examples:
|
276
|
+
* Slot<typeof Button> // Slot is always a Button, and accepts all of Button's Props
|
277
|
+
* NonNullable<Slot<typeof Label>> // Slot is a Label and will always be rendered (can't be set to null by the user)
|
278
|
+
* ```
|
279
|
+
*/
|
280
|
+
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 ? {
|
281
|
+
as?: Type;
|
282
|
+
} & WithSlotRenderFunction<IntrisicElementProps<Type>> : Type extends React_2.ComponentType<infer Props> ? WithSlotRenderFunction<Props> : Type> | {
|
283
|
+
[As in AlternateAs]: {
|
284
|
+
as: As;
|
285
|
+
} & WithSlotRenderFunction<IntrisicElementProps<As>>;
|
286
|
+
}[AlternateAs] | null : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';
|
287
|
+
|
288
|
+
/**
|
289
|
+
* Helper type to correctly define the slot class names object.
|
290
|
+
*/
|
291
|
+
export declare type SlotClassNames<Slots> = {
|
292
|
+
[SlotName in keyof Slots]-?: string;
|
293
|
+
};
|
294
|
+
|
295
|
+
/**
|
296
|
+
* Matches any component's Slots type (such as ButtonSlots).
|
297
|
+
*
|
298
|
+
* This should ONLY be used in type templates as in `extends SlotPropsRecord`;
|
299
|
+
* it shouldn't be used as a component's Slots type.
|
300
|
+
*/
|
301
|
+
export declare type SlotPropsRecord = Record<string, UnknownSlotProps | SlotShorthandValue | null | undefined>;
|
302
|
+
|
303
|
+
export declare type SlotRenderFunction<Props> = (Component: React_2.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React_2.ReactNode;
|
304
|
+
|
305
|
+
export declare type Slots<S extends SlotPropsRecord> = {
|
306
|
+
[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]>>;
|
307
|
+
};
|
308
|
+
|
309
|
+
/**
|
310
|
+
* The shorthand value of a slot allows specifying its child
|
311
|
+
*/
|
312
|
+
export declare type SlotShorthandValue = React_2.ReactChild | React_2.ReactNodeArray | React_2.ReactPortal;
|
313
|
+
|
314
|
+
/**
|
315
|
+
* When using SSR with Fluent UI, applications must be wrapped in an SSRProvider. This ensures that auto generated ids
|
316
|
+
* are consistent between the client and server.
|
317
|
+
*
|
318
|
+
* @public
|
319
|
+
*/
|
320
|
+
export declare const SSRProvider: React_2.FC;
|
321
|
+
|
322
|
+
/**
|
323
|
+
* Converts a union type (`A | B | C`) to an intersection type (`A & B & C`)
|
324
|
+
*/
|
325
|
+
declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;
|
326
|
+
|
327
|
+
/**
|
328
|
+
* Matches any slot props type.
|
329
|
+
*
|
330
|
+
* This should ONLY be used in type templates as in `extends UnknownSlotProps`;
|
331
|
+
* it shouldn't be used as the type of a slot.
|
332
|
+
*/
|
333
|
+
declare type UnknownSlotProps = Pick<React_2.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
|
334
|
+
as?: keyof JSX.IntrinsicElements;
|
335
|
+
};
|
336
|
+
|
337
|
+
/**
|
338
|
+
* A `useState`-like hook to manage a value that could be either controlled or uncontrolled,
|
339
|
+
* such as a checked state or text input string.
|
340
|
+
*
|
341
|
+
* Unlike `setState`, it's okay to call the returned updater (dispatch) function for either a
|
342
|
+
* controlled or uncontrolled component. Calls will only be respected if the component is uncontrolled.
|
343
|
+
*
|
344
|
+
* @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array
|
345
|
+
* of the current value and an updater (dispatch) function. The updater function is referentially
|
346
|
+
* stable (won't change during the component's lifecycle). It can take either a new value, or a
|
347
|
+
* function which is passed the previous value and returns the new value. Unlike `setState`, calls
|
348
|
+
* to the updater function will only be respected if the component is uncontrolled.
|
349
|
+
* @see https://reactjs.org/docs/uncontrolled-components.html
|
350
|
+
*/
|
351
|
+
export declare const useControllableState: <State>(options: UseControllableStateOptions<State>) => [State, React_2.Dispatch<React_2.SetStateAction<State>>];
|
352
|
+
|
353
|
+
export declare type UseControllableStateOptions<State> = {
|
354
|
+
/**
|
355
|
+
* User-provided default state or initializer, for uncontrolled usage.
|
356
|
+
*/
|
357
|
+
defaultState?: State | (() => State);
|
358
|
+
/**
|
359
|
+
* User-provided controlled state. `undefined` means internal state will be used.
|
360
|
+
*/
|
361
|
+
state: State | undefined;
|
362
|
+
/**
|
363
|
+
* Used as the initial state if `state` and `defaultState` are both `undefined`.
|
364
|
+
* If `undefined` is the correct initial state, pass that here.
|
365
|
+
*/
|
366
|
+
initialState: State;
|
367
|
+
};
|
368
|
+
|
369
|
+
/**
|
370
|
+
* https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
|
371
|
+
*
|
372
|
+
* Modified `useCallback` that can be used when dependencies change too frequently. Can occur when
|
373
|
+
* e.g. user props are dependencies which could change on every render
|
374
|
+
* e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently
|
375
|
+
*
|
376
|
+
* This should not be used often, but can be a useful re-render optimization since the callback is a ref and
|
377
|
+
* will not be invalidated between re-renders
|
378
|
+
*
|
379
|
+
* @param fn - The callback function that will be used
|
380
|
+
*/
|
381
|
+
export declare const useEventCallback: <Args extends unknown[], Return>(fn: (...args: Args) => Return) => (...args: Args) => Return;
|
382
|
+
|
383
|
+
/**
|
384
|
+
* Checks if components was mounted the first time.
|
385
|
+
* Since concurrent mode will be released in the future this needs to be verified
|
386
|
+
* Currently (React 17) will always render the initial mount once
|
387
|
+
* https://codesandbox.io/s/heuristic-brook-s4w0q?file=/src/App.jsx
|
388
|
+
* https://codesandbox.io/s/holy-grass-8nieu?file=/src/App.jsx
|
389
|
+
*
|
390
|
+
* @example
|
391
|
+
* const isFirstMount = useFirstMount();
|
392
|
+
*/
|
393
|
+
export declare function useFirstMount(): boolean;
|
394
|
+
|
395
|
+
/**
|
396
|
+
* Forces a re-render, similar to `forceUpdate` in class components.
|
397
|
+
*/
|
398
|
+
export declare function useForceUpdate(): DispatchWithoutAction;
|
399
|
+
|
400
|
+
/**
|
401
|
+
* Hook to generate a unique ID.
|
402
|
+
*
|
403
|
+
* @param prefix - Optional prefix for the ID. Defaults to 'fui-'.
|
404
|
+
* @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,
|
405
|
+
* without conditioning the hook call
|
406
|
+
* @returns The ID
|
407
|
+
*/
|
408
|
+
export declare function useId(prefix?: string, providedId?: string): string;
|
409
|
+
|
410
|
+
/**
|
411
|
+
* React currently throws a warning when using useLayoutEffect on the server. To get around it, we can conditionally
|
412
|
+
* useEffect on the server (no-op) and useLayoutEffect in the browser. We occasionally need useLayoutEffect to
|
413
|
+
* ensure we don't get a render flash for certain operations, but we may also need affected components to render on
|
414
|
+
* the server.
|
415
|
+
*
|
416
|
+
* https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
|
417
|
+
* https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js
|
418
|
+
*/
|
419
|
+
export declare const useIsomorphicLayoutEffect: typeof React_2.useEffect;
|
420
|
+
|
421
|
+
/**
|
422
|
+
* Returns whether the component is currently being server side rendered or hydrated on the client. Can be used to delay
|
423
|
+
* browser-specific rendering until after hydration. May cause re-renders on a client when is used within SSRProvider.
|
424
|
+
*/
|
425
|
+
export declare function useIsSSR(): boolean;
|
426
|
+
|
427
|
+
/**
|
428
|
+
* Combine two event callbacks into a single callback function that calls each one in order.
|
429
|
+
*
|
430
|
+
* This is useful to add an event listener to an existing element without overwriting the current listener, if any.
|
431
|
+
*
|
432
|
+
* For example:
|
433
|
+
* ```ts
|
434
|
+
* state.slot.onChange = useMergedCallbacks(state.slot.onChange, ev => {
|
435
|
+
* // Handle onChange
|
436
|
+
* });
|
437
|
+
* ```
|
438
|
+
*
|
439
|
+
* @param callback1 - The first callback to be called
|
440
|
+
* @param callback2 - The second callback to be called
|
441
|
+
*
|
442
|
+
* @returns An event callback that calls the callbacks in order, and is stable between renders
|
443
|
+
*/
|
444
|
+
export declare function useMergedEventCallbacks<Args extends unknown[]>(callback1: ((...args: Args) => void) | undefined, callback2: ((...args: Args) => void) | undefined): (...args: Args) => void;
|
445
|
+
|
446
|
+
/**
|
447
|
+
* React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that
|
448
|
+
* updates all provided refs
|
449
|
+
* @param refs - Refs to collectively update with one ref value.
|
450
|
+
* @returns A function with an attached "current" prop, so that it can be treated like a RefObject.
|
451
|
+
*/
|
452
|
+
export declare function useMergedRefs<T>(...refs: (React_2.Ref<T> | undefined)[]): RefObjectFunction<T>;
|
453
|
+
|
454
|
+
export declare type UseOnClickOrScrollOutsideOptions = {
|
455
|
+
/**
|
456
|
+
* The element to listen for the click event
|
457
|
+
*/
|
458
|
+
element: Document | undefined;
|
459
|
+
/**
|
460
|
+
* Refs to elements that check if the click is outside
|
461
|
+
*/
|
462
|
+
refs: React_2.MutableRefObject<HTMLElement | undefined | null>[];
|
463
|
+
/**
|
464
|
+
* By default uses element.contains, but custom contain function can be provided
|
465
|
+
* @param parentRef - provided parent ref
|
466
|
+
* @param child - event target element
|
467
|
+
*/
|
468
|
+
contains?(parent: HTMLElement | null, child: HTMLElement): boolean;
|
469
|
+
/**
|
470
|
+
* Disables event listeners
|
471
|
+
*/
|
472
|
+
disabled?: boolean;
|
473
|
+
/**
|
474
|
+
* Called if the click is outside the element refs
|
475
|
+
*/
|
476
|
+
callback: (ev: MouseEvent | TouchEvent) => void;
|
477
|
+
};
|
478
|
+
|
479
|
+
/**
|
480
|
+
* Utility to perform checks where a click/touch event was made outside a component
|
481
|
+
*/
|
482
|
+
export declare const useOnClickOutside: (options: UseOnClickOrScrollOutsideOptions) => void;
|
483
|
+
|
484
|
+
/**
|
485
|
+
* Utility to perform checks where a click/touch event was made outside a component
|
486
|
+
*/
|
487
|
+
export declare const useOnScrollOutside: (options: UseOnClickOrScrollOutsideOptions) => void;
|
488
|
+
|
489
|
+
export declare const usePrevious: <ValueType = unknown>(value: ValueType) => ValueType | null;
|
490
|
+
|
491
|
+
/**
|
492
|
+
* Helper to manage a browser timeout.
|
493
|
+
* Ensures that the timeout isn't set multiple times at once,
|
494
|
+
* and is cleaned up when the component is unloaded.
|
495
|
+
*
|
496
|
+
* @returns A pair of [setTimeout, clearTimeout] that are stable between renders.
|
497
|
+
*/
|
498
|
+
export declare function useTimeout(): readonly [(fn: () => void, delay: number) => void, () => void];
|
499
|
+
|
500
|
+
/**
|
501
|
+
* Helper type for {@link Slot}. Takes the props we want to support for a slot and adds the ability for `children`
|
502
|
+
* to be a render function that takes those props.
|
503
|
+
*/
|
504
|
+
declare type WithSlotRenderFunction<Props extends {
|
505
|
+
children?: unknown;
|
506
|
+
}> = Props & {
|
507
|
+
children?: Props['children'] | SlotRenderFunction<Props>;
|
508
|
+
};
|
509
|
+
|
510
|
+
/**
|
511
|
+
* Helper type for {@link Slot}. Adds shorthand types that are assignable to the slot's `children`.
|
512
|
+
*/
|
513
|
+
declare type WithSlotShorthandValue<Props extends {
|
514
|
+
children?: unknown;
|
515
|
+
}> = Props | Extract<SlotShorthandValue, Props['children']>;
|
516
|
+
|
517
|
+
export { }
|
File without changes
|
package/lib/compose/getSlots.js
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
import { __rest } from "tslib";
|
2
1
|
import * as React from 'react';
|
3
|
-
import { nullRender } from './nullRender';
|
4
2
|
import { omit } from '../utils/omit';
|
5
3
|
/**
|
6
4
|
* Given the state and an array of slot names, will break out `slots` and `slotProps`
|
@@ -11,35 +9,28 @@ import { omit } from '../utils/omit';
|
|
11
9
|
* Slots will render as null if they are rendered as primitives with undefined children.
|
12
10
|
*
|
13
11
|
* The slotProps will always omit the `as` prop within them, and for slots that are string
|
14
|
-
* primitives, the props will be filtered according
|
15
|
-
* slot is rendered `as: 'a'`, the props will be filtered for acceptable
|
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.
|
16
16
|
*
|
17
17
|
* @param state - State including slot definitions
|
18
|
-
* @param slotNames - Name of which props are slots
|
19
18
|
* @returns An object containing the `slots` map and `slotProps` map.
|
20
19
|
*/
|
21
20
|
|
22
|
-
export function getSlots(state
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
var slots = {};
|
28
|
-
var slotProps = {};
|
29
|
-
|
30
|
-
for (var _i = 0, slotNames_1 = slotNames; _i < slotNames_1.length; _i++) {
|
31
|
-
var slotName = slotNames_1[_i];
|
32
|
-
|
33
|
-
var _a = getSlot(state, slotName),
|
34
|
-
slot = _a[0],
|
35
|
-
props = _a[1];
|
21
|
+
export function getSlots(state) {
|
22
|
+
const slots = {};
|
23
|
+
const slotProps = {};
|
24
|
+
const slotNames = Object.keys(state.components);
|
36
25
|
|
26
|
+
for (const slotName of slotNames) {
|
27
|
+
const [slot, props] = getSlot(state, slotName);
|
37
28
|
slots[slotName] = slot;
|
38
29
|
slotProps[slotName] = props;
|
39
30
|
}
|
40
31
|
|
41
32
|
return {
|
42
|
-
slots
|
33
|
+
slots,
|
43
34
|
slotProps: slotProps
|
44
35
|
};
|
45
36
|
}
|
@@ -48,25 +39,25 @@ function getSlot(state, slotName) {
|
|
48
39
|
var _a, _b, _c;
|
49
40
|
|
50
41
|
if (state[slotName] === undefined) {
|
51
|
-
return [
|
42
|
+
return [null, undefined];
|
52
43
|
}
|
53
44
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
45
|
+
const {
|
46
|
+
children,
|
47
|
+
as: asProp,
|
48
|
+
...rest
|
49
|
+
} = state[slotName];
|
50
|
+
const slot = ((_a = state.components) === null || _a === void 0 ? void 0 : _a[slotName]) === undefined || typeof state.components[slotName] === 'string' ? asProp || ((_b = state.components) === null || _b === void 0 ? void 0 : _b[slotName]) || 'div' : state.components[slotName];
|
60
51
|
|
61
52
|
if (typeof children === 'function') {
|
62
|
-
|
53
|
+
const render = children;
|
63
54
|
return [React.Fragment, {
|
64
55
|
children: render(slot, rest)
|
65
56
|
}];
|
66
57
|
}
|
67
58
|
|
68
|
-
|
69
|
-
|
59
|
+
const shouldOmitAsProp = typeof slot === 'string' && ((_c = state[slotName]) === null || _c === void 0 ? void 0 : _c.as);
|
60
|
+
const slotProps = shouldOmitAsProp ? omit(state[slotName], ['as']) : state[slotName];
|
70
61
|
return [slot, slotProps];
|
71
62
|
}
|
72
63
|
//# sourceMappingURL=getSlots.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["compose/getSlots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA,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,EAEa;;;AAEX,MAAI,KAAK,CAAC,QAAD,CAAL,KAAoB,SAAxB,EAAmC;AACjC,WAAO,CAAC,IAAD,EAAO,SAAP,CAAP;AACD;;AACD,QAAM;AAAE,IAAA,QAAF;AAAY,IAAA,EAAE,EAAE,MAAhB;AAAwB,OAAG;AAA3B,MAAoC,KAAK,CAAC,QAAD,CAA/C;AAEA,QAAM,IAAI,GAAI,CAAA,CAAA,EAAA,GAAA,KAAK,CAAC,UAAN,MAAgB,IAAhB,IAAgB,EAAA,KAAA,KAAA,CAAhB,GAAgB,KAAA,CAAhB,GAAgB,EAAA,CAAG,QAAH,CAAhB,MAAiC,SAAjC,IAA8C,OAAO,KAAK,CAAC,UAAN,CAAiB,QAAjB,CAAP,KAAsC,QAApF,GACV,MAAM,KAAI,CAAA,EAAA,GAAA,KAAK,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","sourcesContent":["import * as React from 'react';\n\nimport { omit } from '../utils/omit';\nimport type {\n AsIntrinsicElement,\n ComponentState,\n ExtractSlotProps,\n SlotPropsRecord,\n SlotRenderFunction,\n UnionToIntersection,\n} from './types';\n\nexport type Slots<S extends SlotPropsRecord> = {\n [K in keyof S]: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As>\n ? // for slots with an `as` prop, the slot will be any one of the possible values of `as`\n As\n : ExtractSlotProps<S[K]> extends React.ComponentType<infer P>\n ? React.ElementType<NonNullable<P>>\n : React.ElementType<ExtractSlotProps<S[K]>>;\n};\n\ntype ObjectSlotProps<S extends SlotPropsRecord> = {\n [K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As>\n ? // For intrinsic element types, return the intersection of all possible\n // element's props, to be compatible with the As type returned by Slots<>\n UnionToIntersection<JSX.IntrinsicElements[As]>\n : ExtractSlotProps<S[K]> extends React.ComponentType<infer P>\n ? P\n : never;\n};\n\n/**\n * Given the state and an array of slot names, will break out `slots` and `slotProps`\n * collections.\n *\n * The root is derived from a mix of `components` props and `as` prop.\n *\n * Slots will render as null if they are rendered as primitives with undefined children.\n *\n * The slotProps will always omit the `as` prop within them, and for slots that are string\n * primitives, the props will be filtered according to the slot type by the type system.\n * For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable\n * anchor props. Note that this is only enforced at build time by Typescript -- there is no\n * runtime code filtering props in this function.\n *\n * @param state - State including slot definitions\n * @returns An object containing the `slots` map and `slotProps` map.\n */\nexport function getSlots<R extends SlotPropsRecord>(\n state: ComponentState<R>,\n): {\n slots: Slots<R>;\n slotProps: ObjectSlotProps<R>;\n} {\n const slots = {} as Slots<R>;\n const slotProps = {} as R;\n\n const slotNames: (keyof R)[] = Object.keys(state.components);\n for (const slotName of slotNames) {\n const [slot, props] = getSlot(state, slotName);\n slots[slotName] = slot as Slots<R>[typeof slotName];\n slotProps[slotName] = props;\n }\n return { slots, slotProps: (slotProps as unknown) as ObjectSlotProps<R> };\n}\n\nfunction getSlot<R extends SlotPropsRecord, K extends keyof R>(\n state: ComponentState<R>,\n slotName: K,\n): readonly [React.ElementType<R[K]> | null, R[K]] {\n if (state[slotName] === undefined) {\n return [null, undefined as R[K]];\n }\n const { children, as: asProp, ...rest } = state[slotName]!;\n\n const slot = (state.components?.[slotName] === undefined || typeof state.components[slotName] === 'string'\n ? asProp || state.components?.[slotName] || 'div'\n : state.components[slotName]) as React.ElementType<R[K]>;\n\n if (typeof children === 'function') {\n const render = children as SlotRenderFunction<R[K]>;\n return [\n React.Fragment,\n ({\n children: render(slot, rest as Omit<R[K], 'children' | 'as'>),\n } as unknown) as R[K],\n ];\n }\n\n const shouldOmitAsProp = typeof slot === 'string' && state[slotName]?.as;\n const slotProps = (shouldOmitAsProp ? omit(state[slotName]!, ['as']) : state[slotName]) as R[K];\n\n return [slot, slotProps];\n}\n"],"sourceRoot":"../src/"}
|
package/lib/compose/index.js
CHANGED
package/lib/compose/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["compose/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC","sourcesContent":["export * from './getSlots';\nexport * from './resolveShorthand';\nexport * from './types';\n"]}
|