shadcn.io is not affiliated with official shadcn/ui
Before After Toggle Features Block for React
A Before and After control that cross-fades a settings screen between a cluttered version (warning banners, a nested menu, badges everywhere) and a clean one, in a frame that never changes height.
Installation
Overview
A before and after feature section for React with Base UI, written for Sortwell, a fictional admin-settings cleanup tool. A centred header sits over a band with one segmented control, Before and After. Under it, a settings screen is drawn in greyscale in a hairline frame with + marks on its corners. Before shows what most admin pages become: two warning banners, a nested navigation with badges and counts, and ten settings with toggles, selects, checkboxes and "Beta", "Legacy" and "Pro" tags, fading out at its foot. After shows the same page with four navigation items and four notification settings. Choosing a side cross-fades the two: both screens share one grid cell, so the frame keeps its height and nothing around it moves. A caption under the screen counts the controls, computed from the same lists the drawings are made from, so the numbers always match what you see. It's built from Segment Group, Badge and Guides with CSS transitions and your theme's tokens; there is no call to action, and nothing is in your primary colour. For settings, admin and dashboard products whose pitch is that they got simpler.
FAQ
How do I change what each screen shows?
Each side is a few lists at the top of the file: BEFORE_NAV, BEFORE_ROWS and BEFORE_BANNERS for the cluttered screen, and AFTER_NAV and AFTER_ROWS for the clean one. A row has a label, the kind of control it draws (toggle, select, check or tag) and an optional tag. The caption's counts are computed from these lists.
Why doesn't anything move when I switch?
The two screens sit in one grid cell, inside a frame with a fixed height, and only their opacity changes. A screen turns visible at once and fades out before it becomes invisible, so the one you chose can take focus immediately. The hidden screen is invisible, aria-hidden and inert, which takes it out of the tab order and the accessibility tree. Under reduced motion there is no fade, only a swap.
How do screen readers and keyboards handle it?
The control is a named group ("Settings screen") of two options, operated with the arrow keys and Space, with a visible focus ring. The screens are pictures, so they are hidden from assistive technology; instead a polite status line says which one is showing and how many controls it has ("The cleaned-up settings screen, with 8 controls"), and the caption states the same counts in text.
Does it follow my theme?
Yes. Every surface is a theme token and the warnings are drawn with an icon and a tint, not a colour: no red or amber. A switch that is on is filled with the foreground colour, so the screens are light on a light page and dark on a dark one and your primary colour is never used.
How does it fit on a phone?
The control sits centred above the screen. On a phone the navigation column is hidden and the screen shows its settings at full width, still fading out at the foot on the cluttered side, so both sides stay inside about three screens and nothing scrolls sideways at 320 pixels.
Related
- Pro
Before After Visual Features
Proof and comparisonsThree measured outcomes as ruled rows, each with its own Before and After control that swaps both the figure and the bar: page weight, load time and weekly support tickets.
- Pro
Drag Handle Responsive Comparator Features
Live controlsA responsive-width resizer for a preview tool: drag the edge of a small shop page, or pick Phone, Tablet or Desktop, and the page reflows at its real breakpoints while a badge names the width.
- Pro
Split Layout Before After Slider Hero
Interactive demosA split hero for a site speed tool: a headline, a Shine Button and a second action beside a speed report that fills its cell edge to edge, before on one side of a handle and after on the other.
- Pro
Full-Width Before After Slider Hero
Interactive demosA showcase hero with centred copy over a wide before and after panel in a hairline frame, with a draggable handle and a band of four results.
- Pro
Animated Reveal Features
Tabs and accordionsA features section for a dashboard builder with a framed drawing of its editor at the start and four steps as vertical tabs at the end: each step adds a layer to the drawing and keeps the ones before it.
- Pro
Vertical Slider Board Features
Live controlsA board of six vertical sliders for an alert-tuning tool, each with a level meter and a readout, and a composite readout of pages a week and incidents caught worked out from the six settings.