import {Button} from '@primer/react'
This is the default variant for the Button component.
<Button>Default</Button>
The danger variant of Button is used to warn users about potentially destructive actions
<Button variant="danger">Danger</Button>
The invisible variant of Button indicates that the action is a low priority one.
<Button variant="invisible">Invisible</Button>
Button component supports three different sizes. small, medium, large.
<><Button size="small">Search</Button><Button sx={{mt: 2}}>Search</Button><Button sx={{mt: 2}} size="large">Search</Button></>
We can place an icon inside the Button in either the leading or the trailing position to enhance the visual context.
It is recommended to use an octicon here.
<><Button leadingVisual={SearchIcon}>Search</Button><Button trailingVisual={SearchIcon} sx={{mt: 2}}>Search</Button><Button leadingVisual={SearchIcon} trailingVisual={CheckIcon} sx={{mt: 2}}>Search</Button></>
A separate component called IconButton is used if the action shows only an icon with no text. This button will remain square in shape.
<IconButton aria-label="Search" icon={SearchIcon} />
IconButton also supports the three different sizes. small, medium, large.
<><IconButton aria-label="Search" size="small" icon={SearchIcon} /><IconButton aria-label="Search" icon={SearchIcon} sx={{ml: 2}} /><IconButton aria-label="Search" size="large" icon={SearchIcon} sx={{ml: 2}} /></>
To show a count value as a trailing visual inside Button, pass a value to the count prop. The counter will match the variant styles of the parent button.
<Button count="1">Watch</Button>
Use the block prop for full width buttons.
<Button block>Block</Button>
Native <button> HTML attributes are forwarded to the underlying React button component and are not listed below.
| Name | Type | Default | Description |
|---|---|---|---|
| children Required | React.ReactNode | Button description along with other components like Counter could be used here. | |
| variant | 'default' | 'primary' | 'danger' | 'outline' | 'invisible' | Changes the look and feel of the button which is different for each variant | |
| size | 'small' | 'medium' | 'large' | Changes the size of the button component | |
| block | boolean | Full width button fills the parent container | |
| leadingVisual | Component | provide an octicon. It will be placed before the button text | |
| trailingVisual | Component | provide an octicon. It will be placed after the button text | |
| as | React.ElementType | "button" | The underlying element to render — either a HTML element name or a React component. |
| sx | SystemStyleObject | Style overrides to apply to the component. See also overriding styles. | |
Additional props are passed to the <button> element. See MDN for a list of props accepted by the <button> element. If an as prop is specified, the accepted props will change accordingly. | |||
| Name | Type | Default | Description |
|---|---|---|---|
| children Required | number | The counter value as a number | |
| sx | SystemStyleObject | Style overrides to apply to the component. See also overriding styles. |