render()

in packages/aws-amplify-react/src/Auth/Authenticator.tsx [221:339]


	render() {
		const { authState, authData } = this.state;
		const theme = this.props.theme || AmplifyTheme;
		const messageMap = this.props.errorMessage || AmplifyMessageMap;
		// If container prop is undefined, default to AWS Amplify UI Container
		// otherwise if truthy, use the supplied render prop
		// otherwise if falsey, use EmptyContainer
		const Wrapper =
			this.props.container === undefined
				? Container
				: this.props.container || EmptyContainer;

		let {
			hideDefault,
			hide = [],
			federated,
			signUpConfig,
			usernameAttributes,
		} = this.props;
		if (hideDefault) {
			hide = hide.concat([
				Greetings,
				SignIn,
				ConfirmSignIn,
				RequireNewPassword,
				SignUp,
				ConfirmSignUp,
				VerifyContact,
				ForgotPassword,
				TOTPSetup,
				Loading,
			]);
		}

		let props_children = [];
		if (typeof this.props.children === 'object') {
			if (Array.isArray(this.props.children)) {
				props_children = this.props.children;
			} else {
				props_children.push(this.props.children);
			}
		}

		const default_children = [
			<Greetings federated={federated} />,
			<SignIn federated={federated} />,
			<ConfirmSignIn />,
			<RequireNewPassword />,
			<SignUp signUpConfig={signUpConfig} />,
			<ConfirmSignUp />,
			<VerifyContact />,
			<ForgotPassword />,
			<TOTPSetup />,
			<Loading />,
		];

		const props_children_override = React.Children.map(
			props_children,
			child => child.props.override
		);
		hide = hide.filter(
			component => !props_children.find(child => child.type === component)
		);

		const render_props_children = React.Children.map(
			props_children,
			(child, index) => {
				return React.cloneElement(child, {
					key: 'aws-amplify-authenticator-props-children-' + index,
					theme,
					messageMap,
					authState,
					authData,
					onStateChange: this.handleStateChange,
					onAuthEvent: this.handleAuthEvent,
					hide,
					override: props_children_override,
					usernameAttributes,
				});
			}
		);

		const render_default_children = hideDefault
			? []
			: React.Children.map(default_children, (child, index) => {
					return React.cloneElement(child, {
						key: 'aws-amplify-authenticator-default-children-' + index,
						theme,
						messageMap,
						authState,
						authData,
						onStateChange: this.handleStateChange,
						onAuthEvent: this.handleAuthEvent,
						hide,
						override: props_children_override,
						usernameAttributes,
					});
			  });

		const render_children = render_default_children.concat(
			render_props_children
		);
		const error = this.state.error;

		return (
			<Wrapper theme={theme}>
				{this.state.showToast && (
					<Toast
						theme={theme}
						onClose={() => this.setState({ showToast: false })}
						data-test={auth.signIn.signInError}
					>
						{I18n.get(error)}
					</Toast>
				)}
				{render_children}
			</Wrapper>
		);
	}