# Colour swatch picker

> Round colour swatches where the chosen one gets an animated ring and its name appears underneath.

- Category: [Filters](https://library.aimran.es/components/filters)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-f-mob-color
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

The swatch row on a product page is often where people fall for a product. Picture a shop selling backpacks in six shades: tap one, a ring closes around it and the colour name shows below. Switching the product photo to match is the natural next step. People searching for a colour swatch selector or variant picker end up here.

Always show the colour name, not just the dot; “Navy” and “Black” are easy to confuse on screen. Add a subtle border on very light swatches, or white disappears against a white page.

## Code

### HTML

```html
<div class="uv-fcl"><div class="tt">Color</div><div class="rw"><button class="" style="--k2:#1d1d1f"><i></i></button><button class="on" style="--k2:#0071e3"><i></i></button><button class="" style="--k2:#34c759"><i></i></button><button class="" style="--k2:#ff9f0a"><i></i></button><button class="" style="--k2:#ff375f"><i></i></button><button class="" style="--k2:#af52de"><i></i></button></div><b class="nm">Blue</b></div>
```

### CSS

```css
.uv-fcl {
  --c1: #0071e3;
  --c2: #8ec5ff;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uv-fcl {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .9em;
}

.uv-fcl .tt {
  font-size: calc(var(--s) * .8);
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  opacity: .45;
}

.uv-fcl .rw {
  display: flex;
  gap: .7em;
}

.uv-fcl button {
  position: relative;
  width: 2.3em;
  height: 2.3em;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform calc(0.35s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-fcl button:hover {
  transform: scale(1.1);
}

.uv-fcl i {
  width: 1.65em;
  height: 1.65em;
  border-radius: 50%;
  background: var(--k2);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12),0 3px 8px rgba(0,0,0,.18);
  transition: transform calc(0.4s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-fcl button::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--k2);
  scale: .72;
  opacity: 0;
  transition: scale calc(0.45s / var(--k)) cubic-bezier(.34,1.56,.64,1),opacity calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uv-fcl button.on::after {
  scale: 1;
  opacity: 1;
}

.uv-fcl button.on i {
  transform: scale(.82);
}

.uv-fcl .nm {
  font-size: calc(var(--s) * .85);
  font-weight: 600;
}
```

### JavaScript

```js
document.querySelectorAll(".uv-fcl").forEach(el => {
  const nm=el.querySelector(".nm"),ns=["Black","Blue","Green","Orange","Red","Purple"];el.querySelectorAll("button").forEach((b,i)=>b.addEventListener("click",()=>{el.querySelectorAll("button").forEach(x=>x.classList.remove("on"));b.classList.add("on");nm.textContent=ns[i]}))
});
```

### React

```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uv-fcl {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .9em;
}

.uv-fcl .tt {
  font-size: calc(var(--s) * .8);
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  opacity: .45;
}

.uv-fcl .rw {
  display: flex;
  gap: .7em;
}

.uv-fcl button {
  position: relative;
  width: 2.3em;
  height: 2.3em;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform calc(0.35s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-fcl button:hover {
  transform: scale(1.1);
}

.uv-fcl i {
  width: 1.65em;
  height: 1.65em;
  border-radius: 50%;
  background: var(--k2);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12),0 3px 8px rgba(0,0,0,.18);
  transition: transform calc(0.4s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-fcl button::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--k2);
  scale: .72;
  opacity: 0;
  transition: scale calc(0.45s / var(--k)) cubic-bezier(.34,1.56,.64,1),opacity calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uv-fcl button.on::after {
  scale: 1;
  opacity: 1;
}

.uv-fcl button.on i {
  transform: scale(.82);
}

.uv-fcl .nm {
  font-size: calc(var(--s) * .85);
  font-weight: 600;
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const nm=el.querySelector(".nm"),ns=["Black","Blue","Green","Orange","Red","Purple"];el.querySelectorAll("button").forEach((b,i)=>b.addEventListener("click",()=>{el.querySelectorAll("button").forEach(x=>x.classList.remove("on"));b.classList.add("on");nm.textContent=ns[i]}))
}

export default function FMobColor() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uv-fcl"><div className="tt">Color</div><div className="rw"><button className="" style={{ "--k2": "#1d1d1f" } as CSSProperties}><i></i></button><button className="on" style={{ "--k2": "#0071e3" } as CSSProperties}><i></i></button><button className="" style={{ "--k2": "#34c759" } as CSSProperties}><i></i></button><button className="" style={{ "--k2": "#ff9f0a" } as CSSProperties}><i></i></button><button className="" style={{ "--k2": "#ff375f" } as CSSProperties}><i></i></button><button className="" style={{ "--k2": "#af52de" } as CSSProperties}><i></i></button></div><b className="nm">Blue</b></div>
      </div>
    </>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Colour swatch picker” block (Filters) from AIMRAN Library to my project.

## What it is
Round colour swatches where the chosen one gets an animated ring and its name appears underneath.

## Chosen settings
- Main color: #0071e3
- Secondary color: #8ec5ff
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with plain HTML and CSS (the reference wraps it in a React component with its CSS). If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uv-fcl {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .9em;
}

.uv-fcl .tt {
  font-size: calc(var(--s) * .8);
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  opacity: .45;
}

.uv-fcl .rw {
  display: flex;
  gap: .7em;
}

.uv-fcl button {
  position: relative;
  width: 2.3em;
  height: 2.3em;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform calc(0.35s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-fcl button:hover {
  transform: scale(1.1);
}

.uv-fcl i {
  width: 1.65em;
  height: 1.65em;
  border-radius: 50%;
  background: var(--k2);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12),0 3px 8px rgba(0,0,0,.18);
  transition: transform calc(0.4s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-fcl button::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--k2);
  scale: .72;
  opacity: 0;
  transition: scale calc(0.45s / var(--k)) cubic-bezier(.34,1.56,.64,1),opacity calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uv-fcl button.on::after {
  scale: 1;
  opacity: 1;
}

.uv-fcl button.on i {
  transform: scale(.82);
}

.uv-fcl .nm {
  font-size: calc(var(--s) * .85);
  font-weight: 600;
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const nm=el.querySelector(".nm"),ns=["Black","Blue","Green","Orange","Red","Purple"];el.querySelectorAll("button").forEach((b,i)=>b.addEventListener("click",()=>{el.querySelectorAll("button").forEach(x=>x.classList.remove("on"));b.classList.add("on");nm.textContent=ns[i]}))
}

export default function FMobColor() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uv-fcl"><div className="tt">Color</div><div className="rw"><button className="" style={{ "--k2": "#1d1d1f" } as CSSProperties}><i></i></button><button className="on" style={{ "--k2": "#0071e3" } as CSSProperties}><i></i></button><button className="" style={{ "--k2": "#34c759" } as CSSProperties}><i></i></button><button className="" style={{ "--k2": "#ff9f0a" } as CSSProperties}><i></i></button><button className="" style={{ "--k2": "#ff375f" } as CSSProperties}><i></i></button><button className="" style={{ "--k2": "#af52de" } as CSSProperties}><i></i></button></div><b className="nm">Blue</b></div>
      </div>
    </>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
