Skip to content

Drag-a-theme Chip

Drag one of the admin theme presets onto a preview card and every token remaps at once, with the WCAG contrast checks recomputed on each apply so a failing preset is named rather than hidden.

220

What you should hear: Tab reaches the control, Enter or Space activates it — and every state change is announced in the same words the page shows.

MIT licensev1.0.02.4 KB gzipzero dependenciesby Motif Studioadded 2026-09-10review due 2026-12-09
Live playground — drag, click, hoversandboxed previewsample copy

Drop a theme on a card

no theme applied

Component preview

Pricing, but it breathes

Three tiers, one accent, no gradient soup. Drop a different chip on this card and every value remaps at once.

Choose a plan

14-day refund · no card

Four theme presets from the admin control room. Drag one onto the card, or press it.

The chips are the presets the admin theme control room stores, and the contrast figures are the same WCAG arithmetic that room runs — so a preset that fails is named here, not quietly dropped from the menu. Pressing a chip does exactly what dropping it does; the drag is a shortcut, never the only way in.

Ambience
vibes

Ambience is a live light wash over the preview. Full palette re-theming of every demo arrives with Theme Studio (Pro).

deps: zeroJSX + TailwindMIT · original
theme-drop.tsx
// Drag-a-theme Chip — the demo's own source, extracted verbatim.
// From src/components/demos/scenes-17.tsx, export ThemeDrop.
// Needs React 18+ and Tailwind CSS v4. The classes below include this site's
// token utilities (bg-panel, text-ink-dim, chip …); their values are served as
// CSS custom properties at /api/exports/tokens.json. The reduced-motion branch
// is part of the source, not an afterthought.
// 10 helpers the demo imports are inlined above it, verbatim.

import { useState } from "react";

export interface ThemeToken {
  key: "bg" | "panel" | "raised" | "ink" | "inkDim" | "inkFaint" | "accent" | "accent2" | "mint";
  label: string;
  cssVar: string;
}

export type ThemeValues = Record<ThemeToken["key"], string>;

export interface ThemePreset {
  id: string;
  label: string;
  note: string;
  values: ThemeValues;
}

export const THEME_PRESETS: ThemePreset[] = [
  {
    id: "shipped",
    label: "Shipped dark",
    note: "The palette the site ships with, read out of globals.css. Faint text sits at #747b87 because the check below caught the original #5b6472 at 3.24:1 on the panel colour.",
    values: {
      bg: "#06070b",
      panel: "#0b0d14",
      raised: "#10131d",
      ink: "#edf0f7",
      inkDim: "#9aa3b5",
      inkFaint: "#747b87",
      accent: "#8b5cf6",
      accent2: "#22d3ee",
      mint: "#34d399",
    },
  },
  {
    id: "paper",
    label: "Paper",
    note: "A light surface for print-style review. Dim text is darkened until it clears AA on the page colour.",
    values: {
      bg: "#f6f5f2",
      panel: "#ffffff",
      raised: "#efece6",
      ink: "#14161c",
      inkDim: "#4a505d",
      inkFaint: "#6d7381",
      accent: "#6d28d9",
      accent2: "#0e7490",
      mint: "#047857",
    },
  },
  {
    id: "contrast",
    label: "High contrast",
    note: "Near-black page, pure-white text, saturated accents — for judging hairline borders and focus rings.",
    values: {
      bg: "#000000",
      panel: "#0a0a0a",
      raised: "#151515",
      ink: "#ffffff",
      inkDim: "#d4d4d4",
      inkFaint: "#a3a3a3",
      accent: "#a78bfa",
      accent2: "#22d3ee",
      mint: "#6ee7b7",
    },
  },
  {
    id: "cyan",
    label: "Cyan-forward",
    note: "Swaps the accent roles to test whether any surface has a hard-coded violet.",
    values: {
      bg: "#04070b",
      panel: "#081019",
      raised: "#0d1a26",
      ink: "#eef6fb",
      inkDim: "#9fb3c2",
      inkFaint: "#677e8f",
      accent: "#22d3ee",
      accent2: "#8b5cf6",
      mint: "#34d399",
    },
  },
];

export interface ContrastCheck {
  label: string;
  foreground: string;
  background: string;
  ratio: number;
  /** 4.5 for body text, 3 for large text and UI edges (WCAG AA) */
  line: number;
  pass: boolean;
}

const hex = (c: string): [number, number, number] => {
  const s = c.trim().replace("#", "");
  const full = s.length === 3 ? s.split("").map((x) => x + x).join("") : s;
  return [parseInt(full.slice(0, 2), 16), parseInt(full.slice(2, 4), 16), parseInt(full.slice(4, 6), 16)];
};

export function relativeLuminance(color: string): number {
  const [r, g, b] = hex(color).map((v) => {
    const c = v / 255;
    return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
  });
  return 0.2126 * r + 0.7152 * g + 0.0722 * b;
}

export function contrastRatio(a: string, b: string): number {
  const la = relativeLuminance(a);
  const lb = relativeLuminance(b);
  const [hi, lo] = la >= lb ? [la, lb] : [lb, la];
  return Math.round(((hi + 0.05) / (lo + 0.05)) * 100) / 100;
}

export function contrastChecks(values: ThemeValues): ContrastCheck[] {
  const pairs: { label: string; fg: ThemeToken["key"]; bg: ThemeToken["key"]; line: number }[] = [
    { label: "Body text on page", fg: "ink", bg: "bg", line: 4.5 },
    { label: "Body text on panel", fg: "ink", bg: "panel", line: 4.5 },
    { label: "Dim text on panel", fg: "inkDim", bg: "panel", line: 4.5 },
    { label: "Faint text on panel", fg: "inkFaint", bg: "panel", line: 4.5 },
    { label: "Accent on page", fg: "accent", bg: "bg", line: 4.5 },
    { label: "Accent as a large label", fg: "accent", bg: "bg", line: 3 },
    { label: "Success chip on raised", fg: "mint", bg: "raised", line: 3 },
  ];
  return pairs.map((p) => {
    const ratio = contrastRatio(values[p.fg], values[p.bg]);
    return { label: p.label, foreground: values[p.fg], background: values[p.bg], ratio, line: p.line, pass: ratio >= p.line };
  });
}

const TOKEN_LABELS: { key: keyof ThemeValues; label: string }[] = [
  { key: "bg", label: "page" },
  { key: "panel", label: "panel" },
  { key: "ink", label: "text" },
  { key: "accent", label: "accent" },
];

export function ThemeDrop() {
  const [applied, setApplied] = useState<(typeof THEME_PRESETS)[number] | null>(null);
  const [hovering, setHovering] = useState(false);
  const [status, setStatus] = useState("Four theme presets from the admin control room. Drag one onto the card, or press it.");
  const checks = applied ? contrastChecks(applied.values) : [];
  const failing = checks.filter((c) => !c.pass);

  const apply = (preset: (typeof THEME_PRESETS)[number], how: string) => {
    setApplied(preset);
    const rows = contrastChecks(preset.values);
    const bad = rows.filter((r) => !r.pass).length;
    setStatus(
      bad === 0
        ? `${preset.label} applied ${how}. All ${rows.length} contrast checks pass.`
        : `${preset.label} applied ${how}. ${bad} of ${rows.length} contrast checks fail — the panel below names them.`
    );
  };

  return (
    <div className="flex h-full w-full flex-col items-center justify-center bg-[radial-gradient(70%_90%_at_50%_0%,rgba(167,139,250,0.12),transparent_60%),#08090f] px-6 py-6">
      <div className="w-full max-w-md">
        <div className="mb-3 flex items-baseline justify-between gap-3">
          <p className="text-[10px] font-bold uppercase tracking-[0.24em] text-violet-300/80">Drop a theme on a card</p>
          <p className="text-[10px] text-ink-faint">{applied ? applied.label : "no theme applied"}</p>
        </div>

        <div
          onDragOver={(e) => {
            e.preventDefault();
            setHovering(true);
          }}
          onDragLeave={() => setHovering(false)}
          onDrop={(e) => {
            e.preventDefault();
            setHovering(false);
            const id = e.dataTransfer.getData("text/plain");
            const preset = THEME_PRESETS.find((p) => p.id === id);
            if (preset) apply(preset, "by drop");
          }}
          className={`rounded-2xl border p-4 transition-colors ${hovering ? "border-violet-400/70 bg-violet-400/[.06]" : "border-white/10 bg-white/[.02]"}`}
          style={applied ? { background: applied.values.bg, borderColor: applied.values.accent } : undefined}
        >
          <p className="text-[10px] font-bold uppercase tracking-[0.2em]" style={{ color: applied?.values.inkFaint ?? "#747b87" }}>
            Component preview
          </p>
          <div className="mt-2 rounded-xl border p-3" style={applied ? { background: applied.values.panel, borderColor: `${applied.values.ink}22` } : { background: "#0b0d14", borderColor: "rgba(255,255,255,.1)" }}>
            <p className="text-sm font-extrabold" style={{ color: applied?.values.ink ?? "#edf0f7" }}>
              Pricing, but it breathes
            </p>
            <p className="mt-1 text-[10px] leading-relaxed" style={{ color: applied?.values.inkDim ?? "#9aa3b5" }}>
              Three tiers, one accent, no gradient soup. Drop a different chip on this card and every value remaps at once.
            </p>
            <span
              className="mt-2 inline-block rounded-lg px-2.5 py-1 text-[10px] font-bold"
              style={{ background: applied?.values.accent ?? "#8b5cf6", color: applied?.values.bg ?? "#06070b" }}
            >
              Choose a plan
            </span>
            <p className="mt-1.5 text-[9px]" style={{ color: applied?.values.inkFaint ?? "#747b87" }}>
              14-day refund · no card
            </p>
          </div>
        </div>

        <div className="mt-3 flex flex-wrap gap-2">
          {THEME_PRESETS.map((preset) => (
            <button
              key={preset.id}
              type="button"
              draggable
              onDragStart={(e) => {
                e.dataTransfer.setData("text/plain", preset.id);
                e.dataTransfer.effectAllowed = "copy";
              }}
              onClick={() => apply(preset, "with a press")}
              aria-pressed={applied?.id === preset.id}
              className="flex cursor-grab items-center gap-2 rounded-xl border border-white/10 bg-white/[.03] px-2.5 py-1.5 text-[10px] text-ink-dim transition-colors hover:border-violet-400/50 hover:text-ink active:cursor-grabbing"
            >
              <span className="flex gap-1" aria-hidden>
                {TOKEN_LABELS.map(({ key, label }) => (
                  <span key={label} className="h-3 w-3 rounded-full border border-white/20" style={{ background: preset.values[key] }} />
                ))}
              </span>
              {preset.label}
            </button>
          ))}
        </div>

        {applied && (
          <div className="mt-3 rounded-2xl border border-white/10 bg-white/[.02] p-3">
            <p className="text-[9px] font-bold uppercase tracking-widest text-ink-faint">
              Contrast, recomputed on every apply ({checks.length - failing.length}/{checks.length} pass)
            </p>
            <ul className="mt-1.5 space-y-1">
              {checks.map((c) => (
                <li key={c.label} className="flex items-center justify-between gap-2 text-[10px]">
                  <span className="truncate text-ink-dim">{c.label}</span>
                  <span className={`shrink-0 tabular-nums ${c.pass ? "text-emerald-300" : "text-amber-300"}`}>
                    {c.ratio.toFixed(2)}:1 · {c.pass ? "pass" : `needs ${c.line}`}
                  </span>
                </li>
              ))}
            </ul>
          </div>
        )}

        <p aria-live="polite" className="mt-2 min-h-[1rem] text-[10px] leading-relaxed text-violet-200/80">
          {status}
        </p>
        <p className="mt-1 text-[10px] leading-relaxed text-ink-faint">
          The chips are the presets the admin theme control room stores, and the contrast figures are the same WCAG arithmetic
          that room runs — so a preset that fails is named here, not quietly dropped from the menu. Pressing a chip does exactly
          what dropping it does; the drag is a shortcut, never the only way in.
        </p>
      </div>
    </div>
  );
}

Snippet provenance

lines 1–265 · v1.0.0
v1.0.0Motif Studio2026-09-10the only version the catalog records for this asset

No changelog entry mentions “Drag-a-theme Chip”, so the catalog records a single version for it.

Every line above is attributed to the single version this catalog records — we keep no per-line history, so no per-line attribution is invented. See the provenance page for the rule and the gaps.

Review notes · anchored to code lines

Threads attach to a line number in this asset's snippet, so a remark about the focus trap stays next to it.

demo · stored in this browser

Loading notes…

The snippet on this page is 265 lines long, so anchors run 1–265. Notes are per-asset and per-browser; a shared review thread is a server feature, and this panel is the local stand-in that proves the anchoring works.

Dependency-aware copy: zero packages to install — paste and run. All markup is original Motif UI content (MIT).

Course rail — understand it before you ship it

Theme Studio preview

Theming example — two token themes

Assets are token-driven (100% design-token driven). Here the same scene runs under two theme presets from the token sheet.

Midnight / violet

Drop a theme on a card

no theme applied

Component preview

Pricing, but it breathes

Three tiers, one accent, no gradient soup. Drop a different chip on this card and every value remaps at once.

Choose a plan

14-day refund · no card

Four theme presets from the admin control room. Drag one onto the card, or press it.

The chips are the presets the admin theme control room stores, and the contrast figures are the same WCAG arithmetic that room runs — so a preset that fails is named here, not quietly dropped from the menu. Pressing a chip does exactly what dropping it does; the drag is a shortcut, never the only way in.

--accent 262 · dark surfaces

Bone / amber

Drop a theme on a card

no theme applied

Component preview

Pricing, but it breathes

Three tiers, one accent, no gradient soup. Drop a different chip on this card and every value remaps at once.

Choose a plan

14-day refund · no card

Four theme presets from the admin control room. Drag one onto the card, or press it.

The chips are the presets the admin theme control room stores, and the contrast figures are the same WCAG arithmetic that room runs — so a preset that fails is named here, not quietly dropped from the menu. Pressing a chip does exactly what dropping it does; the drag is a shortcut, never the only way in.

--accent 40 · paper surfaces

90-second read

Usage recipe — where this fits

Put it where a micro-decision happens: a toggle, a loader, a hover state — the small moments that make an interface feel considered.

Drop it into the exact spot it belongs, keep the default props until the copy is final, then tune the one knob that matters for your context.

belongs in elementsdrag behaviourclick behaviourkeyboard behaviour

Cost honesty

Performance note

2.4 KB gzipnegligible — a single painted surface; nothing moves unless hovered.

Cheaper alternative — if you need even lighter, the plain HTML version skips React entirely — same result, ~0 KB.

What it needs

Browser support strip

HTML semanticsfocus-visiblecustom propertiesprefers-reduced-motionall evergreen browsers

No polyfills ship with the asset — if a listed feature is missing in a target browser, the graceful fallback is the static layout.

prefers-reduced-motion

Reduced-motion fallback

With prefers-reduced-motion: reduce, the animation loop and travel are removed; state changes keep working through opacity and colour (≤ 300ms). The demo you see above honours the switch — try it in your OS settings and the loop will quiet down.

Design rule: the reduced branch is a second design, not a stripped page — every state change stays visible.

Pressable step-through

Keyboard walk demo

Step through what a keyboard user experiences with this asset.

1

Tab to the element — the focus ring is visible before interaction

Auto-suggested

Composition map — what pairs well

One original micro-case

Inspiration context

The settings row that got fewer support tickets

A settings screen had seventeen identical switches with no press state. Users could not tell whether a tap had registered, so they tapped twice — and support logs filled with 'it toggles back'. The fix was one press-state scale plus a 250ms state fade per row. Ticket volume on that screen dropped by half in a month.

Written in-house — no screenshots, no borrowed imagery. The pattern, not the pixels.

Every version, why

Changelog — this asset

v1.0.02026-09-10

Current release — this page documents the asset as shipped.

v1.0.02026-08-18

Token pass: colours and radii moved to the design-token sheet; a11y score raised to the current bar.

v0.1.02026-07-02

Initial release to the library — original markup, MIT licensed.

30-day sparkline

Copy history

220copies this month

Sample series from this asset's usage fingerprint · last 12 days shown.

Future queue

Community remixes

Queue opens after launch. Remixes arrive as alternate versions of this asset — same job, different voice — submitted by users and audited by the studio before they appear beside the original.

0 remixes yetaudited by studiocredit + link back to the remixer

Star / favourite

Save this asset

Your collection is stored in this browser (localStorage) — no account needed.

Build a page around it

Pairs well with a prompt

This asset belongs inside a bigger build — here is the prompt that would generate a page containing it:

A11y-strict page — WCAG AA as a hard requirement

AA requirements · Contrast audit · Keyboard map

featured

Exact tree

Bundled dependencies — disclosed

theme-drop.tsx10.4 KB raw · ~1 KB gzip
(no runtime dependencies)the CSS ships with the snippet

Full snippet ≈ 10.4 KB raw, ~1 KB gzip — before any framework you already load.

Download

Export as single file

Grab the asset as one file, ready to paste into your project.

Files are generated in your browser from the snippets on this page — nothing leaves the tab.

Scale, not clutter

Sizing system — three densities

Density is a token decision, not a per-page override — pick one density per product surface and hold it. Active: Default.

Runnable copy

Open in a sandbox

Opens this asset in a new tab with its stylesheet injected — a real, editable HTML document in your browser. No account, no upload.

If the tab is blocked, use the single-file export instead — same content, saved locally.

Written version first

Tutorial transcript

This asset does not have a video yet — so the written version stands in: the code line walk below narrates the snippet line by line, and the design rationale on this page explains the default decisions. When a video ships, this exact panel hosts its full transcript.

video: not yettranscript: line walk belowformat: markdown, searchable

Annotated snippet

Code line walk

The lines that matter, with the reason they matter. Click one:

Trade-off, visible

Size vs. quality slider

~2 KB~6 KB~12 KB

Standard · CSS + hover states

~6 KB

adds transitions, focus-visible and reduced-motion rules

The slider is honest: the slim tier has no JS, the pro tier pays for behaviour. Start slim, upgrade only the surfaces that need it.

HTML → React, priced

Stack-switch cost note

Taking the HTML/CSS version into a React component costs real work — and the cost is predictable:

Event wiring

Hover, focus and click become handlers — the CSS stays, the state appears.

Props for the knobs

Every inline value that should vary becomes a prop with a default — the defaults must match the CSS exactly.

The estimate

A clean port of this asset is 20–45 minutes for a React developer — the 0-character stylesheet is the easy half.

Find it the way you say it

Tag synonyms

Search on this site resolves synonyms globally — "dropdown", "select" and "picker" land on the same asset, so you never need to know the catalog's internal vocabulary.

When to pick which

Sibling comparison

Data table — data table
CompareDrag-a-theme ChipPrism SwitchHalo Button
KindElementsElementsElements
Bundle2.4 KB gzip1.2 KB gzip2.1 KB gzip
a11y95/10098/10096/100
Dependenciesnonenonenone
Copies / mo2204,8203,910
Interactionsdrag, click, keyboardclick, hoverhover, click, drag

The honest verdict — Prism Switch is lighter, but Drag-a-theme Chip carries richer behaviour — pick by the interaction your screen actually needs, then swap tokens, not pages.

Read next — two guides and a prompt

picked by tag overlap, not by hand

How these three were chosen: essays scored on shared tags (1 and 1 matches), then prompt scored on block/vibe overlap (0 matches). The rule lives in src/lib/spine.ts, so the same asset always links to the same three pages and a second reader can reproduce the choice.

–remixes · this browser

The counter is a note to yourself — it adds one each time you tap, in motif:remix-count:v1, and goes nowhere. A real, public remix count would need a server and accounts; this site has neither, and it would rather say that than print a number it cannot own.

Was this helpful?