@jobber/components-native 0.101.5 → 0.101.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docs/ActionItem/ActionItem.md +65 -0
- package/dist/docs/ActionItemGroup/ActionItemGroup.md +33 -0
- package/dist/docs/ActionLabel/ActionLabel.md +43 -0
- package/dist/docs/ActivityIndicator/ActivityIndicator.md +116 -0
- package/dist/docs/Animation/Animation.md +71 -0
- package/dist/docs/AtlantisThemeContext/AtlantisThemeContext.md +256 -0
- package/dist/docs/AutoLink/AutoLink.md +47 -0
- package/dist/docs/Banner/Banner.md +390 -0
- package/dist/docs/Borders/Borders.md +45 -0
- package/dist/docs/BottomSheet/BottomSheet.md +67 -0
- package/dist/docs/Button/Button.md +918 -0
- package/dist/docs/ButtonGroup/ButtonGroup.md +89 -0
- package/dist/docs/Card/Card.md +270 -0
- package/dist/docs/Checkbox/Checkbox.md +69 -0
- package/dist/docs/Chip/Chip.md +371 -0
- package/dist/docs/Colors/Colors.md +217 -0
- package/dist/docs/Content/Content.md +67 -0
- package/dist/docs/ContentOverlay/ContentOverlay.md +64 -0
- package/dist/docs/Disclosure/Disclosure.md +161 -0
- package/dist/docs/Divider/Divider.md +84 -0
- package/dist/docs/Elevations/Elevations.md +76 -0
- package/dist/docs/EmptyState/EmptyState.md +72 -0
- package/dist/docs/Flex/Flex.md +37 -0
- package/dist/docs/Form/Form.md +126 -0
- package/dist/docs/FormField/FormField.md +57 -0
- package/dist/docs/FormatFile/FormatFile.md +56 -0
- package/dist/docs/Glimmer/Glimmer.md +143 -0
- package/dist/docs/Heading/Heading.md +132 -0
- package/dist/docs/Icon/Icon.md +585 -0
- package/dist/docs/IconButton/IconButton.md +25 -0
- package/dist/docs/InputCurrency/InputCurrency.md +61 -0
- package/dist/docs/InputDate/InputDate.md +133 -0
- package/dist/docs/InputEmail/InputEmail.md +69 -0
- package/dist/docs/InputFieldWrapper/InputFieldWrapper.md +70 -0
- package/dist/docs/InputNumber/InputNumber.md +72 -0
- package/dist/docs/InputPassword/InputPassword.md +61 -0
- package/dist/docs/InputPressable/InputPressable.md +64 -0
- package/dist/docs/InputSearch/InputSearch.md +49 -0
- package/dist/docs/InputText/InputText.md +324 -0
- package/dist/docs/InputTime/InputTime.md +54 -0
- package/dist/docs/Opacity/Opacity.md +12 -0
- package/dist/docs/ProgressBar/ProgressBar.md +39 -0
- package/dist/docs/Radii/Radii.md +23 -0
- package/dist/docs/ResponsiveBreakpoint/ResponsiveBreakpoint.md +74 -0
- package/dist/docs/Select/Select.md +213 -0
- package/dist/docs/Spacing/Spacing.md +103 -0
- package/dist/docs/StatusLabel/StatusLabel.md +119 -0
- package/dist/docs/Switch/Switch.md +54 -0
- package/dist/docs/Text/Text.md +368 -0
- package/dist/docs/TextList/TextList.md +29 -0
- package/dist/docs/ThumbnailList/ThumbnailList.md +16 -0
- package/dist/docs/Toast/Toast.md +71 -0
- package/dist/docs/Typography/Typography.md +170 -0
- package/dist/docs/choosing-components/choosing-components.md +76 -0
- package/dist/docs/customizing-components/customizing-components.md +167 -0
- package/dist/docs/disabled-states/disabled-states.md +86 -0
- package/dist/docs/empty-states/empty-states.md +126 -0
- package/dist/docs/errors/errors.md +114 -0
- package/dist/docs/index.md +64 -0
- package/dist/docs/interaction/interaction.md +109 -0
- package/dist/docs/page-layouts/page-layouts.md +323 -0
- package/dist/docs/scaffolding/scaffolding.md +109 -0
- package/dist/docs/settings/settings.md +58 -0
- package/dist/docs/usage-guidelines/usage-guidelines.md +177 -0
- package/dist/package.json +8 -4
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +8 -4
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Button Group
|
|
2
|
+
|
|
3
|
+
The ButtonGroup component is used to horizontally group one or more actions
|
|
4
|
+
represented by buttons. The layout of the buttons is dependent on the number and
|
|
5
|
+
type of actions provided.
|
|
6
|
+
|
|
7
|
+
Up to 2 primary actions are displayed as buttons, in the order provided.
|
|
8
|
+
Additional primary actions are hidden in a `More` menu.
|
|
9
|
+
|
|
10
|
+
Secondary actions can also be specified which are always displayed in the `More`
|
|
11
|
+
menu.
|
|
12
|
+
|
|
13
|
+
The `More` button opens the additional actions in a `BottomSheet`.
|
|
14
|
+
|
|
15
|
+
It can optionally display a heading above the Secondary actions bottom sheet. It
|
|
16
|
+
can also optionally display a cancel button in the footer, which closes the
|
|
17
|
+
sheet.
|
|
18
|
+
|
|
19
|
+
## Design & usage guidelines
|
|
20
|
+
|
|
21
|
+
Actions will be displayed in the order provided. Secondary actions will always
|
|
22
|
+
be placed in the `More` menu. In general, at least one primary action should be
|
|
23
|
+
provided.
|
|
24
|
+
|
|
25
|
+
Primary actions can optionally specify alternative button types and variations
|
|
26
|
+
depending on use case.
|
|
27
|
+
|
|
28
|
+
## Content guidelines
|
|
29
|
+
|
|
30
|
+
A ButtonGroup must contain one or more children that are of the type
|
|
31
|
+
`ButtonGroup.PrimaryAction` or `ButtonGroup.SecondaryAction`
|
|
32
|
+
|
|
33
|
+
## Accessibility
|
|
34
|
+
|
|
35
|
+
Each button within the group will support all the accessibility attributes that
|
|
36
|
+
the Button component provides.
|
|
37
|
+
|
|
38
|
+
The ButtonGroup itself does not have additional accessibility attributes.
|
|
39
|
+
|
|
40
|
+
## Responsiveness
|
|
41
|
+
|
|
42
|
+
On wider screens such as on tablets, additional buttons will be shown in the
|
|
43
|
+
horizontal list (up to 4), rather than hidden under the "More" button.
|
|
44
|
+
|
|
45
|
+
Secondary actions are always hidden in "More", regardless of space.
|
|
46
|
+
|
|
47
|
+
Button labels will overlap multiple lines. All buttons in the group should size
|
|
48
|
+
to match the height of the largest button.
|
|
49
|
+
|
|
50
|
+
## Mockup
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
## Props
|
|
54
|
+
|
|
55
|
+
### Mobile
|
|
56
|
+
|
|
57
|
+
#### ButtonGroup
|
|
58
|
+
|
|
59
|
+
| Prop | Type | Required | Default | Description |
|
|
60
|
+
|------|------|----------|---------|-------------|
|
|
61
|
+
| `allowTapWhenOffline` | `boolean` | No | `false` | Allows you to Tap the button while offline |
|
|
62
|
+
| `bottomSheetHeading` | `string` | No | — | An optional heading to display in the secondary bottom sheet header. |
|
|
63
|
+
| `onCloseBottomSheet` | `() => void` | No | — | Callback that is called when the secondary actions bottom sheet is closed. |
|
|
64
|
+
| `onOpenBottomSheet` | `() => void` | No | — | Callback that is called when the secondary actions bottom sheet is opened. |
|
|
65
|
+
| `showCancelInBottomSheet` | `boolean` | No | — | Display a cancel button in the secondary bottom sheet footer. |
|
|
66
|
+
|
|
67
|
+
#### ButtonGroup.PrimaryAction
|
|
68
|
+
|
|
69
|
+
| Prop | Type | Required | Default | Description |
|
|
70
|
+
|------|------|----------|---------|-------------|
|
|
71
|
+
| `label` | `string` | Yes | — | Text to be displayed on the action button |
|
|
72
|
+
| `onPress` | `() => void` | Yes | — | Press handler for the action button |
|
|
73
|
+
| `buttonType` | `ButtonType` | No | — | Sets the action button style (default: "primary") |
|
|
74
|
+
| `buttonVariation` | `ButtonVariation` | No | — | Themes the action button to the type of action it performs (default: "work") |
|
|
75
|
+
| `customButton` | `ReactElement<unknown, string | JSXElementConstructor<any>>` | No | — | Optional custom button that can be rendered in place of the primary action button |
|
|
76
|
+
| `icon` | `IconNames` | No | — | Icon to be displayed on the action button |
|
|
77
|
+
| `iconColor` | `"destructive" | "task" | "text" | "warning" | "icon" | "white" | "grey" | "greyBlue" | "greyBlueDark" | "greyBlueLighter" | "blue" | "lightBlue" | "green" | "yellow" | "red" | ... 34 more ... | "brandHighlight"` | No | — | Determines the color of the icon. If not specified, some icons have a default system colour which will be used Others... |
|
|
78
|
+
| `loading` | `boolean` | No | — | |
|
|
79
|
+
|
|
80
|
+
#### ButtonGroup.SecondaryAction
|
|
81
|
+
|
|
82
|
+
| Prop | Type | Required | Default | Description |
|
|
83
|
+
|------|------|----------|---------|-------------|
|
|
84
|
+
| `label` | `string` | Yes | — | Text to be displayed on the action button |
|
|
85
|
+
| `onPress` | `() => void` | Yes | — | Press handler for the action button |
|
|
86
|
+
| `destructive` | `boolean` | No | — | Indicates whether the secondary action is destructive in nature. |
|
|
87
|
+
| `icon` | `IconNames` | No | — | Icon to be displayed on the action button |
|
|
88
|
+
| `iconColor` | `"destructive" | "task" | "text" | "warning" | "icon" | "white" | "grey" | "greyBlue" | "greyBlueDark" | "greyBlueLighter" | "blue" | "lightBlue" | "green" | "yellow" | "red" | ... 34 more ... | "brandHighlight"` | No | — | Determines the color of the icon. If not specified, some icons have a default system colour which will be used Others... |
|
|
89
|
+
| `loading` | `boolean` | No | — | |
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# Card
|
|
2
|
+
|
|
3
|
+
A card is used to group related information and tasks so our users can scan and
|
|
4
|
+
prioritize information more easily.
|
|
5
|
+
|
|
6
|
+
## Design & usage guidelines
|
|
7
|
+
|
|
8
|
+
A card is useful for grouping content because of its distinct visual boundaries.
|
|
9
|
+
However, similar to the idea that "making everything stand out means that
|
|
10
|
+
nothing stands out", you should be mindful in your application of cards.
|
|
11
|
+
|
|
12
|
+
A card should be the smallest-possible self-contained section of content. If you
|
|
13
|
+
find yourself putting a card inside of another card, the outer card should be
|
|
14
|
+
removed, and it may be worth re-assessing the hierarchy of your interface.
|
|
15
|
+
|
|
16
|
+
### Clickable
|
|
17
|
+
|
|
18
|
+
If clicking on the entire Card will navigate the user to a new view or perform
|
|
19
|
+
an action, the Card will have interactive hover and focus states.
|
|
20
|
+
|
|
21
|
+
It is important to signify to the user that the Card is clickable. This can be
|
|
22
|
+
done by using elevation or by using the `arrowRight` chevron icon in the Card.
|
|
23
|
+
Common examples of this pattern can be found in the
|
|
24
|
+
[Card Figma.](https://www.figma.com/design/rIIhulZvcp9M82lNOCGv16/Product%2FOnline?m=auto\&node-id=22677-10476\&t=YbmsOsxL9J6ggqVA-1)
|
|
25
|
+
|
|
26
|
+
### Elevation
|
|
27
|
+
|
|
28
|
+
By default, it should be assumed that a Card is on the same "plane" as the
|
|
29
|
+
surface it sits on and has no elevation.
|
|
30
|
+
|
|
31
|
+
If the Card benefits from having elevation indicated, such as when it sits
|
|
32
|
+
overtop another Card or is used in a Carousel fashion, the appropriate elevation
|
|
33
|
+
level can be set. See
|
|
34
|
+
[Mobile/Elevation](/storybook/mobile/?path=/story/components-layouts-and-structure-card--elevation)
|
|
35
|
+
for an example.
|
|
36
|
+
|
|
37
|
+
## Related components
|
|
38
|
+
|
|
39
|
+
[Content](../Content/Content.md) and [Flex](../Flex/Flex.md) are the most common
|
|
40
|
+
layout tools for managing the Card's children. Generally, Card is un-opinionated
|
|
41
|
+
about what goes inside of it.
|
|
42
|
+
|
|
43
|
+
If you require more customization over the appearance of your container,
|
|
44
|
+
[Box](/components/Box) is the preferred way to achieve this without writing CSS.
|
|
45
|
+
|
|
46
|
+
## Content guidelines
|
|
47
|
+
|
|
48
|
+
Card headers should be sentence-cased.
|
|
49
|
+
|
|
50
|
+
| ✅ Do | ❌ Don't |
|
|
51
|
+
| ----------------------- | ----------------------- |
|
|
52
|
+
| Client property details | Client Property Details |
|
|
53
|
+
| Assigned team | ASSIGNED TEAM |
|
|
54
|
+
| Required deposit | Required Deposit |
|
|
55
|
+
|
|
56
|
+
As previously mentioned, a Card should be "self-contained" and nesting Cards
|
|
57
|
+
inside of other Cards should be avoided.
|
|
58
|
+
|
|
59
|
+
## Accessibility
|
|
60
|
+
|
|
61
|
+
The Card itself is already accessible and does not require any additional setup.
|
|
62
|
+
|
|
63
|
+
With that said, it should not be wrapped in an element with an `aria-label` or
|
|
64
|
+
`accessibilityLabel` describing it as a card. This is redundant and will cause
|
|
65
|
+
unexpected behaviour for screen readers. For example, wrapping a Card with an
|
|
66
|
+
`accessibilityLabel` on mobile hides the entire Card from screen readers.
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## Configuration
|
|
70
|
+
|
|
71
|
+
### Card Types
|
|
72
|
+
|
|
73
|
+
The Card component supports three distinct types of cards:
|
|
74
|
+
|
|
75
|
+
1. **Regular Card** - A basic card without any click behavior
|
|
76
|
+
2. **Link Card** - A card that navigates to a URL when clicked
|
|
77
|
+
3. **Clickable Card** - A card that triggers a custom click handler
|
|
78
|
+
|
|
79
|
+
### Component Customization
|
|
80
|
+
|
|
81
|
+
#### Composable Usage
|
|
82
|
+
|
|
83
|
+
The Card component supports both prop-driven and composable approaches. The
|
|
84
|
+
standard prop-driven usage with `title` and `header` props is straightforward
|
|
85
|
+
and suitable for most use cases. For advanced customization needs, the Card
|
|
86
|
+
component also provides `Card.Header` and `Card.Body` components.
|
|
87
|
+
|
|
88
|
+
`Card.Header` is used to display custom header content of the card. `Card.Body`
|
|
89
|
+
is used to display the main content of the card.
|
|
90
|
+
|
|
91
|
+
Here's an example of converting a prop-driven card to a composable one when more
|
|
92
|
+
customization is needed:
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
<Card title="Card Title" header="Header Text">
|
|
96
|
+
<p>Card content</p>
|
|
97
|
+
</Card>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
becomes
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
<Card>
|
|
104
|
+
<Card.Header>
|
|
105
|
+
<Text>Card Title</Text>
|
|
106
|
+
</Card.Header>
|
|
107
|
+
<Card.Body>
|
|
108
|
+
<p>Card content</p>
|
|
109
|
+
</Card.Body>
|
|
110
|
+
</Card>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### Link Card Example
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
<Card url="/dashboard" external={true}>
|
|
117
|
+
<Card.Header>
|
|
118
|
+
<Text>External Link</Text>
|
|
119
|
+
</Card.Header>
|
|
120
|
+
<Card.Body>
|
|
121
|
+
<p>Click to navigate to dashboard</p>
|
|
122
|
+
</Card.Body>
|
|
123
|
+
</Card>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### Clickable Card Example
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
<Card onClick={handleClick}>
|
|
130
|
+
<Card.Header>
|
|
131
|
+
<Text>Interactive Card</Text>
|
|
132
|
+
</Card.Header>
|
|
133
|
+
<Card.Body>
|
|
134
|
+
<p>Click to trigger action</p>
|
|
135
|
+
</Card.Body>
|
|
136
|
+
</Card>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Props Compatibility
|
|
140
|
+
|
|
141
|
+
The Card component uses a discriminated union pattern to ensure proper usage.
|
|
142
|
+
This means that the component can be one of three distinct types, each with its
|
|
143
|
+
own set of valid props:
|
|
144
|
+
|
|
145
|
+
* A Link Card must have a `url` prop and cannot have an `onClick` handler
|
|
146
|
+
* A Clickable Card must have an `onClick` prop and cannot have a `url`
|
|
147
|
+
* A Regular Card has neither `url` nor `onClick`
|
|
148
|
+
|
|
149
|
+
This type system ensures that each card has a clear and single responsibility
|
|
150
|
+
for its interaction behavior, making it impossible to create ambiguous card
|
|
151
|
+
states (like having both a URL and click handler).
|
|
152
|
+
|
|
153
|
+
### Styling
|
|
154
|
+
|
|
155
|
+
Cards can be customized with the following props:
|
|
156
|
+
|
|
157
|
+
* `accent`: Applies an accent color to the card
|
|
158
|
+
* `elevation`: Controls the card's shadow elevation ("none" | "base" | "raised"
|
|
159
|
+
\| "floating")
|
|
160
|
+
|
|
161
|
+
Example with styling:
|
|
162
|
+
|
|
163
|
+
```tsx
|
|
164
|
+
<Card accent="purple" elevation="raised">
|
|
165
|
+
<Card.Header>
|
|
166
|
+
<Text>Styled Card</Text>
|
|
167
|
+
</Card.Header>
|
|
168
|
+
<Card.Body>
|
|
169
|
+
<p>Card with purple accent and raised elevation</p>
|
|
170
|
+
</Card.Body>
|
|
171
|
+
</Card>
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### UNSAFE\_ props (advanced usage)
|
|
175
|
+
|
|
176
|
+
General information for using `UNSAFE_` props can be found
|
|
177
|
+
[here](../customizing-components/customizing-components.md).
|
|
178
|
+
|
|
179
|
+
Card has two elements that can be targeted with classes or styles. These are the
|
|
180
|
+
container and the header.
|
|
181
|
+
|
|
182
|
+
**Note**: Use of `UNSAFE_` props is **at your own risk** and should be
|
|
183
|
+
considered a **last resort**. Future Card updates may lead to unintended
|
|
184
|
+
breakages.
|
|
185
|
+
|
|
186
|
+
#### UNSAFE\_className
|
|
187
|
+
|
|
188
|
+
Use `UNSAFE_className` to apply custom classes to the Card. This can be useful
|
|
189
|
+
for applying styles via CSS Modules.
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
// YourComponent.tsx
|
|
193
|
+
<Card
|
|
194
|
+
header="Custom Styled Card"
|
|
195
|
+
UNSAFE_className={{
|
|
196
|
+
container: styles.customCardContainer,
|
|
197
|
+
header: styles.customCardHeader,
|
|
198
|
+
}}
|
|
199
|
+
>
|
|
200
|
+
<p>Card content with custom styling</p>
|
|
201
|
+
</Card>
|
|
202
|
+
|
|
203
|
+
// YourComponent.module.css
|
|
204
|
+
.customCardContainer {
|
|
205
|
+
border: 2px solid var(--color-blue);
|
|
206
|
+
border-radius: var(--radius-large);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.customCardHeader {
|
|
210
|
+
background-color: var(--color-surface--background);
|
|
211
|
+
border-bottom: 1px solid var(--color-border);
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
#### UNSAFE\_style
|
|
216
|
+
|
|
217
|
+
Use `UNSAFE_style` to apply inline custom styles to the Card.
|
|
218
|
+
|
|
219
|
+
```tsx
|
|
220
|
+
<Card
|
|
221
|
+
header="Inline Styled Card"
|
|
222
|
+
UNSAFE_style={{
|
|
223
|
+
container: {
|
|
224
|
+
backgroundColor: "var(--color-surface--hover)",
|
|
225
|
+
transform: "rotate(1deg)",
|
|
226
|
+
},
|
|
227
|
+
header: {
|
|
228
|
+
backgroundColor: "var(--color-blue)",
|
|
229
|
+
color: "white",
|
|
230
|
+
},
|
|
231
|
+
}}
|
|
232
|
+
>
|
|
233
|
+
<p>Card content with inline styling</p>
|
|
234
|
+
</Card>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Compound Component Card
|
|
238
|
+
|
|
239
|
+
If you're using Card with its composable subcomponents, note that currently
|
|
240
|
+
these subcomponents are simply fragments. As such, you are free to provide any
|
|
241
|
+
desired markup and have no need for either UNSAFE.
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
<Card>
|
|
245
|
+
<Card.Header>
|
|
246
|
+
<div className="custom" style={{padding: "var(--space-base)}}>
|
|
247
|
+
<Heading level={3}>My Custom Header</Heading>
|
|
248
|
+
</div>
|
|
249
|
+
</Card.Header>
|
|
250
|
+
<Card.Body>
|
|
251
|
+
<div style={{ background: "#29d", padding: "var(--space-base)"}}>
|
|
252
|
+
<Text>Card content</Text>
|
|
253
|
+
</div>
|
|
254
|
+
</Card.Body>
|
|
255
|
+
</Card>
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
## Props
|
|
260
|
+
|
|
261
|
+
### Mobile
|
|
262
|
+
|
|
263
|
+
| Prop | Type | Required | Default | Description |
|
|
264
|
+
|------|------|----------|---------|-------------|
|
|
265
|
+
| `elevation` | `elevationProp` | No | `none` | |
|
|
266
|
+
| `error` | `string` | No | — | |
|
|
267
|
+
| `footer` | `FooterProps` | No | — | |
|
|
268
|
+
| `header` | `HeaderProps` | No | — | @deprecated Use <ActionItem /> with the title and onPress properties instead |
|
|
269
|
+
| `reportCardHeight` | `(height: number) => void` | No | — | |
|
|
270
|
+
| `testID` | `string` | No | `card` | |
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Checkbox
|
|
2
|
+
|
|
3
|
+
A checkbox lets a user select one or more items from a set of options.
|
|
4
|
+
|
|
5
|
+
## Design & usage guidelines
|
|
6
|
+
|
|
7
|
+
A checkbox is a familiar pattern for users who need to choose from a set of
|
|
8
|
+
options, or opt in to a single choice. It allows a user to provide boolean
|
|
9
|
+
input. It can also be in an indeterminate state when we don't know if the
|
|
10
|
+
checkbox is considered checked or not.
|
|
11
|
+
|
|
12
|
+
A single checkbox, a [Switch](../Switch/Switch.md), and a pair of
|
|
13
|
+
[radio buttons](/components/RadioGroup) can seem similar in theory, as all can
|
|
14
|
+
represent an either/or decision for the user. Use a switch when the user must
|
|
15
|
+
make a decision to turn something on or off, and a single checkbox when a user
|
|
16
|
+
is opting in to a choice. A pair of radio buttons can be used to help the user
|
|
17
|
+
decide between two discrete options, such as “fixed price” and “per visit”
|
|
18
|
+
invoicing options.
|
|
19
|
+
|
|
20
|
+
Of note: when a single selection is to be made, a Switch should be used rather
|
|
21
|
+
than a single Checkbox. Use a Checkbox only when there are multiple selection
|
|
22
|
+
options to choose from. when the volume of Radio options is greater than 5 (or
|
|
23
|
+
there are otherwise critical vertical space constraints) use Select. when the
|
|
24
|
+
labels on a set of Radio options are consistently small (1–2 words), use Chip.
|
|
25
|
+
|
|
26
|
+
## Related components
|
|
27
|
+
|
|
28
|
+
* To let people turn a setting on or off instantly, use a
|
|
29
|
+
[Switch](../Switch/Switch.md).
|
|
30
|
+
* To present a set of options where people can only make a single choice, use a
|
|
31
|
+
[RadioGroup](/components/RadioGroup).
|
|
32
|
+
|
|
33
|
+
## Mockup
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## Platform considerations
|
|
37
|
+
|
|
38
|
+
### Event Handlers
|
|
39
|
+
|
|
40
|
+
While Checkbox exposes mouse event handlers like `onClick`, the recommended way
|
|
41
|
+
to access the new value is via the `onChange` prop.
|
|
42
|
+
|
|
43
|
+
### CheckboxGroup (mobile)
|
|
44
|
+
|
|
45
|
+
The `<CheckboxGroup>` component is a component that provides a grouping of
|
|
46
|
+
checkboxes. It allows you to optionally provide a label which will allow you to
|
|
47
|
+
control the Checkbox children with a single parent checkbox. If some but not all
|
|
48
|
+
children are checked then the parent checkbox will show the indeterminate state.
|
|
49
|
+
An important thing to note is that when using `<CheckboxGroup>` the child
|
|
50
|
+
Checkboxes must have a name provided as a prop. This is so the CheckboxGroup is
|
|
51
|
+
able to keep track the state of the child Checkboxes. See
|
|
52
|
+
[Checkbox/Mobile/Checkbox Group Example](/storybook/mobile/?path=/story/components-selections-checkbox--checkbox-group-example)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## Props
|
|
56
|
+
|
|
57
|
+
### Mobile
|
|
58
|
+
|
|
59
|
+
| Prop | Type | Required | Default | Description |
|
|
60
|
+
|------|------|----------|---------|-------------|
|
|
61
|
+
| `accessibilityLabel` | `string` | No | — | Accessibility Label for the checkbox. Defaults to label |
|
|
62
|
+
| `assistiveText` | `string` | No | — | Assistive Text, shown under label |
|
|
63
|
+
| `checked` | `boolean` | No | — | If the checkbox is checked. This should be set when this is intended as a controlled component |
|
|
64
|
+
| `defaultChecked` | `boolean` | No | — | Default value for when the checkbox is uncontrolled |
|
|
65
|
+
| `disabled` | `boolean` | No | — | Checkbox is disabled |
|
|
66
|
+
| `indeterminate` | `boolean` | No | — | When true, the checkbox is shown as indeterminate |
|
|
67
|
+
| `label` | `string` | No | — | Label to be displayed beside the checkbox |
|
|
68
|
+
| `name` | `string` | No | — | Name of the checkbox; this is important when using in a form component |
|
|
69
|
+
| `onChange` | `((value: boolean) => void) | ((value: boolean) => void)` | No | — | Press handler |
|