Generates accessible color combinations that meet WCAG contrast requirements.Documentation Index
Fetch the complete documentation index at: https://anvil.servicetitan.com/llms.txt
Use this file to discover all available pages before exploring further.
Usage
Parameters
| Parameter | Type | Description |
|---|---|---|
hex | string | The hex color to generate accessible colors for (e.g., "#FF0000") |
mode | "light" | "dark" | The color mode for context-aware generation |
Return Value
| Property | Type | Description |
|---|---|---|
foreground | string | undefined | Accessible text color (4.5:1 contrast ratio) |
background | string | undefined | The background color |
border | string | undefined | Accessible border color (3:1 contrast ratio) |
Contrast Requirements
The hook ensures colors meet WCAG accessibility standards:- Text (foreground): 4.5:1 contrast ratio against background
- Border: 3:1 contrast ratio against page background
- Colors are iteratively adjusted up to 16 times to meet requirements
Examples
Dynamic Badge Colors
Theme-Aware Colors
User-Selected Colors
Algorithm Details
Light Mode
- Determines if the background is light or dark using contrast comparison
- Selects white or dark text based on background
- Ensures 4.5:1 contrast ratio for text readability
- Falls back to black text if contrast is insufficient
- Generates border color with 3:1 contrast against page background
Dark Mode
- Starts with the provided color for both foreground and background
- Ensures background meets darkness threshold for dark themes
- Iteratively adjusts foreground and background for 4.5:1 contrast
- Prioritizes background darkening to maintain theme consistency
- Generates border color with 3:1 contrast against page background