@aws-amplify/ui-react-core 2.1.31 → 2.1.33

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.
@@ -1,14 +1,19 @@
1
1
  import React from 'react';
2
2
  export declare const INVALID_OPTIONS_MESSAGE = "an `errorMessage` or a `defaultValue` must be provided in `options`";
3
- type OptionsWithDefaultValue<ContextType extends {}> = {
4
- contextName: string;
3
+ type ContextOptions<ContextType, ContextName extends string> = {
4
+ contextName: ContextName;
5
+ } & (// exclude `errorMessage` if `defaultValue` is present
6
+ {
5
7
  defaultValue: ContextType;
6
- };
7
- type OptionsWithErrorMessage = {
8
- contextName: string;
8
+ errorMessage?: never;
9
+ } | {
9
10
  errorMessage: string;
11
+ defaultValue?: never;
12
+ });
13
+ type UtilityKey<ContextName extends string> = `${ContextName}Provider` | `use${ContextName}` | `${ContextName}Context`;
14
+ type CreateContextUtilitiesReturn<ContextType, ContextName extends string> = {
15
+ [Key in UtilityKey<ContextName>]: Key extends `${string}Provider` ? React.ComponentType<React.PropsWithChildren<Partial<ContextType>>> : Key extends `use${string}` ? () => ContextType : Key extends `${string}Context` ? React.Context<ContextType | undefined> : never;
10
16
  };
11
- type ContextOptions<ContextType extends {}> = OptionsWithDefaultValue<ContextType> | OptionsWithErrorMessage;
12
17
  /**
13
18
  * Use a `ContextType` generic and `options` to create:
14
19
  * - `Context`: React Context of type `ContextType`
@@ -18,7 +23,7 @@ type ContextOptions<ContextType extends {}> = OptionsWithDefaultValue<ContextTyp
18
23
  *
19
24
  * @template ContextType Type definition of the Context.
20
25
  * > For most use cases the keys of `ContextType` should not be optional in
21
- * preference of explicit `undefined` to avoid having optional types on the
26
+ * preference of explicit `undefined` to avoid optional types on the
22
27
  * Utility Hook return
23
28
  *
24
29
  * @param options Context utility options. Requires a `contextName`, and either
@@ -39,21 +44,17 @@ type ContextOptions<ContextType extends {}> = OptionsWithDefaultValue<ContextTyp
39
44
  * }
40
45
  *
41
46
  * // with `defaultValue`
42
- * const [StuffProvider, useStuff] = createContextUtilities<StuffContextType>({
47
+ * const { StuffProvider, useStuff } = createContextUtilities<StuffContextType>({
43
48
  * contextName: 'Stuff',
44
49
  * defaultValue: { things: 7 }
45
50
  * });
46
51
  *
47
52
  * // with `errorMessage`
48
- * const [StuffProvider, useStuff] = createContextUtilities<StuffContextType>({
53
+ * const { StuffProvider, useStuff } = createContextUtilities<StuffContextType>({
49
54
  * contextName: 'Stuff',
50
55
  * errorMessage: '`useStuff` must be used in a `StuffProvider`'
51
56
  * });
52
57
  * ```
53
58
  */
54
- export default function createContextUtilities<ContextType extends {}>(options: ContextOptions<ContextType>): {
55
- Provider: React.ComponentType<React.PropsWithChildren<Partial<ContextType>>>;
56
- useContext: () => ContextType;
57
- Context: React.Context<ContextType | undefined>;
58
- };
59
+ export default function createContextUtilities<ContextType, ContextName extends string = string>(options: ContextOptions<ContextType, ContextName>): CreateContextUtilitiesReturn<ContextType, ContextName>;
59
60
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/ui-react-core",
3
- "version": "2.1.31",
3
+ "version": "2.1.33",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/esm/index.mjs",
6
6
  "react-native": "dist/index.js",
@@ -31,7 +31,7 @@
31
31
  "typecheck": "tsc --noEmit"
32
32
  },
33
33
  "dependencies": {
34
- "@aws-amplify/ui": "5.7.2",
34
+ "@aws-amplify/ui": "5.8.1",
35
35
  "@xstate/react": "3.0.1",
36
36
  "lodash": "4.17.21",
37
37
  "xstate": "^4.33.6"