Skip to content

Commit 23ad290

Browse files
feat(react): Add support to passing react elements as child props to components
1 parent 5462aab commit 23ad290

File tree

7 files changed

+65
-16
lines changed

7 files changed

+65
-16
lines changed

packages/react/src/components/SignIn/SignIn.tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,17 @@ import IdentifierFirst from './fragments/IdentifierFirst';
6262
* @returns {ReactElement} - React element.
6363
*/
6464
const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
65-
const {brandingProps, showFooter = true, showLogo = true, showSignUp} = props;
65+
const {
66+
basicAuthChildren,
67+
brandingProps,
68+
emailOtpChildren,
69+
identifierFirstChildren,
70+
showFooter = true,
71+
showLogo = true,
72+
showSignUp,
73+
smsOtpChildren,
74+
totpChildren,
75+
} = props;
6676

6777
const [isComponentLoading, setIsComponentLoading] = useState<boolean>(true);
6878
const [alert, setAlert] = useState<AlertType>();
@@ -231,7 +241,9 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
231241
(auth: Authenticator) => auth.authenticatorId !== usernamePasswordAuthenticator.authenticatorId,
232242
),
233243
)}
234-
/>
244+
>
245+
{basicAuthChildren}
246+
</BasicAuth>
235247
);
236248
}
237249

@@ -252,7 +264,9 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
252264
(auth: Authenticator) => auth.authenticatorId !== identifierFirstAuthenticator.authenticatorId,
253265
),
254266
)}
255-
/>
267+
>
268+
{identifierFirstChildren}
269+
</IdentifierFirst>
256270
);
257271
}
258272

@@ -264,7 +278,9 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
264278
authenticator={authenticators[0]}
265279
alert={alert}
266280
handleAuthenticate={handleAuthenticate}
267-
/>
281+
>
282+
{totpChildren}
283+
</Totp>
268284
);
269285
}
270286
if (
@@ -279,7 +295,9 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
279295
brandingProps={brandingProps}
280296
authenticator={authenticators[0]}
281297
handleAuthenticate={handleAuthenticate}
282-
/>
298+
>
299+
{emailOtpChildren}
300+
</EmailOtp>
283301
);
284302
}
285303

@@ -295,7 +313,9 @@ const SignIn: FC<SignInProps> = (props: SignInProps): ReactElement => {
295313
brandingProps={brandingProps}
296314
authenticator={authenticators[0]}
297315
handleAuthenticate={handleAuthenticate}
298-
/>
316+
>
317+
{smsOtpChildren}
318+
</SmsOtp>
299319
);
300320
}
301321
}

packages/react/src/components/SignIn/fragments/BasicAuth.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import {ScreenType, keys} from '@asgardeo/js';
2020
import {CircularProgress, Grid, Skeleton} from '@oxygen-ui/react';
21-
import {ReactElement, useContext, useState} from 'react';
21+
import {PropsWithChildren, ReactElement, useContext, useState} from 'react';
2222
import AsgardeoContext from '../../../contexts/asgardeo-context';
2323
import useTranslations from '../../../hooks/use-translations';
2424
import BasicAuthProps from '../../../models/basic-auth-props';
@@ -41,11 +41,12 @@ import './basic-auth.scss';
4141
const BasicAuth = ({
4242
handleAuthenticate,
4343
authenticator,
44+
children,
4445
alert,
4546
brandingProps,
4647
showSelfSignUp,
4748
renderLoginOptions,
48-
}: BasicAuthProps): ReactElement => {
49+
}: PropsWithChildren<BasicAuthProps>): ReactElement => {
4950
const [password, setPassword] = useState<string>('');
5051

5152
const {isAuthLoading, username, setUsername} = useContext(AsgardeoContext);
@@ -102,6 +103,8 @@ const BasicAuth = ({
102103
onChange={(e: React.ChangeEvent<HTMLInputElement>): void => setPassword(e.target.value)}
103104
/>
104105

106+
{children}
107+
105108
<UISignIn.Button
106109
color="primary"
107110
variant="contained"

packages/react/src/components/SignIn/fragments/EmailOtp.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import {ScreenType, keys} from '@asgardeo/js';
2020
import {CircularProgress, Skeleton} from '@oxygen-ui/react';
21-
import {ReactElement, useContext, useState} from 'react';
21+
import {PropsWithChildren, ReactElement, useContext, useState} from 'react';
2222
import AsgardeoContext from '../../../contexts/asgardeo-context';
2323
import useTranslations from '../../../hooks/use-translations';
2424
import EmailOtpProps from '../../../models/email-otp-props';
@@ -35,7 +35,7 @@ import './email-otp.scss';
3535
* @param {AlertType} props.alert - Alert type.
3636
* @return {ReactElement}
3737
*/
38-
const EmailOtp = ({alert, brandingProps, authenticator, handleAuthenticate}: EmailOtpProps): ReactElement => {
38+
const EmailOtp = ({alert, brandingProps, authenticator, children, handleAuthenticate}: PropsWithChildren<EmailOtpProps>): ReactElement => {
3939
const [inputValue, setInputValue] = useState<string>();
4040
const [isContinueLoading, setIsContinueLoading] = useState<boolean>(false);
4141
const [isResendLoading, setIsResendLoading] = useState<boolean>(false);
@@ -90,6 +90,8 @@ const EmailOtp = ({alert, brandingProps, authenticator, handleAuthenticate}: Ema
9090
onChange={(e: React.ChangeEvent<HTMLInputElement>): void => setInputValue(e.target.value)}
9191
/>
9292

93+
{ children }
94+
9395
<UISignIn.Button
9496
fullWidth
9597
variant="contained"

packages/react/src/components/SignIn/fragments/IdentifierFirst.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import {ScreenType, keys} from '@asgardeo/js';
2020
import {CircularProgress, Grid, Skeleton} from '@oxygen-ui/react';
21-
import {ReactElement, useContext, useState} from 'react';
21+
import {PropsWithChildren, ReactElement, useContext, useState} from 'react';
2222
import AsgardeoContext from '../../../contexts/asgardeo-context';
2323
import useTranslations from '../../../hooks/use-translations';
2424
import BasicAuthProps from '../../../models/basic-auth-props';
@@ -43,9 +43,10 @@ const IdentifierFirst = ({
4343
authenticator,
4444
alert,
4545
brandingProps,
46+
children,
4647
showSelfSignUp,
4748
renderLoginOptions,
48-
}: BasicAuthProps): ReactElement => {
49+
}: PropsWithChildren<BasicAuthProps>): ReactElement => {
4950
const {isAuthLoading, username, setUsername} = useContext(AsgardeoContext);
5051

5152
const {t, isLoading} = useTranslations({
@@ -89,6 +90,8 @@ const IdentifierFirst = ({
8990
onChange={(e: React.ChangeEvent<HTMLInputElement>): void => setUsername(e.target.value)}
9091
/>
9192

93+
{children}
94+
9295
<UISignIn.Button
9396
color="primary"
9497
variant="contained"

packages/react/src/components/SignIn/fragments/SmsOtp.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@
1818

1919
import {ScreenType, keys} from '@asgardeo/js';
2020
import {CircularProgress} from '@oxygen-ui/react';
21-
import {ReactElement, useState} from 'react';
21+
import {PropsWithChildren, ReactElement, useState} from 'react';
2222
import useTranslations from '../../../hooks/use-translations';
2323
import EmailOtpProps from '../../../models/email-otp-props';
2424
import {SignIn as UISignIn} from '../../../oxygen-ui-react-auth-components';
2525

26-
const SmsOtp = ({alert, brandingProps, authenticator, handleAuthenticate}: EmailOtpProps): ReactElement => {
26+
const SmsOtp = ({
27+
alert,
28+
brandingProps,
29+
authenticator,
30+
children,
31+
handleAuthenticate,
32+
}: PropsWithChildren<EmailOtpProps>): ReactElement => {
2733
const [otp, setOtp] = useState<string>();
2834

2935
const {isLoading, t} = useTranslations({
@@ -50,6 +56,8 @@ const SmsOtp = ({alert, brandingProps, authenticator, handleAuthenticate}: Email
5056

5157
<UISignIn.PinInput length={6} onPinChange={setOtp} />
5258

59+
{children}
60+
5361
<UISignIn.Button
5462
fullWidth
5563
variant="contained"

packages/react/src/components/SignIn/fragments/Totp.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import {ScreenType, keys} from '@asgardeo/js';
2020
import {CircularProgress, Grid, Skeleton} from '@oxygen-ui/react';
21-
import {useState, ReactElement, useContext} from 'react';
21+
import {useState, ReactElement, useContext, PropsWithChildren} from 'react';
2222
import AsgardeoContext from '../../../contexts/asgardeo-context';
2323
import useTranslations from '../../../hooks/use-translations';
2424
import TotpProps from '../../../models/totp-props';
@@ -36,7 +36,13 @@ import './totp.scss';
3636
*
3737
* @return {ReactElement}
3838
*/
39-
const Totp = ({brandingProps, authenticator, handleAuthenticate, alert}: TotpProps): ReactElement => {
39+
const Totp = ({
40+
brandingProps,
41+
authenticator,
42+
children,
43+
handleAuthenticate,
44+
alert,
45+
}: PropsWithChildren<TotpProps>): ReactElement => {
4046
const [totp, setTotp] = useState<string>();
4147

4248
const {isAuthLoading} = useContext(AsgardeoContext);
@@ -79,6 +85,8 @@ const Totp = ({brandingProps, authenticator, handleAuthenticate, alert}: TotpPro
7985

8086
<UISignIn.PinInput length={6} onPinChange={setTotp} pinValue={totp} />
8187

88+
{children}
89+
8290
<UISignIn.Button
8391
color="primary"
8492
variant="contained"

packages/react/src/models/sign-in.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ import {BrandingProps} from '@asgardeo/js';
2020
import {ReactElement} from 'react';
2121

2222
export interface SignInProps {
23+
basicAuthChildren?: ReactElement;
2324
brandingProps?: BrandingProps;
25+
emailOtpChildren?: ReactElement;
26+
identifierFirstChildren?: ReactElement;
2427
showFooter?: boolean;
2528
showLogo?: boolean;
2629
showSignUp?: boolean;
30+
smsOtpChildren?: ReactElement;
31+
totpChildren?: ReactElement;
2732
}
2833

2934
export type AlertType = {

0 commit comments

Comments
 (0)