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.
- 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. - 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. - v3.0.18 Fixed A clear Action Button with
sweepandfrom: '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.sweepPagetakesunder: nullfor the same. - 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. - v3.0.9 Improved
sweeptakestune, numbers ofSWEEPfor that button's turn alone, assweepPagedoes. The example plays the band from under the button (look: 'band',from: 'center') with the kit's settings, its palette turned orange. - 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:onActionis the work,sweep.changewhat turns the page,fromandcolorsas 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. - All changes→
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.jsonUsage
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
pendingLabeland a spinner turns where the arrow was, until the promise fromonActionsettles. - Success. Still one body:
successLabeland 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 setresetAfter. - Error. If
onActionthrows, the droplet splits off again,errorLabeltakes the label's place until the next press andonActionErrorgets the error. - Start over. Change
resetKeyand the droplet splits off again from any state. Don't remount the button withkey: 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.
<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
| Prop | Type | Default |
|---|---|---|
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 | (error) => void | — |
pendingLabel Label while | ReactNode | children |
successLabel Label after it succeeds. | ReactNode | children |
errorLabel Replaces the idle label after a failure, until the next press. Say what went wrong and that a press tries again. | ReactNode | children |
resetAfter Milliseconds before splitting off again after a success. | number | 0 |
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. | ReactNode | arrow |
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 | 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 attributes | — |
Accessibility
- A real
<button>; Enter and Space run the action. - Pending sets
aria-busy, and pending or done setsaria-disabledinstead ofdisabled, 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
sweepplays nothing: the page just turns.
Liquid Glass Svelte is open source and MIT licensed. If it saves you time, you can support the project.