Skip to content

Commit 6877b8c

Browse files
authored
docs: Revamp GridForm docs
Adds new GridForm documentation for the fields available and breaks up the docs based on categories
1 parent 59a2eaa commit 6877b8c

File tree

17 files changed

+1680
-1654
lines changed

17 files changed

+1680
-1654
lines changed

packages/styleguide/src/lib/Meta/About.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { parameters as bestPracticesParameters } from './Best Practices.mdx';
1010
import { parameters as brandParameters } from './Brand.mdx';
1111
import { parameters as contributingParameters } from './Contributing.mdx';
12+
import { parameters as deepControlsParameters } from './Deep Controls Add-On.mdx';
1213
import { parameters as faqsParameters } from './FAQs.mdx';
1314
import { parameters as installationParameters } from './Installation.mdx';
1415
import { parameters as storiesParameters } from './Stories.mdx';
@@ -29,6 +30,7 @@ export const parameters = {
2930
links={addParentPath(parameters.id, [
3031
bestPracticesParameters,
3132
contributingParameters,
33+
deepControlsParameters,
3234
faqsParameters,
3335
storiesParameters,
3436
brandParameters,

packages/styleguide/src/lib/Meta/Deep Controls Add-On.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import { Meta } from '@storybook/blocks';
22

33
import { Callout, ImageWrapper, LinkTo } from '~styleguide/blocks';
44

5+
export const parameters = {
6+
id: 'Deep Controls Add-On',
7+
title: 'Deep Controls Add-On',
8+
subtitle: `Enables Storybook controls for nested component properties, allowing you to interactively modify deeply nested props directly from the Controls panel without having to manually edit complex object structures.`,
9+
status: 'static',
10+
};
11+
512
<Meta title="Meta/Deep Controls add-on" />
613

714
# Deep Controls add-on

packages/styleguide/src/lib/Organisms/About.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '~styleguide/blocks';
88

99
import { parameters as connectedFormParameters } from './ConnectedForm/About.mdx';
10-
import { parameters as gridFormParameters } from './GridForm/GridForm.mdx';
10+
import { parameters as gridFormParameters } from './GridForm/About.mdx';
1111
import { parameters as listsTablesParameters } from './Lists & Tables/About.mdx';
1212
import { parameters as markdownParameters } from './Markdown/Markdown.mdx';
1313

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Meta } from '@storybook/blocks';
2+
3+
import {
4+
AboutHeader,
5+
addParentPath,
6+
LinkTo,
7+
TableOfContents,
8+
} from '~styleguide/blocks';
9+
10+
import { parameters as buttonsParameters } from './Buttons.mdx';
11+
import { parameters as fieldsParameters } from './Fields.mdx';
12+
import { parameters as layoutParameters } from './Layout.mdx';
13+
import { parameters as statesParameters } from './States.mdx';
14+
import { parameters as usageParameters } from './Usage.mdx';
15+
import { parameters as validationParameters } from './Validation.mdx';
16+
17+
export const parameters = {
18+
id: 'Organisms/GridForm',
19+
title: 'GridForm',
20+
subtitle: 'An efficient way to build and design forms on a grid.',
21+
};
22+
23+
<Meta title="Organisms/GridForm/About" />
24+
25+
<AboutHeader {...parameters} />
26+
27+
## Getting started
28+
29+
If you're new to `GridForm`, start with <LinkTo id="Organisms/GridForm/Usage">Usage</LinkTo> to see an overview of how `GridForm` works and interact with a live playground.
30+
31+
All other pages below provide guidance on specific parts of `GridForm`.
32+
33+
<TableOfContents
34+
links={addParentPath(parameters.id, [
35+
usageParameters,
36+
fieldsParameters,
37+
buttonsParameters,
38+
validationParameters,
39+
layoutParameters,
40+
statesParameters,
41+
])}
42+
/>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { Canvas, Meta } from '@storybook/blocks';
2+
3+
import { ComponentHeader, LinkTo } from '~styleguide/blocks';
4+
5+
import * as ButtonsStories from './Buttons.stories';
6+
7+
export const parameters = {
8+
title: 'Buttons',
9+
subtitle: 'Configure submit and cancel buttons for your forms.',
10+
status: 'static',
11+
};
12+
13+
<Meta title="Organisms/GridForm/Buttons" />
14+
15+
<ComponentHeader {...parameters} />
16+
17+
## Submit button position
18+
19+
We can position the submit button by passing the `position` prop within `submit` with a
20+
value of `'left'`, `'center'`, `'right'`, or `'stretch'`. The default is `'left'`.
21+
22+
<Canvas of={ButtonsStories.SubmitButtonRight} />
23+
24+
<Canvas of={ButtonsStories.SubmitButtonLeft} />
25+
26+
<Canvas of={ButtonsStories.SubmitButtonCenter} />
27+
28+
<Canvas of={ButtonsStories.SubmitButtonStretch} />
29+
30+
## Submit button type
31+
32+
We can specify the type submit button by passing the `type` prop within `submit`. We can choose between
33+
the <LinkTo id="atoms-button--fill-button">`FillButton`</LinkTo> or <LinkTo id="atoms-button--cta-button">`CTAButton`</LinkTo>. The default is `'fill'`.
34+
35+
<Canvas of={ButtonsStories.SubmitButtonFill} />
36+
37+
<Canvas of={ButtonsStories.SubmitButtonCTA} />
38+
39+
## Inline submit button
40+
41+
We can make the Submit button inline with an input by setting the column
42+
sizes so they fit on the same row (e.g size 6 for an input and size 4 for
43+
the submit).
44+
45+
We can additionally remove the label from text inputs and checkbox inputs.
46+
Use the `hideLabel` prop to remove the label, allowing the submit button to
47+
align nicely with the input. **However**, if using `hideLabel` to remove the default label, you should provide an `aria-label` and/or include another label to the right/left of the input to ensure the input is accessible.
48+
49+
<Canvas of={ButtonsStories.SubmitButtonInline} />
50+
51+
## Cancel button
52+
53+
Optionally, include a cancel button.
54+
55+
<Canvas of={ButtonsStories.CancelButton} />
56+
57+
## Button states
58+
59+
### Loading
60+
61+
We can set the state of the submit button to `loading` as `true` to show a loading spinner. This is useful when you need to show the user that the form is submitting.
62+
63+
<Canvas of={ButtonsStories.Loading} />
64+
65+
### Disabled
66+
67+
You can also set `disabled` to `true` to disable submission.
68+
69+
<Canvas of={ButtonsStories.Disabled} />
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import { GridForm } from '@codecademy/gamut';
2+
import { action } from '@storybook/addon-actions';
3+
import type { Meta, StoryObj } from '@storybook/react';
4+
5+
const meta: Meta<typeof GridForm> = {
6+
component: GridForm,
7+
args: {
8+
onSubmit: (values) => {
9+
action('Form Submitted')(values);
10+
// eslint-disable-next-line no-console
11+
console.log('Form Submitted', values);
12+
},
13+
fields: [
14+
{
15+
label: 'Simple text',
16+
name: 'simple-text',
17+
type: 'text',
18+
size: 12,
19+
},
20+
],
21+
},
22+
};
23+
24+
export default meta;
25+
type Story = StoryObj<typeof GridForm>;
26+
27+
export const SubmitButtonRight: Story = {
28+
args: {
29+
submit: {
30+
contents: 'Right Submit!?',
31+
position: 'right',
32+
size: 12,
33+
},
34+
},
35+
};
36+
37+
export const SubmitButtonLeft: Story = {
38+
args: {
39+
submit: {
40+
contents: 'Left Submit!?',
41+
position: 'left',
42+
size: 12,
43+
},
44+
},
45+
};
46+
47+
export const SubmitButtonCenter: Story = {
48+
args: {
49+
submit: {
50+
contents: 'Center Submit!?',
51+
position: 'center',
52+
size: 12,
53+
},
54+
},
55+
};
56+
57+
export const SubmitButtonStretch: Story = {
58+
args: {
59+
submit: {
60+
contents: 'Stretch Submit!?',
61+
position: 'stretch',
62+
size: 12,
63+
},
64+
},
65+
};
66+
67+
export const SubmitButtonFill: Story = {
68+
args: {
69+
submit: {
70+
contents: 'Fill Submit!?',
71+
type: 'fill',
72+
size: 12,
73+
},
74+
},
75+
};
76+
77+
export const SubmitButtonCTA: Story = {
78+
args: {
79+
submit: {
80+
contents: 'CTA Submit!?',
81+
type: 'cta',
82+
size: 12,
83+
},
84+
},
85+
};
86+
87+
export const SubmitButtonInline: Story = {
88+
args: {
89+
fields: [
90+
{
91+
label: 'Simple text',
92+
name: 'simple-text',
93+
type: 'text',
94+
size: 6,
95+
},
96+
],
97+
submit: {
98+
contents: 'Inline Submit!?',
99+
size: 4,
100+
position: 'right',
101+
},
102+
},
103+
};
104+
105+
export const CancelButton: Story = {
106+
args: {
107+
cancel: {
108+
children: 'Cancel',
109+
onClick: () => {},
110+
},
111+
submit: {
112+
contents: 'Submit!?',
113+
position: 'right',
114+
size: 12,
115+
},
116+
},
117+
};
118+
119+
export const Loading: Story = {
120+
args: {
121+
submit: {
122+
contents: 'Loading Submit!?',
123+
loading: true,
124+
size: 12,
125+
},
126+
},
127+
};
128+
129+
export const Disabled: Story = {
130+
args: {
131+
submit: {
132+
contents: 'Disabled Submit!?',
133+
disabled: true,
134+
size: 12,
135+
},
136+
},
137+
};
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { Canvas, Meta } from '@storybook/blocks';
2+
3+
import { ComponentHeader } from '~styleguide/blocks';
4+
5+
import * as FieldsStories from './Fields.stories';
6+
7+
export const parameters = {
8+
title: 'Fields',
9+
subtitle: 'Comprehensive GridForm field types to cover various input needs.',
10+
status: 'static',
11+
};
12+
13+
<Meta title="Organisms/GridForm/Fields" />
14+
15+
<ComponentHeader {...parameters} />
16+
17+
## Text inputs
18+
19+
Text inputs support various HTML input types including `text`, `email`, `password`, `number`, `tel`, `url`, `search`, `date`, `time`, and more. All text inputs share the same basic properties but may have different validation patterns.
20+
21+
<Canvas of={FieldsStories.TextField} />
22+
23+
### Default value
24+
25+
<Canvas of={FieldsStories.DefaultTextField} />
26+
27+
### Placeholder text
28+
29+
Text inputs are allowed to have traditional `placeholder` text.
30+
This is a somewhat dangerous behavior for accessibility, as browsers
31+
generally don't render placeholder text with high enough color contrast
32+
for AA standards. If you do need to use placeholder text, such as on
33+
landing page forms that have been shown to have higher completion rates
34+
with the text, please make sure the placeholder text doesn't add any new
35+
information to the form — it should really only rephrase the text label.
36+
37+
See [this article](https://www.nngroup.com/articles/form-design-placeholders/) for
38+
more details on why using placeholders is often bad.
39+
40+
<Canvas of={FieldsStories.PlaceholderTextField} />
41+
42+
## Textarea input
43+
44+
<Canvas of={FieldsStories.TextareaField} />
45+
46+
## Select input
47+
48+
<Canvas of={FieldsStories.SelectField} />
49+
50+
## Radio group input
51+
52+
<Canvas of={FieldsStories.RadioGroupField} />
53+
54+
## File upload input
55+
56+
File upload fields allow users to select and upload files. You can add custom validation to restrict file types and sizes.
57+
58+
<Canvas of={FieldsStories.FileUploadField} />
59+
60+
## Checkbox input
61+
62+
<Canvas of={FieldsStories.CheckboxField} />
63+
64+
### Spacing
65+
66+
Checkboxes can use tight spacing when you need them to fit in smaller areas:
67+
68+
<Canvas of={FieldsStories.CheckboxSpacing} />
69+
70+
## Nested checkboxes input
71+
72+
Nested checkboxes allow for hierarchical selection with parent-child relationships between options. Infinite levels of nesting are supported. Clicking a parent checkbox toggles all its children accordingly. Individual child checkboxes can be toggled independently. Checkbox states are `checked` if all children are checked, `indeterminate` if some children are checked, or `unchecked` if no children are checked. The values returned by the form on submit or update are an array of all selected values, including all children.
73+
74+
<Canvas of={FieldsStories.NestedCheckboxesField} />
75+
76+
## Custom inputs
77+
78+
Some forms, such as the checkout flows that use Recurly, need to define
79+
their own inputs. We can specify a `'custom'` field type along with a [`render` prop](https://reactjs.org/docs/render-props.html).
80+
81+
We also have a `'custom-group'` type for when you are passing in a custom `FormGroup` - including a label. If you do not want `GridForm` to surface errors for your field, you should likely use a `'custom-group'`. If you chose to go this route, please be aware of [accessibility best practices](https://www.deque.com/blog/anatomy-of-accessible-forms-best-practices/) for forms.
82+
83+
<Canvas of={FieldsStories.CustomInputs} />
84+
85+
## Hidden input
86+
87+
Hidden inputs can be used to include data that users can't see or modify with the submission. For this implementation you can set the `defaultValue` in the object and it will be submitted with the regular form data.
88+
89+
<Canvas of={FieldsStories.HiddenInput} />
90+
91+
## Sweet container input
92+
93+
"Sweet container" ([honeypot](<https://en.wikipedia.org/wiki/Honeypot_(computing)>)) inputs can be used to detect bots by providing a field that would not generally be clicked by human users, but might be triggered automatically by bots.
94+
95+
We call it a "sweet container" so that bots do not immediately detect it as a honeypot input.
96+
97+
<Canvas of={FieldsStories.SweetContainer} />

0 commit comments

Comments
 (0)