feat: add border color customization for user profile chips and improve text contrast
This commit is contained in:
@@ -138,3 +138,24 @@ export const splitWithSpace = (content: string): string[] => {
|
||||
if (trimmedContent === '') return [];
|
||||
return trimmedContent.split(' ');
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculate contrasting text color (black or white) for a given background color
|
||||
* @param bgColor - Hex color string (e.g., '#RRGGBB' or '#RRGGBBAA')
|
||||
* @returns '#000000' for light backgrounds, '#FFFFFF' for dark backgrounds
|
||||
*/
|
||||
export const getContrastingTextColor = (bgColor: string): string => {
|
||||
// Remove # if present
|
||||
const hex = bgColor.replace('#', '');
|
||||
|
||||
// Parse RGB values (ignore alpha if present)
|
||||
const r = parseInt(hex.substring(0, 2), 16);
|
||||
const g = parseInt(hex.substring(2, 4), 16);
|
||||
const b = parseInt(hex.substring(4, 6), 16);
|
||||
|
||||
// Calculate relative luminance using WCAG formula
|
||||
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
||||
|
||||
// Return black for light backgrounds, white for dark backgrounds
|
||||
return luminance > 0.5 ? '#000000' : '#FFFFFF';
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user