Skip to content

Commit 4d20882

Browse files
authored
chore: Improve button docs (#230)
* chore: Improve button docs * Fix responsive issues * Fix typo
1 parent d7728ce commit 4d20882

File tree

4 files changed

+653
-306
lines changed

4 files changed

+653
-306
lines changed
Lines changed: 173 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,215 @@
1-
### Primary Button
1+
Buttons allow users to take actions and make choices with a single tap. They communicate what action will occur when the user interacts with them.
22

3-
Use primary buttons for high emphasis actions. These buttons have the most visual impact and should be reserved for the most important, final actions that complete a flow, like Save, Join now, or Confirm. Try to use one per screen. Multiple primary buttons make it confusing for the user to understand what action they should take.
3+
## Basics
4+
5+
The only required prop is `children`, which is the button's label. Buttons default to the `primary` variant.
46

57
```jsx
6-
<Button onPress={console.log} variant="primary">
7-
Primary
8-
</Button>
8+
<Button onPress={console.log}>Get started</Button>
99
```
1010

11-
### Secondary Button
11+
## Variants
1212

13-
These buttons have a medium level of emphasis that should be used for non-critical actions. Secondary buttons can be used on pages without restrictions and works well for multiple actions of equal weight. They can be used in conjunction with a Primary Button or independently.
13+
Use variants to communicate the importance and intent of an action.
14+
15+
- **Primary** — High emphasis for main actions like "Save" or "Confirm". Limit to one per screen.
16+
- **Secondary** — Medium emphasis for multiple actions of equal weight.
17+
- **Tertiary** — High contrast with inverted background.
18+
- **Negative** — Destructive actions that can't be undone. Use sparingly.
1419

1520
```jsx
16-
<Button onPress={console.log} variant="secondary">
17-
Secondary
18-
</Button>
21+
<HStack gap={2} flexWrap="wrap">
22+
<Button onPress={console.log} variant="primary">
23+
Primary
24+
</Button>
25+
<Button onPress={console.log} variant="secondary">
26+
Secondary
27+
</Button>
28+
<Button onPress={console.log} variant="tertiary">
29+
Tertiary
30+
</Button>
31+
<Button onPress={console.log} variant="negative">
32+
Negative
33+
</Button>
34+
</HStack>
1935
```
2036

21-
### Tertiary Button
37+
### Transparent
2238

23-
These buttons provide high contrast with the background through the use of the themable inverted background color.
39+
Use transparent buttons for supplementary actions with lower prominence. The container is only visible on interaction. Works with any variant.
2440

2541
```jsx
26-
<Button onPress={console.log} variant="tertiary">
27-
Tertiary
28-
</Button>
42+
<HStack gap={2}>
43+
<Button onPress={console.log} transparent>
44+
Primary
45+
</Button>
46+
<Button onPress={console.log} variant="secondary" transparent>
47+
Secondary
48+
</Button>
49+
<Button onPress={console.log} variant="negative" transparent>
50+
Negative
51+
</Button>
52+
</HStack>
2953
```
3054

31-
### Negative Button
55+
## States
56+
57+
### Loading
3258

33-
Negative buttons should be used sparingly for destructive actions that will result in data loss, can’t be undone, or will have significant consequences. They commonly appear in confirmation dialogs as the final confirmation before deleting.
59+
Use the `loading` prop to indicate an action is in progress. The button becomes non-interactive and displays a spinner while preserving its width.
3460

3561
```jsx
36-
<Button onPress={console.log} variant="negative">
37-
Negative
38-
</Button>
62+
<HStack gap={2}>
63+
<Button onPress={console.log} loading>
64+
Save changes
65+
</Button>
66+
<Button onPress={console.log} variant="secondary" loading>
67+
Submit
68+
</Button>
69+
</HStack>
3970
```
4071

41-
### Transparent Button
72+
### Disabled
4273

43-
Transparent buttons are used for less important actions that are supplementary. These buttons have lower prominence since its container is not visible until the button is interacted with. Transparent buttons are frequently used on Cards and can be placed on a variety of backgrounds.
74+
Use the `disabled` prop to prevent interaction and indicate the action is unavailable.
4475

4576
```jsx
4677
<HStack gap={2}>
47-
<Button onPress={console.log} transparent>
78+
<Button disabled onPress={console.log}>
4879
Primary
4980
</Button>
50-
<Button onPress={console.log} variant="secondary" transparent>
81+
<Button disabled onPress={console.log} variant="secondary">
5182
Secondary
5283
</Button>
53-
<Button onPress={console.log} variant="negative" transparent>
84+
<Button disabled onPress={console.log} variant="negative">
5485
Negative
5586
</Button>
5687
</HStack>
5788
```
5889

59-
### Buttons with end icon
90+
## Sizing
91+
92+
### Compact
6093

61-
You can add an icon after the label of a button.
94+
Use `compact` for smaller buttons with reduced padding. Useful in dense UIs or alongside other compact elements.
6295

6396
```jsx
64-
<HStack gap={2}>
65-
<Button onPress={console.log} endIcon="add" endIconActive variant="secondary" compact>
66-
Select file
97+
<HStack gap={2} alignItems="center">
98+
<Button onPress={console.log} compact>
99+
Compact
100+
</Button>
101+
<Button onPress={console.log}>Default</Button>
102+
</HStack>
103+
```
104+
105+
### Block
106+
107+
Use `block` to make the button expand to fill its container width.
108+
109+
```jsx
110+
<VStack gap={2}>
111+
<Button onPress={console.log} block>
112+
Full width button
113+
</Button>
114+
<Button onPress={console.log} variant="secondary" block>
115+
Another full width
67116
</Button>
117+
</VStack>
118+
```
119+
120+
## Icons
121+
122+
### End Icon
123+
124+
Add an icon after the label to provide additional context or indicate direction.
125+
126+
```jsx
127+
<HStack gap={2}>
68128
<Button onPress={console.log} endIcon="forwardArrow" variant="secondary" compact>
69129
See more
70130
</Button>
131+
<Button onPress={console.log} endIcon="externalLink" variant="secondary" compact>
132+
Open link
133+
</Button>
134+
</HStack>
135+
```
136+
137+
### Start Icon
138+
139+
Add an icon before the label to reinforce the action.
140+
141+
```jsx
142+
<HStack gap={2}>
143+
<Button onPress={console.log} startIcon="add" startIconActive variant="secondary" compact>
144+
Add item
145+
</Button>
146+
<Button onPress={console.log} startIcon="download" variant="secondary" compact>
147+
Download
148+
</Button>
149+
</HStack>
150+
```
151+
152+
### Full Width with Icons
153+
154+
When using `block` with icons, the content automatically spreads across the button width.
155+
156+
```jsx
157+
<Button onPress={console.log} startIcon="wallet" endIcon="forwardArrow" variant="secondary" block>
158+
Connect wallet
159+
</Button>
160+
```
161+
162+
## Accessibility
163+
164+
Buttons automatically use their `children` as the accessible label. For buttons with only icons or ambiguous labels, provide an `accessibilityLabel`.
165+
166+
```jsx
167+
<Button onPress={handleClose} accessibilityLabel="Close dialog">
168+
×
169+
</Button>
170+
```
171+
172+
## Composed Examples
173+
174+
### Confirmation Dialog
175+
176+
A common pattern using primary and secondary buttons together.
177+
178+
```jsx
179+
<HStack gap={2} justifyContent="flex-end">
180+
<Button onPress={console.log} variant="secondary" transparent>
181+
Cancel
182+
</Button>
183+
<Button onPress={console.log}>Confirm</Button>
184+
</HStack>
185+
```
186+
187+
### Destructive Confirmation
188+
189+
Use negative buttons with a secondary cancel option for destructive actions.
190+
191+
```jsx
192+
<HStack gap={2} justifyContent="flex-end">
193+
<Button onPress={console.log} variant="secondary" transparent>
194+
Cancel
195+
</Button>
196+
<Button onPress={console.log} variant="negative">
197+
Delete
198+
</Button>
71199
</HStack>
72200
```
201+
202+
### Form Actions
203+
204+
A full-width primary action with a compact secondary option.
205+
206+
```jsx
207+
<VStack gap={2}>
208+
<Button onPress={console.log} block>
209+
Create account
210+
</Button>
211+
<Button onPress={console.log} variant="secondary" transparent block>
212+
Already have an account? Sign in
213+
</Button>
214+
</VStack>
215+
```

0 commit comments

Comments
 (0)