-
Notifications
You must be signed in to change notification settings - Fork 937
refactor: Add components for styling forms #1169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,29 @@ | ||
import { ComponentMeta, Story } from "@storybook/react" | ||
import React from "react" | ||
import { FormFooter, FormFooterProps } from "./FormFooter" | ||
|
||
export default { | ||
title: "components/FormFooter", | ||
component: FormFooter, | ||
argTypes: { | ||
onCancel: { action: "cancel" }, | ||
}, | ||
} as ComponentMeta<typeof FormFooter> | ||
|
||
const Template: Story<FormFooterProps> = (args) => <FormFooter {...args} /> | ||
|
||
export const Ready = Template.bind({}) | ||
Ready.args = { | ||
isLoading: false, | ||
} | ||
|
||
export const Custom = Template.bind({}) | ||
Custom.args = { | ||
isLoading: false, | ||
submitLabel: "Create", | ||
} | ||
|
||
export const Loading = Template.bind({}) | ||
Loading.args = { | ||
isLoading: true, | ||
} |
This file contains hidden or 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,46 @@ | ||
import Button from "@material-ui/core/Button" | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import React from "react" | ||
import { LoadingButton } from "../LoadingButton/LoadingButton" | ||
|
||
const Language = { | ||
cancelLabel: "Cancel", | ||
defaultSubmitLabel: "Submit", | ||
} | ||
|
||
export interface FormFooterProps { | ||
onCancel: () => void | ||
isLoading: boolean | ||
submitLabel?: string | ||
} | ||
|
||
const useStyles = makeStyles(() => ({ | ||
footer: { | ||
display: "flex", | ||
flex: "0", | ||
flexDirection: "row", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}, | ||
button: { | ||
margin: "1em", | ||
}, | ||
})) | ||
|
||
export const FormFooter: React.FC<FormFooterProps> = ({ | ||
onCancel, | ||
isLoading, | ||
submitLabel = Language.defaultSubmitLabel, | ||
}) => { | ||
const styles = useStyles() | ||
return ( | ||
<div className={styles.footer}> | ||
<Button className={styles.button} onClick={onCancel} variant="outlined"> | ||
{Language.cancelLabel} | ||
</Button> | ||
<LoadingButton loading={isLoading} className={styles.button} variant="contained" color="primary" type="submit"> | ||
{submitLabel} | ||
</LoadingButton> | ||
</div> | ||
) | ||
} |
This file contains hidden or 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,35 @@ | ||
import TextField from "@material-ui/core/TextField" | ||
import { action } from "@storybook/addon-actions" | ||
import { ComponentMeta, Story } from "@storybook/react" | ||
import React from "react" | ||
import { FormFooter } from "../FormFooter/FormFooter" | ||
import { Stack } from "../Stack/Stack" | ||
import { FullPageForm, FullPageFormProps } from "./FullPageForm" | ||
|
||
export default { | ||
title: "components/FullPageForm", | ||
component: FullPageForm, | ||
} as ComponentMeta<typeof FullPageForm> | ||
|
||
const Template: Story<FullPageFormProps> = (args) => ( | ||
<FullPageForm {...args}> | ||
<form | ||
onSubmit={(e) => { | ||
e.preventDefault() | ||
}} | ||
> | ||
<Stack> | ||
<TextField fullWidth variant="outlined" label="Field 1" name="field1" /> | ||
<TextField fullWidth variant="outlined" label="Field 2" name="field2" /> | ||
<FormFooter isLoading={false} onCancel={action("cancel")} /> | ||
</Stack> | ||
</form> | ||
</FullPageForm> | ||
) | ||
|
||
export const Example = Template.bind({}) | ||
Example.args = { | ||
title: "My Form", | ||
detail: "Lorem ipsum dolor", | ||
onCancel: action("cancel"), | ||
} |
This file contains hidden or 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,32 @@ | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import React from "react" | ||
import { FormCloseButton } from "../FormCloseButton/FormCloseButton" | ||
import { FormTitle } from "../FormTitle/FormTitle" | ||
|
||
export interface FullPageFormProps { | ||
title: string | ||
detail?: React.ReactNode | ||
onCancel: () => void | ||
} | ||
|
||
const useStyles = makeStyles(() => ({ | ||
root: { | ||
maxWidth: "1380px", | ||
width: "100%", | ||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "center", | ||
}, | ||
})) | ||
|
||
export const FullPageForm: React.FC<FullPageFormProps> = ({ title, detail, onCancel, children }) => { | ||
const styles = useStyles() | ||
return ( | ||
<main className={styles.root}> | ||
<FormTitle title={title} detail={detail} /> | ||
<FormCloseButton onClose={onCancel} /> | ||
|
||
{children} | ||
</main> | ||
) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to read up again to remind myself what exactly is considered as a
ReactNode
source
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsjoeio do you think it's the wrong type? I took it from
FormTitle
which is where this ends up but I could change it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no, sorry, I think it's right. It just surprised me, that's all. I thought
detail
might have been astring
when I first saw the component. Whatever you think is best!