@aws-amplify/ui-react-core 2.1.29 → 2.1.31
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/dist/esm/index.mjs +0 -1
- package/dist/index.js +0 -5
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/types.d.ts +1 -0
- package/dist/types/utils/createContextUtilities.d.ts +59 -0
- package/dist/types/utils/index.d.ts +1 -1
- package/package.json +2 -2
- package/dist/esm/utils/index.mjs +0 -7
package/dist/esm/index.mjs
CHANGED
|
@@ -8,4 +8,3 @@ export { default as RenderNothing } from './components/RenderNothing/RenderNothi
|
|
|
8
8
|
export { default as useDeprecationWarning } from './hooks/useDeprecationWarning.mjs';
|
|
9
9
|
export { default as useHasValueUpdated } from './hooks/useHasValueUpdated.mjs';
|
|
10
10
|
export { default as usePreviousValue } from './hooks/usePreviousValue.mjs';
|
|
11
|
-
export { templateJoin } from './utils/index.mjs';
|
package/dist/index.js
CHANGED
|
@@ -528,15 +528,10 @@ function useHasValueUpdated(value, ignoreFirstRender = false) {
|
|
|
528
528
|
return previous !== value;
|
|
529
529
|
}
|
|
530
530
|
|
|
531
|
-
function templateJoin(values, template) {
|
|
532
|
-
return values.reduce((acc, curr) => `${acc}${ui.isString(curr) ? template(curr) : ''}`, '');
|
|
533
|
-
}
|
|
534
|
-
|
|
535
531
|
exports.AuthenticatorProvider = AuthenticatorProvider;
|
|
536
532
|
exports.RenderNothing = RenderNothing;
|
|
537
533
|
exports.isAuthenticatorComponentRouteKey = isComponentRouteKey;
|
|
538
534
|
exports.resolveAuthenticatorComponents = resolveAuthenticatorComponents;
|
|
539
|
-
exports.templateJoin = templateJoin;
|
|
540
535
|
exports.useAuthenticator = useAuthenticator;
|
|
541
536
|
exports.useAuthenticatorInitMachine = useAuthenticatorInitMachine;
|
|
542
537
|
exports.useAuthenticatorRoute = useAuthenticatorRoute;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { AuthenticatorComponentDefaults, AuthenticatorComponentDefaultProps, AuthenticatorComponentOverrides, AuthenticatorFooterComponent, AuthenticatorFormFieldsComponent, AuthenticatorHeaderComponent, AuthenticatorLegacyField, AuthenticatorMachineContext, AuthenticatorProvider, AuthenticatorRouteComponentKey, AuthenticatorRouteComponentName, isAuthenticatorComponentRouteKey, resolveAuthenticatorComponents, useAuthenticator, useAuthenticatorRoute, UseAuthenticator, useAuthenticatorInitMachine, UseAuthenticatorRoute, } from './Authenticator';
|
|
2
2
|
export { RenderNothing } from './components';
|
|
3
3
|
export { useDeprecationWarning, UseDeprecationWarning, useHasValueUpdated, usePreviousValue, } from './hooks';
|
|
4
|
-
export {
|
|
4
|
+
export { MergeProps } from './types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MergeProps } from './types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type MergeProps<C, P> = C & Omit<P, keyof C>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React from 'react';
|
|
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;
|
|
5
|
+
defaultValue: ContextType;
|
|
6
|
+
};
|
|
7
|
+
type OptionsWithErrorMessage = {
|
|
8
|
+
contextName: string;
|
|
9
|
+
errorMessage: string;
|
|
10
|
+
};
|
|
11
|
+
type ContextOptions<ContextType extends {}> = OptionsWithDefaultValue<ContextType> | OptionsWithErrorMessage;
|
|
12
|
+
/**
|
|
13
|
+
* Use a `ContextType` generic and `options` to create:
|
|
14
|
+
* - `Context`: React Context of type `ContextType`
|
|
15
|
+
* - `Provider`: React Context `Provider` component exposing the `ContextType`
|
|
16
|
+
* as optional props
|
|
17
|
+
* - `useContext`: Utility Hook exposing the values of `ContextType`
|
|
18
|
+
*
|
|
19
|
+
* @template ContextType Type definition of the Context.
|
|
20
|
+
* > 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
|
|
22
|
+
* Utility Hook return
|
|
23
|
+
*
|
|
24
|
+
* @param options Context utility options. Requires a `contextName`, and either
|
|
25
|
+
* a `defaultValue` of `ContextType` or `errorMessage` allowing for differing
|
|
26
|
+
* behaviors of the Utility Hook when used outside a parent `Provider`:
|
|
27
|
+
*
|
|
28
|
+
* - `defaultValue`: Ensures the Utility Hook returns a default value for
|
|
29
|
+
* scenarios **where the missing context values should not impact usage**
|
|
30
|
+
* - `errorMessage`: Ensures the Utility Hook throws an error for
|
|
31
|
+
* scenarios **where the missing context values should prevent** usage
|
|
32
|
+
*
|
|
33
|
+
* @returns `Context`, `Provider` Component and `useContext` Utility Hook
|
|
34
|
+
*
|
|
35
|
+
* @usage
|
|
36
|
+
* ```ts
|
|
37
|
+
* interface StuffContextType {
|
|
38
|
+
* things: number;
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* // with `defaultValue`
|
|
42
|
+
* const [StuffProvider, useStuff] = createContextUtilities<StuffContextType>({
|
|
43
|
+
* contextName: 'Stuff',
|
|
44
|
+
* defaultValue: { things: 7 }
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* // with `errorMessage`
|
|
48
|
+
* const [StuffProvider, useStuff] = createContextUtilities<StuffContextType>({
|
|
49
|
+
* contextName: 'Stuff',
|
|
50
|
+
* errorMessage: '`useStuff` must be used in a `StuffProvider`'
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
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 {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { default as createContextUtilities } from './createContextUtilities';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/ui-react-core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.31",
|
|
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.
|
|
34
|
+
"@aws-amplify/ui": "5.7.2",
|
|
35
35
|
"@xstate/react": "3.0.1",
|
|
36
36
|
"lodash": "4.17.21",
|
|
37
37
|
"xstate": "^4.33.6"
|