-
Notifications
You must be signed in to change notification settings - Fork 616
Input field components - text, checkbox, radio #1611
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
Changes from all commits
a23e32d
779e5fe
0ad2715
f8668ce
e0addd0
0d3ae10
a67c80f
fe9696a
dd08828
6054f1c
910ee68
00ecaba
115bb4e
fc84152
f70f8ad
793c00d
e50bde8
e9bcee9
4533f20
ad1c9e8
024b5d3
006e976
79c2286
581b4ca
54b43a4
7b7c1f8
0a220ad
6ea5201
504a9d9
d721895
e5a964f
15da266
cbab1ae
ec1312a
b092729
6577aa8
7424440
69334dc
2691adc
4b20f1a
b137a07
3c18363
4e06ca7
a179e92
73285ba
98a67e8
b6781f4
ff79a52
f4ff5c8
58efa2b
c6c2062
e3f7a6e
e283cbe
05f96dd
c1c4808
ce49a84
6a7bb75
12d8047
fd269bf
73ad10c
5c56710
b42dc39
03156ef
00f5ff2
50a7f81
398e541
d6d3f03
c17ec66
a450bb8
7e6da8a
4d04066
15bf95c
709d5a9
ad9e954
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@primer/react': minor | ||
--- | ||
|
||
Adds TextInputField, CheckboxInputField, and RadioInputField components. Also adds a few internal (private to primer/react) components to support form fields |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
--- | ||
componentId: choiceInputField | ||
title: ChoiceInputField | ||
status: Alpha | ||
description: The ChoiceInputField component is used to render a labelled checkbox or radio inputs with optional hint text. | ||
source: https://github.com/primer/react/blob/main/src/ChoiceInputField.tsx | ||
storybook: '/react/storybook?path=/story/forms-choiceinputfield--checkbox-input-field' | ||
--- | ||
|
||
import {ChoiceInputField, Checkbox, Radio} from '@primer/react' | ||
import {MarkGithubIcon} from '@primer/octicons-react' | ||
import {PropsTable} from '../src/props-table' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of these imports may not be needed anymore There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll see what I can get rid of. When I excluded the |
||
import {ComponentChecklist} from '../src/component-checklist' | ||
|
||
## Examples | ||
|
||
### Checkbox | ||
|
||
```jsx live | ||
<ChoiceInputField> | ||
<ChoiceInputField.Label>Option one</ChoiceInputField.Label> | ||
<Checkbox /> | ||
</ChoiceInputField> | ||
``` | ||
|
||
### Radio | ||
|
||
```jsx live | ||
<fieldset style={{margin: 0, padding: 0, border: 0}}> | ||
<ChoiceInputField> | ||
<ChoiceInputField.Label>Option one</ChoiceInputField.Label> | ||
<Radio name="radioExample" value="one" /> | ||
</ChoiceInputField> | ||
<ChoiceInputField> | ||
<ChoiceInputField.Label>Option two</ChoiceInputField.Label> | ||
<Radio name="radioExample" value="two" /> | ||
</ChoiceInputField> | ||
</fieldset> | ||
``` | ||
|
||
### Disabled field | ||
|
||
```jsx live | ||
<ChoiceInputField disabled> | ||
<ChoiceInputField.Label>Option one</ChoiceInputField.Label> | ||
<Checkbox /> | ||
</ChoiceInputField> | ||
``` | ||
|
||
### With a caption | ||
|
||
```jsx live | ||
<ChoiceInputField> | ||
<ChoiceInputField.Label>Option One</ChoiceInputField.Label> | ||
<Checkbox /> | ||
<ChoiceInputField.Caption>Hint: the first and only option</ChoiceInputField.Caption> | ||
</ChoiceInputField> | ||
``` | ||
|
||
### With a LeadingVisual | ||
|
||
```jsx live | ||
<> | ||
<ChoiceInputField> | ||
<ChoiceInputField.Label>Option one</ChoiceInputField.Label> | ||
<ChoiceInputField.LeadingVisual> | ||
<MarkGithubIcon /> | ||
</ChoiceInputField.LeadingVisual> | ||
<Checkbox /> | ||
</ChoiceInputField> | ||
|
||
<ChoiceInputField> | ||
<ChoiceInputField.Label>Option two</ChoiceInputField.Label> | ||
<ChoiceInputField.LeadingVisual> | ||
<MarkGithubIcon /> | ||
</ChoiceInputField.LeadingVisual> | ||
<Checkbox /> | ||
<ChoiceInputField.Caption>This one has a caption</ChoiceInputField.Caption> | ||
</ChoiceInputField> | ||
</> | ||
``` | ||
|
||
## Props | ||
|
||
### ChoiceInputField | ||
|
||
The container that handles the layout and passes the relevant IDs and ARIA attributes it's children. | ||
|
||
`ChoiceInputField.Label` and `ChoiceInputField.Input` are required children. | ||
|
||
<PropsTable> | ||
<PropsTable.Row | ||
name="children" | ||
type="ChoiceInputField.Label | ChoiceInputField.Caption | ChoiceInputField.LeadingVisual | Checkbox | Radio" | ||
required | ||
/> | ||
<PropsTable.Row | ||
name="disabled" | ||
type="boolean" | ||
defaultValue="false" | ||
description="Whether the field is ready for user input" | ||
/> | ||
<PropsTable.Row | ||
name="id" | ||
type="string" | ||
defaultValue="a generated string" | ||
description="The unique identifier for this field. Used to associate the label, validation text, and caption text" | ||
/> | ||
</PropsTable> | ||
|
||
### ChoiceInputField.Label | ||
|
||
A `ChoiceInputField.Label` must be passed, but it may be visually hidden. | ||
|
||
<PropsTable> | ||
<PropsTable.Row name="children" type="React.ReactNode" description="The title that describes the choice input" /> | ||
</PropsTable> | ||
|
||
### ChoiceInputField.Caption | ||
|
||
If this field needs additional context, a `ChoiceInputField.Caption` may be used to render hint text. | ||
|
||
<PropsTable> | ||
<PropsTable.Row | ||
name="children" | ||
type="React.ReactNode" | ||
description="The content (usually just text) that is rendered to give contextual info about the field" | ||
/> | ||
</PropsTable> | ||
|
||
### ChoiceInputField.LeadingVisual | ||
|
||
If the selectable option would be easier to understand with a visual, the `ChoiceInputField.LeadingVisual` component may be used. | ||
|
||
<PropsTable> | ||
<PropsTable.Row | ||
name="children" | ||
type="React.ReactNode" | ||
description="The visual to render before the choice input's label" | ||
/> | ||
</PropsTable> | ||
|
||
## Status | ||
|
||
<ComponentChecklist | ||
items={{ | ||
propsDocumented: true, | ||
noUnnecessaryDeps: true, | ||
adaptsToThemes: true, | ||
adaptsToScreenSizes: true, | ||
fullTestCoverage: true, | ||
usedInProduction: false, | ||
usageExamplesDocumented: true, | ||
designReviewed: false, | ||
a11yReviewed: true, | ||
stableApi: false, | ||
addressedApiFeedback: false, | ||
hasDesignGuidelines: false, | ||
hasFigmaComponent: false | ||
}} | ||
/> |
Uh oh!
There was an error while loading. Please reload this page.