Skip to content

Components

SweepNew

A page that turns behind a wave of colour: the page leans in towards where the wave will come from while the work runs and is struck further in when it is done, a wave crosses the screen, bending and blurring the page as it passes and leaving its colour on the edges, and the next page is there behind it. You choose where it comes from and what it is coloured with.

Latest changeImprovedv3.0.11When a sweep looks for the page's own view transition names, as the turn starts and once the new page is there, it no longer goes inside an element that is not displayed: nothing in it is in the transition, whatever its name, and the browser had to work out a style for each of its elements, one by one, while the screen stood still. On a phone that is the docs' sidebar and their table of contents. Turning the landing page to the docs on a phone, 340 of 2,173 style lookups are gone, and the sweep's search for names takes a fifth to a half of the time it did (about 15 ms to 3–6 ms on a phone slowed six times, with the profiler on). The whole frozen frame is a few hundred milliseconds, so this is within its noise. Nothing on the screen changes, frame by frame.
  1. v3.0.11ImprovedWhen a sweep looks for the page's own view transition names, as the turn starts and once the new page is there, it no longer goes inside an element that is not displayed: nothing in it is in the transition, whatever its name, and the browser had to work out a style for each of its elements, one by one, while the screen stood still. On a phone that is the docs' sidebar and their table of contents. Turning the landing page to the docs on a phone, 340 of 2,173 style lookups are gone, and the sweep's search for names takes a fifth to a half of the time it did (about 15 ms to 3–6 ms on a phone slowed six times, with the profiler on). The whole frozen frame is a few hundred milliseconds, so this is within its noise. Nothing on the screen changes, frame by frame.
  2. v3.0.6ImprovedWhile a sweep turns the page, the page's own view transition names are held off element by element: the elements that carry one are found as the turn starts and once the new page is there, and marked data-sweep-unnamed. A rule on every element did it before, and every element's style paid for it, the new page's too, while the browser held the screen still to put it up. On a phone slowed six times the frame the screen stands still in, between the blow and the wave, is about 80 ms shorter. Nothing on the screen changes, frame by frame.
  3. v3.0.4ImprovedWhat crosses the screen once the page has been struck is now a wave: it bends and blurs the page along its front, throws particles ahead and leaves its colour on the edges of the screen, and the new page is live right behind it. It is Jakub Antalik's Distortion Waves (libraries.dev/waves, MIT), its timeline and shader taken whole into the kit as glass-wave-model.ts and glass-wave-renderer.ts. Every sweepPage call plays it, from any side or center and in your colors, and so do Action Button's sweep and the slide on this site's landing page; the lean and the blow before it are as they were. The wave's own numbers go in SWEEP.wave. The band that came before is still there, in the kit's palette, in Mono or in any colours of yours: look: 'band' on a call (or SWEEP.look for the whole app, and on Action Button's sweep), and the example on the Sweep page plays both. It plays by itself where there is no WebGL2. This site's theme switch keeps the band. The example at the top of the Sweep page is now an Action Button with sweep: the wave opens from under the button, which swells and turns green as its success lands.
  4. v3.0.0NewSweep is the turn of this site's landing page, now yours: sweepPage() in glass-sweep.ts. The page leans in while the work runs and is struck further in when it is done; a band of colour crosses the screen, and the next page is there behind it. You choose where the band comes from (from: a side of the screen, or center, a ring from under the control) and what it is coloured with (colors: four of your own, or the kit's palette), for one call or for the whole app on SWEEP. The page leans in towards the place the band comes from, so the bend and the light are one thing. A band given colours is a front with a wake: a pale line at the front, the brightest colour right behind it, a wake that deepens towards where it came from, and specks of light in it; the four are read from the back of the wake to its front (deep, vivid, light, pale), and SWEEP.wake = 0 makes it a crest like the palette's. The docs page has both to try: choose a side, start from one of six sets of colours or change each of the four, play, and copy the call. pullPage() lets the page lean in while a Slide to Confirm is still being pulled. What was pressed takes no second press until the turn is over. It needs no package, brings its own CSS, and plays nothing under reduced motion, without WebGL or without view transitions.
  5. v3.0.0NewOne turn can differ from the rest: sweepPage takes tune, any of SWEEP's numbers for that call alone. Two of them are for such a turn and off by default: soft, which lets the old page run into the new one under the band instead of being cut along the crest, and dusk, which darkens the page a little while it leans in. A lean that goes all the way in while it waits (hold no less than strike) softens and brings the band up to strength as it goes. However far the lean reaches, it stays under whatever is marked data-sweep-above (above).
  6. v3.0.0FixedA band centred on a control near a side of a tall screen changed its width along a line; it now runs on evenly. An icon drawn for the first time was missing from the picture of a page that leans in (Sweep, and a toast's arrival); the picture is taken again as soon as the icon is there.
  7. All changes →
glass-sweep-basic.tsx

$48.00

Two tickets, Friday at 20:00

Use it for

  • The one step that changes everything on the screen: signing in, paying, opening the product from its landing page.
  • A page that has to wait for something first (a route that loads, a request): the lean is the wait, and the band leaves when it is over.
  • The end of a Slide to Confirm: the page starts leaning in while the thumb is still being pulled (pullPage).

Not for

  • Every link and every tab: it takes the whole screen for two seconds. Ordinary navigation just navigates.
  • Something that changes a part of the page: a Dialog, a Popover or an Accordion opens where it is.
  • News nobody asked for: that is Toast. Its page leans in the same way, and stays the same page.

Installation

npx shadcn@latest add https://liquidglass.onemorethink.dev/r/sweep.json

Sweep needs no package and is not a React component: it is a function you call. The turn is a view transition (the View Transitions API), and the band and the lean are drawn with WebGL. Where one of them is missing, or with reduced motion on, sweepPage plays nothing and returns false: turn the page yourself, as the examples do. It brings its own CSS, added to the page on the first sweep.

Usage

open.tsx
import { GlassButton } from '@/components/liquid-glass'
import { sweepFrom, sweepPage } from '@/components/liquid-glass/glass-sweep'

function open(button: Element) {
  const work = router.preloadRoute({ to: '/app' })      // what the page waits on
  const change = () => router.navigate({ to: '/app' })  // what turns it
  // false: nothing plays here (reduced motion, no WebGL, no view transitions).
  if (!sweepPage({ ...sweepFrom(button), work, change })) work.then(change)
}

<GlassButton onClick={(event) => open(event.currentTarget)}>Open the app</GlassButton>

sweepFrom(control) gives the sweep what it needs from the control that was pressed: the point the page leans in towards, which is where the band will come from (the place on that side of the screen in line with the control, or the control itself for a ring), and the control itself, which is left as it is while the page leans in. work is a promise the page waits on. The page leans in for as long as it takes, a second and a half at the least, and is struck further in when it settles. Then change runs, inside a view transition: whatever it does (a navigation, a state update flushed with flushSync), the new page has to be there when it returns or resolves. The band crosses, with the old page still ahead of it and the new one behind, and a ripple leaves the control through the old page. The new page takes presses as soon as the band's front has left the screen, and a press, a scroll or a key ends the turn at once. One sweep plays at a time, and what was pressed takes no second press until the turn is over (it is inert for that long). A work that fails lets the page go without turning it.

Where it comes from, and its colours

from is where the band comes from: top (the default), bottom, left or right send a band across the screen from that side, its ends trailing its middle; center opens a ring from under the control instead: the band is drawn around the control, never over it, and the control stays in front until the ring has left it behind. The page leans in towards the same place the band comes from, so the bend and the light are one thing. colors is four colours of your own, as hex; null is the kit's own palette (cyan, blue, indigo, purple). A band given colours is a front with a wake: a pale line at the front, the brightest colour right behind it, and a wake that deepens towards where it came from, with specks of light in it. The four are read from the back of the wake to its front: deep, vivid, light, pale. Give them to one call, or set them once for the whole app on SWEEP, the object every sweep reads its defaults from. Choose below and play it: a set fills the four colours, and each of the four can be changed. What you see is what the call under the button gives you.

Choose a side and four colours, then play it
glass-sweep-options.tsx

Page one

sweepPage({ ...sweepFrom(button, 'top'), look: 'wave', colors: ['#18c8ff', '#2f6bff', '#5b3dff', '#19e0c4'], work, change })
sweep.ts
import { SWEEP, sweepFrom, sweepPage } from '@/components/liquid-glass/glass-sweep'

// From the back of the wake to its front: deep, vivid, light, pale.
const GREEN = ['#0d4d1e', '#3fae2a', '#86d44a', '#e4f5dc']

// For one call:
sweepPage({ ...sweepFrom(button, 'left'), colors: GREEN, work, change })

// Or once, for every sweep in the app:
SWEEP.from = 'left'
SWEEP.colors = GREEN

After a slide

A Slide to Confirm is pulled before it is confirmed, and the page can lean in with the pull: pullPage(slider) draws the page in a little as the thumb goes, and takes it back with the thumb when it is let go early. The sweepPage that the slide's onConfirm calls carries on from where the slide left the page. Give it the slide itself, the element with role="slider". A box around the slide marked data-sweep-keep is what the page leans in around, instead of the track alone: a held thumb's shadow falls outside the track, and the picture of the page would cut it off there. Something above the control that moves by itself (a marquee) is marked data-sweep-above, and the lean stops short of it.

hero.tsx
import { useEffect, useRef } from 'react'

import { GlassSlideToConfirm } from '@/components/liquid-glass'
import { pullPage, sweepFrom, sweepPage } from '@/components/liquid-glass/glass-sweep'

const slide = useRef<HTMLDivElement>(null)
const slider = () => slide.current?.querySelector('[role="slider"]')

// The page leans in as the thumb is pulled. What it returns stops it.
useEffect(() => {
  const control = slider()
  if (control) return pullPage(control)
}, [])

const open = () => {
  const work = router.preloadRoute({ to: '/app' })
  const change = () => router.navigate({ to: '/app' })
  const control = slider()
  if (!control || !sweepPage({ ...sweepFrom(control), work, change })) work.then(change)
  return work  // the slide shows its spinner until then
}

// Room for the thumb's shadow: the page leans in around this box.
<div ref={slide} data-sweep-keep="" className="rounded-[80px] px-8 pt-3 pb-16">
  <GlassSlideToConfirm onConfirm={open}>Slide to open</GlassSlideToConfirm>
</div>

The numbers

What crosses the screen is a wave (SWEEP.look, 'wave'): it bends and blurs the page along its front, throws particles ahead and leaves its colour on the edges of the screen, and the new page is the page itself right behind it. It is Jakub Antalik's Distortion Waves (libraries.dev/waves, MIT), its two files taken whole into the kit (glass-wave-model.ts, glass-wave-renderer.ts); its own numbers go in SWEEP.wave, over the defaults of its type, and SWEEP.letGo is how long the page takes to let go as it leaves. look: 'band' is the band that came before it, and where there is no WebGL2 the band plays in its place. Everything else about the turn is a number on SWEEP, read as each sweep begins: how long the page leans in (gather), how far in it waits and how far the blow takes it (hold, strike), the ripple that leaves the control (ripple, rippleRun), how long the page takes to let go and the band to cross (release, run), how narrow and how curved the band is (tight, curve), its brightness on a light page and on a dark one (brightness, dim), the wake a band with colours of its own leaves, the line at its front and the specks of light in it (wake, line, dots; with wake at 0 that band is a crest like the palette's, its four colours run into one another), and how far a slide draws the page in (drag). Each is described in glass-sweep.ts. They are tuned together: change one at a time, and leave them alone if the turn already looks right. The motion is ported from glimm (glimm.dev, MIT); what was taken and what is different is written at the top of the file.

A turn of its own

One turn in an app can differ from the rest without touching SWEEP: tune takes any of its numbers for that call alone. This site's theme switch is such a turn. It is glimm's "Toggle the theme" (glimm.dev/demos/theme, MIT), with that demo's numbers: the page leans in all the way in 620 ms with nothing to wait on, the theme changes, and a narrower band takes 2.7 s to come down, with the new theme behind it. A hold that is no less than strike leaves nothing for a blow: the page then softens and the band comes up to strength with the lean itself. Two numbers exist for a turn like this one, and are off by default. soft lets the old page run into the new one under the band (in half-widths of the band, either side of its crest; 0 cuts the old page along the crest), which a turn between a light page and a dark one needs: a cut shows as a line there. dusk darkens the rest of the page a little while it leans in. palette is the cosine palette the band reads when colors is null.

theme.ts
import { sweepFrom, sweepPage } from '@/components/liquid-glass/glass-sweep'

// glimm's theme demo: a quick lean with no blow, a narrow band, a soft edge.
const TURN = { gather: 620, hold: 1, strike: 1, snap: 440, release: 220, run: 2700, tight: 28, curve: 0.12, alpha: 1.1, brightness: 1.15, dim: 1.15, swell: 0.15, tones: 0, soft: 1.2, dusk: 0.09 }

function turnTheme(next: 'light' | 'dark', button: Element) {
  const change = () => document.documentElement.setAttribute('data-theme', next)
  if (!sweepPage({ ...sweepFrom(button, 'top'), tune: TURN, work: Promise.resolve(), change })) change()
}

API reference

PropTypeDefault
sweepPage(options)

Turns the page behind a band. Returns false when nothing plays (reduced motion, no WebGL, no view transitions, a hidden page, or a sweep already on the screen): change is not called then.

(options) => boolean—
work

What the page waits on. It leans in for as long as this takes (SWEEP.gather ms at the least), and the band leaves when it settles. If it rejects, the page is let go and nothing turns.

Promise<unknown>—
change

Turns the page. It runs inside the view transition, so what it returns is waited for, 200 ms at most: a page that takes longer is not held under a still picture, and the band runs over it once it is there.

() => unknown—
from

Where the band comes from: a side of the screen, or center, a ring that opens from at, from under the control.

'top' | 'bottom' | 'left' | 'right' | 'center'SWEEP.from (top)
colors

Four colours of your own (hex), read from the back of the band's wake to its front: deep, vivid, light, pale. null is the kit's palette.

string[] | nullSWEEP.colors (null)
at

The point of the viewport the page leans in towards, in CSS px. sweepFrom gives where the band comes from: the place on that side of the screen in line with the control, or the control's middle for center.

{ x: number; y: number }—
keep

The element that was pressed: it is left as it is, live, while the page leans in around it, and takes no press until the turn is over. sweepFrom gives the control, or the box around it marked data-sweep-keep.

Element—
under

What a ring (center) comes out from under: the band is drawn around it, and it stays in front until the ring has left it behind. sweepFrom gives the control itself.

Elementkeep
span

How far the lean reaches, in CSS px. Default: the shorter side of the screen. sweepFrom stops it short of anything above the control marked data-sweep-above.

number—
above

A line of the viewport the lean does not reach above, in CSS px from its top: what runs by itself up there (a marquee) is left alone. sweepFrom gives the bottom of anything above the control marked data-sweep-above.

number—
look

What crosses the screen: wave, which bends and blurs the page as it passes, or band, the band of colour that came before it: a crest in the kit's palette, a front with a wake in your colours (Mono among the sets of the example above).

'wave' | 'band'SWEEP.look (wave)
tune

Numbers of SWEEP for this turn alone (see "A turn of its own"). from and colors win over it.

Partial<typeof SWEEP>—
sweepFrom(control, from?)

What a sweep from a control is given, ready to spread into sweepPage. The point is where the band comes from: on a side, the place of that side in line with the control; with center, the control's middle, or for a slide the far end of its track, where the slide ended.

(Element, from?) => { at, keep, under, span, above, from }—
pullPage(slider, from?)

The page leans in as a slide is pulled, before its sweep; slider is the element with role="slider". Returns what stops it.

(Element, from?) => () => void—
SWEEP

The defaults every sweep reads as it begins: from, colors, and the numbers of the turn (see above).

object—

Liquid Glass is built and maintained by one person. If it saves you time, you can sponsor the work.