@fluentui/react-utilities 0.0.0-nightlyd3bf09bf8120211201.1 → 0.0.0-nightlye1926bfeca20220204.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/CHANGELOG.json +80 -6
  2. package/CHANGELOG.md +13 -6
  3. package/dist/react-utilities.d.ts +155 -84
  4. package/lib/compose/getSlots.d.ts +11 -10
  5. package/lib/compose/getSlots.js +6 -4
  6. package/lib/compose/getSlots.js.map +1 -1
  7. package/lib/compose/resolveShorthand.d.ts +5 -5
  8. package/lib/compose/resolveShorthand.js +3 -3
  9. package/lib/compose/types.d.ts +48 -26
  10. package/lib/compose/types.js.map +1 -1
  11. package/lib/hooks/index.d.ts +1 -1
  12. package/lib/hooks/index.js +1 -1
  13. package/lib/hooks/index.js.map +1 -1
  14. package/lib/hooks/useControllableState.d.ts +16 -6
  15. package/lib/hooks/useControllableState.js +13 -8
  16. package/lib/hooks/useControllableState.js.map +1 -1
  17. package/lib/hooks/useMergedEventCallbacks.d.ts +18 -0
  18. package/lib/hooks/useMergedEventCallbacks.js +26 -0
  19. package/lib/hooks/useMergedEventCallbacks.js.map +1 -0
  20. package/lib/hooks/useOnClickOutside.js.map +1 -1
  21. package/lib/utils/applyTriggerPropsToChildren.d.ts +1 -1
  22. package/lib/utils/applyTriggerPropsToChildren.js +19 -2
  23. package/lib/utils/applyTriggerPropsToChildren.js.map +1 -1
  24. package/lib/utils/getReactCallbackName.d.ts +25 -0
  25. package/lib/utils/getReactCallbackName.js +26 -0
  26. package/lib/utils/getReactCallbackName.js.map +1 -0
  27. package/lib/utils/getTriggerChild.d.ts +22 -0
  28. package/lib/utils/getTriggerChild.js +26 -0
  29. package/lib/utils/getTriggerChild.js.map +1 -0
  30. package/lib/utils/index.d.ts +2 -1
  31. package/lib/utils/index.js +2 -1
  32. package/lib/utils/index.js.map +1 -1
  33. package/lib/utils/isFluentTrigger.d.ts +22 -0
  34. package/lib/utils/isFluentTrigger.js +8 -0
  35. package/lib/utils/isFluentTrigger.js.map +1 -0
  36. package/lib/utils/properties.js +40 -20
  37. package/lib/utils/properties.js.map +1 -1
  38. package/lib-commonjs/compose/getSlots.d.ts +11 -10
  39. package/lib-commonjs/compose/getSlots.js +6 -4
  40. package/lib-commonjs/compose/getSlots.js.map +1 -1
  41. package/lib-commonjs/compose/resolveShorthand.d.ts +5 -5
  42. package/lib-commonjs/compose/resolveShorthand.js +3 -3
  43. package/lib-commonjs/compose/types.d.ts +48 -26
  44. package/lib-commonjs/compose/types.js.map +1 -1
  45. package/lib-commonjs/hooks/index.d.ts +1 -1
  46. package/lib-commonjs/hooks/index.js +2 -2
  47. package/lib-commonjs/hooks/index.js.map +1 -1
  48. package/lib-commonjs/hooks/useControllableState.d.ts +16 -6
  49. package/lib-commonjs/hooks/useControllableState.js +13 -8
  50. package/lib-commonjs/hooks/useControllableState.js.map +1 -1
  51. package/lib-commonjs/hooks/useMergedEventCallbacks.d.ts +18 -0
  52. package/lib-commonjs/hooks/useMergedEventCallbacks.js +36 -0
  53. package/lib-commonjs/hooks/useMergedEventCallbacks.js.map +1 -0
  54. package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
  55. package/lib-commonjs/utils/applyTriggerPropsToChildren.d.ts +1 -1
  56. package/lib-commonjs/utils/applyTriggerPropsToChildren.js +19 -2
  57. package/lib-commonjs/utils/applyTriggerPropsToChildren.js.map +1 -1
  58. package/lib-commonjs/utils/getReactCallbackName.d.ts +25 -0
  59. package/lib-commonjs/utils/getReactCallbackName.js +35 -0
  60. package/lib-commonjs/utils/getReactCallbackName.js.map +1 -0
  61. package/lib-commonjs/utils/getTriggerChild.d.ts +22 -0
  62. package/lib-commonjs/utils/getTriggerChild.js +37 -0
  63. package/lib-commonjs/utils/getTriggerChild.js.map +1 -0
  64. package/lib-commonjs/utils/index.d.ts +2 -1
  65. package/lib-commonjs/utils/index.js +4 -2
  66. package/lib-commonjs/utils/index.js.map +1 -1
  67. package/lib-commonjs/utils/isFluentTrigger.d.ts +22 -0
  68. package/lib-commonjs/utils/isFluentTrigger.js +17 -0
  69. package/lib-commonjs/utils/isFluentTrigger.js.map +1 -0
  70. package/lib-commonjs/utils/properties.js +40 -20
  71. package/lib-commonjs/utils/properties.js.map +1 -1
  72. package/package.json +3 -7
  73. package/lib/hooks/useControllableValue.d.ts +0 -20
  74. package/lib/hooks/useControllableValue.js +0 -57
  75. package/lib/hooks/useControllableValue.js.map +0 -1
  76. package/lib/utils/onlyChild.d.ts +0 -5
  77. package/lib/utils/onlyChild.js +0 -13
  78. package/lib/utils/onlyChild.js.map +0 -1
  79. package/lib-commonjs/hooks/useControllableValue.d.ts +0 -20
  80. package/lib-commonjs/hooks/useControllableValue.js +0 -68
  81. package/lib-commonjs/hooks/useControllableValue.js.map +0 -1
  82. package/lib-commonjs/utils/onlyChild.d.ts +0 -5
  83. package/lib-commonjs/utils/onlyChild.js +0 -23
  84. package/lib-commonjs/utils/onlyChild.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/onlyChild.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA;;AAEG;;AACH,OAAO,MAAM,SAAS,GACpB,KADuB,IAEE;AACzB,MAAI,eAAC,KAAK,CAAC,cAAN,CAAqB,KAArB,CAAL,EAAkC;AAChC,UAAM,IAAI,KAAJ,CAAU,4CAAV,CAAN;AACD;;AAED,SAAO,KAAK,CAAC,IAAN,KAAe,KAAK,CAAC,QAArB,GAAgC,SAAS,CAAC,KAAK,CAAC,KAAN,CAAY,QAAb,CAAzC,GAAkE,KAAzE;AACD,CARM","sourceRoot":""}
@@ -1,20 +0,0 @@
1
- import * as React from 'react';
2
- export declare type ChangeCallback<TElement extends HTMLElement, TValue, TEvent extends React.SyntheticEvent<TElement> | undefined> = (ev: TEvent, newValue: TValue | undefined) => void;
3
- /**
4
- * Default value can be a value or an initializer
5
- */
6
- declare type DefaultValue<TValue> = TValue | (() => TValue);
7
- /**
8
- * Hook to manage a value that could be either controlled or uncontrolled, such as a checked state or
9
- * text box string.
10
- * @param controlledValue - The controlled value passed in the props. This value will always be used if provided,
11
- * and the internal state will be updated to reflect it.
12
- * @param defaultUncontrolledValue - Initial value for the internal state in the uncontrolled case.
13
- * @returns An array of the current value and an updater callback. Like `React.useState`, the updater
14
- * callback always has the same identity, and it can take either a new value, or a function which
15
- * is passed the previous value and returns the new value.
16
- * @see https://reactjs.org/docs/uncontrolled-components.html
17
- */
18
- export declare function useControllableValue<TValue, TElement extends HTMLElement>(controlledValue: TValue, defaultUncontrolledValue: DefaultValue<TValue>): Readonly<[TValue, (update: React.SetStateAction<TValue>) => void]>;
19
- export declare function useControllableValue<TValue, TElement extends HTMLElement, TEvent extends React.SyntheticEvent<TElement> | undefined>(controlledValue: TValue, defaultUncontrolledValue: DefaultValue<TValue>, onChange: ChangeCallback<TElement, TValue, TEvent>): Readonly<[TValue, (update: React.SetStateAction<TValue>, ev?: React.FormEvent<TElement>) => void]>;
20
- export {};
@@ -1,68 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useControllableValue = void 0;
7
-
8
- const React = /*#__PURE__*/require("react");
9
-
10
- const useConst_1 = /*#__PURE__*/require("./useConst");
11
-
12
- function useControllableValue(controlledValue, defaultUncontrolledValue, onChange) {
13
- const [value, setValue] = React.useState(defaultUncontrolledValue);
14
- const isControlled = useIsControlled(controlledValue);
15
- const currentValue = isControlled ? controlledValue : value; // Duplicate the current value and onChange in refs so they're accessible from
16
- // setValueOrCallOnChange without creating a new callback every time
17
-
18
- const valueRef = React.useRef(currentValue);
19
- const onChangeRef = React.useRef(onChange);
20
- React.useEffect(() => {
21
- valueRef.current = currentValue;
22
- onChangeRef.current = onChange;
23
- }); // To match the behavior of the setter returned by React.useState, this callback's identity
24
- // should never change. This means it MUST NOT directly reference variables that can change.
25
-
26
- const setValueOrCallOnChange = useConst_1.useConst(() => (update, ev) => {
27
- // Assuming here that TValue is not a function, because a controllable value will typically
28
- // be something a user can enter as input
29
- const newValue = typeof update === 'function' ? update(valueRef.current) : update;
30
-
31
- if (onChangeRef.current) {
32
- onChangeRef.current(ev, newValue);
33
- }
34
-
35
- if (!isControlled) {
36
- setValue(newValue);
37
- }
38
- });
39
- return [currentValue, setValueOrCallOnChange];
40
- }
41
-
42
- exports.useControllableValue = useControllableValue;
43
- /**
44
- * Helper hook to handle previous comparison of controlled/uncontrolled
45
- * Prints an error when isControlled value switches between subsequent renders
46
- */
47
-
48
- const useIsControlled = controlledValue => {
49
- const isControlled = useConst_1.useConst(controlledValue !== undefined);
50
-
51
- if (process.env.NODE_ENV !== 'production') {
52
- // We don't want these warnings in production even though it is against native behaviour
53
- // eslint-disable-next-line react-hooks/rules-of-hooks
54
- React.useEffect(() => {
55
- if (isControlled !== (controlledValue !== undefined)) {
56
- const error = new Error();
57
- const controlWarning = isControlled ? 'a controlled value to be uncontrolled' : 'an uncontrolled value to be controlled';
58
- const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined'; // eslint-disable-next-line no-console
59
-
60
- console.error([// Default react error
61
- '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(' '));
62
- }
63
- }, [isControlled, controlledValue]);
64
- }
65
-
66
- return isControlled;
67
- };
68
- //# sourceMappingURL=useControllableValue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/hooks/useControllableValue.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,UAAA,gBAAA,OAAA,CAAA,YAAA,CAAA;;AAqCA,SAAgB,oBAAhB,CAKE,eALF,EAME,wBANF,EAOE,QAPF,EAOqD;AAEnD,QAAM,CAAC,KAAD,EAAQ,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AAe,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":""}
@@ -1,5 +0,0 @@
1
- import * as React from 'react';
2
- /**
3
- * Similar to React.Children.only, but drills into fragments rather than treating them as a single child
4
- */
5
- export declare const onlyChild: <P>(child: string | number | boolean | {} | React.ReactNodeArray | React.ReactPortal | React.ReactElement<P, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)> | null) | (new (props: any) => React.Component<any, any, any>)> | null | undefined) => React.ReactElement<P, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)> | null) | (new (props: any) => React.Component<any, any, any>)>;
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.onlyChild = void 0;
7
-
8
- const React = /*#__PURE__*/require("react");
9
- /**
10
- * Similar to React.Children.only, but drills into fragments rather than treating them as a single child
11
- */
12
-
13
-
14
- const onlyChild = child => {
15
- if (!React.isValidElement(child)) {
16
- throw new Error(`Component's child must be a single element`);
17
- }
18
-
19
- return child.type === React.Fragment ? exports.onlyChild(child.props.children) : child;
20
- };
21
-
22
- exports.onlyChild = onlyChild;
23
- //# sourceMappingURL=onlyChild.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/onlyChild.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAEA;;AAEG;;;AACI,MAAM,SAAS,GACpB,KADuB,IAEE;AACzB,MAAI,CAAC,KAAK,CAAC,cAAN,CAAqB,KAArB,CAAL,EAAkC;AAChC,UAAM,IAAI,KAAJ,CAAU,4CAAV,CAAN;AACD;;AAED,SAAO,KAAK,CAAC,IAAN,KAAe,KAAK,CAAC,QAArB,GAAgC,OAAA,CAAA,SAAA,CAAU,KAAK,CAAC,KAAN,CAAY,QAAtB,CAAhC,GAAkE,KAAzE;AACD,CARM;;AAAM,OAAA,CAAA,SAAA,GAAS,SAAT","sourceRoot":""}