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 outline
variant of Button
is typically used as a secondary button
<Button variant="outline">Outline</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 leadingIcon={SearchIcon}>Search</Button><Button trailingIcon={SearchIcon} sx={{mt: 2}}>Search</Button><Button leadingIcon={SearchIcon} trailingIcon={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}} /></>
A common use case for primer is a button with a counter component which shows the child count value.
We provide Button.Counter
as a composite component which requires you to provide a number as child.
The counter will match the variant
styles of the parent button.
<Button>Watch<Button.Counter>1</Button.Counter></Button>
Use the block
prop for full width buttons.
<Button block>Block</Button>
Name | Type | Default | Description |
---|---|---|---|
children Required | React.ReactNode | The content of the button. | |
variant | | 'default' | 'primary' | 'danger' | 'outline' | 'invisible' | 'default' | Change the visual style of the button. |
size | | 'small' | 'medium' | 'large' | 'medium' | |
leadingIcon | React.ComponentType<OcticonProps> | An icon to display before the button text. | |
trailingIcon | React.ComponentType<OcticonProps> | An icon to display 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. | |
ref | React.RefObject<HTMLButtonElement> | A ref to the element rendered by this component. Because this component is polymorphic, the type will vary based on the value of the as prop. | |
Additional props are passed to the <button> element. See button docs for a list of props accepted by the <button> element. |
Name | Type | Default | Description |
---|---|---|---|
children Required | number | The counter value. | |
sx | SystemStyleObject | Style overrides to apply to the component. See also overriding styles. |