@asgardeo/react 0.5.33 → 0.6.0
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/cjs/index.js +319 -156
- package/dist/cjs/index.js.map +4 -4
- package/dist/components/presentation/SignUp/BaseSignUp.d.ts +95 -6
- package/dist/components/presentation/SignUp/SignUp.d.ts +52 -3
- package/dist/components/presentation/SignUp/transformer.d.ts +30 -0
- package/dist/contexts/Theme/ThemeContext.d.ts +4 -0
- package/dist/contexts/Theme/types.d.ts +5 -0
- package/dist/index.js +210 -45
- package/dist/index.js.map +4 -4
- package/package.json +2 -2
|
@@ -16,8 +16,71 @@
|
|
|
16
16
|
* under the License.
|
|
17
17
|
*/
|
|
18
18
|
import { EmbeddedFlowExecuteRequestPayload, EmbeddedFlowExecuteResponse } from '@asgardeo/browser';
|
|
19
|
-
import { FC } from 'react';
|
|
19
|
+
import { FC, ReactNode } from 'react';
|
|
20
20
|
import { CardProps } from '../../primitives/Card/Card';
|
|
21
|
+
/**
|
|
22
|
+
* Render props for custom UI rendering
|
|
23
|
+
*/
|
|
24
|
+
export interface BaseSignUpRenderProps {
|
|
25
|
+
/**
|
|
26
|
+
* Form values
|
|
27
|
+
*/
|
|
28
|
+
values: Record<string, string>;
|
|
29
|
+
/**
|
|
30
|
+
* Form errors
|
|
31
|
+
*/
|
|
32
|
+
errors: Record<string, string>;
|
|
33
|
+
/**
|
|
34
|
+
* Touched fields
|
|
35
|
+
*/
|
|
36
|
+
touched: Record<string, boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Whether the form is valid
|
|
39
|
+
*/
|
|
40
|
+
isValid: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Loading state
|
|
43
|
+
*/
|
|
44
|
+
isLoading: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Current error message
|
|
47
|
+
*/
|
|
48
|
+
error: string | null;
|
|
49
|
+
/**
|
|
50
|
+
* Flow components
|
|
51
|
+
*/
|
|
52
|
+
components: any[];
|
|
53
|
+
/**
|
|
54
|
+
* Function to handle input changes
|
|
55
|
+
*/
|
|
56
|
+
handleInputChange: (name: string, value: string) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Function to handle form submission
|
|
59
|
+
*/
|
|
60
|
+
handleSubmit: (component: any, data?: Record<string, any>) => Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Function to validate the form
|
|
63
|
+
*/
|
|
64
|
+
validateForm: () => {
|
|
65
|
+
isValid: boolean;
|
|
66
|
+
errors: Record<string, string>;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Flow title
|
|
70
|
+
*/
|
|
71
|
+
title: string;
|
|
72
|
+
/**
|
|
73
|
+
* Flow subtitle
|
|
74
|
+
*/
|
|
75
|
+
subtitle: string;
|
|
76
|
+
/**
|
|
77
|
+
* Flow messages
|
|
78
|
+
*/
|
|
79
|
+
messages: Array<{
|
|
80
|
+
message: string;
|
|
81
|
+
type: string;
|
|
82
|
+
}>;
|
|
83
|
+
}
|
|
21
84
|
/**
|
|
22
85
|
* Props for the BaseSignUp component.
|
|
23
86
|
*/
|
|
@@ -86,6 +149,10 @@ export interface BaseSignUpProps {
|
|
|
86
149
|
* Whether to redirect after sign-up.
|
|
87
150
|
*/
|
|
88
151
|
shouldRedirectAfterSignUp?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Render props function for custom UI
|
|
154
|
+
*/
|
|
155
|
+
children?: (props: BaseSignUpRenderProps) => ReactNode;
|
|
89
156
|
}
|
|
90
157
|
/**
|
|
91
158
|
* Base SignUp component that provides embedded sign-up flow.
|
|
@@ -93,6 +160,7 @@ export interface BaseSignUpProps {
|
|
|
93
160
|
* It accepts API functions as props to maintain framework independence.
|
|
94
161
|
*
|
|
95
162
|
* @example
|
|
163
|
+
* // Default UI
|
|
96
164
|
* ```tsx
|
|
97
165
|
* import { BaseSignUp } from '@asgardeo/react';
|
|
98
166
|
*
|
|
@@ -107,20 +175,41 @@ export interface BaseSignUpProps {
|
|
|
107
175
|
* // Your API call to handle sign-up
|
|
108
176
|
* return await handleSignUp(payload);
|
|
109
177
|
* }}
|
|
110
|
-
*
|
|
111
|
-
* console.log('Success:', response);
|
|
112
|
-
* }} * onError={(error) => {
|
|
178
|
+
* onError={(error) => {
|
|
113
179
|
* console.error('Error:', error);
|
|
114
180
|
* }}
|
|
115
|
-
* onComplete={(
|
|
181
|
+
* onComplete={(response) => {
|
|
116
182
|
* // Platform-specific redirect handling (e.g., Next.js router.push)
|
|
117
|
-
* router.push(
|
|
183
|
+
* router.push(response); // or window.location.href = redirectUrl
|
|
118
184
|
* }}
|
|
119
185
|
* className="max-w-md mx-auto"
|
|
120
186
|
* />
|
|
121
187
|
* );
|
|
122
188
|
* };
|
|
123
189
|
* ```
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* // Custom UI with render props
|
|
193
|
+
* ```tsx
|
|
194
|
+
* <BaseSignUp onInitialize={initializeSignUp} onSubmit={handleSignUp}>
|
|
195
|
+
* {({values, errors, handleInputChange, handleSubmit, isLoading, components}) => (
|
|
196
|
+
* <div className="custom-form">
|
|
197
|
+
* <input
|
|
198
|
+
* name="username"
|
|
199
|
+
* value={values.username || ''}
|
|
200
|
+
* onChange={(e) => handleInputChange('username', e.target.value)}
|
|
201
|
+
* />
|
|
202
|
+
* {errors.username && <span>{errors.username}</span>}
|
|
203
|
+
* <button
|
|
204
|
+
* onClick={() => handleSubmit(components[0], values)}
|
|
205
|
+
* disabled={isLoading}
|
|
206
|
+
* >
|
|
207
|
+
* Sign Up
|
|
208
|
+
* </button>
|
|
209
|
+
* </div>
|
|
210
|
+
* )}
|
|
211
|
+
* </BaseSignUp>
|
|
212
|
+
* ```
|
|
124
213
|
*/
|
|
125
214
|
declare const BaseSignUp: FC<BaseSignUpProps>;
|
|
126
215
|
export default BaseSignUp;
|
|
@@ -15,17 +15,27 @@
|
|
|
15
15
|
* specific language governing permissions and limitations
|
|
16
16
|
* under the License.
|
|
17
17
|
*/
|
|
18
|
-
import { FC } from 'react';
|
|
19
|
-
import { BaseSignUpProps } from './BaseSignUp';
|
|
18
|
+
import { FC, ReactNode } from 'react';
|
|
19
|
+
import { BaseSignUpProps, BaseSignUpRenderProps } from './BaseSignUp';
|
|
20
|
+
/**
|
|
21
|
+
* Render props function parameters (re-exported from BaseSignUp for convenience)
|
|
22
|
+
*/
|
|
23
|
+
export type SignUpRenderProps = BaseSignUpRenderProps;
|
|
20
24
|
/**
|
|
21
25
|
* Props for the SignUp component.
|
|
22
26
|
*/
|
|
23
|
-
export type SignUpProps = BaseSignUpProps
|
|
27
|
+
export type SignUpProps = BaseSignUpProps & {
|
|
28
|
+
/**
|
|
29
|
+
* Render props function for custom UI
|
|
30
|
+
*/
|
|
31
|
+
children?: (props: SignUpRenderProps) => ReactNode;
|
|
32
|
+
};
|
|
24
33
|
/**
|
|
25
34
|
* A styled SignUp component that provides embedded sign-up flow with pre-built styling.
|
|
26
35
|
* This component handles the API calls for sign-up and delegates UI logic to BaseSignUp.
|
|
27
36
|
*
|
|
28
37
|
* @example
|
|
38
|
+
* // Default UI
|
|
29
39
|
* ```tsx
|
|
30
40
|
* import { SignUp } from '@asgardeo/react';
|
|
31
41
|
*
|
|
@@ -50,6 +60,45 @@ export type SignUpProps = BaseSignUpProps;
|
|
|
50
60
|
* );
|
|
51
61
|
* };
|
|
52
62
|
* ```
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* // Custom UI with render props
|
|
66
|
+
* ```tsx
|
|
67
|
+
* import { SignUp } from '@asgardeo/react';
|
|
68
|
+
*
|
|
69
|
+
* const App = () => {
|
|
70
|
+
* return (
|
|
71
|
+
* <SignUp
|
|
72
|
+
* onError={(error) => console.error('Error:', error)}
|
|
73
|
+
* onComplete={(response) => console.log('Success:', response)}
|
|
74
|
+
* >
|
|
75
|
+
* {({values, errors, handleInputChange, handleSubmit, isLoading, components}) => (
|
|
76
|
+
* <div className="custom-signup">
|
|
77
|
+
* <h1>Custom Sign Up</h1>
|
|
78
|
+
* {isLoading ? (
|
|
79
|
+
* <p>Loading...</p>
|
|
80
|
+
* ) : (
|
|
81
|
+
* <form onSubmit={(e) => {
|
|
82
|
+
* e.preventDefault();
|
|
83
|
+
* handleSubmit(components[0], values);
|
|
84
|
+
* }}>
|
|
85
|
+
* <input
|
|
86
|
+
* name="username"
|
|
87
|
+
* value={values.username || ''}
|
|
88
|
+
* onChange={(e) => handleInputChange('username', e.target.value)}
|
|
89
|
+
* />
|
|
90
|
+
* {errors.username && <span>{errors.username}</span>}
|
|
91
|
+
* <button type="submit" disabled={isLoading}>
|
|
92
|
+
* {isLoading ? 'Signing up...' : 'Sign Up'}
|
|
93
|
+
* </button>
|
|
94
|
+
* </form>
|
|
95
|
+
* )}
|
|
96
|
+
* </div>
|
|
97
|
+
* )}
|
|
98
|
+
* </SignUp>
|
|
99
|
+
* );
|
|
100
|
+
* };
|
|
101
|
+
* ```
|
|
53
102
|
*/
|
|
54
103
|
declare const SignUp: FC<SignUpProps>;
|
|
55
104
|
export default SignUp;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
|
|
3
|
+
*
|
|
4
|
+
* WSO2 LLC. licenses this file to you under the Apache License,
|
|
5
|
+
* Version 2.0 (the "License"); you may not use this file except
|
|
6
|
+
* in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing,
|
|
12
|
+
* software distributed under the License is distributed on an
|
|
13
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
* KIND, either express or implied. See the License for the
|
|
15
|
+
* specific language governing permissions and limitations
|
|
16
|
+
* under the License.
|
|
17
|
+
*/
|
|
18
|
+
import { EmbeddedFlowComponent } from '@asgardeo/browser';
|
|
19
|
+
import { UseTranslation } from '../../../hooks/useTranslation';
|
|
20
|
+
/**
|
|
21
|
+
* Transform simple flow response to component-driven format
|
|
22
|
+
*/
|
|
23
|
+
export declare const transformSimpleToComponentDriven: (response: any, t: UseTranslation["t"]) => EmbeddedFlowComponent[];
|
|
24
|
+
/**
|
|
25
|
+
* Generic transformer that handles both simple and component-driven responses
|
|
26
|
+
*/
|
|
27
|
+
export declare const normalizeFlowResponse: (response: any, t: UseTranslation["t"]) => {
|
|
28
|
+
flowId: string;
|
|
29
|
+
components: EmbeddedFlowComponent[];
|
|
30
|
+
};
|
|
@@ -19,6 +19,10 @@ import { Theme } from '@asgardeo/browser';
|
|
|
19
19
|
export interface ThemeContextValue {
|
|
20
20
|
theme: Theme;
|
|
21
21
|
colorScheme: 'light' | 'dark';
|
|
22
|
+
/**
|
|
23
|
+
* The text direction for the UI.
|
|
24
|
+
*/
|
|
25
|
+
direction: 'ltr' | 'rtl';
|
|
22
26
|
toggleTheme: () => void;
|
|
23
27
|
/**
|
|
24
28
|
* Whether branding theme is currently loading
|