@fluentui/react-utilities 0.0.0-nightlyd3bf09bf8120211201.1 → 0.0.0-nightlyd514b3e0ee20220121.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +56 -6
- package/CHANGELOG.md +9 -6
- package/dist/react-utilities.d.ts +43 -35
- package/lib/compose/getSlots.d.ts +5 -4
- package/lib/compose/getSlots.js +6 -4
- package/lib/compose/getSlots.js.map +1 -1
- package/lib/compose/types.d.ts +1 -1
- package/lib/hooks/index.d.ts +1 -1
- package/lib/hooks/index.js +1 -1
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useControllableState.d.ts +16 -6
- package/lib/hooks/useControllableState.js +13 -8
- package/lib/hooks/useControllableState.js.map +1 -1
- package/lib/hooks/useOnClickOutside.js.map +1 -1
- package/lib/hooks/useTriggerElement.d.ts +18 -0
- package/lib/hooks/useTriggerElement.js +90 -0
- package/lib/hooks/useTriggerElement.js.map +1 -0
- package/lib/utils/applyTriggerPropsToChildren.d.ts +1 -1
- package/lib/utils/getReactCallbackName.d.ts +25 -0
- package/lib/utils/getReactCallbackName.js +26 -0
- package/lib/utils/getReactCallbackName.js.map +1 -0
- package/lib/utils/onlyChild.d.ts +1 -1
- package/lib/utils/properties.js +40 -20
- package/lib/utils/properties.js.map +1 -1
- package/lib-commonjs/compose/getSlots.d.ts +5 -4
- package/lib-commonjs/compose/getSlots.js +6 -4
- package/lib-commonjs/compose/getSlots.js.map +1 -1
- package/lib-commonjs/compose/types.d.ts +1 -1
- package/lib-commonjs/hooks/index.d.ts +1 -1
- package/lib-commonjs/hooks/index.js +2 -2
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useControllableState.d.ts +16 -6
- package/lib-commonjs/hooks/useControllableState.js +13 -8
- package/lib-commonjs/hooks/useControllableState.js.map +1 -1
- package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
- package/lib-commonjs/hooks/useTriggerElement.d.ts +18 -0
- package/lib-commonjs/hooks/useTriggerElement.js +105 -0
- package/lib-commonjs/hooks/useTriggerElement.js.map +1 -0
- package/lib-commonjs/utils/applyTriggerPropsToChildren.d.ts +1 -1
- package/lib-commonjs/utils/getReactCallbackName.d.ts +25 -0
- package/lib-commonjs/utils/getReactCallbackName.js +35 -0
- package/lib-commonjs/utils/getReactCallbackName.js.map +1 -0
- package/lib-commonjs/utils/onlyChild.d.ts +1 -1
- package/lib-commonjs/utils/properties.js +40 -20
- package/lib-commonjs/utils/properties.js.map +1 -1
- package/package.json +3 -7
- package/lib/hooks/useControllableValue.d.ts +0 -20
- package/lib/hooks/useControllableValue.js +0 -57
- package/lib/hooks/useControllableValue.js.map +0 -1
- package/lib-commonjs/hooks/useControllableValue.d.ts +0 -20
- package/lib-commonjs/hooks/useControllableValue.js +0 -68
- package/lib-commonjs/hooks/useControllableValue.js.map +0 -1
package/CHANGELOG.json
CHANGED
@@ -2,22 +2,72 @@
|
|
2
2
|
"name": "@fluentui/react-utilities",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "
|
6
|
-
"tag": "@fluentui/react-utilities_v0.0.0-
|
7
|
-
"version": "0.0.0-
|
5
|
+
"date": "Fri, 21 Jan 2022 04:16:25 GMT",
|
6
|
+
"tag": "@fluentui/react-utilities_v0.0.0-nightlyd514b3e0ee20220121.1",
|
7
|
+
"version": "0.0.0-nightlyd514b3e0ee20220121.1",
|
8
8
|
"comments": {
|
9
9
|
"prerelease": [
|
10
10
|
{
|
11
11
|
"author": "email not defined",
|
12
12
|
"package": "@fluentui/react-utilities",
|
13
|
-
"commit": "
|
13
|
+
"commit": "89feafb688fbb160fb8519724479b3c68a79d090",
|
14
14
|
"comment": "Release nightly v9"
|
15
15
|
},
|
16
|
+
{
|
17
|
+
"author": "behowell@microsoft.com",
|
18
|
+
"package": "@fluentui/react-utilities",
|
19
|
+
"commit": "7cc28ed8320b00f42d91c63882f10316db2205c5",
|
20
|
+
"comment": "getSlots: remove slotNames param, and infer from state.components instead"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"author": "olfedias@microsoft.com",
|
24
|
+
"package": "@fluentui/react-utilities",
|
25
|
+
"commit": "d2eb57808a403b70845a732a62b55aa64d66b2a0",
|
26
|
+
"comment": "add useTriggerElement() hook"
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"author": "elcraig@microsoft.com",
|
30
|
+
"package": "@fluentui/react-utilities",
|
31
|
+
"commit": "39ce3cbcf15ce2619649e1eddccf932736ceac07",
|
32
|
+
"comment": "[breaking] Remove useControllableValue hook (use useControllableState instead)"
|
33
|
+
},
|
16
34
|
{
|
17
35
|
"author": "beachball",
|
18
36
|
"package": "@fluentui/react-utilities",
|
19
|
-
"comment": "Bump @fluentui/keyboard-keys to v0.0.0-
|
20
|
-
"commit": "
|
37
|
+
"comment": "Bump @fluentui/keyboard-keys to v0.0.0-nightlyd514b3e0ee20220121.1",
|
38
|
+
"commit": "89feafb688fbb160fb8519724479b3c68a79d090"
|
39
|
+
}
|
40
|
+
],
|
41
|
+
"none": [
|
42
|
+
{
|
43
|
+
"author": "elcraig@microsoft.com",
|
44
|
+
"package": "@fluentui/react-utilities",
|
45
|
+
"commit": "3360b45ec159250b1346c91afad7dce138e6bc20",
|
46
|
+
"comment": "Update API file to version generated by typescript 4.3"
|
47
|
+
},
|
48
|
+
{
|
49
|
+
"author": "olfedias@microsoft.com",
|
50
|
+
"package": "@fluentui/react-utilities",
|
51
|
+
"commit": "c061e98be4b4a718c72a144a1f60bb5515824612",
|
52
|
+
"comment": "remove inline-style-expand-shorthand from tsconfigs"
|
53
|
+
},
|
54
|
+
{
|
55
|
+
"author": "martinhochel@microsoft.com",
|
56
|
+
"package": "@fluentui/react-utilities",
|
57
|
+
"commit": "8dfa712156b70414205b87b5b6d099367b0c297d",
|
58
|
+
"comment": "chore: use storybook runner for all vNext packages"
|
59
|
+
},
|
60
|
+
{
|
61
|
+
"author": "seanmonahan@microsoft.com",
|
62
|
+
"package": "@fluentui/react-utilities",
|
63
|
+
"commit": "6404bef16cebf1f67b9b80a9f6d5f605f9873df1",
|
64
|
+
"comment": "Update getSlots() docs."
|
65
|
+
},
|
66
|
+
{
|
67
|
+
"author": "lingfangao@hotmail.com",
|
68
|
+
"package": "@fluentui/react-utilities",
|
69
|
+
"commit": "a4e048a0e03ddd676670da516e3a6612b26ea500",
|
70
|
+
"comment": "chore: Remove enzyme from react-utilities tests"
|
21
71
|
}
|
22
72
|
]
|
23
73
|
}
|
package/CHANGELOG.md
CHANGED
@@ -1,18 +1,21 @@
|
|
1
1
|
# Change Log - @fluentui/react-utilities
|
2
2
|
|
3
|
-
This log was last generated on
|
3
|
+
This log was last generated on Fri, 21 Jan 2022 04:16:25 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
-
## [0.0.0-
|
7
|
+
## [0.0.0-nightlyd514b3e0ee20220121.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v0.0.0-nightlyd514b3e0ee20220121.1)
|
8
8
|
|
9
|
-
|
10
|
-
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.0-beta.4..@fluentui/react-utilities_v0.0.0-
|
9
|
+
Fri, 21 Jan 2022 04:16:25 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.0-beta.4..@fluentui/react-utilities_v0.0.0-nightlyd514b3e0ee20220121.1)
|
11
11
|
|
12
12
|
### Changes
|
13
13
|
|
14
|
-
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/
|
15
|
-
-
|
14
|
+
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/89feafb688fbb160fb8519724479b3c68a79d090) by email not defined)
|
15
|
+
- getSlots: remove slotNames param, and infer from state.components instead ([PR #21134](https://github.com/microsoft/fluentui/pull/21134) by behowell@microsoft.com)
|
16
|
+
- add useTriggerElement() hook ([PR #21225](https://github.com/microsoft/fluentui/pull/21225) by olfedias@microsoft.com)
|
17
|
+
- [breaking] Remove useControllableValue hook (use useControllableState instead) ([PR #20865](https://github.com/microsoft/fluentui/pull/20865) by elcraig@microsoft.com)
|
18
|
+
- Bump @fluentui/keyboard-keys to v0.0.0-nightlyd514b3e0ee20220121.1 ([commit](https://github.com/microsoft/fluentui/commit/89feafb688fbb160fb8519724479b3c68a79d090) by beachball)
|
16
19
|
|
17
20
|
## [9.0.0-beta.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.0.0-beta.4)
|
18
21
|
|
@@ -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 |
|
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;
|
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
|
*
|
@@ -78,7 +76,7 @@ export declare type ComponentProps<Shorthands extends ObjectShorthandPropsRecord
|
|
78
76
|
}, Primary & 'root'> & PropsWithoutRef<Shorthands[Primary]>;
|
79
77
|
|
80
78
|
export declare type ComponentState<Shorthands extends ObjectShorthandPropsRecord> = {
|
81
|
-
components
|
79
|
+
components: {
|
82
80
|
[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
81
|
};
|
84
82
|
} & Shorthands;
|
@@ -100,11 +98,6 @@ export declare type DefaultObjectShorthandProps = ObjectShorthandProps<Pick<Reac
|
|
100
98
|
*/
|
101
99
|
export declare const defaultSSRContextValue: SSRContextValue;
|
102
100
|
|
103
|
-
/**
|
104
|
-
* Default value can be a value or an initializer
|
105
|
-
*/
|
106
|
-
declare type DefaultValue<TValue> = TValue | (() => TValue);
|
107
|
-
|
108
101
|
/**
|
109
102
|
* An array of DIV tag properties and events.
|
110
103
|
*
|
@@ -186,14 +179,15 @@ export declare const getRTLSafeKey: (key: string, dir: 'ltr' | 'rtl') => string;
|
|
186
179
|
* Slots will render as null if they are rendered as primitives with undefined children.
|
187
180
|
*
|
188
181
|
* The slotProps will always omit the `as` prop within them, and for slots that are string
|
189
|
-
* primitives, the props will be filtered according
|
190
|
-
* slot is rendered `as: 'a'`, the props will be filtered for acceptable
|
182
|
+
* primitives, the props will be filtered according to the slot type by the type system.
|
183
|
+
* For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable
|
184
|
+
* anchor props. Note that this is only enforced at build time by Typescript -- there is no
|
185
|
+
* runtime code filtering props in this function.
|
191
186
|
*
|
192
187
|
* @param state - State including slot definitions
|
193
|
-
* @param slotNames - Name of which props are slots
|
194
188
|
* @returns An object containing the `slots` map and `slotProps` map.
|
195
189
|
*/
|
196
|
-
export declare function getSlots<R extends ObjectShorthandPropsRecord>(state: ComponentState<R
|
190
|
+
export declare function getSlots<R extends ObjectShorthandPropsRecord>(state: ComponentState<R>): {
|
197
191
|
slots: Slots<R>;
|
198
192
|
slotProps: SlotProps<R>;
|
199
193
|
};
|
@@ -335,7 +329,7 @@ export declare function omit<TObj extends Record<string, any>, Exclusions extend
|
|
335
329
|
/**
|
336
330
|
* Similar to React.Children.only, but drills into fragments rather than treating them as a single child
|
337
331
|
*/
|
338
|
-
export declare const onlyChild: <P>(child:
|
332
|
+
export declare const onlyChild: <P>(child: boolean | React_2.ReactText | React_2.ReactFragment | React_2.ReactPortal | React_2.ReactElement<P, string | React_2.JSXElementConstructor<any>> | null | undefined) => React_2.ReactElement<P, string | React_2.JSXElementConstructor<any>>;
|
339
333
|
|
340
334
|
export declare const optionProperties: Record<string, number>;
|
341
335
|
|
@@ -493,42 +487,37 @@ export declare type UseBooleanCallbacks = {
|
|
493
487
|
export declare function useConst<T>(initialValue: T | (() => T)): T;
|
494
488
|
|
495
489
|
/**
|
496
|
-
* A useState
|
497
|
-
*
|
498
|
-
*
|
490
|
+
* A `useState`-like hook to manage a value that could be either controlled or uncontrolled,
|
491
|
+
* such as a checked state or text input string.
|
492
|
+
*
|
493
|
+
* Unlike `setState`, it's okay to call the returned updater (dispatch) function for either a
|
494
|
+
* controlled or uncontrolled component. Calls will only be respected if the component is uncontrolled.
|
495
|
+
*
|
496
|
+
* @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array
|
497
|
+
* of the current value and an updater (dispatch) function. The updater function is referentially
|
498
|
+
* stable (won't change during the component's lifecycle). It can take either a new value, or a
|
499
|
+
* function which is passed the previous value and returns the new value. Unlike `setState`, calls
|
500
|
+
* to the updater function will only be respected if the component is uncontrolled.
|
501
|
+
* @see https://reactjs.org/docs/uncontrolled-components.html
|
499
502
|
*/
|
500
503
|
export declare const useControllableState: <State>(options: UseControllableStateOptions<State>) => [State, React_2.Dispatch<React_2.SetStateAction<State>>];
|
501
504
|
|
502
505
|
export declare type UseControllableStateOptions<State> = {
|
503
506
|
/**
|
504
|
-
* User
|
507
|
+
* User-provided default state or initializer, for uncontrolled usage.
|
505
508
|
*/
|
506
509
|
defaultState?: State | (() => State);
|
507
510
|
/**
|
508
|
-
* User
|
511
|
+
* User-provided controlled state. `undefined` means internal state will be used.
|
509
512
|
*/
|
510
513
|
state: State | undefined;
|
511
514
|
/**
|
512
|
-
* Used
|
515
|
+
* Used as the initial state if `state` and `defaultState` are both `undefined`.
|
516
|
+
* If `undefined` is the correct initial state, pass that here.
|
513
517
|
*/
|
514
518
|
initialState: State;
|
515
519
|
};
|
516
520
|
|
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
521
|
/**
|
533
522
|
* https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
|
534
523
|
*
|
@@ -653,6 +642,25 @@ export declare function useSSRContext(): SSRContextValue;
|
|
653
642
|
*/
|
654
643
|
export declare function useTimeout(): readonly [(fn: () => void, delay: number) => void, () => void];
|
655
644
|
|
645
|
+
/**
|
646
|
+
* A hook that handles "trigger" pattern.
|
647
|
+
*
|
648
|
+
* Clones a passed element or calls render props. Merges props including refs and callbacks, callbacks are kept stable
|
649
|
+
* by reference.
|
650
|
+
*/
|
651
|
+
export declare function useTriggerElement<TriggerProps extends React_2.HTMLProps<unknown>>(options: UseTriggerElementOptions<TriggerProps>): React_2.ReactNode;
|
652
|
+
|
653
|
+
export declare type UseTriggerElementOptions<TriggerProps> = {
|
654
|
+
/** An actual trigger element or render props function. */
|
655
|
+
children: React_2.ReactElement | ((props: TriggerProps) => React_2.ReactNode) | null | undefined;
|
656
|
+
/** A ref to trigger element. */
|
657
|
+
ref: React_2.Ref<unknown> | undefined;
|
658
|
+
/** Props that are passed to a parent component and should be forwarded down. */
|
659
|
+
outerProps: React_2.HTMLProps<unknown>;
|
660
|
+
/** Custom props including callbacks. */
|
661
|
+
overrideProps: TriggerProps;
|
662
|
+
};
|
663
|
+
|
656
664
|
/**
|
657
665
|
* Hook which synchronously executes a callback when the component is about to unmount.
|
658
666
|
*
|
@@ -15,14 +15,15 @@ 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
|
19
|
-
* slot is rendered `as: 'a'`, the props will be filtered for acceptable
|
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
|
26
|
+
export declare function getSlots<R extends ObjectShorthandPropsRecord>(state: ComponentState<R>): {
|
26
27
|
slots: Slots<R>;
|
27
28
|
slotProps: SlotProps<R>;
|
28
29
|
};
|
package/lib/compose/getSlots.js
CHANGED
@@ -10,17 +10,19 @@ import { omit } from '../utils/omit';
|
|
10
10
|
* Slots will render as null if they are rendered as primitives with undefined children.
|
11
11
|
*
|
12
12
|
* The slotProps will always omit the `as` prop within them, and for slots that are string
|
13
|
-
* primitives, the props will be filtered according
|
14
|
-
* slot is rendered `as: 'a'`, the props will be filtered for acceptable
|
13
|
+
* primitives, the props will be filtered according to the slot type by the type system.
|
14
|
+
* For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable
|
15
|
+
* anchor props. Note that this is only enforced at build time by Typescript -- there is no
|
16
|
+
* runtime code filtering props in this function.
|
15
17
|
*
|
16
18
|
* @param state - State including slot definitions
|
17
|
-
* @param slotNames - Name of which props are slots
|
18
19
|
* @returns An object containing the `slots` map and `slotProps` map.
|
19
20
|
*/
|
20
21
|
|
21
|
-
export function getSlots(state
|
22
|
+
export function getSlots(state) {
|
22
23
|
const slots = {};
|
23
24
|
const slotProps = {};
|
25
|
+
const slotNames = Object.keys(state.components);
|
24
26
|
|
25
27
|
for (const slotName of slotNames) {
|
26
28
|
const [slot, props] = getSlot(state, slotName);
|
@@ -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
|
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;;;;;;;;;;;;;;;;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,C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;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":""}
|
package/lib/compose/types.d.ts
CHANGED
@@ -79,7 +79,7 @@ export declare type ComponentProps<Shorthands extends ObjectShorthandPropsRecord
|
|
79
79
|
[Key in keyof Shorthands]?: ShorthandProps<NonNullable<Shorthands[Key]>>;
|
80
80
|
}, Primary & 'root'> & PropsWithoutRef<Shorthands[Primary]>;
|
81
81
|
export declare type ComponentState<Shorthands extends ObjectShorthandPropsRecord> = {
|
82
|
-
components
|
82
|
+
components: {
|
83
83
|
[Key in keyof Shorthands]-?: React.ComponentType<NonNullable<Shorthands[Key]> extends ObjectShorthandProps<infer P> ? P : NonNullable<Shorthands[Key]>> | (NonNullable<Shorthands[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
|
84
84
|
};
|
85
85
|
} & Shorthands;
|
package/lib/hooks/index.d.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
export * from './useControllableState';
|
2
2
|
export * from './useBoolean';
|
3
3
|
export * from './useConst';
|
4
|
-
export * from './useControllableValue';
|
5
4
|
export * from './useEventCallback';
|
6
5
|
export * from './useFirstMount';
|
7
6
|
export * from './useId';
|
@@ -12,5 +11,6 @@ export * from './useOnClickOutside';
|
|
12
11
|
export * from './useOnScrollOutside';
|
13
12
|
export * from './usePrevious';
|
14
13
|
export * from './useTimeout';
|
14
|
+
export * from './useTriggerElement';
|
15
15
|
export * from './useUnmount';
|
16
16
|
export * from './useForceUpdate';
|
package/lib/hooks/index.js
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
export * from './useControllableState';
|
2
2
|
export * from './useBoolean';
|
3
3
|
export * from './useConst';
|
4
|
-
export * from './useControllableValue';
|
5
4
|
export * from './useEventCallback';
|
6
5
|
export * from './useFirstMount';
|
7
6
|
export * from './useId';
|
@@ -12,6 +11,7 @@ export * from './useOnClickOutside';
|
|
12
11
|
export * from './useOnScrollOutside';
|
13
12
|
export * from './usePrevious';
|
14
13
|
export * from './useTimeout';
|
14
|
+
export * from './useTriggerElement';
|
15
15
|
export * from './useUnmount';
|
16
16
|
export * from './useForceUpdate';
|
17
17
|
//# sourceMappingURL=index.js.map
|
package/lib/hooks/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC"}
|
@@ -1,21 +1,31 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
export declare type UseControllableStateOptions<State> = {
|
3
3
|
/**
|
4
|
-
* User
|
4
|
+
* User-provided default state or initializer, for uncontrolled usage.
|
5
5
|
*/
|
6
6
|
defaultState?: State | (() => State);
|
7
7
|
/**
|
8
|
-
* User
|
8
|
+
* User-provided controlled state. `undefined` means internal state will be used.
|
9
9
|
*/
|
10
10
|
state: State | undefined;
|
11
11
|
/**
|
12
|
-
* Used
|
12
|
+
* Used as the initial state if `state` and `defaultState` are both `undefined`.
|
13
|
+
* If `undefined` is the correct initial state, pass that here.
|
13
14
|
*/
|
14
15
|
initialState: State;
|
15
16
|
};
|
16
17
|
/**
|
17
|
-
* A useState
|
18
|
-
*
|
19
|
-
*
|
18
|
+
* A `useState`-like hook to manage a value that could be either controlled or uncontrolled,
|
19
|
+
* such as a checked state or text input string.
|
20
|
+
*
|
21
|
+
* Unlike `setState`, it's okay to call the returned updater (dispatch) function for either a
|
22
|
+
* controlled or uncontrolled component. Calls will only be respected if the component is uncontrolled.
|
23
|
+
*
|
24
|
+
* @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array
|
25
|
+
* of the current value and an updater (dispatch) function. The updater function is referentially
|
26
|
+
* stable (won't change during the component's lifecycle). It can take either a new value, or a
|
27
|
+
* function which is passed the previous value and returns the new value. Unlike `setState`, calls
|
28
|
+
* to the updater function will only be respected if the component is uncontrolled.
|
29
|
+
* @see https://reactjs.org/docs/uncontrolled-components.html
|
20
30
|
*/
|
21
31
|
export declare const useControllableState: <State>(options: UseControllableStateOptions<State>) => [State, React.Dispatch<React.SetStateAction<State>>];
|
@@ -1,23 +1,28 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { useConst } from './useConst';
|
3
3
|
|
4
|
-
function isUndefined(state) {
|
5
|
-
return typeof state === 'undefined';
|
6
|
-
}
|
7
|
-
|
8
4
|
function isFactoryDispatch(newState) {
|
9
5
|
return typeof newState === 'function';
|
10
6
|
}
|
11
7
|
/**
|
12
|
-
* A useState
|
13
|
-
*
|
14
|
-
*
|
8
|
+
* A `useState`-like hook to manage a value that could be either controlled or uncontrolled,
|
9
|
+
* such as a checked state or text input string.
|
10
|
+
*
|
11
|
+
* Unlike `setState`, it's okay to call the returned updater (dispatch) function for either a
|
12
|
+
* controlled or uncontrolled component. Calls will only be respected if the component is uncontrolled.
|
13
|
+
*
|
14
|
+
* @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array
|
15
|
+
* of the current value and an updater (dispatch) function. The updater function is referentially
|
16
|
+
* stable (won't change during the component's lifecycle). It can take either a new value, or a
|
17
|
+
* function which is passed the previous value and returns the new value. Unlike `setState`, calls
|
18
|
+
* to the updater function will only be respected if the component is uncontrolled.
|
19
|
+
* @see https://reactjs.org/docs/uncontrolled-components.html
|
15
20
|
*/
|
16
21
|
|
17
22
|
|
18
23
|
export const useControllableState = options => {
|
19
24
|
const isControlled = useIsControlled(options.state);
|
20
|
-
const initialState =
|
25
|
+
const initialState = typeof options.defaultState === 'undefined' ? options.initialState : options.defaultState;
|
21
26
|
const [internalState, setInternalState] = React.useState(initialState);
|
22
27
|
const state = isControlled ? options.state : internalState;
|
23
28
|
const stateRef = React.useRef(state);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useControllableState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,YAAzB;;
|
1
|
+
{"version":3,"sources":["../../src/hooks/useControllableState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,YAAzB;;AAkBA,SAAS,iBAAT,CAAkC,QAAlC,EAAuE;AACrE,SAAO,OAAO,QAAP,KAAoB,UAA3B;AACD;AAED;;;;;;;;;;;;;AAaG;;;AACH,OAAO,MAAM,oBAAoB,GAC/B,OADkC,IAEsB;AACxD,QAAM,YAAY,GAAG,eAAe,CAAC,OAAO,CAAC,KAAT,CAAp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Ac,KAAA,CAAd,GAAA,cAAc,CAAE,WAAhB,MAA2B,IAA3B,IAA2B,EAAA,KAAA,KAAA,CAA3B,GAA2B,KAAA,CAA3B,GAA2B,EAAA,CAAE,WAAF,CAAc,MAAK;AACjE,cAAM,aAAa,GAAG,cAAc,KAAA,IAAd,IAAA,cAAc,KAAA,KAAA,CAAd,GAAc,KAAA,CAAd,GAAA,cAAc,CAAE,aAAtC;;AACA,YAAI,CAAA,aAAa,KAAA,IAAb,IAAA,aAAa,KAAA,KAAA,CAAb,GAAa,KAAA,CAAb,GAAA,aAAa,CAAE,OAAf,MAA2B,QAA/B,EAAyC;AACvC,gBAAM,KAAK,GAAG,IAAI,WAAJ,CAAgB,eAAhB,EAAiC;AAAE,YAAA,OAAO,EAAE;AAAX,WAAjC,CAAd;AACA,UAAA,aAAa,CAAC,aAAd,CAA4B,KAA5B;AACD;AACF,OAN+C,EAM7C,YAN6C,CAAhD;AAOD;;AACD,WAAO,MAAK;;;AACV,OAAA,EAAA,GAAA,cAAc,KAAA,IAAd,IAAA,cAAc,KAAA,KAAA,CAAd,GAAc,KAAA,CAAd,GAAA,cAAc,CAAE,WAAhB,MAA2B,IAA3B,IAA2B,EAAA,KAAA,KAAA,CAA3B,GAA2B,KAAA,CAA3B,GAA2B,EAAA,CAAE,YAAF,CAAe,UAAU,CAAC,OAA1B,CAA3B;AACD,KAFD;AAGD,GAbD,EAaG,CAAC,cAAD,EAAiB,wBAAjB,EAA2C,YAA3C,CAbH;AAcD,CAvCD","sourceRoot":""}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
export declare type UseTriggerElementOptions<TriggerProps> = {
|
3
|
+
/** An actual trigger element or render props function. */
|
4
|
+
children: React.ReactElement | ((props: TriggerProps) => React.ReactNode) | null | undefined;
|
5
|
+
/** A ref to trigger element. */
|
6
|
+
ref: React.Ref<unknown> | undefined;
|
7
|
+
/** Props that are passed to a parent component and should be forwarded down. */
|
8
|
+
outerProps: React.HTMLProps<unknown>;
|
9
|
+
/** Custom props including callbacks. */
|
10
|
+
overrideProps: TriggerProps;
|
11
|
+
};
|
12
|
+
/**
|
13
|
+
* A hook that handles "trigger" pattern.
|
14
|
+
*
|
15
|
+
* Clones a passed element or calls render props. Merges props including refs and callbacks, callbacks are kept stable
|
16
|
+
* by reference.
|
17
|
+
*/
|
18
|
+
export declare function useTriggerElement<TriggerProps extends React.HTMLProps<unknown>>(options: UseTriggerElementOptions<TriggerProps>): React.ReactNode;
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { applyTriggerPropsToChildren } from '../utils/applyTriggerPropsToChildren';
|
3
|
+
import { getReactCallbackName } from '../utils/getReactCallbackName';
|
4
|
+
import { onlyChild } from '../utils/onlyChild';
|
5
|
+
import { useEventCallback } from './useEventCallback';
|
6
|
+
import { useMergedRefs } from './useMergedRefs';
|
7
|
+
const CAPTURE_CALLBACK_REGEX = /on[A-Z].+Capture$/;
|
8
|
+
const CALLBACK_REGEX = /on[A-Z].+/;
|
9
|
+
/**
|
10
|
+
* A hook that handles "trigger" pattern.
|
11
|
+
*
|
12
|
+
* Clones a passed element or calls render props. Merges props including refs and callbacks, callbacks are kept stable
|
13
|
+
* by reference.
|
14
|
+
*/
|
15
|
+
|
16
|
+
export function useTriggerElement(options) {
|
17
|
+
const {
|
18
|
+
children,
|
19
|
+
ref,
|
20
|
+
outerProps,
|
21
|
+
overrideProps
|
22
|
+
} = options;
|
23
|
+
let childProps = {};
|
24
|
+
let childRef = null; // child can be a render func, `applyTriggerPropsToChildren`does the same check again
|
25
|
+
// TODO figure out a way to only do this check once
|
26
|
+
|
27
|
+
if ( /*#__PURE__*/React.isValidElement(children)) {
|
28
|
+
const child = onlyChild(children);
|
29
|
+
childProps = child.props;
|
30
|
+
childRef = child.ref;
|
31
|
+
} // Two separate callbacks are needed to handle properly bubble and capture callbacks
|
32
|
+
// "getReactCallbackName()" could return proper callback name, but it's possible only with React 17
|
33
|
+
|
34
|
+
|
35
|
+
const handleBubbleEvent = useEventCallback(ev => {
|
36
|
+
var _a, _b, _c;
|
37
|
+
|
38
|
+
const callbackName = getReactCallbackName(ev);
|
39
|
+
|
40
|
+
if (callbackName) {
|
41
|
+
// Typecast is required as "ev" is "React.SyntheticEvent" while callbacks have stricter typings and accept
|
42
|
+
// "FocusEvent", "ClipboardEvent" and etc.
|
43
|
+
|
44
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
45
|
+
(_a = childProps[callbackName]) === null || _a === void 0 ? void 0 : _a.call(childProps, ev);
|
46
|
+
(_b = overrideProps[callbackName]) === null || _b === void 0 ? void 0 : _b.call(overrideProps, ev);
|
47
|
+
(_c = outerProps[callbackName]) === null || _c === void 0 ? void 0 : _c.call(outerProps, ev);
|
48
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
49
|
+
}
|
50
|
+
});
|
51
|
+
const handleCaptureEvent = useEventCallback(ev => {
|
52
|
+
var _a, _b, _c;
|
53
|
+
|
54
|
+
const callbackName = getReactCallbackName(ev) + 'Capture';
|
55
|
+
|
56
|
+
if (callbackName) {
|
57
|
+
// Typecast is required as "ev" is "React.SyntheticEvent" while callbacks have stricter typings and accept
|
58
|
+
// "FocusEvent", "ClipboardEvent" and etc.
|
59
|
+
|
60
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
61
|
+
(_a = childProps[callbackName]) === null || _a === void 0 ? void 0 : _a.call(childProps, ev);
|
62
|
+
(_b = overrideProps[callbackName]) === null || _b === void 0 ? void 0 : _b.call(overrideProps, ev);
|
63
|
+
(_c = outerProps[callbackName]) === null || _c === void 0 ? void 0 : _c.call(outerProps, ev);
|
64
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
65
|
+
}
|
66
|
+
});
|
67
|
+
const mergedPropEntries = Object.entries({ ...outerProps,
|
68
|
+
...overrideProps,
|
69
|
+
...childProps,
|
70
|
+
// Undocumented, but React supports ref cloning through props
|
71
|
+
ref: useMergedRefs(childRef, ref)
|
72
|
+
}); // TODO: fix me after https://github.com/microsoft/fluentui/issues/21229
|
73
|
+
// Causes TS error:
|
74
|
+
// "Property 'fromEntries' does not exist on type 'ObjectConstructor'"
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
76
|
+
|
77
|
+
const triggerProps = Object.fromEntries(mergedPropEntries.map(([propName, propValue]) => {
|
78
|
+
if (propName.match(CAPTURE_CALLBACK_REGEX)) {
|
79
|
+
return [propName, handleCaptureEvent];
|
80
|
+
}
|
81
|
+
|
82
|
+
if (propName.match(CALLBACK_REGEX)) {
|
83
|
+
return [propName, handleBubbleEvent];
|
84
|
+
}
|
85
|
+
|
86
|
+
return [propName, propValue];
|
87
|
+
}));
|
88
|
+
return applyTriggerPropsToChildren(children, triggerProps);
|
89
|
+
}
|
90
|
+
//# sourceMappingURL=useTriggerElement.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useTriggerElement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA,SAAS,2BAAT,QAA4C,sCAA5C;AACA,SAAS,oBAAT,QAAqC,+BAArC;AACA,SAAS,SAAT,QAA0B,oBAA1B;AACA,SAAS,gBAAT,QAAiC,oBAAjC;AACA,SAAS,aAAT,QAA8B,iBAA9B;AAiBA,MAAM,sBAAsB,GAAG,mBAA/B;AACA,MAAM,cAAc,GAAG,WAAvB;AAEA;;;;;AAKG;;AACH,OAAM,SAAU,iBAAV,CACJ,OADI,EAC2C;AAE/C,QAAM;AAAE,IAAA,QAAF;AAAY,IAAA,GAAZ;AAAiB,IAAA,UAAjB;AAA6B,IAAA;AAA7B,MAA+C,OAArD;AAEA,MAAI,UAAU,GAA6B,EAA3C;AACA,MAAI,QAAQ,GAAG,IAAf,CAL+C,CAO/C;AACA;;AACA,oBAAI,KAAK,CAAC,cAAN,CAAqB,QAArB,CAAJ,EAAoC;AAClC,UAAM,KAAK,GAAG,SAAS,CAAC,QAAD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B,EAAA,KAAA,KAAA,CAA3B,GAA2B,KAAA,CAA3B,GAA2B,EAAA,CAAA,IAAA,CAA3B,aAA2B,EAAG,EAAH,CAA3B;AACA,OAAA,EAAA,GAAA,UAAU,CAAC,YAAD,CAAV,MAAwB,IAAxB,IAAwB,EAAA,KAAA,KAAA,CAAxB,GAAwB,KAAA,CAAxB,GAAwB,EAAA,CAAA,IAAA,CAAxB,UAAwB,EAAG,EAAH,CAAxB;AACA;AACD;AACF,GAZ0C,CAA3C;AAcA,QAAM,iBAAiB,GAAG,MAAM,CAAC,OAAP,CAAe,EACvC,GAAG,UADoC;AAEvC,OAAG,aAFoC;AAGvC,OAAG,UAHoC;AAIvC;AACA,IAAA,GAAG,EAAE,aAAa,CAAC,QAAD,EAAW,GAAX;AALqB,GAAf,CAA1B,CA9C+C,CAsD/C;AACA;AACA;AACA;;AACA,QAAM,YAAY,GAAI,MAAc,CAAC,WAAf,CACpB,iBAAiB,CAAC,GAAlB,CAAsB,CAAC,CAAC,QAAD,EAAW,SAAX,CAAD,KAA0B;AAC9C,QAAI,QAAQ,CAAC,KAAT,CAAe,sBAAf,CAAJ,EAA4C;AAC1C,aAAO,CAAC,QAAD,EAAW,kBAAX,CAAP;AACD;;AAED,QAAI,QAAQ,CAAC,KAAT,CAAe,cAAf,CAAJ,EAAoC;AAClC,aAAO,CAAC,QAAD,EAAW,iBAAX,CAAP;AACD;;AAED,WAAO,CAAC,QAAD,EAAW,SAAX,CAAP;AACD,GAVD,CADoB,CAAtB;AAcA,SAAO,2BAA2B,CAAC,QAAD,EAAW,YAAX,CAAlC;AACD","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 |
|
5
|
+
export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: React.ReactElement<any, string | React.JSXElementConstructor<any>> | ((props: TTriggerProps) => React.ReactNode) | null | undefined, triggerProps: TTriggerProps) => React.ReactNode;
|