Interactive
Blossom picker
A colour picker shaped like a flower: hover swells a petal while its neighbours give way on springs, and picking one slides out a curved bar of its shades
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071'use client';
// A client component: in the App Router (v0, `npx shadcn add`) it runs in the browser. The Pages Router ignores this.
import { useRef, useState } from 'react';
import { BlossomPicker, type PickInfo } from './picker';
import { BlossomPopover } from './popover';
import styles from './blossom-picker.module.css';
/**
* A colour picker shaped like a flower: 19 overlapping petals on a white glass disc. Hover swells a
* petal outward while its neighbours give way on springs, and a dotted glow lights up in its colour;
* picking one slides out a curved bar of seven shades. It opens from a paint button, open to start.
*/
export default function BlossomPickerBlock() {
const [open, setOpen] = useState(true);
const [paint, setPaint] = useState('#d64fc0');
const [info, setInfo] = useState<PickInfo | null>({ name: 'Fuchsia', base: '#d64fc0', shade: 3 });
const button = useRef<HTMLButtonElement>(null);
return (
<section className={styles.stage}>
<figure className={styles.example}>
<div className={styles.toolbar}>
<button
ref={button}
type="button"
className={styles.tool}
aria-label="Paint colour"
aria-expanded={open}
onClick={() => setOpen((o) => !o)}
>
<svg
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
>
<path d="m19 11-8-8-8.6 8.6a2 2 0 0 0 0 2.8l5.2 5.2c.8.8 2 .8 2.8 0L19 11Z" />
<path d="m5 2 5 5" />
<path d="M2 13h15" />
<path d="M22 20a2 2 0 1 1-4 0c0-1.6 1.7-2.4 2-4 .3 1.6 2 2.4 2 4Z" />
</svg>
<span className={styles.dot} style={{ background: paint }} />
</button>
</div>
<figcaption className={styles.readout} aria-live="polite">
<span className={styles.chip} style={{ background: paint }} />
<span className={styles.name}>{info?.name ?? 'Colour'}</span>
<span className={styles.hex}>{paint}</span>
</figcaption>
<BlossomPopover open={open} onOpenChange={setOpen} anchor={button}>
{(closing) => (
<BlossomPicker
value={paint}
onChange={(hex, pick) => {
setPaint(hex);
setInfo(pick);
}}
closing={closing}
/>
)}
</BlossomPopover>
</figure>
</section>
);
}