No Preview

Sorry, but you either have no stories or none are selected somehow.

If the problem persists, check the browser console, or the terminal you've run Storybook from.

The component failed to render properly, likely due to a configuration issue in Storybook. Here are some common causes and how you can address them:

  1. Missing Context/Providers: You can use decorators to supply specific contexts or providers, which are sometimes necessary for components to render correctly. For detailed instructions on using decorators, please visit the Decorators documentation.
  2. Misconfigured Webpack or Vite: Verify that Storybook picks up all necessary settings for loaders, plugins, and other relevant parameters. You can find step-by-step guides for configuring Webpack or Vite with Storybook.
  3. Missing Environment Variables: Your Storybook may require specific environment variables to function as intended. You can set up custom environment variables as outlined in the Environment Variables documentation.

Button

Buttons allow users to perform an action or to navigate to another page. They have multiple styles for various needs, and are ideal for calling attention to where a user needs to do something in order to move forward in a flow.

There are four available variants that are used for different levels of emphasis and different types of actions. By default, a button uses the fill style with a solid background. The primary and secondary variants also have an outline option.

Variants

Accent

The accent button communicates strong emphasis and is reserved for encouraging critical actions. In general, only use the emphasized option for the most important action on the page.

Disabled

A button in a disabled state shows that an action exists, but is not available in that circumstance. This state can be used to maintain layout continuity and to communicate that an action may become available later.

Negative

The negative button is for emphasizing actions that can be destructive or have negative consequences if taken. Use it sparingly.

Pending

The pending button is for indicating that a quick progress action is taking place. In this case, the label and optional icon disappear and a progress circle appears. The progress circle always shows an indeterminate progress. We recommend the use of the .is-pending class on the component’s parent container, but there is also an option to use an attribute of pending instead. Buttons should have the disabled attribute when the pending state is applied.

Primary

The primary button is for medium emphasis. Use it in place of an accent button when the action requires less prominence, or if there are multiple primary actions of the same importance in the same view. Both the fill (default) and outline styles are demonstrated in this example.

Secondary

The secondary button is for low emphasis. It’s paired with other button types to surface less prominent actions, and should never be the only button in a group. Both the fill (default) and outline styles are demonstrated in this example.

Sizing

Buttons come in four different sizes: small, medium, large, and extra large. The medium size is the default and most frequently used option. Use the other sizes sparingly; they should be used to create a hierarchy of importance within the page.

Small
Medium
Large
Extra-large

Static black - primary

When a button needs to be placed on top of a light color background or a visual, use the static black options. Static color buttons do not change shades or values depending upon the color theme.

Static black - secondary

Static white - primary

When a button needs to be placed on top of a dark color background or a visual, use the static white options. Static color buttons do not change shades or values depending upon the color theme.

Static white - secondary

Text overflow

When the button text is too long for the horizontal space available, it wraps to form another line. When there is no icon present, the text is aligned center. When there is an icon present, the text is aligned start (left with a writing direction of left-to-right) and the icon remains vertically aligned at the top.

Text overflow - disabled text wrap

The normal behavior for lengthy text in the given horizontal space available is that it will wrap to form another line. By using the .spectrum-Button--noWrap class, the lengthy button text will not cause a line break and the width of the button will expand until it reaches its maximum width. Please note: this can cause undesired overflow experiences and to help prevent this, the overflowing text will attempt to hide by showing an ellipsis (...). This is demonstrated in the last two examples below, by constraining the maximum width of the button. This option is not part of the design spec, so please use carefully, with consideration of the overflow behavior and the readability of the button's content.

Properties

The component accepts the following inputs (properties):

NameDescriptionDefault
Component
Size*
string
-
Treatment
string
-
Variant
string
-
Content
Label
string
-
Workflow icons
string
-
State
Disabled
boolean
-
Pending
boolean
-
Active
boolean
-
Focused
boolean
-
Hovered
boolean
-
Advanced
Disable label wrap
Used to keep the button label text on one line. Note that this option is not a part of the design specifications which intend for the label to wrap. Use with care and consideration of this option's overflow behavior and the readability of the button's content.
boolean
-
Static color
Used when component is layered over a background or visual contrary to the general theme.
string
-

Modifiable custom properties

These are empty CSS custom property hooks available in this component that enable one-off customizations specific to a product implementation.

Property
--mod-button-animation-duration
--mod-button-background-color-default
--mod-button-background-color-disabled
--mod-button-background-color-down
--mod-button-background-color-focus
--mod-button-background-color-hover
--mod-button-border-color-default
--mod-button-border-color-disabled
--mod-button-border-color-down
--mod-button-border-color-focus
--mod-button-border-color-hover
--mod-button-border-radius
--mod-button-border-width
--mod-button-bottom-to-text
--mod-button-content-color-default
--mod-button-content-color-disabled
--mod-button-content-color-down
--mod-button-content-color-focus
--mod-button-content-color-hover
--mod-button-edge-to-text
--mod-button-edge-to-visual
--mod-button-edge-to-visual-only
--mod-button-focus-ring-border-radius
--mod-button-focus-ring-color
--mod-button-focus-ring-gap
--mod-button-focus-ring-thickness
--mod-button-font-family
--mod-button-font-size
--mod-button-font-weight
--mod-button-height
--mod-button-icon-margin-block-start
--mod-button-line-height
--mod-button-margin-block
--mod-button-margin-left
--mod-button-margin-right
--mod-button-max-inline-size
--mod-button-min-width
--mod-button-padding-label-to-icon
--mod-button-text-align
--mod-button-text-align-with-icon
--mod-button-top-to-icon
--mod-button-top-to-text

Tagged releases