@fluentui/react-utilities 0.0.0-nightlya372ad979820211103.1 → 0.0.0-nightlyc49127232120220201.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 +120 -6
- package/CHANGELOG.md +30 -6
- package/dist/react-utilities.d.ts +134 -81
- package/lib/compose/getSlots.d.ts +11 -10
- package/lib/compose/getSlots.js +20 -28
- package/lib/compose/getSlots.js.map +1 -1
- package/lib/compose/nullRender.js +1 -3
- package/lib/compose/nullRender.js.map +1 -1
- package/lib/compose/resolveShorthand.d.ts +5 -5
- package/lib/compose/resolveShorthand.js +11 -10
- package/lib/compose/resolveShorthand.js.map +1 -1
- package/lib/compose/types.d.ts +48 -27
- package/lib/compose/types.js.map +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/useBoolean.js +10 -21
- package/lib/hooks/useBoolean.js.map +1 -1
- package/lib/hooks/useConst.js +1 -1
- package/lib/hooks/useConst.js.map +1 -1
- package/lib/hooks/useControllableState.d.ts +16 -6
- package/lib/hooks/useControllableState.js +26 -25
- 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 +2 -4
- 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/useMergedRefs.js +5 -13
- package/lib/hooks/useMergedRefs.js.map +1 -1
- package/lib/hooks/useMount.js +3 -3
- package/lib/hooks/useMount.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 -17
- package/lib/hooks/useTimeout.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/hooks/useUnmount.js +5 -7
- package/lib/hooks/useUnmount.js.map +1 -1
- package/lib/ssr/SSRContext.js +9 -15
- package/lib/ssr/SSRContext.js.map +1 -1
- package/lib/utils/applyTriggerPropsToChildren.d.ts +1 -1
- package/lib/utils/applyTriggerPropsToChildren.js +1 -1
- 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.d.ts +22 -0
- package/lib/utils/getNativeElementProps.js +24 -2
- 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.d.ts +25 -0
- package/lib/utils/getReactCallbackName.js +26 -0
- package/lib/utils/getReactCallbackName.js.map +1 -0
- package/lib/utils/omit.js +2 -2
- package/lib/utils/omit.js.map +1 -1
- package/lib/utils/onlyChild.d.ts +1 -1
- package/lib/utils/onlyChild.js +2 -2
- package/lib/utils/onlyChild.js.map +1 -1
- package/lib/utils/properties.js +55 -44
- package/lib/utils/properties.js.map +1 -1
- package/lib/utils/shouldPreventDefaultOnKeyDown.js +4 -4
- package/lib/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
- package/lib-commonjs/compose/getSlots.d.ts +11 -10
- package/lib-commonjs/compose/getSlots.js +23 -32
- package/lib-commonjs/compose/getSlots.js.map +1 -1
- package/lib-commonjs/compose/index.js +1 -1
- package/lib-commonjs/compose/nullRender.js +1 -3
- package/lib-commonjs/compose/nullRender.js.map +1 -1
- package/lib-commonjs/compose/resolveShorthand.d.ts +5 -5
- package/lib-commonjs/compose/resolveShorthand.js +12 -12
- package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
- package/lib-commonjs/compose/types.d.ts +48 -27
- package/lib-commonjs/compose/types.js.map +1 -1
- package/lib-commonjs/hooks/index.d.ts +1 -1
- package/lib-commonjs/hooks/index.js +3 -3
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useBoolean.js +12 -23
- package/lib-commonjs/hooks/useBoolean.js.map +1 -1
- package/lib-commonjs/hooks/useConst.js +2 -2
- package/lib-commonjs/hooks/useConst.js.map +1 -1
- package/lib-commonjs/hooks/useControllableState.d.ts +16 -6
- package/lib-commonjs/hooks/useControllableState.js +28 -27
- 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 +4 -6
- 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/useMergedRefs.js +6 -15
- package/lib-commonjs/hooks/useMergedRefs.js.map +1 -1
- package/lib-commonjs/hooks/useMount.js +4 -4
- package/lib-commonjs/hooks/useMount.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 +15 -19
- package/lib-commonjs/hooks/useTimeout.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/hooks/useUnmount.js +6 -8
- package/lib-commonjs/hooks/useUnmount.js.map +1 -1
- package/lib-commonjs/index.js +1 -1
- package/lib-commonjs/ssr/SSRContext.js +9 -15
- package/lib-commonjs/ssr/SSRContext.js.map +1 -1
- package/lib-commonjs/ssr/index.js +1 -1
- package/lib-commonjs/utils/applyTriggerPropsToChildren.d.ts +1 -1
- package/lib-commonjs/utils/applyTriggerPropsToChildren.js +3 -3
- 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.d.ts +22 -0
- package/lib-commonjs/utils/getNativeElementProps.js +28 -4
- 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.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/index.js +1 -1
- package/lib-commonjs/utils/omit.js +2 -2
- package/lib-commonjs/utils/omit.js.map +1 -1
- package/lib-commonjs/utils/onlyChild.d.ts +1 -1
- package/lib-commonjs/utils/onlyChild.js +3 -3
- package/lib-commonjs/utils/onlyChild.js.map +1 -1
- package/lib-commonjs/utils/properties.js +50 -39
- package/lib-commonjs/utils/properties.js.map +1 -1
- package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js +5 -5
- package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
- package/package.json +6 -11
- 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-commonjs/hooks/useControllableValue.d.ts +0 -20
- package/lib-commonjs/hooks/useControllableValue.js +0 -73
- package/lib-commonjs/hooks/useControllableValue.js.map +0 -1
@@ -5,13 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.getSlots = void 0;
|
7
7
|
|
8
|
-
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
9
|
|
10
|
-
|
10
|
+
const nullRender_1 = /*#__PURE__*/require("./nullRender");
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
var omit_1 = /*#__PURE__*/require("../utils/omit");
|
12
|
+
const omit_1 = /*#__PURE__*/require("../utils/omit");
|
15
13
|
/**
|
16
14
|
* Given the state and an array of slot names, will break out `slots` and `slotProps`
|
17
15
|
* collections.
|
@@ -21,36 +19,29 @@ var omit_1 = /*#__PURE__*/require("../utils/omit");
|
|
21
19
|
* Slots will render as null if they are rendered as primitives with undefined children.
|
22
20
|
*
|
23
21
|
* The slotProps will always omit the `as` prop within them, and for slots that are string
|
24
|
-
* primitives, the props will be filtered according
|
25
|
-
* slot is rendered `as: 'a'`, the props will be filtered for acceptable
|
22
|
+
* primitives, the props will be filtered according to the slot type by the type system.
|
23
|
+
* For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable
|
24
|
+
* anchor props. Note that this is only enforced at build time by Typescript -- there is no
|
25
|
+
* runtime code filtering props in this function.
|
26
26
|
*
|
27
27
|
* @param state - State including slot definitions
|
28
|
-
* @param slotNames - Name of which props are slots
|
29
28
|
* @returns An object containing the `slots` map and `slotProps` map.
|
30
29
|
*/
|
31
30
|
|
32
31
|
|
33
|
-
function getSlots(state
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
var slots = {};
|
39
|
-
var slotProps = {};
|
40
|
-
|
41
|
-
for (var _i = 0, slotNames_1 = slotNames; _i < slotNames_1.length; _i++) {
|
42
|
-
var slotName = slotNames_1[_i];
|
43
|
-
|
44
|
-
var _a = getSlot(state, slotName),
|
45
|
-
slot = _a[0],
|
46
|
-
props = _a[1];
|
32
|
+
function getSlots(state) {
|
33
|
+
const slots = {};
|
34
|
+
const slotProps = {};
|
35
|
+
const slotNames = Object.keys(state.components);
|
47
36
|
|
37
|
+
for (const slotName of slotNames) {
|
38
|
+
const [slot, props] = getSlot(state, slotName);
|
48
39
|
slots[slotName] = slot;
|
49
40
|
slotProps[slotName] = props;
|
50
41
|
}
|
51
42
|
|
52
43
|
return {
|
53
|
-
slots
|
44
|
+
slots,
|
54
45
|
slotProps: slotProps
|
55
46
|
};
|
56
47
|
}
|
@@ -64,22 +55,22 @@ function getSlot(state, slotName) {
|
|
64
55
|
return [nullRender_1.nullRender, undefined];
|
65
56
|
}
|
66
57
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
58
|
+
const {
|
59
|
+
children,
|
60
|
+
as: asProp,
|
61
|
+
...rest
|
62
|
+
} = state[slotName];
|
63
|
+
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];
|
73
64
|
|
74
65
|
if (typeof children === 'function') {
|
75
|
-
|
66
|
+
const render = children;
|
76
67
|
return [React.Fragment, {
|
77
68
|
children: render(slot, rest)
|
78
69
|
}];
|
79
70
|
}
|
80
71
|
|
81
|
-
|
82
|
-
|
72
|
+
const shouldOmitAsProp = typeof slot === 'string' && ((_c = state[slotName]) === null || _c === void 0 ? void 0 : _c.as);
|
73
|
+
const slotProps = shouldOmitAsProp ? omit_1.omit(state[slotName], ['as']) : state[slotName];
|
83
74
|
return [slot, slotProps];
|
84
75
|
}
|
85
76
|
//# sourceMappingURL=getSlots.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/compose/getSlots.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"sources":["../../src/compose/getSlots.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AAEA,MAAA,YAAA,gBAAA,OAAA,CAAA,cAAA,CAAA;;AACA,MAAA,MAAA,gBAAA,OAAA,CAAA,eAAA,CAAA;AA6BA;;;;;;;;;;;;;;;;AAgBG;;;AACH,SAAgB,QAAhB,CACE,KADF,EAC0B;AAKxB,QAAM,KAAK,GAAG,EAAd;AACA,QAAM,SAAS,GAAG,EAAlB;AAEA,QAAM,SAAS,GAAgB,MAAM,CAAC,IAAP,CAAY,KAAK,CAAC,UAAlB,CAA/B;;AACA,OAAK,MAAM,QAAX,IAAuB,SAAvB,EAAkC;AAChC,UAAM,CAAC,IAAD,EAAO,KAAP,IAAgB,OAAO,CAAC,KAAD,EAAQ,QAAR,CAA7B;AACA,IAAA,KAAK,CAAC,QAAD,CAAL,GAAkB,IAAlB;AACA,IAAA,SAAS,CAAC,QAAD,CAAT,GAAsB,KAAtB;AACD;;AACD,SAAO;AAAE,IAAA,KAAF;AAAS,IAAA,SAAS,EAAG;AAArB,GAAP;AACD;;AAhBD,OAAA,CAAA,QAAA,GAAA,QAAA;;AAkBA,SAAS,OAAT,CACE,KADF,EAEE,QAFF,EAEa;;;AAEX,MAAI,KAAK,CAAC,QAAD,CAAL,KAAoB,SAAxB,EAAmC;AACjC,WAAO,CAAC,YAAA,CAAA,UAAD,EAAa,SAAb,CAAP;AACD;;AACD,QAAM;AAAE,IAAA,QAAF;AAAY,IAAA,EAAE,EAAE,MAAhB;AAAwB,OAAG;AAA3B,MAAoC,KAAK,CAAC,QAAD,CAA/C;AAEA,QAAM,IAAI,GAAI,CAAA,CAAA,EAAA,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,MAAA,CAAA,IAAA,CAAK,KAAK,CAAC,QAAD,CAAV,EAAuB,CAAC,IAAD,CAAvB,CAAH,GAAoC,KAAK,CAAC,QAAD,CAA5E;AAEA,SAAO,CAAC,IAAD,EAAO,SAAP,CAAP;AACD","sourceRoot":""}
|
@@ -8,9 +8,7 @@ exports.nullRender = void 0;
|
|
8
8
|
* Simple constant function for returning null, used to render empty templates in JSX.
|
9
9
|
*/
|
10
10
|
|
11
|
-
|
12
|
-
return null;
|
13
|
-
};
|
11
|
+
const nullRender = () => null;
|
14
12
|
|
15
13
|
exports.nullRender = nullRender;
|
16
14
|
//# sourceMappingURL=nullRender.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/compose/nullRender.tsx"],"names":[],"mappings":";;;;;;AAAA;;AAEG;;AACI,
|
1
|
+
{"version":3,"sources":["../../src/compose/nullRender.tsx"],"names":[],"mappings":";;;;;;AAAA;;AAEG;;AACI,MAAM,UAAU,GAAG,MAAM,IAAzB;;AAAM,OAAA,CAAA,UAAA,GAAU,UAAV","sourceRoot":""}
|
@@ -1,12 +1,12 @@
|
|
1
|
-
import type {
|
1
|
+
import type { UnknownSlotProps, ShorthandProps } from './types';
|
2
2
|
export declare type ResolveShorthandOptions<Props extends Record<string, any>, Required extends boolean = false> = {
|
3
3
|
required?: Required;
|
4
4
|
defaultProps?: Props;
|
5
5
|
};
|
6
6
|
/**
|
7
|
-
* Resolves
|
7
|
+
* Resolves shorthands into slot props, to ensure normalization of the signature
|
8
8
|
* being passed down to getSlots method
|
9
|
-
* @param value - the base
|
10
|
-
* @param options - options to resolve
|
9
|
+
* @param value - the base shorthand props
|
10
|
+
* @param options - options to resolve shorthand props
|
11
11
|
*/
|
12
|
-
export declare function resolveShorthand<Props extends
|
12
|
+
export declare function resolveShorthand<Props extends UnknownSlotProps, Required extends boolean = false>(value: ShorthandProps<Props>, options?: ResolveShorthandOptions<Props, Required>): Required extends false ? Props | undefined : Props;
|
@@ -5,28 +5,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.resolveShorthand = void 0;
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
var react_1 = /*#__PURE__*/require("react");
|
8
|
+
const react_1 = /*#__PURE__*/require("react");
|
11
9
|
/**
|
12
|
-
* Resolves
|
10
|
+
* Resolves shorthands into slot props, to ensure normalization of the signature
|
13
11
|
* being passed down to getSlots method
|
14
|
-
* @param value - the base
|
15
|
-
* @param options - options to resolve
|
12
|
+
* @param value - the base shorthand props
|
13
|
+
* @param options - options to resolve shorthand props
|
16
14
|
*/
|
17
15
|
|
18
16
|
|
19
17
|
function resolveShorthand(value, options) {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
const {
|
19
|
+
required = false,
|
20
|
+
defaultProps
|
21
|
+
} = options || {};
|
24
22
|
|
25
23
|
if (value === null || value === undefined && !required) {
|
26
24
|
return undefined;
|
27
25
|
}
|
28
26
|
|
29
|
-
|
27
|
+
let resolvedShorthand = {};
|
30
28
|
|
31
29
|
if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || react_1.isValidElement(value)) {
|
32
30
|
resolvedShorthand.children = value;
|
@@ -34,7 +32,9 @@ function resolveShorthand(value, options) {
|
|
34
32
|
resolvedShorthand = value;
|
35
33
|
}
|
36
34
|
|
37
|
-
return defaultProps ?
|
35
|
+
return defaultProps ? { ...defaultProps,
|
36
|
+
...resolvedShorthand
|
37
|
+
} : resolvedShorthand;
|
38
38
|
}
|
39
39
|
|
40
40
|
exports.resolveShorthand = resolveShorthand;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/compose/resolveShorthand.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"sources":["../../src/compose/resolveShorthand.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,OAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AASA;;;;;AAKG;;;AACH,SAAgB,gBAAhB,CACE,KADF,EAEE,OAFF,EAEoD;AAElD,QAAM;AAAE,IAAA,QAAQ,GAAG,KAAb;AAAoB,IAAA;AAApB,MAAqC,OAAO,IAAI,EAAtD;;AACA,MAAI,KAAK,KAAK,IAAV,IAAmB,KAAK,KAAK,SAAV,IAAuB,CAAC,QAA/C,EAA0D;AACxD,WAAO,SAAP;AACD;;AAED,MAAI,iBAAiB,GAAG,EAAxB;;AAEA,MAAI,OAAO,KAAP,KAAiB,QAAjB,IAA6B,OAAO,KAAP,KAAiB,QAA9C,IAA0D,KAAK,CAAC,OAAN,CAAc,KAAd,CAA1D,IAAkF,OAAA,CAAA,cAAA,CAAe,KAAf,CAAtF,EAA6G;AAC3G,IAAA,iBAAiB,CAAC,QAAlB,GAA6B,KAA7B;AACD,GAFD,MAEO,IAAI,OAAO,KAAP,KAAiB,QAArB,EAA+B;AACpC,IAAA,iBAAiB,GAAG,KAApB;AACD;;AAED,SAAQ,YAAY,GAAG,EAAE,GAAG,YAAL;AAAmB,OAAG;AAAtB,GAAH,GAA+C,iBAAnE;AAGD;;AApBD,OAAA,CAAA,gBAAA,GAAA,gBAAA","sourceRoot":""}
|
@@ -1,46 +1,60 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
export declare type
|
3
|
-
export declare type
|
4
|
-
export declare type ShorthandProps<Props extends
|
2
|
+
export declare type SlotRenderFunction<Props> = (Component: React.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React.ReactNode;
|
3
|
+
export declare type SlotPropsRecord = Record<string, UnknownSlotProps | undefined>;
|
4
|
+
export declare type ShorthandProps<Props extends UnknownSlotProps> = React.ReactChild | React.ReactNodeArray | React.ReactPortal | number | null | undefined | Props;
|
5
5
|
/**
|
6
|
-
* Matches any
|
6
|
+
* Matches any slot props type.
|
7
7
|
*
|
8
|
-
* This should ONLY be used in type templates as in `extends
|
8
|
+
* This should ONLY be used in type templates as in `extends DefaultObjectSlotProps`;
|
9
9
|
* it shouldn't be used as the type of a slot.
|
10
10
|
*/
|
11
|
-
export declare type
|
12
|
-
children?: React.ReactNode;
|
11
|
+
export declare type UnknownSlotProps = SlotProps<Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
|
13
12
|
as?: keyof JSX.IntrinsicElements;
|
14
13
|
}>;
|
15
14
|
/**
|
16
|
-
*
|
17
|
-
*
|
18
|
-
* For intrinsic elements like 'div', use {@link IntrinsicShorthandProps} instead.
|
15
|
+
* Takes the props we want to support for a slot and adds the ability for `children` to be a render function that takes
|
16
|
+
* those props.
|
19
17
|
*/
|
20
|
-
export declare type
|
18
|
+
export declare type SlotProps<Props extends {
|
21
19
|
children?: React.ReactNode;
|
22
20
|
} = {}> = Props & {
|
23
|
-
children?: Props['children'] |
|
21
|
+
children?: Props['children'] | SlotRenderFunction<Props>;
|
24
22
|
};
|
23
|
+
/**
|
24
|
+
* Defines the slot props for a slot that supports a Component type.
|
25
|
+
*
|
26
|
+
* For intrinsic/native elements like 'div', use {@link IntrinsicSlotProps} instead.
|
27
|
+
*
|
28
|
+
* The generic param is the type of a control, i.e. a React component. For example:
|
29
|
+
*
|
30
|
+
* @example
|
31
|
+
* ```
|
32
|
+
* type Props = {...}
|
33
|
+
* const Button: React.FC<Props> = () => {...}
|
34
|
+
* // $ExpectType ...
|
35
|
+
* type SlotProps = ComponentSlotProps<typeof Button>
|
36
|
+
* ```
|
37
|
+
*/
|
38
|
+
export declare type ComponentSlotProps<Component extends React.ComponentType> = Component extends React.ComponentType<infer Props> ? SlotProps<Props> : never;
|
25
39
|
/**
|
26
40
|
* Define the slot arguments for a slot that supports one or more intrinsic element types, such as 'div'.
|
27
|
-
* For slots that support custom components, use {@link
|
41
|
+
* For slots that support custom components, use {@link ComponentSlotProps} instead.
|
28
42
|
*
|
29
43
|
* The first param is the slot's default type if no `as` prop is specified.
|
30
44
|
* The second param is an optional union of alternative types that can be specified for the `as` prop.
|
31
45
|
*
|
32
46
|
* ```
|
33
|
-
*
|
34
|
-
*
|
35
|
-
*
|
47
|
+
* IntrinsicSlotProps<'div'> // Slot is always div
|
48
|
+
* IntrinsicSlotProps<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
|
49
|
+
* IntrinsicSlotProps<'label', 'span' | 'div'>; // Defaults to label, but allows as="span" or as="div"
|
36
50
|
* ```
|
37
51
|
*/
|
38
|
-
export declare type
|
52
|
+
export declare type IntrinsicSlotProps<DefaultAs extends keyof JSX.IntrinsicElements, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<DefaultAs> extends false ? 'Error: first parameter to IntrinsicSlotProps must be a single element type, not a union of types' : ({
|
39
53
|
as?: DefaultAs;
|
40
|
-
} &
|
54
|
+
} & SlotProps<React.PropsWithRef<JSX.IntrinsicElements[DefaultAs]>>) | {
|
41
55
|
[As in AlternateAs]: {
|
42
56
|
as: As;
|
43
|
-
} &
|
57
|
+
} & SlotProps<React.PropsWithRef<JSX.IntrinsicElements[As]>>;
|
44
58
|
}[AlternateAs];
|
45
59
|
/**
|
46
60
|
* Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.
|
@@ -70,20 +84,27 @@ export declare type AsIntrinsicElement<As extends keyof JSX.IntrinsicElements> =
|
|
70
84
|
export declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;
|
71
85
|
/**
|
72
86
|
* Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
|
73
|
-
*
|
87
|
+
* IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
|
74
88
|
*
|
75
89
|
* The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional
|
76
90
|
* types, to prevent unions from being expanded.
|
77
91
|
*/
|
78
92
|
export declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
93
|
+
/**
|
94
|
+
* Defines the Props type for a component given its slots and the definition of which one is the primary slot,
|
95
|
+
* defaulting to root if one is not provided.
|
96
|
+
*/
|
97
|
+
export declare type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> = Omit<{
|
98
|
+
[Key in keyof Slots]?: ShorthandProps<NonNullable<Slots[Key]>>;
|
99
|
+
}, Primary & 'root'> & PropsWithoutRef<Slots[Primary]>;
|
100
|
+
/**
|
101
|
+
* Defines the State object of a component given its slots.
|
102
|
+
*/
|
103
|
+
export declare type ComponentState<Slots extends SlotPropsRecord> = {
|
104
|
+
components: {
|
105
|
+
[Key in keyof Slots]-?: React.ComponentType<NonNullable<Slots[Key]> extends SlotProps<infer P> ? P : NonNullable<Slots[Key]>> | (NonNullable<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
|
85
106
|
};
|
86
|
-
} &
|
107
|
+
} & Slots;
|
87
108
|
/**
|
88
109
|
* This is part of a hack to infer the element type from a native element *props* type.
|
89
110
|
* The only place the original element is found in a native props type (at least that's workable
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/compose/types.ts"],"names":[],"mappings":";;;;
|
1
|
+
{"version":3,"sources":["../../src/compose/types.ts"],"names":[],"mappings":";;;;IAyKA;AACA;AACA;AACA;AACA","sourceRoot":""}
|
@@ -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';
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
|
7
|
-
|
7
|
+
const tslib_1 = /*#__PURE__*/require("tslib");
|
8
8
|
|
9
9
|
tslib_1.__exportStar(require("./useControllableState"), exports);
|
10
10
|
|
@@ -12,8 +12,6 @@ tslib_1.__exportStar(require("./useBoolean"), exports);
|
|
12
12
|
|
13
13
|
tslib_1.__exportStar(require("./useConst"), exports);
|
14
14
|
|
15
|
-
tslib_1.__exportStar(require("./useControllableValue"), exports);
|
16
|
-
|
17
15
|
tslib_1.__exportStar(require("./useEventCallback"), exports);
|
18
16
|
|
19
17
|
tslib_1.__exportStar(require("./useFirstMount"), exports);
|
@@ -34,6 +32,8 @@ tslib_1.__exportStar(require("./usePrevious"), exports);
|
|
34
32
|
|
35
33
|
tslib_1.__exportStar(require("./useTimeout"), exports);
|
36
34
|
|
35
|
+
tslib_1.__exportStar(require("./useTriggerElement"), exports);
|
36
|
+
|
37
37
|
tslib_1.__exportStar(require("./useUnmount"), exports);
|
38
38
|
|
39
39
|
tslib_1.__exportStar(require("./useForceUpdate"), exports);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,wBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,YAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,
|
1
|
+
{"version":3,"sources":["../../src/hooks/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,wBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,YAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,oBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,SAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,6BAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,YAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,qBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,sBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,eAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,qBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,kBAAA,CAAA,EAAA,OAAA","sourceRoot":""}
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.useBoolean = void 0;
|
7
7
|
|
8
|
-
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
9
|
|
10
|
-
|
10
|
+
const useConst_1 = /*#__PURE__*/require("./useConst");
|
11
11
|
/**
|
12
12
|
* Hook to store a value and generate callbacks for setting the value to true or false.
|
13
13
|
* The identity of the callbacks will always stay the same.
|
@@ -18,31 +18,20 @@ var useConst_1 = /*#__PURE__*/require("./useConst");
|
|
18
18
|
|
19
19
|
|
20
20
|
function useBoolean(initialState) {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
var setTrue = useConst_1.useConst(function () {
|
26
|
-
return function () {
|
27
|
-
setValue(true);
|
28
|
-
};
|
21
|
+
const [value, setValue] = React.useState(initialState);
|
22
|
+
const setTrue = useConst_1.useConst(() => () => {
|
23
|
+
setValue(true);
|
29
24
|
});
|
30
|
-
|
31
|
-
|
32
|
-
setValue(false);
|
33
|
-
};
|
25
|
+
const setFalse = useConst_1.useConst(() => () => {
|
26
|
+
setValue(false);
|
34
27
|
});
|
35
|
-
|
36
|
-
|
37
|
-
setValue(function (currentValue) {
|
38
|
-
return !currentValue;
|
39
|
-
});
|
40
|
-
};
|
28
|
+
const toggle = useConst_1.useConst(() => () => {
|
29
|
+
setValue(currentValue => !currentValue);
|
41
30
|
});
|
42
31
|
return [value, {
|
43
|
-
setTrue
|
44
|
-
setFalse
|
45
|
-
toggle
|
32
|
+
setTrue,
|
33
|
+
setFalse,
|
34
|
+
toggle
|
46
35
|
}];
|
47
36
|
}
|
48
37
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useBoolean.ts"],"names":[],"mappings":";;;;;;;AAAA,
|
1
|
+
{"version":3,"sources":["../../src/hooks/useBoolean.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,UAAA,gBAAA,OAAA,CAAA,YAAA,CAAA;AAYA;;;;;;AAMG;;;AACH,SAAgB,UAAhB,CAA2B,YAA3B,EAAgD;AAC9C,QAAM,CAAC,KAAD,EAAQ,QAAR,IAAoB,KAAK,CAAC,QAAN,CAAe,YAAf,CAA1B;AAEA,QAAM,OAAO,GAAG,UAAA,CAAA,QAAA,CAAS,MAAM,MAAK;AAClC,IAAA,QAAQ,CAAC,IAAD,CAAR;AACD,GAFe,CAAhB;AAGA,QAAM,QAAQ,GAAG,UAAA,CAAA,QAAA,CAAS,MAAM,MAAK;AACnC,IAAA,QAAQ,CAAC,KAAD,CAAR;AACD,GAFgB,CAAjB;AAGA,QAAM,MAAM,GAAG,UAAA,CAAA,QAAA,CAAS,MAAM,MAAK;AACjC,IAAA,QAAQ,CAAC,YAAY,IAAI,CAAC,YAAlB,CAAR;AACD,GAFc,CAAf;AAIA,SAAO,CAAC,KAAD,EAAQ;AAAE,IAAA,OAAF;AAAW,IAAA,QAAX;AAAqB,IAAA;AAArB,GAAR,CAAP;AACD;;AAdD,OAAA,CAAA,UAAA,GAAA,UAAA","sourceRoot":""}
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.useConst = void 0;
|
7
7
|
|
8
|
-
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
9
|
/**
|
10
10
|
* Hook to initialize and return a constant value. Unlike `React.useMemo`, this is guaranteed to
|
11
11
|
* always return the same value (and if the initializer is a function, only call it once).
|
@@ -23,7 +23,7 @@ function useConst(initialValue) {
|
|
23
23
|
// Use useRef to store the value because it's the least expensive built-in hook that works here
|
24
24
|
// (we could also use `const [value] = React.useState(initialValue)` but that's more expensive
|
25
25
|
// internally due to reducer handling which we don't need)
|
26
|
-
|
26
|
+
const ref = React.useRef();
|
27
27
|
|
28
28
|
if (ref.current === undefined) {
|
29
29
|
// Box the value in an object so we can tell if it's initialized even if the initializer
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useConst.ts"],"names":[],"mappings":";;;;;;;AAAA,
|
1
|
+
{"version":3,"sources":["../../src/hooks/useConst.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAEA;;;;;;;;;;AAUG;;;AACH,SAAgB,QAAhB,CAA4B,YAA5B,EAAuD;AACrD;AACA;AACA;AACA,QAAM,GAAG,GAAG,KAAK,CAAC,MAAN,EAAZ;;AACA,MAAI,GAAG,CAAC,OAAJ,KAAgB,SAApB,EAA+B;AAC7B;AACA;AACA,IAAA,GAAG,CAAC,OAAJ,GAAc;AACZ,MAAA,KAAK,EAAE,OAAO,YAAP,KAAwB,UAAxB,GAAsC,YAAyB,EAA/D,GAAoE;AAD/D,KAAd;AAGD;;AACD,SAAO,GAAG,CAAC,OAAJ,CAAY,KAAnB;AACD;;AAbD,OAAA,CAAA,QAAA,GAAA,QAAA","sourceRoot":""}
|
@@ -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>>];
|
@@ -5,40 +5,41 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.useControllableState = void 0;
|
7
7
|
|
8
|
-
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
function isUndefined(state) {
|
13
|
-
return typeof state === 'undefined';
|
14
|
-
}
|
10
|
+
const useConst_1 = /*#__PURE__*/require("./useConst");
|
15
11
|
|
16
12
|
function isFactoryDispatch(newState) {
|
17
13
|
return typeof newState === 'function';
|
18
14
|
}
|
19
15
|
/**
|
20
|
-
* A useState
|
21
|
-
*
|
22
|
-
*
|
16
|
+
* A `useState`-like hook to manage a value that could be either controlled or uncontrolled,
|
17
|
+
* such as a checked state or text input string.
|
18
|
+
*
|
19
|
+
* Unlike `setState`, it's okay to call the returned updater (dispatch) function for either a
|
20
|
+
* controlled or uncontrolled component. Calls will only be respected if the component is uncontrolled.
|
21
|
+
*
|
22
|
+
* @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array
|
23
|
+
* of the current value and an updater (dispatch) function. The updater function is referentially
|
24
|
+
* stable (won't change during the component's lifecycle). It can take either a new value, or a
|
25
|
+
* function which is passed the previous value and returns the new value. Unlike `setState`, calls
|
26
|
+
* to the updater function will only be respected if the component is uncontrolled.
|
27
|
+
* @see https://reactjs.org/docs/uncontrolled-components.html
|
23
28
|
*/
|
24
29
|
|
25
30
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
var state = isControlled ? options.state : internalState;
|
35
|
-
var stateRef = React.useRef(state);
|
36
|
-
React.useEffect(function () {
|
31
|
+
const useControllableState = options => {
|
32
|
+
const isControlled = useIsControlled(options.state);
|
33
|
+
const initialState = typeof options.defaultState === 'undefined' ? options.initialState : options.defaultState;
|
34
|
+
const [internalState, setInternalState] = React.useState(initialState);
|
35
|
+
const state = isControlled ? options.state : internalState;
|
36
|
+
const stateRef = React.useRef(state);
|
37
|
+
React.useEffect(() => {
|
37
38
|
stateRef.current = state;
|
38
39
|
}, [state]); // To match the behavior of the setter returned by React.useState, this callback's identity
|
39
40
|
// should never change. This means it MUST NOT directly reference variables that can change.
|
40
41
|
|
41
|
-
|
42
|
+
const setState = React.useCallback(newState => {
|
42
43
|
// React dispatch can use a factory
|
43
44
|
// https://reactjs.org/docs/hooks-reference.html#functional-updates
|
44
45
|
if (isFactoryDispatch(newState)) {
|
@@ -59,17 +60,17 @@ exports.useControllableState = useControllableState;
|
|
59
60
|
* @returns - whether the value is controlled
|
60
61
|
*/
|
61
62
|
|
62
|
-
|
63
|
-
|
63
|
+
const useIsControlled = controlledValue => {
|
64
|
+
const isControlled = useConst_1.useConst(controlledValue !== undefined);
|
64
65
|
|
65
66
|
if (process.env.NODE_ENV !== 'production') {
|
66
67
|
// We don't want these warnings in production even though it is against native behaviour
|
67
68
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
68
|
-
React.useEffect(
|
69
|
+
React.useEffect(() => {
|
69
70
|
if (isControlled !== (controlledValue !== undefined)) {
|
70
|
-
|
71
|
-
|
72
|
-
|
71
|
+
const error = new Error();
|
72
|
+
const controlWarning = isControlled ? 'a controlled value to be uncontrolled' : 'an uncontrolled value to be controlled';
|
73
|
+
const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined'; // eslint-disable-next-line no-console
|
73
74
|
|
74
75
|
console.error([// Default react error
|
75
76
|
'A component is changing ' + controlWarning + '. This is likely caused by the value', 'changing from ' + undefinedWarning + ' value, which should not happen.', 'Decide between using a controlled or uncontrolled input element for the lifetime of the component.', 'More info: https://reactjs.org/link/controlled-components', error.stack].join(' '));
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useControllableState.ts"],"names":[],"mappings":";;;;;;;AAAA,
|
1
|
+
{"version":3,"sources":["../../src/hooks/useControllableState.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,UAAA,gBAAA,OAAA,CAAA,YAAA,CAAA;;AAkBA,SAAS,iBAAT,CAAkC,QAAlC,EAAuE;AACrE,SAAO,OAAO,QAAP,KAAoB,UAA3B;AACD;AAED;;;;;;;;;;;;;AAaG;;;AACI,MAAM,oBAAoB,GAC/B,OADkC,IAEsB;AACxD,QAAM,YAAY,GAAG,eAAe,CAAC,OAAO,CAAC,KAAT,CAApC;AACA,QAAM,YAAY,GAAG,OAAO,OAAO,CAAC,YAAf,KAAgC,WAAhC,GAA8C,OAAO,CAAC,YAAtD,GAAqE,OAAO,CAAC,YAAlG;AACA,QAAM,CAAC,aAAD,EAAgB,gBAAhB,IAAoC,KAAK,CAAC,QAAN,CAAsB,YAAtB,CAA1C;AAEA,QAAM,KAAK,GAAG,YAAY,GAAI,OAAO,CAAC,KAAZ,GAA8B,aAAxD;AAEA,QAAM,QAAQ,GAAG,KAAK,CAAC,MAAN,CAAa,KAAb,CAAjB;AACA,EAAA,KAAK,CAAC,SAAN,CAAgB,MAAK;AACnB,IAAA,QAAQ,CAAC,OAAT,GAAmB,KAAnB;AACD,GAFD,EAEG,CAAC,KAAD,CAFH,EARwD,CAYxD;AACA;;AACA,QAAM,QAAQ,GAAG,KAAK,CAAC,WAAN,CAAmB,QAAD,IAA0C;AAC3E;AACA;AACA,QAAI,iBAAiB,CAAC,QAAD,CAArB,EAAiC;AAC/B,MAAA,QAAQ,CAAC,OAAT,GAAmB,QAAQ,CAAC,QAAQ,CAAC,OAAV,CAA3B;AACD,KAFD,MAEO;AACL,MAAA,QAAQ,CAAC,OAAT,GAAmB,QAAnB;AACD;;AAED,IAAA,gBAAgB,CAAC,QAAQ,CAAC,OAAV,CAAhB;AACD,GAVgB,EAUd,EAVc,CAAjB;AAYA,SAAO,CAAC,KAAD,EAAQ,QAAR,CAAP;AACD,CA7BM;;AAAM,OAAA,CAAA,oBAAA,GAAoB,oBAApB;AA+Bb;;;;AAIG;;AACH,MAAM,eAAe,GAAI,eAAD,IAA6B;AACnD,QAAM,YAAY,GAAG,UAAA,CAAA,QAAA,CAAkB,eAAe,KAAK,SAAtC,CAArB;;AAEA,MAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;AACA;AACA,IAAA,KAAK,CAAC,SAAN,CAAgB,MAAK;AACnB,UAAI,YAAY,MAAM,eAAe,KAAK,SAA1B,CAAhB,EAAsD;AACpD,cAAM,KAAK,GAAG,IAAI,KAAJ,EAAd;AAEA,cAAM,cAAc,GAAG,YAAY,GAC/B,uCAD+B,GAE/B,wCAFJ;AAIA,cAAM,gBAAgB,GAAG,YAAY,GAAG,yBAAH,GAA+B,wBAApE,CAPoD,CASpD;;AACA,QAAA,OAAO,CAAC,KAAR,CACE,CACE;AACA,qCAA6B,cAA7B,GAA8C,sCAFhD,EAGE,mBAAmB,gBAAnB,GAAsC,kCAHxC,EAIE,oGAJF,EAKE,2DALF,EAME,KAAK,CAAC,KANR,EAOE,IAPF,CAOO,GAPP,CADF;AAUD;AACF,KAtBD,EAsBG,CAAC,YAAD,EAAe,eAAf,CAtBH;AAuBD;;AAED,SAAO,YAAP;AACD,CAhCD","sourceRoot":""}
|