Skip to content
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

Adds a component to support checkbox and radio groups #1657

Merged
merged 119 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
a23e32d
adds components and stories for basic usage
mperrotti Nov 12, 2021
779e5fe
supports checkbox and radio fields
mperrotti Nov 15, 2021
0ad2715
styles disabled label styles, adds stories, jsdocs props, cleanups
mperrotti Nov 16, 2021
f8668ce
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Nov 16, 2021
e0addd0
adds missing jsdoc comment
mperrotti Nov 16, 2021
0d3ae10
adds components to render groups of radios or checkboxes
mperrotti Nov 17, 2021
a67c80f
supports LeadingVisual for checkbox and radio inputs
mperrotti Nov 17, 2021
fe9696a
animate in field validation message
mperrotti Nov 17, 2021
dd08828
updates validation API
mperrotti Nov 19, 2021
6054f1c
creates text, checkbox, and radio input field components
mperrotti Nov 22, 2021
910ee68
makes InputField validation props smarter
mperrotti Nov 22, 2021
00ecaba
rm ChoiceFieldset from this changeset
mperrotti Nov 22, 2021
115bb4e
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Nov 22, 2021
fc84152
fixes ts errors
mperrotti Nov 22, 2021
f70f8ad
fixes bad imports
mperrotti Nov 22, 2021
793c00d
cleanup
mperrotti Nov 22, 2021
e50bde8
adds VisuallyHidden component
mperrotti Nov 22, 2021
e9bcee9
require label to be passed
mperrotti Nov 23, 2021
4533f20
fixes typo from last commit
mperrotti Nov 23, 2021
ad1c9e8
adds React component docs for TextInputField, RadioInputField, and Ch…
mperrotti Nov 23, 2021
024b5d3
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Nov 23, 2021
006e976
adds tests, fixes check for Label slot
mperrotti Nov 24, 2021
79c2286
warns if id, required, or disabled props are passed directly to the I…
mperrotti Nov 24, 2021
581b4ca
fix issue where the input still had a top margin when the label was h…
mperrotti Nov 24, 2021
54b43a4
marks new internal components as private
mperrotti Nov 24, 2021
7b7c1f8
adds changeset
mperrotti Nov 24, 2021
0a220ad
updates imports
mperrotti Nov 24, 2021
6ea5201
Merge github.com:primer/react into mp/form-field-component
mperrotti Nov 24, 2021
504a9d9
updates stories and docs
mperrotti Nov 24, 2021
d721895
Merge github.com:primer/react into mp/form-field-component
mperrotti Nov 24, 2021
e5a964f
adds React component docs to doc nav, updates docs
mperrotti Nov 24, 2021
15da266
updates CheckboxInputField to use new Checkbox component
mperrotti Nov 24, 2021
cbab1ae
updates snapshots from using checkbox component
mperrotti Nov 24, 2021
9880c53
adds ChoiceFieldset components and stories
mperrotti Nov 24, 2021
ec1312a
Merge branch 'main' into mp/form-field-component
mperrotti Nov 24, 2021
69e99f6
fixes ts error
mperrotti Nov 24, 2021
b092729
Merge github.com:primer/react into mp/form-field-component
mperrotti Nov 30, 2021
6577aa8
Merge branch 'main' into mp/form-field-component
mperrotti Nov 30, 2021
7424440
lightens caption when field is disabled
mperrotti Nov 30, 2021
69334dc
removes unusable export from checkbox and radio input fields
mperrotti Nov 30, 2021
2691adc
Merge branch 'mp/form-field-component' of github.com:primer/react int…
mperrotti Nov 30, 2021
6af2f8c
Merge branch 'mp/form-field-component' of github.com:primer/react int…
mperrotti Nov 30, 2021
3869fff
rename ChoiceField to Item
mperrotti Nov 30, 2021
689ace4
adds a prop to disable the fieldset
mperrotti Nov 30, 2021
f33ff51
exports ChoiceFieldset list item component
mperrotti Nov 30, 2021
14af744
rm ChoiceFieldInput component, improve dev experience for onSelect ha…
mperrotti Dec 1, 2021
2684d58
rm unused imports and exports
mperrotti Dec 1, 2021
06c5f3b
replaced fieldset caption with fieldset description
mperrotti Dec 1, 2021
3c5351a
API improvements and storybook story updates
mperrotti Dec 1, 2021
cfc2e86
adds and updates docs, little fixes and improvments
mperrotti Dec 2, 2021
2f2a998
adds tests
mperrotti Dec 3, 2021
a78625f
adds changeset
mperrotti Dec 3, 2021
d0b19a2
fix lint errors
mperrotti Dec 3, 2021
4b20f1a
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Dec 3, 2021
9c17471
updates docs, adds ChoiceFieldset to docs sidebar
mperrotti Dec 3, 2021
b137a07
updates Checkbox docs to point to CheckboxInputField
mperrotti Dec 3, 2021
72e886d
adds ComponentChecklst to component docs
mperrotti Dec 3, 2021
3c18363
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Dec 6, 2021
4e06ca7
uses new Radio component to render the input
mperrotti Dec 6, 2021
3c312f9
Merge branch 'mp/form-field-component' of github.com:primer/react int…
mperrotti Dec 6, 2021
a0465ee
ensures name prop cannot be undefined when passed to input
mperrotti Dec 6, 2021
18767e1
wraps snapshot renders in SSRProvider
mperrotti Dec 6, 2021
8ef90f2
addresses PR feedback
mperrotti Dec 7, 2021
55aa8e3
rm unused imports
mperrotti Dec 8, 2021
ee2f9bf
Merge branch 'main' of github.com:primer/react into mp/choice-group
mperrotti Dec 8, 2021
a179e92
Merge branch 'main' into mp/form-field-component
mperrotti Dec 8, 2021
ea439d3
wraps snapshot tests in SSRProvider
mperrotti Dec 8, 2021
1aa9277
fixes typo
mperrotti Dec 8, 2021
c33fe78
Merge branch 'mp/form-field-component' of github.com:primer/react int…
mperrotti Dec 8, 2021
73285ba
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Dec 13, 2021
98a67e8
Merge branch 'mp/form-field-component' of github.com:primer/react int…
mperrotti Dec 13, 2021
b6781f4
fixes bad import
mperrotti Dec 13, 2021
8699756
Merge branch 'main' of github.com:primer/react into mp/choice-group
mperrotti Dec 13, 2021
ef2ae4f
Merge branch 'mp/form-field-component' of github.com:primer/react int…
mperrotti Dec 13, 2021
ff79a52
uses new package name
mperrotti Dec 13, 2021
90f40e0
Merge branch 'mp/form-field-component' of github.com:primer/react int…
mperrotti Dec 13, 2021
bfe3b65
uses new package name
mperrotti Dec 13, 2021
f4ff5c8
replaces CheckboxInputField and RadioInputField with 1 component - Ch…
mperrotti Dec 13, 2021
58efa2b
replaces TextInputField component with InputField component
mperrotti Dec 13, 2021
c6c2062
updates documentation formatting
mperrotti Dec 13, 2021
e3f7a6e
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Dec 13, 2021
95dacc4
Merge branch 'mp/form-field-component' of github.com:primer/react int…
mperrotti Dec 13, 2021
3421225
uses ChoiceInputField instead of checkbox and radio field components
mperrotti Dec 14, 2021
1974d98
updates documentation formatting
mperrotti Dec 14, 2021
e283cbe
more docs updates
mperrotti Dec 14, 2021
fc0b75f
merges from InputField branch, updates more docs
mperrotti Dec 14, 2021
c4c6ac3
fixes copy/paste mistake in docs
mperrotti Dec 14, 2021
05f96dd
Merge branch 'main' into mp/form-field-component
mperrotti Dec 14, 2021
c1c4808
Update docs/content/Checkbox.md
mperrotti Dec 15, 2021
ce49a84
addresses PR feedback + misc cleanup
mperrotti Dec 15, 2021
6a7bb75
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Dec 16, 2021
2a77582
Merge branch 'mp/form-field-component' of github.com:primer/react int…
mperrotti Dec 16, 2021
12d8047
TESTING DEPLOYMENT - revert InputField.mdx to last successful build
mperrotti Dec 16, 2021
fd269bf
Merge branch 'main' into mp/form-field-component
mperrotti Dec 16, 2021
73ad10c
attempting to get InputField docs to build
mperrotti Dec 16, 2021
5c56710
attempting to get InputField docs to build
mperrotti Dec 16, 2021
b42dc39
attempting to get InputField docs to build
mperrotti Dec 16, 2021
03156ef
probably fixed deployment
mperrotti Dec 16, 2021
7e1cc93
Merge branch 'mp/form-field-component' of github.com:primer/react int…
mperrotti Dec 16, 2021
00f5ff2
Merge branch 'main' into mp/form-field-component
mperrotti Dec 16, 2021
50a7f81
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Dec 17, 2021
398e541
Merge branch 'mp/form-field-component' of github.com:primer/react int…
mperrotti Dec 17, 2021
d6d3f03
Update docs/content/ChoiceInputField.mdx
mperrotti Dec 17, 2021
c17ec66
addresses more PR feedback
mperrotti Dec 17, 2021
a450bb8
Merge branch 'mp/form-field-component' of github.com:primer/react int…
mperrotti Dec 17, 2021
7e6da8a
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Dec 17, 2021
4d04066
try adding componentchecklist import to fix deployment failure
mperrotti Dec 17, 2021
15bf95c
adds comopnentId to docs frontmatter
mperrotti Dec 17, 2021
d18effc
Merge branch 'mp/form-field-component' of github.com:primer/react int…
mperrotti Dec 17, 2021
709d5a9
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Dec 17, 2021
ad9e954
Merge branch 'main' into mp/form-field-component
mperrotti Dec 17, 2021
2c4f769
Merge branch 'mp/form-field-component' of github.com:primer/react int…
mperrotti Dec 17, 2021
78c12fe
Merge branch 'main' of github.com:primer/react into mp/choice-group
mperrotti Dec 17, 2021
ea2f769
Merge branch 'main' of github.com:primer/react into mp/choice-group
mperrotti Jan 10, 2022
ce577f2
Merge branch 'main' into mp/choice-group
mperrotti Jan 10, 2022
fdb2147
Merge branch 'main' into mp/choice-group
mperrotti Jan 11, 2022
8dbcfed
docs fixes
mperrotti Jan 11, 2022
da725b8
Merge branch 'mp/choice-group' of github.com:primer/react into mp/cho…
mperrotti Jan 11, 2022
42d1bce
Merge branch 'main' into mp/choice-group
mperrotti Jan 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/afraid-tips-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/components': minor
---

Adds TextInputField, CheckboxInputField, and RadioInputField components. Also adds a few internal (private to primer/react) components to support form fields
5 changes: 5 additions & 0 deletions .changeset/twenty-needles-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/components': minor
---

Adds ChoiceFieldset component
8 changes: 7 additions & 1 deletion docs/content/Checkbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Checkbox
description: Use checkboxes to toggle between checked and unchecked states in a list or as a standalone form field
status: Alpha
source: https://github.com/primer/react/blob/main/src/Checklist.tsx
source: https://github.com/primer/react/blob/main/src/Checkbox.tsx
storybook: '/react/storybook?path=/story/forms-checkbox--default'
---

Expand All @@ -12,6 +12,8 @@ import {ComponentChecklist} from '../src/component-checklist'

The `Checkbox` component can be used in controlled and uncontrolled modes.

**Use [CheckboxInputField](/CheckboxInputField) to render a checkbox with a label and other content related to the field.** Do not use this component on it's own unless you're rendering a "special" checkbox field that cannot be build using the `CheckboxInputField` component. For example: the "Use your administrator privilages..." checkbox at the bottom of PR that doesn't meet the criteria to be merged without admin privilages.

```jsx live
<>
<Box as="form" sx={{p: 3, pt: 0, display: 'flex', alignItems: 'center'}}>
Expand Down Expand Up @@ -116,3 +118,7 @@ items={{
hasFigmaComponent: false
}}
/>

## Related components

- [CheckboxInputField](/CheckboxInputField)
156 changes: 156 additions & 0 deletions docs/content/CheckboxInputField.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
---
title: CheckboxInputField
status: Alpha
source: https://github.com/primer/react/blob/main/src/CheckboxInputField.tsx
storybook: '/react/storybook?path=/story/forms-checkboxinputfield--default'
---

import {ComponentChecklist} from '../src/component-checklist'

<!--
TODO: add `validationStatus` examples when we have the validation styling done
-->

import {CheckboxInputField} from '@primer/components'
import {MarkGithubIcon} from '@primer/octicons-react'

The `CheckboxInputField` component is used to render a labelled checkbox input and, optionally, associated hint text and graphic.

**Use [ChoiceFieldset](/ChoiceFieldset) to render a group of related checkbox input fields.** Do not use this component on it's own unless you're rendering a single checkbox field on it's own, and there will never be related checkboxes.
mperrotti marked this conversation as resolved.
Show resolved Hide resolved

## Basic Example

```jsx live
<CheckboxInputField>
<CheckboxInputField.Label>Option one</CheckboxInputField.Label>
<CheckboxInputField.Input />
</CheckboxInputField>
```

## CheckboxInputField

The container that handles the layout and passes the relevant IDs and ARIA attributes it's children.

`CheckboxInputField.Label` and `CheckboxInputField.Input` are required children.

### Component props

| Name | Type | Default | Description |
| :--------- | :----------------------------------------------------------------------------------------------------------------------- | :--------------: | :--------------------------------------------------------------------------------------------------- |
| children\* | `CheckboxInputField.Label`, `CheckboxInputField.Input`, `CheckboxInputField.Caption`, `CheckboxInputField.LeadingVisual` | - | Required |
| disabled | `boolean` | false | Whether the field is ready for user input |
| id | `string` | generated string | The unique identifier for this field. Used to associate the label, validation text, and caption text |

### Example: disabled

```jsx live
<CheckboxInputField disabled>
<CheckboxInputField.Label>Option one</CheckboxInputField.Label>
<CheckboxInputField.Input />
</CheckboxInputField>
```

## CheckboxInputField.Label

A `CheckboxInputField.Label` must be passed, but it may be visually hidden.

### Component props

| Name | Type | Default | Description |
| :------------- | :-------- | :-----: | :------------------------------------------ |
| visuallyHidden | `boolean` | false | Whether the label should be visually hidden |

### Example: a visually hidden label

```jsx live
<CheckboxInputField>
<CheckboxInputField.Label visuallyHidden>Option One</CheckboxInputField.Label>
<CheckboxInputField.Input />
</CheckboxInputField>
```

## CheckboxInputField.Input

A [CheckboxInput](/CheckboxInput) will be rendered. This cannot be overridden

### Component props

The same props accepted by a [CheckboxInput](/CheckboxInput)

## CheckboxInputField.Caption

If this field needs additional context, a `CheckboxInputField.Caption` may be used to render hint text.

### Component props

| Name | Type | Default | Description |
| :------- | :---------------- | :-----: | :--------------------------------------------------------------------------------------- |
| children | `React.ReactNode` | - | The content (usually just text) that is rendered to give contextual info about the field |

### Example

```jsx live
<CheckboxInputField>
<CheckboxInputField.Label>Option One</CheckboxInputField.Label>
<CheckboxInputField.Input />
<CheckboxInputField.Caption>Hint: the first and only option</CheckboxInputField.Caption>
</CheckboxInputField>
```

## CheckboxInputField.LeadingVisual

If the selectable option would be easier to understand with a visual, the `CheckboxInputField.LeadingVisual` component may be used.

### Component props

| Name | Type | Default | Description |
| :------- | :---------------- | :-----: | :----------------------------------------------- |
| children | `React.ReactNode` | - | The visual to render before the checkbox's label |

### Example

```jsx live
<>
<CheckboxInputField>
<CheckboxInputField.Label>Option one</CheckboxInputField.Label>
<CheckboxInputField.LeadingVisual>
<MarkGithubIcon />
</CheckboxInputField.LeadingVisual>
<CheckboxInputField.Input />
</CheckboxInputField>

<CheckboxInputField>
<CheckboxInputField.Label>Option two</CheckboxInputField.Label>
<CheckboxInputField.LeadingVisual>
<MarkGithubIcon />
</CheckboxInputField.LeadingVisual>
<CheckboxInputField.Input />
<CheckboxInputField.Caption>This one has a caption</CheckboxInputField.Caption>
</CheckboxInputField>
</>
```

## Component 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
}}
/>

## Related components

- [ChoiceFieldset](/ChoiceFieldset)
- [Checkbox](/Checkbox)
Loading