Pixel Swap
ComponentsPixel Swap
ExperimentsNew

Pixel Swap

Switch between product views, project images, or campaign artwork with a pixel wipe.

USE IT FORProduct image viewsCampaign artworkProject image transitions
React + CSS
Live component. Go ahead, interact.
01

Installation

Run this in your shadcn-configured React project. The component and stylesheet are added together.

TERMINAL
npx shadcn@latest add http://localhost:5173/r/pixel-swap.json

This command uses the current site address. For localhost, keep this preview running on the same computer. Files follow your configured components alias.

02

Usage

Import the component and make the details your own.

TypeScript
import { PixelSwap } from '@/components/anticraft/PixelSwap';

export function Example() {
  return (
    <PixelSwap
      frontLabel="Bag — exterior"
      backLabel="Bag — interior"
      buttonLabel="Change product view"
      front={<img src="/images/bag-exterior.jpg" alt="" />}
      back={<img src="/images/bag-interior.jpg" alt="" />}
      columns={8}
      rows={6}
      duration={800}
    />
  );
}
03

Props

PropTypeDefaultDescription
frontReactNodeRequiredDecorative artwork shown initially. Nested links, buttons, and inputs are made inert.
backReactNodeRequiredThe second decorative artwork. Both faces should fill the available stage.
frontLabelstring'First artwork'The accessible name and visible footer label for the first artwork.
backLabelstring'Second artwork'The accessible name and visible footer label for the second artwork.
buttonLabelstring'Swap artwork'A visible action label, such as Change product view. Supply your own image files at the paths shown in the example.
columnsnumber8The number of pixel columns, rounded and clamped between 2 and 20.
rowsnumber6The number of pixel rows, rounded and clamped between 2 and 16.
durationnumber800The complete transition duration in milliseconds, clamped between 240 and 3000.
onValueChange(side: 'front' | 'back') => voidundefinedCalled when the artwork changes beneath the fully covered pixel curtain. Reduced motion changes immediately.
classNamestring''Additional classes. Set --ac-pixel-height, --ac-pixel-curtain and optional --ac-pixel-curtain-secondary/tertiary colors, plus --ac-pixel-paper, --ac-pixel-ink, --ac-pixel-border, and --ac-pixel-radius.
04

Motion & accessibility

Considered by default.

Activate Swap artwork with a mouse, touch, Enter, or Space. A diagonal grid of blocks covers the current face before the artwork changes, then clears away. The button stays focused and ignores repeat activation during a transition. Only the current artwork is exposed to assistive technology, with its supplied label. Reduced motion switches immediately, and changing the preference mid-transition completes the swap.

Use semantic content and meaningful labels in your composition. Check contrast and keyboard behavior with your own styles and content.