import {Button} from '@primer/react'
This is the default variant for the Button
component.
The danger
variant of Button
is used to warn users about potentially destructive actions
The outline
variant of Button
is typically used as a secondary button
The invisible
variant of Button
indicates that the action is a low priority one.
Button
component supports three different sizes. small
, medium
, large
.
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.
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
also supports the three different sizes. small
, medium
, large
.
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.
Use the block
prop for full width buttons.
Name | Type | Default | Description |
---|---|---|---|
children Required | React.ReactNode | The content of the button. | |
variant | | 'default' | 'primary' | 'danger' | 'outline' | 'invisible' | 'link' | '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. |