UNPKG

apphouse

Version:

Component library for React that uses observable state management and theme-able components.

11 lines (10 loc) 428 B
/** * Returns the base color from a CSS gradient string. * * @param {string} gradient - The CSS gradient string. * @returns {string} The base color extracted from the gradient string, or the original gradient string if no base color was found. */ export function getBaseColorFromGradient(gradient: string): string { const match = gradient.match(/rgba?\([^)]+\)|#[A-Fa-f\d]{3,6}/); return match ? match[0] : gradient; }