Founding price: $35, then $99 after 23:59 UTC on 4 November, then $99
Get ProChoose a background color and get the text color that reads best on it, with both ratios and a pass or fail for AA, a live sample, and the nearest passing background if neither black nor white works. Use this when users colour badges, cards or tags themselves.
Derived from this item’s props table, because it declares no controls of its own. This item has no standalone playground, so changes update the code, the share link and the AI prompt.
Users pick background colors (labels, calendars, tags) and the app must choose text that stays readable.
Do not use it when: If you control all the colors, put the text color in your design tokens.
This item is part of tealmac UI Pro
The source for this item installs with a Pro licence key. Log in with your key to see the install command, or read the Pro setup page.
| Prop | Type | Description |
|---|---|---|
initial | string | The starting background. |
onChange | (background, text) => void | The new background and #ffffff or #000000. |
pickTextColor(rgba) and nearestBackground(rgba, target) are exported. Black or white always reaches AA (4.5 : 1) on any background; AAA (7 : 1) needs the right background.
The pattern ships with a Testing Library test (accessible-text-color-chooser.test.tsx) that covers: its main behaviour, the keyboard path and the error or empty states.