gitwtfhub

wtf is swatchbook?

omaroubari/swatchbook — explained in plain English

Analysis updated 2026-05-18

1JavaScriptAudience · developerSetup · easy

TL;DR

A tiny web component that lets you flip through a few design candidates for one page section, one at a time, instead of stacking them all on the page.

Mindmap

mindmap
  root((repo))
    What it does
      Design carousel
      One swatch at a time
      Review tool
    Tech stack
      JavaScript
      Web Components
      Zero dependencies
    Use cases
      Compare hero designs
      Compare pricing tables
      Client review
    Audience
      Frontend developers
      Designers
    Gotchas
      Direct children only
      Needs two swatches
      Unique label per page

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Why would anyone build with this?

REASON 1

Compare two or three hero section designs by clicking through them like a carousel.

REASON 2

Show a client several candidate pricing tables and let them pick a favorite.

REASON 3

Drop the tool into any framework, since it is a plain custom element with no dependencies.

REASON 4

Remove the script before shipping to production so only the chosen default design remains.

What's in the stack?

JavaScriptWeb ComponentsHTMLCSS

How it stacks up

omaroubari/swatchbook0xmukesh/docusaurus-tutorial1tsmejp/palworld-docker-wine
Stars111
LanguageJavaScriptJavaScriptJavaScript
Last pushed2021-12-27
MaintenanceDormant
Setup difficultyeasyeasymoderate
Complexity2/54/5
Audiencedeveloperdeveloperops devops

Figures from each repo's GitHub metadata at analysis time.

How do you spin it up?

Difficulty · easy Time to first run · 5min

Swatches must be direct children of the swatch-book element or the carousel silently fails to activate.

Wtf does this do

Swatchbook is a small web component called swatch-book that lets you compare a few design candidates for the same section of a page, one at a time, instead of stacking them all down the page. It is aimed at the moment when you have two or three versions of a hero section, a pricing table, or a call to action, and you want to click through them to pick a favorite. It has zero dependencies and weighs about 2.5 kilobytes after compression. Because it is a plain custom element rather than a framework-specific piece, it works inside Astro, React, Vue, Svelte, or plain handwritten HTML. You add one script tag, wrap your candidate designs in a swatch-book tag, and mark each candidate with a data-swatch attribute holding its name. One of them can be marked as the default. The component then shows a small floating control with previous and next arrows, dots, and a label showing which swatch is active. A key idea in the README is that the script tag itself acts as the on and off switch. Include the script during a design review and you get the carousel behavior. Leave it out when you ship to production, and the page falls back to showing only the swatch marked as default, as if the tool was never there. This is meant to make it disposable scaffolding rather than something that lingers in the codebase. The README also documents several gotchas. Swatches must be direct children of the swatch-book element, or the component cannot find them and everything renders stacked, which can look like a bug rather than a missing setup step. At least two swatches are required for there to be anything to flip between. Children added after the page loads, such as through async data, will not be picked up. The label attribute doubles as a storage key for remembering the last chosen swatch, so it must be unique on a page with more than one book. It can be installed with a script tag directly from a CDN, or through the pnpm package manager if you prefer to bundle it into your project.

Yoink these prompts

Prompt 1
Give me three candidate designs for the hero section and wrap them in a swatchbook so I can flip between them.
Prompt 2
Add swatchbook from the CDN to this page so I can compare pricing table variants.
Prompt 3
Explain why my swatchbook is rendering all candidates stacked instead of one at a time.
Prompt 4
Show me how to mark one swatch as the default so it displays when the script is removed.

Frequently asked questions

wtf is swatchbook?

A tiny web component that lets you flip through a few design candidates for one page section, one at a time, instead of stacking them all on the page.

What language is swatchbook written in?

Mainly JavaScript. The stack also includes JavaScript, Web Components, HTML.

How hard is swatchbook to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is swatchbook for?

Mainly developer.

View the repo → Decode another repo

This repo across BitVibe Labs

Don't trust strangers blindly. Verify against the repo.