Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
feat(RegisterPage): add RegisterPage component
Browse files Browse the repository at this point in the history
  • Loading branch information
jonthomp committed May 28, 2018
1 parent b418d1a commit 06f5d02
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 25 deletions.
27 changes: 2 additions & 25 deletions example/src/pages/RegisterPage.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,12 @@

import * as React from "react";

import {
FormCard,
FormTextInput,
FormCheckboxInput,
StandaloneFormPage,
} from "tabler-react";
import { RegisterPage as TablerRegisterPage } from "tabler-react";

type Props = {||};

function RegisterPage(props: Props): React.Node {
return (
<StandaloneFormPage>
<FormCard
action=""
buttonText="Create Account"
method="get"
title="Create New Account"
>
<FormTextInput label="Name" placeHolder="Enter name" />
<FormTextInput label="Email Address" placeHolder="Enter email" />
<FormTextInput
type="password"
label="Password"
placeHolder="Password"
/>
<FormCheckboxInput label="Agree to the terms and policy" />
</FormCard>
</StandaloneFormPage>
);
return <TablerRegisterPage />;
}

export default RegisterPage;
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ export { default as FormTextInput } from "./forms/FormTextInput.react";
export { default as FormCheckboxInput } from "./forms/FormCheckboxInput.react";
export { default as colors } from "./colors";
export { default as LoginPage } from "./page_templates/account/LoginPage";
export { default as RegisterPage } from "./page_templates/account/RegisterPage";
117 changes: 117 additions & 0 deletions src/page_templates/account/RegisterPage/RegisterPage.react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// @flow

import * as React from "react";

import {
FormCard,
FormTextInput,
FormCheckboxInput,
StandaloneFormPage,
} from "../../../";
import withTouchedErrors from "../../../helpers/withTouchedErrors.react";

import defaultStrings from "./RegisterPage.strings";
import type { stringTypes } from "./RegisterPage.strings";

type fieldTypes = {|
name?: string,
email?: string,
password?: string,
terms?: string,
|};

type touchedTypes = {|
name?: boolean,
email?: boolean,
password?: boolean,
terms?: string,
|};

type Props = {|
+strings?: stringTypes,
+action?: string,
+method?: string,
+onSubmit?: Function,
+onChange?: (SyntheticInputEvent<HTMLInputElement>) => void,
+onBlur?: (SyntheticInputEvent<HTMLInputElement>) => void,
+values?: fieldTypes,
+errors?: fieldTypes,
+touched?: touchedTypes,
|};

/**
* A register page
* Can be easily wrapped with form libraries like formik and redux-form
*/
function RegisterPage(props: Props): React.Node {
const {
action,
method,
onSubmit,
onChange,
onBlur,
values,
strings = {},
errors,
} = props;

return (
<StandaloneFormPage>
<FormCard
buttonText={strings.buttonText || defaultStrings.buttonText}
title={strings.title || defaultStrings.title}
onSubmit={onSubmit}
action={action}
method={method}
>
<FormTextInput
name="name"
label={strings.nameLabel || defaultStrings.nameLabel}
placeholder={
strings.namePlaceholder || defaultStrings.namePlaceholder
}
onChange={onChange}
onBlur={onBlur}
value={values && values.name}
error={errors && errors.name}
/>
<FormTextInput
name="email"
label={strings.emailLabel || defaultStrings.emailLabel}
placeholder={
strings.emailPlaceholder || defaultStrings.emailPlaceholder
}
onChange={onChange}
onBlur={onBlur}
value={values && values.email}
error={errors && errors.email}
/>
<FormTextInput
name="password"
type="password"
label={strings.passwordLabel || defaultStrings.passwordLabel}
placeholder={
strings.passwordPlaceholder || defaultStrings.passwordPlaceholder
}
onChange={onChange}
onBlur={onBlur}
value={values && values.password}
error={errors && errors.password}
/>
<FormCheckboxInput
onChange={onChange}
onBlur={onBlur}
value={values && values.terms}
name="terms"
label={strings.termsLabel || defaultStrings.termsLabel}
/>
</FormCard>
</StandaloneFormPage>
);
}

const RegisterPageWithTouchedErrors: React.ComponentType<
Props
> = withTouchedErrors(["name", "email", "password", "terms"])(RegisterPage);

export default RegisterPageWithTouchedErrors;
16 changes: 16 additions & 0 deletions src/page_templates/account/RegisterPage/RegisterPage.strings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@flow
const strings = {
title: "Create New Account",
buttonText: "Create Account",
nameLabel: "Name",
namePlaceholder: "Enter name",
emailLabel: "Email Address",
emailPlaceholder: "Enter email",
passwordLabel: "Password",
passwordPlaceholder: "Password",
termsLabel: "Agree to the terms and policy",
};

export default strings;

export type stringTypes = { [$Keys<typeof strings>]: string };
3 changes: 3 additions & 0 deletions src/page_templates/account/RegisterPage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import RegisterPage from "./RegisterPage.react";

export default RegisterPage;

0 comments on commit 06f5d02

Please sign in to comment.