packages/ui/src/utils/colors/README.md
This folder contains the color manipulation utilities for Clerk's UI components. The system automatically chooses between legacy and modern color handling based on browser support.
The color system uses a progressive enhancement approach:
legacy.ts)#ff0000 becomes { h: 0, s: 100, l: 50, a: 1 }hsla(0, 100%, 50%, 1)modern.ts)color-mix() or relative color syntaxcolor-mix(in srgb, #ff0000 80%, white 20%) for lightening// Lighten a color by percentage
colors.lighten('#ff0000', 20); // Makes red 20% lighter
// Make a color transparent
colors.makeTransparent('#ff0000', 50); // Makes red 50% transparent
// Set specific opacity
colors.setAlpha('#ff0000', 0.5); // Sets red to 50% opacity
// Adjust for better contrast
colors.adjustForLightness('#333333', 10); // Slightly lightens dark colors
The system checks for these modern CSS features:
color-mix() functionhsl(from white h s l))If either is supported, modern handling is used. Otherwise, legacy handling kicks in.