@fluentui/react-utilities 0.0.0-nightly01492e29df20211105.1 → 0.0.0-nightly39ce3cbcf120211206.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 (32) hide show
  1. package/CHANGELOG.json +55 -9
  2. package/CHANGELOG.md +24 -6
  3. package/dist/react-utilities.d.ts +41 -31
  4. package/lib/compose/types.d.ts +2 -3
  5. package/lib/compose/types.js.map +1 -1
  6. package/lib/hooks/index.d.ts +0 -1
  7. package/lib/hooks/index.js +0 -1
  8. package/lib/hooks/index.js.map +1 -1
  9. package/lib/hooks/useControllableState.d.ts +16 -6
  10. package/lib/hooks/useControllableState.js +13 -8
  11. package/lib/hooks/useControllableState.js.map +1 -1
  12. package/lib/utils/getNativeElementProps.d.ts +22 -0
  13. package/lib/utils/getNativeElementProps.js +22 -0
  14. package/lib/utils/getNativeElementProps.js.map +1 -1
  15. package/lib-commonjs/compose/types.d.ts +2 -3
  16. package/lib-commonjs/compose/types.js.map +1 -1
  17. package/lib-commonjs/hooks/index.d.ts +0 -1
  18. package/lib-commonjs/hooks/index.js +0 -2
  19. package/lib-commonjs/hooks/index.js.map +1 -1
  20. package/lib-commonjs/hooks/useControllableState.d.ts +16 -6
  21. package/lib-commonjs/hooks/useControllableState.js +13 -8
  22. package/lib-commonjs/hooks/useControllableState.js.map +1 -1
  23. package/lib-commonjs/utils/getNativeElementProps.d.ts +22 -0
  24. package/lib-commonjs/utils/getNativeElementProps.js +25 -1
  25. package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
  26. package/package.json +5 -6
  27. package/lib/hooks/useControllableValue.d.ts +0 -20
  28. package/lib/hooks/useControllableValue.js +0 -57
  29. package/lib/hooks/useControllableValue.js.map +0 -1
  30. package/lib-commonjs/hooks/useControllableValue.d.ts +0 -20
  31. package/lib-commonjs/hooks/useControllableValue.js +0 -68
  32. package/lib-commonjs/hooks/useControllableValue.js.map +0 -1
package/CHANGELOG.json CHANGED
@@ -2,28 +2,74 @@
2
2
  "name": "@fluentui/react-utilities",
3
3
  "entries": [
4
4
  {
5
- "date": "Fri, 05 Nov 2021 04:16:06 GMT",
6
- "tag": "@fluentui/react-utilities_v0.0.0-nightly01492e29df20211105.1",
7
- "version": "0.0.0-nightly01492e29df20211105.1",
5
+ "date": "Mon, 06 Dec 2021 04:16:56 GMT",
6
+ "tag": "@fluentui/react-utilities_v0.0.0-nightly39ce3cbcf120211206.1",
7
+ "version": "0.0.0-nightly39ce3cbcf120211206.1",
8
8
  "comments": {
9
9
  "prerelease": [
10
10
  {
11
11
  "author": "email not defined",
12
12
  "package": "@fluentui/react-utilities",
13
- "commit": "d254c37e35cfc6231bcc255cbf3c541a8222706d",
13
+ "commit": "f5d813357240886d3e3a5215ab8304bf1034298f",
14
14
  "comment": "Release nightly v9"
15
15
  },
16
16
  {
17
- "author": "gcox@microsoft.com",
17
+ "author": "elcraig@microsoft.com",
18
18
  "package": "@fluentui/react-utilities",
19
- "commit": "c9bd5b5a02ae94a8239ce1b56cac2f0d0dbd3586",
20
- "comment": "Updated beta and RC components to ES2019"
19
+ "commit": "39ce3cbcf15ce2619649e1eddccf932736ceac07",
20
+ "comment": "[breaking] Remove useControllableValue hook (use useControllableState instead)"
21
21
  },
22
22
  {
23
23
  "author": "beachball",
24
24
  "package": "@fluentui/react-utilities",
25
- "comment": "Bump @fluentui/keyboard-keys to v0.0.0-nightly01492e29df20211105.1",
26
- "commit": "d254c37e35cfc6231bcc255cbf3c541a8222706d"
25
+ "comment": "Bump @fluentui/keyboard-keys to v0.0.0-nightly39ce3cbcf120211206.1",
26
+ "commit": "f5d813357240886d3e3a5215ab8304bf1034298f"
27
+ }
28
+ ]
29
+ }
30
+ },
31
+ {
32
+ "date": "Thu, 25 Nov 2021 08:34:09 GMT",
33
+ "tag": "@fluentui/react-utilities_v9.0.0-beta.4",
34
+ "version": "9.0.0-beta.4",
35
+ "comments": {
36
+ "none": [
37
+ {
38
+ "author": "lingfangao@hotmail.com",
39
+ "package": "@fluentui/react-utilities",
40
+ "commit": "718e63006d8d07d24efab9c32942041963d78dc7",
41
+ "comment": "Migrate package to use solution style ts-configs"
42
+ }
43
+ ],
44
+ "prerelease": [
45
+ {
46
+ "author": "behowell@microsoft.com",
47
+ "package": "@fluentui/react-utilities",
48
+ "commit": "99adff5a9aab9086e8bc4737040654ab23f0febe",
49
+ "comment": "Update utility types to support specifying a primary slot other than root"
50
+ }
51
+ ]
52
+ }
53
+ },
54
+ {
55
+ "date": "Fri, 12 Nov 2021 13:25:10 GMT",
56
+ "tag": "@fluentui/react-utilities_v9.0.0-beta.3",
57
+ "version": "9.0.0-beta.3",
58
+ "comments": {
59
+ "none": [
60
+ {
61
+ "author": "lingfangao@hotmail.com",
62
+ "package": "@fluentui/react-utilities",
63
+ "commit": "00f70581480b536e723fb69edf0ae617beac4807",
64
+ "comment": "Remove beta release tag"
65
+ }
66
+ ],
67
+ "prerelease": [
68
+ {
69
+ "author": "gcox@microsoft.com",
70
+ "package": "@fluentui/react-utilities",
71
+ "commit": "c9bd5b5a02ae94a8239ce1b56cac2f0d0dbd3586",
72
+ "comment": "Updated beta and RC components to ES2019"
27
73
  }
28
74
  ]
29
75
  }
package/CHANGELOG.md CHANGED
@@ -1,19 +1,37 @@
1
1
  # Change Log - @fluentui/react-utilities
2
2
 
3
- This log was last generated on Fri, 05 Nov 2021 04:16:06 GMT and should not be manually modified.
3
+ This log was last generated on Mon, 06 Dec 2021 04:16:56 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## [0.0.0-nightly01492e29df20211105.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v0.0.0-nightly01492e29df20211105.1)
7
+ ## [0.0.0-nightly39ce3cbcf120211206.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v0.0.0-nightly39ce3cbcf120211206.1)
8
8
 
9
- Fri, 05 Nov 2021 04:16:06 GMT
10
- [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.0-beta.2..@fluentui/react-utilities_v0.0.0-nightly01492e29df20211105.1)
9
+ Mon, 06 Dec 2021 04:16:56 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.0-beta.4..@fluentui/react-utilities_v0.0.0-nightly39ce3cbcf120211206.1)
11
+
12
+ ### Changes
13
+
14
+ - Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/f5d813357240886d3e3a5215ab8304bf1034298f) by email not defined)
15
+ - [breaking] Remove useControllableValue hook (use useControllableState instead) ([PR #20865](https://github.com/microsoft/fluentui/pull/20865) by elcraig@microsoft.com)
16
+ - Bump @fluentui/keyboard-keys to v0.0.0-nightly39ce3cbcf120211206.1 ([commit](https://github.com/microsoft/fluentui/commit/f5d813357240886d3e3a5215ab8304bf1034298f) by beachball)
17
+
18
+ ## [9.0.0-beta.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.0.0-beta.4)
19
+
20
+ Thu, 25 Nov 2021 08:34:09 GMT
21
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.0-beta.3..@fluentui/react-utilities_v9.0.0-beta.4)
22
+
23
+ ### Changes
24
+
25
+ - Update utility types to support specifying a primary slot other than root ([PR #20617](https://github.com/microsoft/fluentui/pull/20617) by behowell@microsoft.com)
26
+
27
+ ## [9.0.0-beta.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.0.0-beta.3)
28
+
29
+ Fri, 12 Nov 2021 13:25:10 GMT
30
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.0-beta.2..@fluentui/react-utilities_v9.0.0-beta.3)
11
31
 
12
32
  ### Changes
13
33
 
14
- - Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/d254c37e35cfc6231bcc255cbf3c541a8222706d) by email not defined)
15
34
  - Updated beta and RC components to ES2019 ([PR #20405](https://github.com/microsoft/fluentui/pull/20405) by gcox@microsoft.com)
16
- - Bump @fluentui/keyboard-keys to v0.0.0-nightly01492e29df20211105.1 ([commit](https://github.com/microsoft/fluentui/commit/d254c37e35cfc6231bcc255cbf3c541a8222706d) by beachball)
17
35
 
18
36
  ## [9.0.0-beta.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.0.0-beta.2)
19
37
 
@@ -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
  *
@@ -75,7 +73,7 @@ export declare const colProperties: Record<string, number>;
75
73
 
76
74
  export declare type ComponentProps<Shorthands extends ObjectShorthandPropsRecord, Primary extends keyof Shorthands = 'root'> = Omit<{
77
75
  [Key in keyof Shorthands]?: ShorthandProps<NonNullable<Shorthands[Key]>>;
78
- }, Primary> & PropsWithoutRef<Shorthands[Primary]>;
76
+ }, Primary & 'root'> & PropsWithoutRef<Shorthands[Primary]>;
79
77
 
80
78
  export declare type ComponentState<Shorthands extends ObjectShorthandPropsRecord> = {
81
79
  components?: {
@@ -89,8 +87,7 @@ export declare type ComponentState<Shorthands extends ObjectShorthandPropsRecord
89
87
  * This should ONLY be used in type templates as in `extends DefaultObjectShorthandProps`;
90
88
  * it shouldn't be used as the type of a slot.
91
89
  */
92
- export declare type DefaultObjectShorthandProps = ObjectShorthandProps<{
93
- children?: React_2.ReactNode;
90
+ export declare type DefaultObjectShorthandProps = ObjectShorthandProps<Pick<React_2.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
94
91
  as?: keyof JSX.IntrinsicElements;
95
92
  }>;
96
93
 
@@ -101,11 +98,6 @@ export declare type DefaultObjectShorthandProps = ObjectShorthandProps<{
101
98
  */
102
99
  export declare const defaultSSRContextValue: SSRContextValue;
103
100
 
104
- /**
105
- * Default value can be a value or an initializer
106
- */
107
- declare type DefaultValue<TValue> = TValue | (() => TValue);
108
-
109
101
  /**
110
102
  * An array of DIV tag properties and events.
111
103
  *
@@ -150,6 +142,29 @@ export declare function getNativeElementProps<TAttributes extends React_2.HTMLAt
150
142
  */
151
143
  export declare function getNativeProps<T extends Record<string, any>>(props: Record<string, any>, allowedPropNames: string[] | Record<string, number>, excludedPropNames?: string[]): T;
152
144
 
145
+ /**
146
+ * Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.
147
+ *
148
+ * This function is only for use with components that have a primary slot other than `root`.
149
+ * Most components should use {@link getNativeElementProps} for their root slot if it is the primary slot.
150
+ *
151
+ * @returns An object containing the native props for the `root` and primary slots.
152
+ */
153
+ export declare const getPartitionedNativeProps: ({ primarySlotTagName, props, excludedPropNames, }: {
154
+ /** The primary slot's element type (e.g. 'div') */
155
+ primarySlotTagName: keyof JSX.IntrinsicElements;
156
+ /** The component's props object */
157
+ props: Pick<React_2.HTMLAttributes<HTMLElement>, 'style' | 'className'>;
158
+ /** List of native props to exclude from the returned value */
159
+ excludedPropNames?: string[] | undefined;
160
+ }) => {
161
+ root: {
162
+ style: React_2.CSSProperties | undefined;
163
+ className: string | undefined;
164
+ };
165
+ primary: React_2.HTMLAttributes<any>;
166
+ };
167
+
153
168
  /**
154
169
  * Finds and swaps a provided key for it's right to left format.
155
170
  */
@@ -471,42 +486,37 @@ export declare type UseBooleanCallbacks = {
471
486
  export declare function useConst<T>(initialValue: T | (() => T)): T;
472
487
 
473
488
  /**
474
- * A useState 'like' hook that allows optional user control
475
- * Useful for components which allow uncontrolled and controlled behaviour for users
476
- * @returns - https://reactjs.org/docs/hooks-state.html
489
+ * A `useState`-like hook to manage a value that could be either controlled or uncontrolled,
490
+ * such as a checked state or text input string.
491
+ *
492
+ * Unlike `setState`, it's okay to call the returned updater (dispatch) function for either a
493
+ * controlled or uncontrolled component. Calls will only be respected if the component is uncontrolled.
494
+ *
495
+ * @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array
496
+ * of the current value and an updater (dispatch) function. The updater function is referentially
497
+ * stable (won't change during the component's lifecycle). It can take either a new value, or a
498
+ * function which is passed the previous value and returns the new value. Unlike `setState`, calls
499
+ * to the updater function will only be respected if the component is uncontrolled.
500
+ * @see https://reactjs.org/docs/uncontrolled-components.html
477
501
  */
478
502
  export declare const useControllableState: <State>(options: UseControllableStateOptions<State>) => [State, React_2.Dispatch<React_2.SetStateAction<State>>];
479
503
 
480
504
  export declare type UseControllableStateOptions<State> = {
481
505
  /**
482
- * User provided default state or factory initializer
506
+ * User-provided default state or initializer, for uncontrolled usage.
483
507
  */
484
508
  defaultState?: State | (() => State);
485
509
  /**
486
- * User provided controllable state, undefined state means internal state will be used
510
+ * User-provided controlled state. `undefined` means internal state will be used.
487
511
  */
488
512
  state: State | undefined;
489
513
  /**
490
- * Used to initialize state if all user provided states are undefined
514
+ * Used as the initial state if `state` and `defaultState` are both `undefined`.
515
+ * If `undefined` is the correct initial state, pass that here.
491
516
  */
492
517
  initialState: State;
493
518
  };
494
519
 
495
- /**
496
- * Hook to manage a value that could be either controlled or uncontrolled, such as a checked state or
497
- * text box string.
498
- * @param controlledValue - The controlled value passed in the props. This value will always be used if provided,
499
- * and the internal state will be updated to reflect it.
500
- * @param defaultUncontrolledValue - Initial value for the internal state in the uncontrolled case.
501
- * @returns An array of the current value and an updater callback. Like `React.useState`, the updater
502
- * callback always has the same identity, and it can take either a new value, or a function which
503
- * is passed the previous value and returns the new value.
504
- * @see https://reactjs.org/docs/uncontrolled-components.html
505
- */
506
- export declare function useControllableValue<TValue, TElement extends HTMLElement>(controlledValue: TValue, defaultUncontrolledValue: DefaultValue<TValue>): Readonly<[TValue, (update: React_2.SetStateAction<TValue>) => void]>;
507
-
508
- 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]>;
509
-
510
520
  /**
511
521
  * https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
512
522
  *
@@ -8,8 +8,7 @@ export declare type ShorthandProps<Props extends DefaultObjectShorthandProps> =
8
8
  * This should ONLY be used in type templates as in `extends DefaultObjectShorthandProps`;
9
9
  * it shouldn't be used as the type of a slot.
10
10
  */
11
- export declare type DefaultObjectShorthandProps = ObjectShorthandProps<{
12
- children?: React.ReactNode;
11
+ export declare type DefaultObjectShorthandProps = ObjectShorthandProps<Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
13
12
  as?: keyof JSX.IntrinsicElements;
14
13
  }>;
15
14
  /**
@@ -78,7 +77,7 @@ export declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U :
78
77
  export declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;
79
78
  export declare type ComponentProps<Shorthands extends ObjectShorthandPropsRecord, Primary extends keyof Shorthands = 'root'> = Omit<{
80
79
  [Key in keyof Shorthands]?: ShorthandProps<NonNullable<Shorthands[Key]>>;
81
- }, Primary> & PropsWithoutRef<Shorthands[Primary]>;
80
+ }, Primary & 'root'> & PropsWithoutRef<Shorthands[Primary]>;
82
81
  export declare type ComponentState<Shorthands extends ObjectShorthandPropsRecord> = {
83
82
  components?: {
84
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);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/compose/types.ts"],"names":[],"mappings":"WA2IA;AACA;AACA;AACA;AACA","sourceRoot":""}
1
+ {"version":3,"sources":["../../src/compose/types.ts"],"names":[],"mappings":"WAgJA;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';
@@ -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';
@@ -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,wBAAwB,CAAC;AACvC,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,cAAc,CAAC;AAC7B,cAAc,kBAAkB,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,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 provided default state or factory initializer
4
+ * User-provided default state or initializer, for uncontrolled usage.
5
5
  */
6
6
  defaultState?: State | (() => State);
7
7
  /**
8
- * User provided controllable state, undefined state means internal state will be used
8
+ * User-provided controlled state. `undefined` means internal state will be used.
9
9
  */
10
10
  state: State | undefined;
11
11
  /**
12
- * Used to initialize state if all user provided states are undefined
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 'like' hook that allows optional user control
18
- * Useful for components which allow uncontrolled and controlled behaviour for users
19
- * @returns - https://reactjs.org/docs/hooks-state.html
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 'like' hook that allows optional user control
13
- * Useful for components which allow uncontrolled and controlled behaviour for users
14
- * @returns - https://reactjs.org/docs/hooks-state.html
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 = isUndefined(options.defaultState) ? options.initialState : options.defaultState;
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;;AAiBA,SAAS,WAAT,CAAqB,KAArB,EAAmC;AACjC,SAAO,OAAO,KAAP,KAAiB,WAAxB;AACD;;AAED,SAAS,iBAAT,CAAkC,QAAlC,EAAuE;AACrE,SAAO,OAAO,QAAP,KAAoB,UAA3B;AACD;AAED;;;;AAIG;;;AACH,OAAO,MAAM,oBAAoB,GAC/B,OADkC,IAEsB;AACxD,QAAM,YAAY,GAAG,eAAe,CAAC,OAAO,CAAC,KAAT,CAApC;AACA,QAAM,YAAY,GAAG,WAAW,CAAC,OAAO,CAAC,YA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AAD,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;AA+BP;;;;AAIG;;AACH,MAAM,eAAe,GAAI,eAAD,IAA6B;AACnD,QAAM,YAAY,GAAG,QAAQ,CAAU,eAAe,KAAK,SAA9B,CAA7B;;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":""}
@@ -7,3 +7,25 @@ import * as React from 'react';
7
7
  * @param excludedPropNames - List of props to disallow
8
8
  */
9
9
  export declare function getNativeElementProps<TAttributes extends React.HTMLAttributes<any>>(tagName: string, props: {}, excludedPropNames?: string[]): TAttributes;
10
+ /**
11
+ * Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.
12
+ *
13
+ * This function is only for use with components that have a primary slot other than `root`.
14
+ * Most components should use {@link getNativeElementProps} for their root slot if it is the primary slot.
15
+ *
16
+ * @returns An object containing the native props for the `root` and primary slots.
17
+ */
18
+ export declare const getPartitionedNativeProps: ({ primarySlotTagName, props, excludedPropNames, }: {
19
+ /** The primary slot's element type (e.g. 'div') */
20
+ primarySlotTagName: keyof JSX.IntrinsicElements;
21
+ /** The component's props object */
22
+ props: Pick<React.HTMLAttributes<HTMLElement>, 'style' | 'className'>;
23
+ /** List of native props to exclude from the returned value */
24
+ excludedPropNames?: string[] | undefined;
25
+ }) => {
26
+ root: {
27
+ style: React.CSSProperties | undefined;
28
+ className: string | undefined;
29
+ };
30
+ primary: React.HTMLAttributes<any>;
31
+ };
@@ -35,4 +35,26 @@ export function getNativeElementProps(tagName, props, excludedPropNames) {
35
35
  allowedPropNames.as = 1;
36
36
  return getNativeProps(props, allowedPropNames, excludedPropNames);
37
37
  }
38
+ /**
39
+ * Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.
40
+ *
41
+ * This function is only for use with components that have a primary slot other than `root`.
42
+ * Most components should use {@link getNativeElementProps} for their root slot if it is the primary slot.
43
+ *
44
+ * @returns An object containing the native props for the `root` and primary slots.
45
+ */
46
+
47
+ export const getPartitionedNativeProps = ({
48
+ primarySlotTagName,
49
+ props,
50
+ excludedPropNames
51
+ }) => {
52
+ return {
53
+ root: {
54
+ style: props.style,
55
+ className: props.className
56
+ },
57
+ primary: getNativeElementProps(primarySlotTagName, props, [...(excludedPropNames || []), 'style', 'className'])
58
+ };
59
+ };
38
60
  //# sourceMappingURL=getNativeElementProps.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/getNativeElementProps.ts"],"names":[],"mappings":"AACA,SACE,eADF,EAEE,eAFF,EAGE,eAHF,EAIE,YAJF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CAAC,OAAD,CAA5B,IAA0C,qBAAnE;AACA,EAAA,gBAAgB,CAAC,EAAjB,GAAsB,CAAtB;AAEA,SAAO,cAAc,CAAC,KAAD,EAAQ,gBAAR,EAA0B,iBAA1B,CAArB;AACD;AAED;;;;;;;AAOG;;AACH,OAAO,MAAM,yBAAyB,GAAG,CAAC;AACxC,EAAA,kBADwC;AAExC,EAAA,KAFwC;AAGxC,EAAA;AAHwC,CAAD,KAapC;AACH,SAAO;AACL,IAAA,IAAI,EAAE;AAAE,MAAA,KAAK,EAAE,KAAK,CAAC,KAAf;AAAsB,MAAA,SAAS,EAAE,KAAK,CAAC;AAAvC,KADD;AAEL,IAAA,OAAO,EAAE,qBAAqB,CAAC,kBAAD,EAAqB,KAArB,EAA4B,CAAC,IAAI,iBAAiB,IAAI,EAAzB,CAAD,EAA+B,OAA/B,EAAwC,WAAxC,CAA5B;AAFzB,GAAP;AAID,CAlBM","sourceRoot":""}
@@ -8,8 +8,7 @@ export declare type ShorthandProps<Props extends DefaultObjectShorthandProps> =
8
8
  * This should ONLY be used in type templates as in `extends DefaultObjectShorthandProps`;
9
9
  * it shouldn't be used as the type of a slot.
10
10
  */
11
- export declare type DefaultObjectShorthandProps = ObjectShorthandProps<{
12
- children?: React.ReactNode;
11
+ export declare type DefaultObjectShorthandProps = ObjectShorthandProps<Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
13
12
  as?: keyof JSX.IntrinsicElements;
14
13
  }>;
15
14
  /**
@@ -78,7 +77,7 @@ export declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U :
78
77
  export declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;
79
78
  export declare type ComponentProps<Shorthands extends ObjectShorthandPropsRecord, Primary extends keyof Shorthands = 'root'> = Omit<{
80
79
  [Key in keyof Shorthands]?: ShorthandProps<NonNullable<Shorthands[Key]>>;
81
- }, Primary> & PropsWithoutRef<Shorthands[Primary]>;
80
+ }, Primary & 'root'> & PropsWithoutRef<Shorthands[Primary]>;
82
81
  export declare type ComponentState<Shorthands extends ObjectShorthandPropsRecord> = {
83
82
  components?: {
84
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);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/compose/types.ts"],"names":[],"mappings":";;;;IA2IA;AACA;AACA;AACA;AACA","sourceRoot":""}
1
+ {"version":3,"sources":["../../src/compose/types.ts"],"names":[],"mappings":";;;;IAgJA;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,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);
@@ -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,wBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,oBAAA,CAAA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AA,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,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,kBAAA,CAAA,EAAA,OAAA","sourceRoot":""}
@@ -1,21 +1,31 @@
1
1
  import * as React from 'react';
2
2
  export declare type UseControllableStateOptions<State> = {
3
3
  /**
4
- * User provided default state or factory initializer
4
+ * User-provided default state or initializer, for uncontrolled usage.
5
5
  */
6
6
  defaultState?: State | (() => State);
7
7
  /**
8
- * User provided controllable state, undefined state means internal state will be used
8
+ * User-provided controlled state. `undefined` means internal state will be used.
9
9
  */
10
10
  state: State | undefined;
11
11
  /**
12
- * Used to initialize state if all user provided states are undefined
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 'like' hook that allows optional user control
18
- * Useful for components which allow uncontrolled and controlled behaviour for users
19
- * @returns - https://reactjs.org/docs/hooks-state.html
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>>];
@@ -9,23 +9,28 @@ const React = /*#__PURE__*/require("react");
9
9
 
10
10
  const useConst_1 = /*#__PURE__*/require("./useConst");
11
11
 
12
- function isUndefined(state) {
13
- return typeof state === 'undefined';
14
- }
15
-
16
12
  function isFactoryDispatch(newState) {
17
13
  return typeof newState === 'function';
18
14
  }
19
15
  /**
20
- * A useState 'like' hook that allows optional user control
21
- * Useful for components which allow uncontrolled and controlled behaviour for users
22
- * @returns - https://reactjs.org/docs/hooks-state.html
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
31
  const useControllableState = options => {
27
32
  const isControlled = useIsControlled(options.state);
28
- const initialState = isUndefined(options.defaultState) ? options.initialState : options.defaultState;
33
+ const initialState = typeof options.defaultState === 'undefined' ? options.initialState : options.defaultState;
29
34
  const [internalState, setInternalState] = React.useState(initialState);
30
35
  const state = isControlled ? options.state : internalState;
31
36
  const stateRef = React.useRef(state);
@@ -1 +1 @@
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;;AAiBA,SAAS,WAAT,CAAqB,KAArB,EAAmC;AACjC,SAAO,OAAO,KAAP,KAAiB,WAAxB;AACD;;AAED,SAAS,iBAAT,CAAkC,QAAlC,EAAuE;AACrE,SAAO,OAAO,QAAP,KAAoB,UAA3B;AACD;AAED;;;;AAIG;;;AACI,MAAM,oBAAoB,GAC/B,OADkC,IAEsB;AACxD,QAAM,YAAY,GAAG,eAAe,CAAC,OAAO,CAAC,KAAT,CAApC;AACA,QAAM,YAAY,GAAG,WAAW,CAAC,OAAO,CAAC,YAAT,CAAX,GAAoC,OAAO,CAAC,YAA5C,GAA2D,OAAO,CAAC,YAAxF;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,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7B,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":""}
@@ -7,3 +7,25 @@ import * as React from 'react';
7
7
  * @param excludedPropNames - List of props to disallow
8
8
  */
9
9
  export declare function getNativeElementProps<TAttributes extends React.HTMLAttributes<any>>(tagName: string, props: {}, excludedPropNames?: string[]): TAttributes;
10
+ /**
11
+ * Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.
12
+ *
13
+ * This function is only for use with components that have a primary slot other than `root`.
14
+ * Most components should use {@link getNativeElementProps} for their root slot if it is the primary slot.
15
+ *
16
+ * @returns An object containing the native props for the `root` and primary slots.
17
+ */
18
+ export declare const getPartitionedNativeProps: ({ primarySlotTagName, props, excludedPropNames, }: {
19
+ /** The primary slot's element type (e.g. 'div') */
20
+ primarySlotTagName: keyof JSX.IntrinsicElements;
21
+ /** The component's props object */
22
+ props: Pick<React.HTMLAttributes<HTMLElement>, 'style' | 'className'>;
23
+ /** List of native props to exclude from the returned value */
24
+ excludedPropNames?: string[] | undefined;
25
+ }) => {
26
+ root: {
27
+ style: React.CSSProperties | undefined;
28
+ className: string | undefined;
29
+ };
30
+ primary: React.HTMLAttributes<any>;
31
+ };
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getNativeElementProps = void 0;
6
+ exports.getPartitionedNativeProps = exports.getNativeElementProps = void 0;
7
7
 
8
8
  const properties_1 = /*#__PURE__*/require("./properties");
9
9
 
@@ -45,4 +45,28 @@ function getNativeElementProps(tagName, props, excludedPropNames) {
45
45
  }
46
46
 
47
47
  exports.getNativeElementProps = getNativeElementProps;
48
+ /**
49
+ * Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.
50
+ *
51
+ * This function is only for use with components that have a primary slot other than `root`.
52
+ * Most components should use {@link getNativeElementProps} for their root slot if it is the primary slot.
53
+ *
54
+ * @returns An object containing the native props for the `root` and primary slots.
55
+ */
56
+
57
+ const getPartitionedNativeProps = ({
58
+ primarySlotTagName,
59
+ props,
60
+ excludedPropNames
61
+ }) => {
62
+ return {
63
+ root: {
64
+ style: props.style,
65
+ className: props.className
66
+ },
67
+ primary: getNativeElementProps(primarySlotTagName, props, [...(excludedPropNames || []), 'style', 'className'])
68
+ };
69
+ };
70
+
71
+ exports.getPartitionedNativeProps = getPartitionedNativeProps;
48
72
  //# sourceMappingURL=getNativeElementProps.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/getNativeElementProps.ts"],"names":[],"mappings":";;;;;;;AACA,MAAA,YAAA,gBAAA,OAAA,CAAA,cAAA,CAAA;;AAyBA,MAAM,gBAAgB,GAA2C;AAC/D,EAAA,KAAK,EAAE,YAAA,CAAA,eADwD;AAE/D,EAAA,KAAK,EAAE,YAAA,CAAA,eAFwD;AAG/D,EAAA,KAAK,EAAE,YAAA,CAAA,eAHwD;AAI/D,EAAA,EAAE,EAAE,YAAA,CAAA,YAJ2D;AAK/D,EAAA,EAAE,EAAE,YAAA,CAAA,YAL2D;AAM/D,EAAA,CAAC,EAAE,YAAA,CAAA,gBAN4D;AAO/D,EAAA,MAAM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AAA,kBADwC;AAExC,EAAA,KAFwC;AAGxC,EAAA;AAHwC,CAAD,KAapC;AACH,SAAO;AACL,IAAA,IAAI,EAAE;AAAE,MAAA,KAAK,EAAE,KAAK,CAAC,KAAf;AAAsB,MAAA,SAAS,EAAE,KAAK,CAAC;AAAvC,KADD;AAEL,IAAA,OAAO,EAAE,qBAAqB,CAAC,kBAAD,EAAqB,KAArB,EAA4B,CAAC,IAAI,iBAAiB,IAAI,EAAzB,CAAD,EAA+B,OAA/B,EAAwC,WAAxC,CAA5B;AAFzB,GAAP;AAID,CAlBM;;AAAM,OAAA,CAAA,yBAAA,GAAyB,yBAAzB","sourceRoot":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-utilities",
3
- "version": "0.0.0-nightly01492e29df20211105.1",
3
+ "version": "0.0.0-nightly39ce3cbcf120211206.1",
4
4
  "description": "A set of general React-specific utilities.",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -20,9 +20,9 @@
20
20
  "lint": "just-scripts lint",
21
21
  "test": "jest",
22
22
  "docs": "api-extractor run --config=config/api-extractor.local.json --local",
23
- "build:local": "tsc -p . --module esnext --emitDeclarationOnly && node ../../scripts/typescript/normalize-import --output dist/react-utilities/src && yarn docs",
24
- "storybook": "start-storybook",
25
- "start": "yarn storybook"
23
+ "build:local": "tsc -p ./tsconfig.lib.json --module esnext --emitDeclarationOnly && node ../../scripts/typescript/normalize-import --output ./dist/packages/react-utilities/src && yarn docs",
24
+ "start": "yarn storybook",
25
+ "type-check": "tsc -b tsconfig.json"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@fluentui/eslint-plugin": "*",
@@ -37,7 +37,7 @@
37
37
  "react-test-renderer": "^16.3.0"
38
38
  },
39
39
  "dependencies": {
40
- "@fluentui/keyboard-keys": "0.0.0-nightly01492e29df20211105.1",
40
+ "@fluentui/keyboard-keys": "0.0.0-nightly39ce3cbcf120211206.1",
41
41
  "tslib": "^2.1.0"
42
42
  },
43
43
  "peerDependencies": {
@@ -45,7 +45,6 @@
45
45
  "react": ">=16.8.0 <18.0.0"
46
46
  },
47
47
  "beachball": {
48
- "tag": "beta",
49
48
  "disallowedChangeTypes": [
50
49
  "major",
51
50
  "minor",
@@ -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,57 +0,0 @@
1
- import * as React from 'react';
2
- import { useConst } from './useConst';
3
- export function useControllableValue(controlledValue, defaultUncontrolledValue, onChange) {
4
- const [value, setValue] = React.useState(defaultUncontrolledValue);
5
- const isControlled = useIsControlled(controlledValue);
6
- const currentValue = isControlled ? controlledValue : value; // Duplicate the current value and onChange in refs so they're accessible from
7
- // setValueOrCallOnChange without creating a new callback every time
8
-
9
- const valueRef = React.useRef(currentValue);
10
- const onChangeRef = React.useRef(onChange);
11
- React.useEffect(() => {
12
- valueRef.current = currentValue;
13
- onChangeRef.current = onChange;
14
- }); // To match the behavior of the setter returned by React.useState, this callback's identity
15
- // should never change. This means it MUST NOT directly reference variables that can change.
16
-
17
- const setValueOrCallOnChange = useConst(() => (update, ev) => {
18
- // Assuming here that TValue is not a function, because a controllable value will typically
19
- // be something a user can enter as input
20
- const newValue = typeof update === 'function' ? update(valueRef.current) : update;
21
-
22
- if (onChangeRef.current) {
23
- onChangeRef.current(ev, newValue);
24
- }
25
-
26
- if (!isControlled) {
27
- setValue(newValue);
28
- }
29
- });
30
- return [currentValue, setValueOrCallOnChange];
31
- }
32
- /**
33
- * Helper hook to handle previous comparison of controlled/uncontrolled
34
- * Prints an error when isControlled value switches between subsequent renders
35
- */
36
-
37
- const useIsControlled = controlledValue => {
38
- const isControlled = useConst(controlledValue !== undefined);
39
-
40
- if (process.env.NODE_ENV !== 'production') {
41
- // We don't want these warnings in production even though it is against native behaviour
42
- // eslint-disable-next-line react-hooks/rules-of-hooks
43
- React.useEffect(() => {
44
- if (isControlled !== (controlledValue !== undefined)) {
45
- const error = new Error();
46
- const controlWarning = isControlled ? 'a controlled value to be uncontrolled' : 'an uncontrolled value to be controlled';
47
- const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined'; // eslint-disable-next-line no-console
48
-
49
- console.error([// Default react error
50
- '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(' '));
51
- }
52
- }, [isControlled, controlledValue]);
53
- }
54
-
55
- return isControlled;
56
- };
57
- //# sourceMappingURL=useControllableValue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/hooks/useControllableValue.ts"],"names":[],"mappings":"AAAA,OAA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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":""}
@@ -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,QAAR,IAAoB,KAAK,CAAC,QAAN,CAAmC,wBAAnC,CAA1B;AACA,QAAM,YAAY,GAAG,eAAe,CAAC,eAAD,CAApC;AACA,QAAM,YAAY,GAAG,YAAY,GAAG,eAAH,GAAqB,KAAtD,CAJmD,CAMnD;AACA;;AACA,QAAM,QAAQ,GAAG,KAAK,CAAC,MAAN,CAAa,YAAb,CAAjB;AACA,QAAM,WAAW,GAAG,KAAK,CAAC,MAAN,CAAa,QAAb,CAApB;AACA,EAAA,KAAK,CAAC,SAAN,CAAgB,MAAK;AACnB,IAAA,QAAQ,CAAC,OAAT,GAAmB,YAAnB;AACA,IAAA,WAAW,CAAC,OAAZ,GAAsB,QAAtB;AACD,GAHD,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