Skip to main content

Use cases

  • Primary actions: Create actions like "Save changes," "Add customer," or "Process payment" that complete workflows.
  • Secondary actions: Provide supporting actions such as "Cancel," "Edit," or "View details."
  • Navigation: Enable screen transitions or launch modal experiences for complex operations.
  • Loading states: Display loading indicators during asynchronous operations while preventing duplicate submissions.

Trigger actions using a Button component with customizable visual styles and tones. This example shows a basic button with text content.

Trigger actions with a button

Trigger actions with a button

<s-button variant="primary">Add customer</s-button>
<s-button variant="secondary">Select more items</s-button>

Configure the following properties on the Button component.

'--auto' | '--show' | '--hide' | '--toggle'
Default: '--auto'

The action to perform on the target element specified by commandFor:

  • '--auto': Execute the target's default action
  • '--show': Display the target element
  • '--hide': Hide the target element
  • '--toggle': Switch the target's visibility state

Learn more about command on MDN.

string

The ID of the target element that should respond to interactions (such as clicks) on this element. Used with command to control other components. Learn more about commandfor on MDN.

boolean
Default: false

Whether the field is disabled, preventing user interaction. Use when the field is temporarily unavailable due to application state, permissions, or dependencies.

string

A unique identifier for the element used for targeting with CSS, JavaScript, or accessibility features.

boolean
Default: false

Indicates whether the button action is currently in progress. When true, typically displays a loading indicator and may disable interaction.

'auto' | 'neutral' | 'caution' | 'warning' | 'critical'
Default: 'auto'

Sets the tone of the button, based on the intention of the information being conveyed.

  • 'auto' - Automatically determines the appropriate tone based on context.
  • 'neutral' - The standard tone for general actions and interactions.
  • 'caution' - Indicates actions that require careful consideration.
  • 'warning' - Alerts users to potential issues or important information.
  • 'critical' - Used for destructive actions like deleting or removing content.
'primary' | 'secondary'
Default: 'auto' - the variant is automatically determined by context

The visual appearance and prominence of the button:

  • 'primary': High visual emphasis for the most important action
  • 'secondary': Less prominent appearance for supporting actions

The Button component provides event callbacks for handling user interactions. Learn more about handling events.

(event: <"s-button">) => void

The callback when the element is activated.

  • Write action-oriented text: Use specific, actionable language like "Save customer" or "Process payment" rather than generic terms like "OK" or "Submit."
  • Choose appropriate variants and tones: Use primary for the main action and secondary for supporting actions. Use critical for destructive actions, caution or warning for actions requiring attention.
  • Show loading states: Set loading to true during async operations to prevent duplicate submissions.
  • Use command system for component control: Use commandFor and command to control modals and overlays declaratively.
  • Structure hierarchies clearly: Group related actions together. Separate destructive actions to prevent accidental activation.
Was this page helpful?