This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 551
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ProfileFormCard): add ProfileFormCard
A Card containing a form designed form profile data
- Loading branch information
Showing
4 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// @flow | ||
|
||
import * as React from "react"; | ||
|
||
import Form from "../../components/Form"; | ||
import Card from "../../components/Card"; | ||
import Button from "../../components/Button"; | ||
import Grid from "../../components/Grid"; | ||
import Avatar from "../../components/Avatar"; | ||
|
||
import defaultStrings from "./ProfileFormCard.strings"; | ||
import type { stringTypes } from "./ProfileFormCard.strings"; | ||
|
||
import withTouchedErrors from "../../helpers/withTouchedErrors.react"; | ||
|
||
type fieldTypes = {| | ||
name?: string, | ||
bio?: string, | ||
email?: string, | ||
password?: string, | ||
|}; | ||
|
||
type touchedTypes = {| | ||
name?: boolean, | ||
bio?: boolean, | ||
email?: boolean, | ||
password?: boolean, | ||
|}; | ||
|
||
export type Props = {| | ||
+strings?: stringTypes, | ||
+action?: string, | ||
+method?: string, | ||
+onSubmit?: Function, | ||
+onChange?: ( | ||
SyntheticInputEvent<HTMLInputElement | HTMLTextAreaElement> | ||
) => void, | ||
+onBlur?: ( | ||
SyntheticInputEvent<HTMLInputElement | HTMLTextAreaElement> | ||
) => void, | ||
+values?: fieldTypes, | ||
+errors?: fieldTypes, | ||
+touched?: touchedTypes, | ||
+avatarURL?: string, | ||
|}; | ||
|
||
function ProfileFormCard(props: Props): React.Node { | ||
const { | ||
action, | ||
method, | ||
onSubmit, | ||
onChange, | ||
onBlur, | ||
values, | ||
errors, | ||
avatarURL, | ||
} = props; | ||
|
||
const strings: stringTypes = Object.assign({}, defaultStrings, props.strings); | ||
|
||
return ( | ||
<Card> | ||
<Card.Header> | ||
<Card.Title>{strings.title}</Card.Title> | ||
</Card.Header> | ||
<Card.Body> | ||
<Form action={action} method={method} onSubmit={onSubmit}> | ||
<Grid.Row> | ||
<Grid.Col auto> | ||
<Avatar size="xl" imageURL={avatarURL} /> | ||
</Grid.Col> | ||
<Grid.Col> | ||
<Form.Group> | ||
<Form.Label>{strings.nameLabel}</Form.Label> | ||
<Form.Input | ||
name="name" | ||
placeholder={strings.namePlaceholder} | ||
onChange={onChange} | ||
onBlur={onBlur} | ||
value={values && values.name} | ||
error={errors && errors.name} | ||
/> | ||
</Form.Group> | ||
</Grid.Col> | ||
</Grid.Row> | ||
<Form.Group> | ||
<Form.Label>{strings.bioLabel}</Form.Label> | ||
<Form.Textarea | ||
rows={5} | ||
name="bio" | ||
placeholder={strings.bioPlaceholder} | ||
onChange={onChange} | ||
onBlur={onBlur} | ||
value={values && values.bio} | ||
error={errors && errors.bio} | ||
/> | ||
</Form.Group> | ||
<Form.Group> | ||
<Form.Label>{strings.emailLabel}</Form.Label> | ||
<Form.Input | ||
name="email" | ||
placeholder={strings.emailPlaceholder} | ||
onChange={onChange} | ||
onBlur={onBlur} | ||
value={values && values.email} | ||
error={errors && errors.email} | ||
/> | ||
</Form.Group> | ||
<Form.Group> | ||
<Form.Label>{strings.passwordLabel}</Form.Label> | ||
<Form.Input | ||
type="password" | ||
name="password" | ||
placeholder={strings.passwordPlaceholder} | ||
onChange={onChange} | ||
onBlur={onBlur} | ||
value={values && values.password} | ||
error={errors && errors.password} | ||
/> | ||
</Form.Group> | ||
<Form.Footer> | ||
<Button type="submit" color="primary" block> | ||
{strings.buttonText} | ||
</Button> | ||
</Form.Footer> | ||
</Form> | ||
</Card.Body> | ||
</Card> | ||
); | ||
} | ||
const ProfileFormCardWithTouchedErrors: React.ComponentType< | ||
Props | ||
> = withTouchedErrors(["name", "bio", "email", "password"])(ProfileFormCard); | ||
|
||
export default ProfileFormCardWithTouchedErrors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//@flow | ||
const strings = { | ||
title: "My Profile", | ||
nameLabel: "Name", | ||
namePlaceholder: "Your name", | ||
bioLabel: "Bio", | ||
bioPlaceholder: "Say something about yourself", | ||
emailLabel: "Email", | ||
emailPlaceholder: "your-email@example.com", | ||
passwordLabel: "Password", | ||
passwordPlaceholder: "password", | ||
buttonText: "Save", | ||
}; | ||
|
||
export default strings; | ||
|
||
export type stringTypes = { [$Keys<typeof strings>]: string }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ProfileFormCard from "./ProfileFormCard.react"; | ||
|
||
export default ProfileFormCard; |