Skip to content

Components

Action Button

A button for one async action. Its arrow floats apart as a glass droplet; press it and the droplet melts into the body, and stays.

Latest change Improved v3.0.18 The button of the first example is blue with white text, and what it sends across the page on a success is now the wave, in the same blue (colors), in place of the band.
  1. v3.0.18 Improved The button of the first example is blue with white text, and what it sends across the page on a success is now the wave, in the same blue (colors), in place of the band.
  2. v3.0.18 Improved The swell at the end of an action is lit: as the success lands the button takes the light of a press at its middle, which holds a moment and fades as it spreads. It is the engine's rule for every button that swells by itself (GlassLayer's pulse), so nothing is set for it.
  3. v3.0.18 Fixed A clear Action Button with sweep and from: 'center' no longer stays a pill of the page's colour in the middle of the band: the ring crosses clear glass as it crosses the page, so its colour shows in the button too. A filled button is kept in front of the ring, as before. sweepPage takes under: null for the same.
  4. v3.0.16 Improved New errorLabel: after a failed action it takes the label's place until the next press, and screen readers hear it too. The failing example uses it, so a failure no longer passes in silence.
  5. v3.0.9 Improved sweep takes tune, numbers of SWEEP for that button's turn alone, as sweepPage does. The example plays the band from under the button (look: 'band', from: 'center') with the kit's settings, its palette turned orange.
  6. v3.0.0 Improved Action Button takes sweep, for the one action that changes everything on the screen (Publish, Pay, Sign in). The page leans in towards where the band will come from while the action runs, the button showing its pending label and spinner meanwhile; on the success a band of colour crosses the screen, and behind it the button has landed and the page is the next one. It is Sweep called from the button: onAction is the work, sweep.change what turns the page, from and colors as on Sweep. Where no sweep can play the button behaves as before. The page's lean now follows the control it leaves alone, so a button whose label grows while the page leans in is never covered.
  7. All changes→
glass-action-button-basic.svelte

Use it for

  • One async commit whose result belongs on the button: Deploy, Publish, Add to cart, Subscribe.
  • Actions that stay done: the merged "Deployed ✓" is the new state of the page.

Not for

  • Plain links and instant actions: use GlassButton.
  • Toggling back and forth between two states: use GlassTabs.
  • More than one per screen: the droplet is the kit's one gooey effect, keep it special.

Installation

npx shadcn-svelte@latest add https://liquidglass.pulse.city/r/action-button.json

Usage

app.tsx
import { GlassActionButton } from '@/components/liquid-glass'

<GlassActionButton
  material="tinted"
  className="bg-neutral-900 text-white"
  pendingLabel="Deploying"
  successLabel="Deployed"
  onAction={deploy} // return the promise
>
  Deploy
</GlassActionButton>

The flow

  • Idle. The arrow floats apart from the body as a separate glass droplet.
  • Press. The droplet stretches back on a gooey bridge and melts into the body.
  • Pending. One body; the label morphs to pendingLabel and a spinner turns where the arrow was, until the promise from onAction settles.
  • Success. Still one body: successLabel and a check that draws itself in. As it lands the glass swells, as if hovered and pressed at the same time, lights up from its middle as a press lights it, and stretches the label and the check with it; it lets go a moment after the label is in. It stays merged, unless you set resetAfter.
  • Error. If onAction throws, the droplet splits off again, errorLabel takes the label's place until the next press and onActionError gets the error.
  • Start over. Change resetKey and the droplet splits off again from any state. Don't remount the button with key: that snaps it back.

An action that turns the page

Some actions change everything on the screen: Publish, Pay, Sign in. Give that one button sweep. The page leans in towards where the wave will come from (the top of the screen, unless from says otherwise) for as long as the action runs, the button showing its pendingLabel and its spinner meanwhile; when the action succeeds the page is struck further in, a wave of colour crosses the screen, and behind it the success has landed and the page is the next one. The button at the top of this page has it, as a ring opening from under the button (from: 'center') in four blues of its own (colors): press Deploy.

publish.tsx
<GlassActionButton
  pendingLabel="Publishing"
  successLabel="Published"
  onAction={publish}                                   // what the page waits on
  sweep={{
    change: () => router.push('/published'),           // what turns the page
    from: 'top',                                       // or bottom, left, right, center
    colors: ['#cb30e0', '#ff2d55', '#ff8d28', '#ffcc00'],
  }}
>
  Publish
</GlassActionButton>

This is Sweep (sweepPage of glass-sweep.ts), called from the button: onAction is the work the page waits on, and sweep.change is what turns the page, a navigation or a state update (flushed for you). from and colors are Sweep's own, and default to SWEEP's; sweep alone, with no change, sends the band across the page as it is. The page is given a second and a half to lean in however soon the action is done, so keep sweep for an action worth that wait. An action that fails lets the page go without turning it. Where no sweep can play (reduced motion, no WebGL, no view transitions) the button behaves as it does without sweep, and change is still called. It is the same motion as glimm's Publish demo (glimm.dev, MIT), from which Sweep is ported.

API reference

PropTypeDefault
children

The idle label, and the button's accessible name.

ReactNode—
onAction

Required. Runs on press; return a promise to stay pending until it settles.

() => unknown—
onActionError

Called when onAction throws; the button returns to idle.

(error) => void—
pendingLabel

Label while onAction runs.

ReactNodechildren
successLabel

Label after it succeeds.

ReactNodechildren
errorLabel

Replaces the idle label after a failure, until the next press. Say what went wrong and that a press tries again.

ReactNodechildren
resetAfter

Milliseconds before splitting off again after a success. 0 stays merged.

number0
resetKey

Change it to return to idle: the droplet splits off again. A running action's result is dropped.

unknown—
icon

The droplet's idle icon.

ReactNodearrow
sweep

Turns the page on a success: the page leans in towards where the wave will come from while the action runs, then a wave of colour crosses the screen with the success, and what change did, behind it. from, colors and tune (numbers of SWEEP for this turn alone) as on Sweep.

boolean | { change?: () => unknown; from?: SweepFrom; colors?: string[] | null; tune?: Partial<typeof SWEEP> }false
material

As on GlassButton.

'clear' | 'tinted''clear'
size

Height 32, 40 or 48 px.

'sm' | 'md' | 'lg''md'
…rest

Passed to the <button> (not onClick: use onAction).

button attributes—

Accessibility

  • A real <button>; Enter and Space run the action.
  • Pending sets aria-busy, and pending or done sets aria-disabled instead of disabled, so focus stays on the button.
  • A role="status" region announces the pending and success labels.
  • With reduced motion the droplet and labels switch without animation, and sweep plays nothing: the page just turns.

Liquid Glass Svelte is open source and MIT licensed. If it saves you time, you can support the project.