shadcn.io is not affiliated with official shadcn/ui
Tone Picker Command Menu Block for React
A design tool's tone picker as a command menu shown open over its Fill row: an eleven-step grey ramp and recent tones, a HEX, RGB or HSL switch that rewrites every value and what Enter copies, and a band with the highlighted tone's contrast on white and on black.
Installation
Overview
Choose a tone and see how it reads before you use it with this tone picker command menu for React with Base UI. It opens from the Fill row of Swatchmill, a design tool, whose header holds an outline field with its ⌘ K cap, and the tool's inspector is drawn under a soft scrim inside a hairline frame with a plus mark on each corner. The menu is the catalog Command: a ramp of eleven greys from 50 to 950, each row a swatch, a name and its value, and a Recent group of three tones at the top. A switch above the list picks HEX, RGB or HSL and rewrites every value at once, and Enter copies the highlighted tone in that format through the clipboard, sets the Fill and moves the tone to the front of Recent. A band under the list follows the highlight and says how the tone reads on white and on black as ratios worked out from the tone itself with the WCAG formula ("4.7:1, AA"), in words rather than in colour, with a Copy button that copies without choosing. The tones are the tool's own fixed greys and every swatch is exactly the value beside it, so nothing depends on the page's theme and nothing on the page changes. For preview the menu is drawn open in place when the page loads; the field, or Ctrl or ⌘ K while focus is in the block, opens the real command dialog with the same format, Fill and query. For design tools, theme builders and any product that lets people choose a tone.
FAQ
Why is the menu already open, and what do I keep?
So you can see it without a click. On load the menu is the Command with its two bands drawn inline under a picture of the inspector, in a plain shell that is not modal, so nothing is trapped, hidden or focused and the page around the preview keeps working. The header's field opens the real command dialog, modal, with its focus trap, Escape and focus return, and the inline copy stays closed until a reload. Both show the same Palette and share the block's state, so the format you chose in the copy is the one the dialog opens with. In your app keep the dialog and drop the copy: the "in-place" state, the scrim with its shell and the Escape and blur effects.
How is the contrast worked out?
Each tone is a pure grey, so the band computes its relative luminance with the WCAG formula and divides: the lighter of the tone and the ground, plus 0.05, over the darker plus 0.05. That is the ratio shown to one place, and the words follow the usual thresholds: 7 and up is AAA, 4.5 and up AA, 3 and up AA for large text only, and under 3 is below AA. White and black are fixed grounds, not the page, so the numbers stay the same in every theme. The drawn sample beside each ratio is a short bar of the tone on that ground, not text.
What does the format switch change?
Every value in the list, the band and what gets copied. HEX writes #737373, RGB rgb(115, 115, 115) and HSL hsl(0, 0%, 45%); the ramp is neutral, so the hue and the saturation are zero and the three formats describe the same grey. One format is always chosen, the status line says which, and the search reads all three, so typing 737373, rgb or dark finds the tone.
What does Enter copy, and what changes?
The highlighted tone, written in the chosen format, through the clipboard; the status line says what was copied, or that the browser refused. Enter then sets the Fill (the swatch and the name in the drawn inspector, and the drawn rectangle on its canvas), moves the tone to the front of Recent (three at most, no repeats) and closes the menu with focus on the field. The Copy button in the band copies the same text and changes nothing else.
What stays local, and how do I wire it?
All of it. The ramp, the Recent list and the Fill are typed state in the block; nothing is saved and the clipboard is the only thing the browser really does. In your app build TONES from your own palette, write the chosen tone to the selected layer in pick, and persist Recent where you keep user settings.
Is it accessible from the keyboard?
Yes. Type to search by step, value or word, the arrow keys move through the tones, Enter copies and chooses, and Escape closes the menu and puts focus on the field; Tab reaches the format switch and Copy. Ctrl or ⌘ K opens the dialog while focus is inside the block, and only then. The rows are options of a cmdk listbox; the block turns off its own fuzzy filter and lists the rows itself. The swatches are hidden from assistive technology; every row carries the name and the value, and the Fill is read as ", the Fill".
How does it look on a phone?
The inspector goes and the two bands stay. The copy shown on load docks to the top of the page at full width, so the keyboard does not cover the foot; the key hints go, the count stays, and the band's two ratios stack. The real dialog keeps the Command dialog's own phone layout.
Related
- Pro
Design Tokens Command Menu
Visual pickersA design-system inspector's token picker as a command menu hung from a Fill field: tokens in groups with their resolved values and a small drawing, a box pane that wears whatever you apply, the alias chain of the last token, and a copy as CSS variable or JSON.
- Pro
Appearance Command Menu
Visual pickersA dashboard app's appearance menu shown open beside a live mini app: mode, corner radius, density and text size in four groups with a tick on each current choice, and a preview that restyles the moment you choose while the menu stays open.
- AaAgAaAaAaPro
Font Picker Command Menu
Visual pickersA document editor's font menu hung from the toolbar's font name, with six system font stacks each set in its own real CSS stack, a specimen band that follows the highlight, a row of weights and an italic toggle, and Enter to set the document's font.
- Pro
Layout Switcher Command Menu
Visual pickersA dashboard configurator's layout switcher as a command menu docked at the end of the page: six layouts each with a greyscale diagram, a band that draws the highlighted one larger, and Enter to re-arrange the drawn dashboard, still under reduced motion.
- Pro
Icon Picker Command Menu
Visual pickersA page builder's icon picker as a command menu shown open over a block's settings: forty icons drawn at the chosen size and stroke, two sliders that restyle every row, and Enter copies the JSX.
- Pro
Basic Command Menu
Search everythingA team workspace's home page with its command menu shown open: eleven pages in three groups, a shortcut on the five most used, matches marked, an empty state that says what to try and a foot with the key hints and a spoken count.