diff --git a/src/components/page/theming/ColorGenerator/index.tsx b/src/components/page/theming/ColorGenerator/index.tsx index b025f6b6f4c..c3ce85df95f 100644 --- a/src/components/page/theming/ColorGenerator/index.tsx +++ b/src/components/page/theming/ColorGenerator/index.tsx @@ -45,7 +45,6 @@ const ColorGenerator = (props: ComponentProps<'section'>) => { const { tint, shade, value } = color; const nameCap = name[0].toUpperCase() + name.substring(1); - const formattedValue = value.charAt(0) === '#' ? value : '#' + value; const isOpen = activeColor === name ? true : false; return ( @@ -56,13 +55,13 @@ const ColorGenerator = (props: ComponentProps<'section'>) => { >
- + {nameCap}
event.stopPropagation()} - color={formattedValue} + color={value} setColor={(color) => setColors((colors) => { colors[name] = generateColor(color); diff --git a/src/components/page/theming/_utils/color.ts b/src/components/page/theming/_utils/color.ts index 2f4ca062833..1f724ebe559 100755 --- a/src/components/page/theming/_utils/color.ts +++ b/src/components/page/theming/_utils/color.ts @@ -164,10 +164,10 @@ export class Color { constructor(value: string | RGB | HSL) { if (typeof value === 'string' && /rgb\(/.test(value)) { const matches = /rgb\((\d{1,3}), ?(\d{1,3}), ?(\d{1,3})\)/.exec(value) ?? []; - value = { r: parseInt(matches[0]!, 10), g: parseInt(matches[1]!, 10), b: parseInt(matches[2]!, 10) }; + value = { r: parseInt(matches[1]!, 10), g: parseInt(matches[2]!, 10), b: parseInt(matches[3]!, 10) }; } else if (typeof value === 'string' && /hsl\(/.test(value)) { const matches = /hsl\((\d{1,3}), ?(\d{1,3}%), ?(\d{1,3}%)\)/.exec(value) ?? []; - value = { h: parseInt(matches[0]!, 10), s: parseInt(matches[1]!, 10), l: parseInt(matches[2]!, 10) }; + value = { h: parseInt(matches[1]!, 10), s: parseInt(matches[2]!, 10), l: parseInt(matches[3]!, 10) }; } if (typeof value === 'string') { diff --git a/src/components/page/theming/_utils/index.tsx b/src/components/page/theming/_utils/index.tsx index e8353afd96e..a0e9a9f6d2b 100644 --- a/src/components/page/theming/_utils/index.tsx +++ b/src/components/page/theming/_utils/index.tsx @@ -13,7 +13,8 @@ export const generateColor = (value: string): GeneratedColorVariable => { const contrast = color.contrast(); const tint = color.tint(); const shade = color.shade(); - const formattedValue = value.startsWith('#') ? value : `#${value}`; + // Bare hex such as `0054e9` gets its `#`; `rgb()` and `hsl()` values pass through. + const formattedValue = /^[0-9a-f]+$/i.test(value) ? `#${value}` : value; return { value: formattedValue,