Layout Switch, animated React component
- Pro
- Motion Effects
- Spring
A photo set that glides between grid, row, feature and pile arrangements on springs, with nothing fading or cutting. Click a photo and it grows to fill the frame; click again or press Escape to put it back.
Taps when you switch layouts. Sound is off on this site until you switch it on.
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| count | number | 6 | How many photos to show, 3 to 6. |
| gap | number | 10 | Space between photos in px, 0 to 24. |
| radius | number | 16 | Roundness of the photo corners in px, 0 to 32. A photo opened full size is 8px rounder. |
| stiffness | number | 220 | How strongly photos spring toward their new place, 100 to 500. Higher moves faster. |
| damping | number | 26 | How quickly the spring settles, 12 to 40. Lower overshoots and bounces more. |
| autoplay | boolean | false | Changes layouts by itself until someone interacts. |
| enableSound | boolean | true | Plays interface sounds on interaction. They follow the sound switch (setSoundsEnabled, on by default) and stay silent on hover. Autoplay makes the same sounds once the visitor has used the page. Pass false to silence this component. |
Add it to your project
- 1
Set up your project once
You need a Next.js project with Tailwind CSS and the
@/import alias. In its root folder, run this once. It createscomponents.jsonand thecn()helper insrc/lib/utils.ts:npx shadcn@latest init -d
Starting from nothing? The Quick Start walks through the whole thing.
- 2
Connect the registry with your API key
Layout Switch is a Pro item, so the CLI has to send your API key. Do this once per project:
- Create a key at nexus-ui.com/dashboard/api-key. Copy it straight away: it starts with
nxs_and is shown only once. - In your project root, next to
package.json, create a file named.env.localwith this line, using your own key:NEXUS_API_KEY=nxs_your_key_here
- Open
components.jsonand add this entry inside the outermost braces, next to"aliases". Leave{name}and${NEXUS_API_KEY}exactly as written; the CLI fills them in:"registries": { "@nexus-labs": { "url": "https://www.nexus-ui.com/api/registry/{name}", "headers": { "Authorization": "Bearer ${NEXUS_API_KEY}" } } }
- Create a key at nexus-ui.com/dashboard/api-key. Copy it straight away: it starts with
How Layout Switch works
The same photos glide between four arrangements. Nothing fades or cuts: each one springs from its old box to its new one, and clicking a photo grows it to fill the frame.
The source, the install command and the build prompt come with Pro.
Layout Switch questions
How do I install Layout Switch?
Run `npx shadcn@latest add @nexus-labs/layout-switch`. It installs framer-motion. Layout Switch is a Pro component, so it needs a Pro plan and an API key; key setup is on the CLI docs page (/docs/cli).
Which layouts are there, and how do I switch them?
There are four: "grid", "row", "feature" and "pile", chosen with the segmented buttons above the photos (each has `aria-pressed`). The photos spring from their old box to the new one instead of fading.
How do I use my own photos?
There is no photos prop. The six photos are a `PHOTOS` array at the top of the file, each with an `id`, a `title` and a CSS background in `art`. Edit that array; the grid layout is sized as 3 columns by 2 rows.
How does opening a photo work?
Click a photo and it grows to fill the frame while the others dim. Click it again or press Escape to put it back. Choosing a layout button also closes it. Each photo is a button labelled "Open" or "Close" plus its title.
Does it make sound, and how do I turn it off?
Taps when you switch layouts. Sounds are synthesised with the Web Audio API, so there are no audio files, and they only play after a click or key press. Pass `enableSound={false}` to silence this component, or call `setSoundsEnabled(false)` from `@/lib/ui-sounds` to switch every sound off at once. The CLI installs `@/lib/ui-sounds` with the component.

