@utilitywarehouse/hearth-react 0.28.6 → 0.29.0
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/README.md +34 -20
- package/SKILL.md +355 -0
- package/dist/{chunk-O7RBVBMN.cjs → chunk-LWHIBSW2.cjs} +2 -2
- package/dist/{chunk-O7RBVBMN.cjs.map → chunk-LWHIBSW2.cjs.map} +1 -1
- package/dist/{chunk-JRVYOIXR.js → chunk-MIVYZGEV.js} +2 -2
- package/dist/components/CardAccordion/CardAccordion.context.d.ts.map +1 -1
- package/dist/components/Combobox/Combobox.cjs +1 -1
- package/dist/components/Combobox/Combobox.js +1 -1
- package/dist/components/ExpandableCard/ExpandableCard.cjs +1 -1
- package/dist/components/ExpandableCard/ExpandableCard.js +1 -1
- package/dist/helpers/get-classname-styles.d.ts.map +1 -1
- package/dist/helpers/logger.d.ts.map +1 -1
- package/dist/helpers/merge-ids.d.ts.map +1 -1
- package/dist/hooks/use-ids.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +18 -12
- package/public/llms/components/accordion.md +321 -0
- package/public/llms/components/alert.md +217 -0
- package/public/llms/components/avatar.md +112 -0
- package/public/llms/components/badge.md +158 -0
- package/public/llms/components/body-text.md +200 -0
- package/public/llms/components/box.md +148 -0
- package/public/llms/components/breadcrumbs.md +97 -0
- package/public/llms/components/button.md +595 -0
- package/public/llms/components/card-accordion.md +277 -0
- package/public/llms/components/card.md +985 -0
- package/public/llms/components/checkbox-group.md +193 -0
- package/public/llms/components/checkbox-tile.md +116 -0
- package/public/llms/components/checkbox.md +108 -0
- package/public/llms/components/combobox.md +360 -0
- package/public/llms/components/container.md +162 -0
- package/public/llms/components/currency-input.md +85 -0
- package/public/llms/components/date-input.md +90 -0
- package/public/llms/components/date-picker.md +159 -0
- package/public/llms/components/description-list.md +149 -0
- package/public/llms/components/detail-text.md +89 -0
- package/public/llms/components/divider.md +88 -0
- package/public/llms/components/em.md +43 -0
- package/public/llms/components/expandable-card.md +231 -0
- package/public/llms/components/flex.md +197 -0
- package/public/llms/components/grid.md +244 -0
- package/public/llms/components/heading.md +65 -0
- package/public/llms/components/helper-text.md +27 -0
- package/public/llms/components/highlight-banner.md +94 -0
- package/public/llms/components/icon-button.md +516 -0
- package/public/llms/components/icon-container.md +247 -0
- package/public/llms/components/inline-link.md +190 -0
- package/public/llms/components/label.md +28 -0
- package/public/llms/components/link.md +236 -0
- package/public/llms/components/list.md +715 -0
- package/public/llms/components/menu.md +270 -0
- package/public/llms/components/modal.md +328 -0
- package/public/llms/components/pagination.md +138 -0
- package/public/llms/components/password-input.md +93 -0
- package/public/llms/components/progress-bar.md +139 -0
- package/public/llms/components/progress-stepper.md +147 -0
- package/public/llms/components/radio-group.md +487 -0
- package/public/llms/components/search-input.md +132 -0
- package/public/llms/components/section-header.md +82 -0
- package/public/llms/components/select.md +148 -0
- package/public/llms/components/skeleton.md +282 -0
- package/public/llms/components/spinner.md +59 -0
- package/public/llms/components/strong.md +49 -0
- package/public/llms/components/switch.md +106 -0
- package/public/llms/components/table.md +230 -0
- package/public/llms/components/tabs.md +320 -0
- package/public/llms/components/text-area.md +141 -0
- package/public/llms/components/text-input.md +228 -0
- package/public/llms/components/toast.md +323 -0
- package/public/llms/components/toggle-button-card.md +513 -0
- package/public/llms/components/tooltip.md +188 -0
- package/public/llms/components/unstyled-icon-button.md +175 -0
- package/public/llms/components/validation-text.md +29 -0
- package/public/llms/components/verification-input.md +96 -0
- package/public/llms/docs/changelog.md +1430 -0
- package/public/llms/docs/common-props/align-self.md +90 -0
- package/public/llms/docs/common-props/border.md +308 -0
- package/public/llms/docs/common-props/colour.md +221 -0
- package/public/llms/docs/common-props/flex-items.md +91 -0
- package/public/llms/docs/common-props/gap.md +111 -0
- package/public/llms/docs/common-props/grid-items.md +96 -0
- package/public/llms/docs/common-props/margin.md +105 -0
- package/public/llms/docs/common-props/opacity.md +100 -0
- package/public/llms/docs/common-props/order.md +90 -0
- package/public/llms/docs/common-props/overflow.md +89 -0
- package/public/llms/docs/common-props/padding.md +102 -0
- package/public/llms/docs/common-props/position.md +92 -0
- package/public/llms/docs/common-props/size.md +93 -0
- package/public/llms/docs/common-props/spacing.md +97 -0
- package/public/llms/docs/common-props/text.md +35 -0
- package/public/llms/docs/common-props/z-index.md +88 -0
- package/public/llms/docs/design-tokens.md +72 -0
- package/public/llms/docs/getting-started.md +117 -0
- package/public/llms/docs/layout.md +135 -0
- package/public/llms/docs/migrating.md +302 -0
- package/public/llms/docs/responsive-design/breakpoints.md +119 -0
- package/public/llms/docs/responsive-design/media-queries.md +89 -0
- package/public/llms/docs/responsive-design/responsive-props.md +37 -0
- package/public/llms.txt +97 -0
- package/scripts/init-ai.js +142 -0
- package/styles.css +2 -2
- /package/dist/{chunk-JRVYOIXR.js.map → chunk-MIVYZGEV.js.map} +0 -0
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
# IconButton
|
|
2
|
+
|
|
3
|
+
Icon Buttons are used to trigger an action on a page or to complete tasks in other components. Use Icon Buttons when you want to display an action quickly and visually, and when space is limited.
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
<Flex direction="column" gap="600">
|
|
7
|
+
<Flex gap="200" direction="column">
|
|
8
|
+
<Heading>Emphasis</Heading>
|
|
9
|
+
<Flex gap="400" alignItems="center">
|
|
10
|
+
{sizes.map(size => (
|
|
11
|
+
<Flex key={size} gap="100">
|
|
12
|
+
<IconButton variant="emphasis" colorScheme="highlight" size={size} label="add">
|
|
13
|
+
<AddMediumIcon />
|
|
14
|
+
</IconButton>
|
|
15
|
+
</Flex>
|
|
16
|
+
))}
|
|
17
|
+
</Flex>
|
|
18
|
+
<Flex gap="400" alignItems="center">
|
|
19
|
+
{sizes.map(size => (
|
|
20
|
+
<Flex key={size} gap="100">
|
|
21
|
+
<IconButton disabled variant="emphasis" colorScheme="highlight" size={size} label="add">
|
|
22
|
+
<AddMediumIcon />
|
|
23
|
+
</IconButton>
|
|
24
|
+
</Flex>
|
|
25
|
+
))}
|
|
26
|
+
</Flex>
|
|
27
|
+
<Flex gap="400" alignItems="center">
|
|
28
|
+
{sizes.map(size => (
|
|
29
|
+
<Flex key={size} gap="100">
|
|
30
|
+
<IconButton loading variant="emphasis" colorScheme="highlight" size={size} label="add">
|
|
31
|
+
<AddMediumIcon />
|
|
32
|
+
</IconButton>
|
|
33
|
+
</Flex>
|
|
34
|
+
))}
|
|
35
|
+
</Flex>
|
|
36
|
+
</Flex>
|
|
37
|
+
<Flex gap="200" direction="column">
|
|
38
|
+
<Heading style={{ textTransform: 'capitalize' }}>Solid</Heading>
|
|
39
|
+
<Flex gap="400" alignItems="center">
|
|
40
|
+
{sizes.map(size => (
|
|
41
|
+
<Flex key={size} gap="100">
|
|
42
|
+
{solidColorSchemes.map(colorScheme => (
|
|
43
|
+
<IconButton
|
|
44
|
+
key={colorScheme}
|
|
45
|
+
variant="solid"
|
|
46
|
+
colorScheme={colorScheme}
|
|
47
|
+
size={size}
|
|
48
|
+
label="add"
|
|
49
|
+
>
|
|
50
|
+
<AddMediumIcon />
|
|
51
|
+
</IconButton>
|
|
52
|
+
))}
|
|
53
|
+
</Flex>
|
|
54
|
+
))}
|
|
55
|
+
</Flex>
|
|
56
|
+
<Flex gap="400" alignItems="center">
|
|
57
|
+
{sizes.map(size => (
|
|
58
|
+
<Flex key={size} gap="100">
|
|
59
|
+
{solidColorSchemes.map(colorScheme => (
|
|
60
|
+
<IconButton
|
|
61
|
+
disabled
|
|
62
|
+
key={colorScheme}
|
|
63
|
+
variant="solid"
|
|
64
|
+
colorScheme={colorScheme}
|
|
65
|
+
size={size}
|
|
66
|
+
label="add"
|
|
67
|
+
>
|
|
68
|
+
<AddMediumIcon />
|
|
69
|
+
</IconButton>
|
|
70
|
+
))}
|
|
71
|
+
</Flex>
|
|
72
|
+
))}
|
|
73
|
+
</Flex>
|
|
74
|
+
<Flex gap="400" alignItems="center">
|
|
75
|
+
{sizes.map(size => (
|
|
76
|
+
<Flex key={size} gap="100">
|
|
77
|
+
{solidColorSchemes.map(colorScheme => (
|
|
78
|
+
<IconButton
|
|
79
|
+
loading
|
|
80
|
+
key={colorScheme}
|
|
81
|
+
variant="solid"
|
|
82
|
+
colorScheme={colorScheme}
|
|
83
|
+
size={size}
|
|
84
|
+
label="add"
|
|
85
|
+
>
|
|
86
|
+
<AddMediumIcon />
|
|
87
|
+
</IconButton>
|
|
88
|
+
))}
|
|
89
|
+
</Flex>
|
|
90
|
+
))}
|
|
91
|
+
</Flex>
|
|
92
|
+
</Flex>
|
|
93
|
+
{(['outline', 'ghost'] as const).map(variant => (
|
|
94
|
+
<Flex key={variant} gap="200" direction="column">
|
|
95
|
+
<Heading style={{ textTransform: 'capitalize' }}>{variant}</Heading>
|
|
96
|
+
<Flex gap="400" alignItems="center">
|
|
97
|
+
{sizes.map(size => (
|
|
98
|
+
<Flex key={size} gap="100">
|
|
99
|
+
{otherColorSchemes.map(colorScheme => (
|
|
100
|
+
<IconButton
|
|
101
|
+
key={colorScheme}
|
|
102
|
+
variant={variant}
|
|
103
|
+
colorScheme={colorScheme}
|
|
104
|
+
size={size}
|
|
105
|
+
label="add"
|
|
106
|
+
>
|
|
107
|
+
<AddMediumIcon />
|
|
108
|
+
</IconButton>
|
|
109
|
+
))}
|
|
110
|
+
</Flex>
|
|
111
|
+
))}
|
|
112
|
+
</Flex>
|
|
113
|
+
<Flex gap="400" alignItems="center">
|
|
114
|
+
{sizes.map(size => (
|
|
115
|
+
<Flex key={size} gap="100">
|
|
116
|
+
{otherColorSchemes.map(colorScheme => (
|
|
117
|
+
<IconButton
|
|
118
|
+
disabled
|
|
119
|
+
key={colorScheme}
|
|
120
|
+
variant={variant}
|
|
121
|
+
colorScheme={colorScheme}
|
|
122
|
+
size={size}
|
|
123
|
+
label="add"
|
|
124
|
+
>
|
|
125
|
+
<AddMediumIcon />
|
|
126
|
+
</IconButton>
|
|
127
|
+
))}
|
|
128
|
+
</Flex>
|
|
129
|
+
))}
|
|
130
|
+
</Flex>
|
|
131
|
+
<Flex gap="400" alignItems="center">
|
|
132
|
+
{sizes.map(size => (
|
|
133
|
+
<Flex key={size} gap="100">
|
|
134
|
+
{otherColorSchemes.map(colorScheme => (
|
|
135
|
+
<IconButton
|
|
136
|
+
loading
|
|
137
|
+
key={colorScheme}
|
|
138
|
+
variant={variant}
|
|
139
|
+
colorScheme={colorScheme}
|
|
140
|
+
size={size}
|
|
141
|
+
label="add"
|
|
142
|
+
>
|
|
143
|
+
<AddMediumIcon />
|
|
144
|
+
</IconButton>
|
|
145
|
+
))}
|
|
146
|
+
</Flex>
|
|
147
|
+
))}
|
|
148
|
+
</Flex>
|
|
149
|
+
</Flex>
|
|
150
|
+
))}
|
|
151
|
+
</Flex>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
- [Icons](#icons)
|
|
155
|
+
- [Accessibility](#accessibility)
|
|
156
|
+
- [Disabled buttons](#disabled-buttons)
|
|
157
|
+
- [Variants](#variants)
|
|
158
|
+
- [Colour schemes](#colour-schemes)
|
|
159
|
+
- [Inverted](#inverted)
|
|
160
|
+
- [Size](#size)
|
|
161
|
+
- [Responsive icon sizes](#responsive-icon-sizes)
|
|
162
|
+
- [Semantic HTML](#semantic-html)
|
|
163
|
+
- [API](#api)
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
<IconButton {...args}>
|
|
167
|
+
<AddMediumIcon />
|
|
168
|
+
</IconButton>
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Icons
|
|
172
|
+
|
|
173
|
+
This button is intended to be used with the Hearth Icons packages (to be released). If you do use
|
|
174
|
+
another icon, please add the `data-icon` attribute to your icon so that it
|
|
175
|
+
renders the appropriate styles.
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
<IconButton>
|
|
179
|
+
<AddMediumIcon />
|
|
180
|
+
</IconButton>
|
|
181
|
+
|
|
182
|
+
[...]
|
|
183
|
+
|
|
184
|
+
<IconButton>
|
|
185
|
+
<MyFontIcon aria-hidden="true" data-icon />
|
|
186
|
+
</IconButton>
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Accessibility
|
|
190
|
+
|
|
191
|
+
Follows the [WAI-ARIA Button Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/button/).
|
|
192
|
+
|
|
193
|
+
Given the button contains only an icon (i.e. no text content), it is required
|
|
194
|
+
that a label be provided. This will be announced to a screen reader, and should
|
|
195
|
+
reflect the visual icon being used with the button.
|
|
196
|
+
|
|
197
|
+
Icons from the UW icons packages have `aria-hidden="true"` set by default. If
|
|
198
|
+
you are using an icon from outside these packages, and for purely decorative
|
|
199
|
+
reasons, please ensure it has this attribute set so that the icon is hidden
|
|
200
|
+
from screen readers.
|
|
201
|
+
|
|
202
|
+
### Disabled buttons
|
|
203
|
+
|
|
204
|
+
Disabled buttons use `aria-disabled`, rather than `disabled`, so that they are
|
|
205
|
+
still focusable when using the keyboard. This means that screen readers are
|
|
206
|
+
still able to find the button, with the insight that it is disabled and that
|
|
207
|
+
there is perhaps an action which needs to be taken, rather than not knowing
|
|
208
|
+
there is a button there at all. The `onClick` handler will be disabled, however
|
|
209
|
+
you will need to make sure you disable any other expected actions, including
|
|
210
|
+
when using `type="submit"`.
|
|
211
|
+
|
|
212
|
+
## Variants
|
|
213
|
+
|
|
214
|
+
The variant prop controls the visual appearance of the button.
|
|
215
|
+
|
|
216
|
+
```tsx
|
|
217
|
+
<Flex gap="400">
|
|
218
|
+
<IconButton variant="emphasis" colorScheme="highlight" label="add">
|
|
219
|
+
<AddMediumIcon />
|
|
220
|
+
</IconButton>
|
|
221
|
+
<IconButton variant="solid" colorScheme="highlight" label="add">
|
|
222
|
+
<AddMediumIcon />
|
|
223
|
+
</IconButton>
|
|
224
|
+
<IconButton variant="outline" colorScheme="functional" label="add">
|
|
225
|
+
<AddMediumIcon />
|
|
226
|
+
</IconButton>
|
|
227
|
+
<IconButton variant="ghost" colorScheme="functional" label="add">
|
|
228
|
+
<AddMediumIcon />
|
|
229
|
+
</IconButton>
|
|
230
|
+
</Flex>
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
```tsx
|
|
234
|
+
<Flex gap="400">
|
|
235
|
+
<IconButton variant="emphasis" colorScheme="highlight" label="add">
|
|
236
|
+
<AddMediumIcon />
|
|
237
|
+
</IconButton>
|
|
238
|
+
<IconButton variant="solid" colorScheme="highlight" label="add">
|
|
239
|
+
<AddMediumIcon />
|
|
240
|
+
</IconButton>
|
|
241
|
+
<IconButton variant="outline" colorScheme="functional" label="add">
|
|
242
|
+
<AddMediumIcon />
|
|
243
|
+
</IconButton>
|
|
244
|
+
<IconButton variant="ghost" colorScheme="functional" label="add">
|
|
245
|
+
<AddMediumIcon />
|
|
246
|
+
</IconButton>
|
|
247
|
+
</Flex>
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
- The Emphasis variant of the Button is used for high emphasis actions where there will be no compromise to functionality.
|
|
251
|
+
- Solid Buttons are typically used for actions that require high emphasis and are considered primary actions.
|
|
252
|
+
- Outline Buttons typically have a medium level of emphasis. They are best suited for non-critical actions.
|
|
253
|
+
- Ghost buttons are designed to have a lower prominence compared to other button variants. This makes them suitable for actions that are not as important and also allows them to be used as building blocks for other components.
|
|
254
|
+
|
|
255
|
+
## Colour schemes
|
|
256
|
+
|
|
257
|
+
The `colorScheme` prop will change the button colours.
|
|
258
|
+
|
|
259
|
+
```tsx
|
|
260
|
+
<IconButton colorScheme="highlight">
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Highlight
|
|
264
|
+
|
|
265
|
+
The Highlight colour scheme serves as the default color scheme for primary actions,
|
|
266
|
+
therefore is only available for Emphasis and Solid Buttons variants.
|
|
267
|
+
|
|
268
|
+
```tsx
|
|
269
|
+
<Flex gap="400">
|
|
270
|
+
<IconButton variant="emphasis" colorScheme="highlight" label="add">
|
|
271
|
+
<AddMediumIcon />
|
|
272
|
+
</IconButton>
|
|
273
|
+
<IconButton variant="solid" colorScheme="highlight" label="add">
|
|
274
|
+
<AddMediumIcon />
|
|
275
|
+
</IconButton>
|
|
276
|
+
</Flex>
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Functional
|
|
280
|
+
|
|
281
|
+
The Functional colour scheme is best suited for situations that have lower prominence,
|
|
282
|
+
which is why it is only available for Outline and Ghost Button variants.
|
|
283
|
+
|
|
284
|
+
```tsx
|
|
285
|
+
<Flex gap="400">
|
|
286
|
+
<IconButton variant="outline" colorScheme="functional" label="add">
|
|
287
|
+
<AddMediumIcon />
|
|
288
|
+
</IconButton>
|
|
289
|
+
<IconButton variant="ghost" colorScheme="functional" label="add">
|
|
290
|
+
<AddMediumIcon />
|
|
291
|
+
</IconButton>
|
|
292
|
+
</Flex>
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Destructive
|
|
296
|
+
|
|
297
|
+
The Destructive colour scheme is suitable for destructive actions that are irreversible,
|
|
298
|
+
or will have significant and negative consequences for the user.
|
|
299
|
+
|
|
300
|
+
```tsx
|
|
301
|
+
<Flex gap="400">
|
|
302
|
+
<IconButton variant="solid" colorScheme="destructive" label="add">
|
|
303
|
+
<AddMediumIcon />
|
|
304
|
+
</IconButton>
|
|
305
|
+
<IconButton variant="outline" colorScheme="destructive" label="add">
|
|
306
|
+
<AddMediumIcon />
|
|
307
|
+
</IconButton>
|
|
308
|
+
<IconButton variant="ghost" colorScheme="destructive" label="add">
|
|
309
|
+
<AddMediumIcon />
|
|
310
|
+
</IconButton>
|
|
311
|
+
</Flex>
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Affirmative
|
|
315
|
+
|
|
316
|
+
The Affirmative colour scheme is ideal for indicating positive or affirmative
|
|
317
|
+
actions.
|
|
318
|
+
|
|
319
|
+
```tsx
|
|
320
|
+
<Flex gap="400">
|
|
321
|
+
<IconButton variant="solid" colorScheme="affirmative" label="add">
|
|
322
|
+
<AddMediumIcon />
|
|
323
|
+
</IconButton>
|
|
324
|
+
<IconButton variant="outline" colorScheme="affirmative" label="add">
|
|
325
|
+
<AddMediumIcon />
|
|
326
|
+
</IconButton>
|
|
327
|
+
<IconButton variant="ghost" colorScheme="affirmative" label="add">
|
|
328
|
+
<AddMediumIcon />
|
|
329
|
+
</IconButton>
|
|
330
|
+
</Flex>
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
## Inverted
|
|
334
|
+
|
|
335
|
+
The `inverted` prop should be used when using a button on darker surface
|
|
336
|
+
colours, specifically the UW Purple and Dark Purple colours. It only affects
|
|
337
|
+
the following buttons:
|
|
338
|
+
|
|
339
|
+
- Emphasis/Yellow
|
|
340
|
+
- Solid/Yellow
|
|
341
|
+
- Outline/Grey
|
|
342
|
+
- Ghost/grey.
|
|
343
|
+
|
|
344
|
+
**It is very important to remember to use the `inverted` prop when using the
|
|
345
|
+
Emphasis button on darker backgrounds. While the button itself doesn't change
|
|
346
|
+
colours, the focus ring colour does change, and omitting the `inverted` prop
|
|
347
|
+
will indermine the accessibility of the button.**
|
|
348
|
+
|
|
349
|
+
```tsx
|
|
350
|
+
<Flex gap="400" backgroundColor="brand" padding="400">
|
|
351
|
+
<IconButton variant="emphasis" inverted label="add">
|
|
352
|
+
<AddMediumIcon />
|
|
353
|
+
</IconButton>
|
|
354
|
+
<IconButton variant="solid" colorScheme="highlight" inverted label="add">
|
|
355
|
+
<AddMediumIcon />
|
|
356
|
+
</IconButton>
|
|
357
|
+
<IconButton variant="outline" colorScheme="functional" inverted label="add">
|
|
358
|
+
<AddMediumIcon />
|
|
359
|
+
</IconButton>
|
|
360
|
+
<IconButton variant="ghost" colorScheme="functional" inverted label="add">
|
|
361
|
+
<AddMediumIcon />
|
|
362
|
+
</IconButton>
|
|
363
|
+
</Flex>
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
## Size
|
|
367
|
+
|
|
368
|
+
The size prop controls the size of the `IconButton`. This is a responsive prop and
|
|
369
|
+
can be used to display different sizes at different breakpoints.
|
|
370
|
+
|
|
371
|
+
```tsx
|
|
372
|
+
<IconButton
|
|
373
|
+
size={{
|
|
374
|
+
mobile: 'md',
|
|
375
|
+
tablet: 'sm',
|
|
376
|
+
desktop: 'md',
|
|
377
|
+
wide: 'sm',
|
|
378
|
+
}}
|
|
379
|
+
/>
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
```tsx
|
|
383
|
+
<Flex gap="400" direction="column">
|
|
384
|
+
<Flex gap="400">
|
|
385
|
+
<IconButton variant="emphasis" size="md" label="add">
|
|
386
|
+
<AddMediumIcon />
|
|
387
|
+
</IconButton>
|
|
388
|
+
<IconButton variant="solid" size="md" label="add">
|
|
389
|
+
<AddMediumIcon />
|
|
390
|
+
</IconButton>
|
|
391
|
+
<IconButton variant="outline" size="md" label="add">
|
|
392
|
+
<AddMediumIcon />
|
|
393
|
+
</IconButton>
|
|
394
|
+
<IconButton variant="ghost" size="md" label="add">
|
|
395
|
+
<AddMediumIcon />
|
|
396
|
+
</IconButton>
|
|
397
|
+
</Flex>
|
|
398
|
+
<Flex gap="400">
|
|
399
|
+
<IconButton variant="emphasis" size="sm" label="add">
|
|
400
|
+
<AddMediumIcon />
|
|
401
|
+
</IconButton>
|
|
402
|
+
<IconButton variant="solid" size="sm" label="add">
|
|
403
|
+
<AddMediumIcon />
|
|
404
|
+
</IconButton>
|
|
405
|
+
<IconButton variant="outline" size="sm" label="add">
|
|
406
|
+
<AddMediumIcon />
|
|
407
|
+
</IconButton>
|
|
408
|
+
<IconButton variant="ghost" size="sm" label="add">
|
|
409
|
+
<AddMediumIcon />
|
|
410
|
+
</IconButton>
|
|
411
|
+
</Flex>
|
|
412
|
+
</Flex>
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
### Responsive icon sizes
|
|
416
|
+
|
|
417
|
+
If you need to render different sized icons in conjunction with the responsive
|
|
418
|
+
size prop, there are a couple of ways you can do this.
|
|
419
|
+
|
|
420
|
+
1. Using JS, with the `useMediaQuery` hook.
|
|
421
|
+
|
|
422
|
+
```tsx
|
|
423
|
+
import { AddMediumIcon, AddSmallIcon } from '@utilitywarehouse/hearth-react-icons';
|
|
424
|
+
import { IconButton, useMediaQuery, media } from '@utilitywarehouse/hearth-react';
|
|
425
|
+
|
|
426
|
+
const MyComponent = () => {
|
|
427
|
+
const showDesktopIcon = useMediaQuery(media.above('desktop'));
|
|
428
|
+
|
|
429
|
+
return (
|
|
430
|
+
<IconButton size={{ mobile: 'sm', desktop: 'md' }}>
|
|
431
|
+
{showDesktopIcon ? <AddMediumIcon /> : <AddSmallIcon />}
|
|
432
|
+
</IconButton>
|
|
433
|
+
);
|
|
434
|
+
};
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
2. Using CSS, with `Box` and style props.
|
|
438
|
+
|
|
439
|
+
```tsx
|
|
440
|
+
import { AddMediumIcon, AddSmallIcon } from '@utilitywarehouse/hearthreact-icons';
|
|
441
|
+
import { IconButton, Box } from '@utilitywarehouse/hearth-react';
|
|
442
|
+
|
|
443
|
+
const MyComponent = () => (
|
|
444
|
+
<IconButton size={{ mobile: 'sm', desktop: 'md' }} label="add">
|
|
445
|
+
<Box asChild display={{ mobile: 'none', desktop: 'block' }}>
|
|
446
|
+
<AddMediumIcon />
|
|
447
|
+
</Box>
|
|
448
|
+
<Box asChild display={{ desktop: 'none' }}>
|
|
449
|
+
<AddSmallIcon />
|
|
450
|
+
</Box>
|
|
451
|
+
</IconButton>
|
|
452
|
+
);
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
## Semantic HTML
|
|
456
|
+
|
|
457
|
+
> If it goes somewhere it's a link, if it does something it's a button.
|
|
458
|
+
|
|
459
|
+
A semantic HTML button is rendered by default, however you can change the
|
|
460
|
+
underlying HTML element by using the `asChild` prop.
|
|
461
|
+
|
|
462
|
+
**NOTE:** Be aware that you cannot currently use `asChild` with the `emphasis` variant.
|
|
463
|
+
|
|
464
|
+
When `asChild` is set to true, the button will not render a default DOM element,
|
|
465
|
+
instead cloning the child and passing it the props and behaviour required to
|
|
466
|
+
make it functional.
|
|
467
|
+
|
|
468
|
+
Read more about this idea in the [Radix UI composition docs](https://www.radix-ui.com/primitives/docs/guides/composition).
|
|
469
|
+
|
|
470
|
+
```tsx
|
|
471
|
+
<Flex gap="200">
|
|
472
|
+
<IconButton {...args} asChild>
|
|
473
|
+
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
|
|
474
|
+
<a href={args.disabled ? undefined : 'https://uw.co.uk/services'}>
|
|
475
|
+
<AddMediumIcon />
|
|
476
|
+
</a>
|
|
477
|
+
</IconButton>
|
|
478
|
+
<IconButton {...args} asChild loading>
|
|
479
|
+
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
|
|
480
|
+
<a href={args.disabled ? undefined : 'https://uw.co.uk/services'}>
|
|
481
|
+
<AddMediumIcon />
|
|
482
|
+
</a>
|
|
483
|
+
</IconButton>
|
|
484
|
+
</Flex>
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
```tsx
|
|
488
|
+
<IconButton asChild>
|
|
489
|
+
<a href="https://uw.co.uk/services">
|
|
490
|
+
<AddMediumIcon />
|
|
491
|
+
</a>
|
|
492
|
+
</IconButton>
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
## API
|
|
496
|
+
|
|
497
|
+
This component is based on the `button` element and supports the following common props:
|
|
498
|
+
|
|
499
|
+
- Margin
|
|
500
|
+
|
|
501
|
+
| Prop | Type | Default | Description |
|
|
502
|
+
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------- |
|
|
503
|
+
| `label` | `string` | — | An accessibility label that describes the button. Make sure this label reflects the visual icon. |
|
|
504
|
+
| `margin` | `Responsive<"auto" \| "0" \| "25" \| "50" \| "75" \| "100" \| "150" \| "175" \| "200" \| "250" \| "300" \| "350" \| "400" \| "500" \| "600" \| "700" \| "800" \| "900" \| "1000" \| `var(--h-${string})`>` | — | |
|
|
505
|
+
| `marginTop` | `Responsive<"auto" \| "0" \| "25" \| "50" \| "75" \| "100" \| "150" \| "175" \| "200" \| "250" \| "300" \| "350" \| "400" \| "500" \| "600" \| "700" \| "800" \| "900" \| "1000" \| `var(--h-${string})`>` | — | |
|
|
506
|
+
| `marginRight` | `Responsive<"auto" \| "0" \| "25" \| "50" \| "75" \| "100" \| "150" \| "175" \| "200" \| "250" \| "300" \| "350" \| "400" \| "500" \| "600" \| "700" \| "800" \| "900" \| "1000" \| `var(--h-${string})`>` | — | |
|
|
507
|
+
| `marginBottom` | `Responsive<"auto" \| "0" \| "25" \| "50" \| "75" \| "100" \| "150" \| "175" \| "200" \| "250" \| "300" \| "350" \| "400" \| "500" \| "600" \| "700" \| "800" \| "900" \| "1000" \| `var(--h-${string})`>` | — | |
|
|
508
|
+
| `marginLeft` | `Responsive<"auto" \| "0" \| "25" \| "50" \| "75" \| "100" \| "150" \| "175" \| "200" \| "250" \| "300" \| "350" \| "400" \| "500" \| "600" \| "700" \| "800" \| "900" \| "1000" \| `var(--h-${string})`>` | — | |
|
|
509
|
+
| `marginX` | `Responsive<"auto" \| "0" \| "25" \| "50" \| "75" \| "100" \| "150" \| "175" \| "200" \| "250" \| "300" \| "350" \| "400" \| "500" \| "600" \| "700" \| "800" \| "900" \| "1000" \| `var(--h-${string})`>` | — | |
|
|
510
|
+
| `marginY` | `Responsive<"auto" \| "0" \| "25" \| "50" \| "75" \| "100" \| "150" \| "175" \| "200" \| "250" \| "300" \| "350" \| "400" \| "500" \| "600" \| "700" \| "800" \| "900" \| "1000" \| `var(--h-${string})`>` | — | |
|
|
511
|
+
| `variant` | `"emphasis" \| "solid" \| "outline" \| "ghost"` | — | Sets the button's visual variant |
|
|
512
|
+
| `colorScheme` | `"highlight" \| "affirmative" \| "destructive" \| "functional"` | — | Sets the button's colour scheme |
|
|
513
|
+
| `asChild` | `boolean` | — | Change the default rendered element for the one passed as a child, merging their props and behavior. |
|
|
514
|
+
| `loading` | `boolean` | — | Indicate when the button is in a loading state, will also disable the button. |
|
|
515
|
+
| `inverted` | `boolean` | — | Inverts the component colours, for use on darker surface colours. |
|
|
516
|
+
| `size` | `Responsive<"sm" \| "md">` | `md` | Sets the button height. |
|