|
| 1 | +--- |
| 2 | +title: Button |
| 3 | +description: Buttons are clickable elements that trigger an action that does not change the current URL. |
| 4 | +source: 'sentry/components/core/button' |
| 5 | +resources: |
| 6 | + figma: https://www.figma.com/design/eTJz6aPgudMY9E6mzyZU0B/ChonkUI--App-Components--WIP-?node-id=384-2119&t=DdXZ7WIgTdURJlRv-4 |
| 7 | + js: https://github.com/getsentry/sentry/blob/481d8d642e9cf549eb46fbaac1d0527395e8b490/static/app/components/core/button/index.tsx#L22 |
| 8 | + a11y: |
| 9 | + WCAG 1.4.3: https://www.w3.org/TR/WCAG22/#contrast-minimum |
| 10 | + WCAG 2.1.1: https://www.w3.org/TR/WCAG22/#keyboard |
| 11 | + WCAG 2.4.7: https://www.w3.org/TR/WCAG22/#focus-visible |
| 12 | + WCAG 2.5.8: https://www.w3.org/TR/WCAG22/#target-size-minimum |
| 13 | + WAI-ARIA Button Practices: https://www.w3.org/WAI/ARIA/apg/patterns/button/ |
| 14 | +next: |
| 15 | + link: '/stories/?name=app%2Fcomponents%2Fcore%2Fbutton%2FbuttonBar.stories.tsx' |
| 16 | + label: ButtonBar |
| 17 | +prev: |
| 18 | + link: '?name=app%2Fcomponents%2Fcore%2Fbadge%2Ftag.stories.tsx' |
| 19 | + label: Tag |
| 20 | +--- |
| 21 | + |
| 22 | +import {Button} from 'sentry/components/core/button'; |
| 23 | +import { |
| 24 | + IconAdd, |
| 25 | + IconArrow, |
| 26 | + IconChevron, |
| 27 | + IconClock, |
| 28 | + IconClose, |
| 29 | + IconDelete, |
| 30 | + IconDocs, |
| 31 | + IconEdit, |
| 32 | + IconEllipsis, |
| 33 | + IconLightning, |
| 34 | + IconLink, |
| 35 | + IconOpen, |
| 36 | + IconStar, |
| 37 | + IconZoom, |
| 38 | +} from 'sentry/icons'; |
| 39 | +import * as Storybook from 'sentry/stories'; |
| 40 | + |
| 41 | +import types from '!!type-loader!sentry/components/core/button/index'; |
| 42 | + |
| 43 | +export {types}; |
| 44 | + |
| 45 | +To create a basic button, wrap text in a `<Button>` and pass an `onClick` callback. |
| 46 | + |
| 47 | +```jsx |
| 48 | +<Button onClick={() => alert('Hello world')}>Click here</Button> |
| 49 | +``` |
| 50 | + |
| 51 | +### Priorities |
| 52 | + |
| 53 | +Buttons come in a few different styles: `muted` (default), `primary`, `warning`, `danger`, and `transparent`. |
| 54 | + |
| 55 | +<Storybook.Demo> |
| 56 | + <Button priority="muted">Muted (default)</Button> |
| 57 | + <Button priority="primary">Primary</Button> |
| 58 | + <Button priority="warning">Warning</Button> |
| 59 | + <Button priority="danger">Danger</Button> |
| 60 | + <Button priority="transparent">Transparent</Button> |
| 61 | +</Storybook.Demo> |
| 62 | +```jsx |
| 63 | +<Button priority="muted">Muted (default)</Button> |
| 64 | +<Button priority="primary">Primary</Button> |
| 65 | +<Button priority="warning">Warning</Button> |
| 66 | +<Button priority="danger">Danger</Button> |
| 67 | +<Button priority="transparent">Transparent</Button> |
| 68 | +``` |
| 69 | + |
| 70 | +### Sizes |
| 71 | + |
| 72 | +Buttons are available in different sizes: `md` (default), `sm`, `xs`, and `zero`. |
| 73 | + |
| 74 | +<Storybook.Demo> |
| 75 | + <Button size="md">Medium (default)</Button> |
| 76 | + <Button size="sm">Small</Button> |
| 77 | + <Button size="xs">Extra small</Button> |
| 78 | + <Button size="zero">Zero</Button> |
| 79 | +</Storybook.Demo> |
| 80 | +```jsx |
| 81 | +<Button size="md">Medium (default)</Button> |
| 82 | +<Button size="sm">Small</Button> |
| 83 | +<Button size="xs">Extra small</Button> |
| 84 | +<Button size="zero">Zero</Button> |
| 85 | +``` |
| 86 | + |
| 87 | +### Icons |
| 88 | + |
| 89 | +Buttons support an optional leading icon. |
| 90 | + |
| 91 | +<Storybook.Demo> |
| 92 | + <Button icon={<IconAdd />} priority="primary"> |
| 93 | + Add |
| 94 | + </Button> |
| 95 | +</Storybook.Demo> |
| 96 | +```jsx |
| 97 | +<Button icon={<IconAdd />} priority="primary"> |
| 98 | + Add |
| 99 | +</Button> |
| 100 | +``` |
| 101 | + |
| 102 | +We have standardized call to action copy and specific icon pairings. When creating an icon button, please use a pairing from the following list. |
| 103 | + |
| 104 | +| Icon | Name | Copy | Meaning | |
| 105 | +| ------------------------------------------ | ----------- | -------------------------------------- | --------------------------------------------------------- | |
| 106 | +| <IconAdd /> | `add` | Create | Spawn something from nothing | |
| 107 | +| <IconAdd /> | `add` | Add | Append another thing in the group | |
| 108 | +| <IconDelete /> | `trash` | Delete | Destroy thing in the group | |
| 109 | +| | | Manage | Broader meaning, includes bulk order, add, remove, etc. | |
| 110 | +| <IconEdit /> | `edit` | Edit | Modifies fundamental attribute of the thing | |
| 111 | +| <IconOpen /> | `open` | Open in `Product` | Leaves existing view and goes to another product | |
| 112 | +| <IconClose /> | `close` | Close | Potentially reopen this again later | |
| 113 | +| <IconDocs /> | `docs` | Read Docs | Similar to “Open In” but always goes to Sentry Docs | |
| 114 | +| <IconEllipsis /> | `ellipses` | More `Samples` | See more of the same thing | |
| 115 | +| | Show More | Accordions down to reveal more content | |
| 116 | +| <IconChevron direction="up" /> | `chevron` | Expand | Content is completely hidden except for title | |
| 117 | +| <IconChevron direction='down' /> | `chevron` | Collapse | Content is completely shown and need to hide except title | |
| 118 | +| <IconChevron isDouble direction="left" /> | `chevron` | Expand | Content is completely hidden (depends on direction) | |
| 119 | +| <IconChevron isDouble direction="right" /> | `chevron` | Collapse | Content is completely shown (depends on direction) | |
| 120 | +| | | Dismiss | Get rid of forever | |
| 121 | +| <IconClock /> | `clock` | Remind Me Later | Get rid of temporarily | |
| 122 | +| <IconArrow /> | `arrow` | Back | Go to previous screen | |
| 123 | +| <IconLightning /> | `lightning` | Upgrade | Upgrade to Business Plan | |
| 124 | +| | | Save `Item` | Preserve changes | |
| 125 | +| <IconClose /> | `close` | Cancel | Exit without saving changes | |
| 126 | +| <IconLink /> | `link` | Share | Copies link to paste anywhere | |
| 127 | +| | | Connect | Create link between two objects | |
| 128 | +| | | Disconnect | Break link between two objects | |
| 129 | +| <IconZoom isZoomIn /> | `zoom` | Zoom In | Applies to charts and zooms to fit | |
| 130 | +| <IconZoom /> | `zoom` | Zoom Out | Applies to charts and zooms out (i.e. 200%) | |
| 131 | +| <IconStar /> | `star` | Favorite | Hoisting item to primary view | |
| 132 | + |
| 133 | +### Icon-only Buttons |
| 134 | + |
| 135 | +In scenarios where high information density is critical, buttons may be displayed without text. |
| 136 | + |
| 137 | +> [!WARNING] |
| 138 | +> Buttons with icons and no `children` **must** include a `label` for screen readers! |
| 139 | +
|
| 140 | +<Storybook.Demo> |
| 141 | + <Button icon={<IconAdd />} label="Add" /> |
| 142 | +</Storybook.Demo> |
| 143 | +```jsx |
| 144 | +<Button icon={<IconAdd />} label="Add" /> |
| 145 | +``` |
| 146 | + |
| 147 | +### Accessibility |
| 148 | + |
| 149 | +To meet WCAG 2.2 AA compliance, `<Button>` automatically meets the [WCAG 1.4.3](https://www.w3.org/TR/WCAG22/#contrast-minimum), [WCAG 2.1.1](https://www.w3.org/TR/WCAG22/#keyboard), [WCAG 2.4.7](https://www.w3.org/TR/WCAG22/#focus-visible), [WCAG 2.5.8](https://www.w3.org/TR/WCAG22/#target-size-minimum) success criteria. |
| 150 | + |
| 151 | +Developers should take care to ensure that their implementations additionally follow the [WAI-ARIA Button Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/button/) and properly handle focus changes when an action is triggered. |
0 commit comments