|
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. |
2 | 2 |
|
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. |
4 | 6 |
|
5 | 7 | ```jsx |
6 | | -<Button onPress={console.log} variant="primary"> |
7 | | - Primary |
8 | | -</Button> |
| 8 | +<Button onPress={console.log}>Get started</Button> |
9 | 9 | ``` |
10 | 10 |
|
11 | | -### Secondary Button |
| 11 | +## Variants |
12 | 12 |
|
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. |
14 | 19 |
|
15 | 20 | ```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> |
19 | 35 | ``` |
20 | 36 |
|
21 | | -### Tertiary Button |
| 37 | +### Transparent |
22 | 38 |
|
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. |
24 | 40 |
|
25 | 41 | ```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> |
29 | 53 | ``` |
30 | 54 |
|
31 | | -### Negative Button |
| 55 | +## States |
| 56 | + |
| 57 | +### Loading |
32 | 58 |
|
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. |
34 | 60 |
|
35 | 61 | ```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> |
39 | 70 | ``` |
40 | 71 |
|
41 | | -### Transparent Button |
| 72 | +### Disabled |
42 | 73 |
|
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. |
44 | 75 |
|
45 | 76 | ```jsx |
46 | 77 | <HStack gap={2}> |
47 | | - <Button onPress={console.log} transparent> |
| 78 | + <Button disabled onPress={console.log}> |
48 | 79 | Primary |
49 | 80 | </Button> |
50 | | - <Button onPress={console.log} variant="secondary" transparent> |
| 81 | + <Button disabled onPress={console.log} variant="secondary"> |
51 | 82 | Secondary |
52 | 83 | </Button> |
53 | | - <Button onPress={console.log} variant="negative" transparent> |
| 84 | + <Button disabled onPress={console.log} variant="negative"> |
54 | 85 | Negative |
55 | 86 | </Button> |
56 | 87 | </HStack> |
57 | 88 | ``` |
58 | 89 |
|
59 | | -### Buttons with end icon |
| 90 | +## Sizing |
| 91 | + |
| 92 | +### Compact |
60 | 93 |
|
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. |
62 | 95 |
|
63 | 96 | ```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 |
67 | 116 | </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}> |
68 | 128 | <Button onPress={console.log} endIcon="forwardArrow" variant="secondary" compact> |
69 | 129 | See more |
70 | 130 | </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> |
71 | 199 | </HStack> |
72 | 200 | ``` |
| 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