accounts-frontend/packages/app/components/auth/factory.tsx

51 lines
1.3 KiB
TypeScript
Raw Normal View History

import React, { ComponentProps, ComponentType } from 'react';
import { Button } from 'app/components/ui/form';
import RejectionLink from 'app/components/auth/RejectionLink';
import AuthTitle from 'app/components/auth/AuthTitle';
2019-12-07 16:58:52 +05:30
import { MessageDescriptor } from 'react-intl';
import { Color } from 'app/components/ui';
import BaseAuthBody from './BaseAuthBody';
2019-12-07 16:58:52 +05:30
export type Factory = () => {
Title: ComponentType;
Body: typeof BaseAuthBody;
Footer: ComponentType;
Links: ComponentType;
};
type RejectionLinkProps = ComponentProps<typeof RejectionLink>;
interface FactoryParams {
2019-12-07 16:58:52 +05:30
title: MessageDescriptor;
body: typeof BaseAuthBody;
2019-12-07 16:58:52 +05:30
footer: {
color?: Color;
label: string | MessageDescriptor;
autoFocus?: boolean;
};
links?: RejectionLinkProps | Array<RejectionLinkProps>;
}
export default function ({
title,
body,
footer,
links,
}: FactoryParams): Factory {
2019-12-07 16:58:52 +05:30
return () => ({
Title: () => <AuthTitle title={title} />,
Body: body,
Footer: () => <Button type="submit" {...footer} />,
Links: () =>
links ? (
<span>
{([] as Array<RejectionLinkProps>)
2019-12-07 16:58:52 +05:30
.concat(links)
.map((link, index) => [
index ? ' | ' : '',
<RejectionLink {...link} key={index} />,
])}
</span>
) : null,
});
}