Skip to main content

Components

Button

Button allows users to perform actions.

variant
Description

Specify which variant to use

Type
"primary" | "secondary" | "tertiary"
Default
primary
icon
Description

Toggle icon only styling, pass icon as children When combined with loading, the loading-icon will be shown instead of the icon.

Type
boolean
Default
false
loading
Description

Toggle loading state. Pass an element if you want to display a custom loader.

Type
any
Default
false
asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
type
Description

Specify the type of button. Unset when `asChild` is true

Type
"button" | "submit" | "reset"
Default
'button'
NameTypeDefaultDescription
variant"primary" | "secondary" | "tertiary"primary

Specify which variant to use

iconbooleanfalse

Toggle icon only styling, pass icon as children When combined with loading, the loading-icon will be shown instead of the icon.

loadinganyfalse

Toggle loading state. Pass an element if you want to display a custom loader.

asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

type"button" | "submit" | "reset"'button'

Specify the type of button. Unset when `asChild` is true

Usage

Examples

Variants

variant is used to change the appearance of the button.

Colors

Either you set data-color directly on Button, or it inherits from the closest parent element with data-color.

Icon

If you only have an icon in the button, you can set icon={true} to make it square. If you have other content, such as text, the button will automatically have air around the icon.

asChild is used to change the button to a link. Read more about composition in the Designsystem.

Buttons that load

Below we use loading={true} to show that the button is loading something. Here you can also submit your own loading component if our Spinner does not fit.

In the example above, aria-disabled is automatically set when loading={true}. This is the recommended way to show that a button is disabled. Then the button can still get focus when the user navigates with the keyboard. This way, screen readers and other assistive devices are informed that the button exists, but that it is not active.

Note: Neither loading="true" nor aria-disabled automatically prevents the button from triggering onClick. You must ensure that the callback function does not run when the button is disabled.

HTML

The class name ds-button is set to <button>. In React, we also set type="button" by default, to avoid unexpected submits in forms.

There are three data attributes you can use for customization: data-icon - set if the button only has an icon. data-variant - set variant of the button (primary, secondary, tertiary). data-fullWidth - set if the button should be full width.

If you want a button that loads, you have to add a loading indicator yourself.

CSS variables and data attributes

CSS Variables
NameValue
--dsc-button-background--activevar(--ds-color-base-active)
--dsc-button-background--hovervar(--ds-color-base-hover)
--dsc-button-backgroundvar(--ds-color-base-default)
--dsc-button-colorvar(--ds-color-base-contrast-default)
--dsc-button-color--hovervar(--ds-color-base-contrast-default)
--dsc-button-border-widthvar(--ds-border-width-default)
--dsc-button-border-stylesolid
--dsc-button-border-colortransparent
--dsc-button-gapvar(--ds-size-2)
--dsc-button-paddingvar(--ds-size-2) var(--ds-size-4)
--dsc-button-sizevar(--ds-size-12)
Data Attributes
NameValue
data-variantsecondary, tertiary
data-icon
data-fullwidth
Edit this page on github.com (opens in a new tab)