Button
Button component is used to trigger an action or event, such as submitting a form, opening a Dialog, canceling an action, or performing a delete operation.
Import#
Usage#
Button Sizes#
Use the size
prop to change the size of the button. You can set the value to
xs
, sm
, md
, or lg
.
Button Variant#
Use the variant
prop to change the visual style of the Button. You can set the
value to solid
, ghost
, outline
, or link
.
Button with Icon#
You can add left and right icons to the Button components. See how to add icons to your project
You can also use icons from popular libraries like react-icons and just pass it into the button.
Button loading state#
Pass isLoading
prop to the Button component to show it's loading state. You
can optionally pass loadingText
prop, if you do, the button will show a
spinner and the loading text. Otherwise, the button will take the width of the
text label and show only the spinner
Accessibility#
- Button has
role
button. - When Button has focus, Space and Enter activates it.
Composition#
Button composes PseudoBox and all props you pass (variant, variantColor, etc.) are converted to style props. This means you can override any style of the Button via props.
Custom Button#
In event you need to make your own custom button, you can leverage the
PseudoBox
component. It provides the hover
, focus
, active
and disabled
style props to style the button.
Props#
The Button composes the PseudoBox
component so you can pass props for
PseudoBox
. These are props related to the Button component.
Name | Type | Default | Description |
---|---|---|---|
aria-label | string | The label of the button | |
variantColor | string | The color of the button. Use a color key passed in theme.colors . | |
variant | outline , ghost , unstyled , link , solid | solid | The variant of the button style to use. |
isDisabled | boolean | If true , the button will be disabled. | |
isLoading | boolean | If true , the button will show a spinner. | |
loadingText | string | The label to show in the button when isLoading is true. If no text is passed, it only shows the spinner | |
size | xs , sm , md , lg | md | The size of the button. |