Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/components/page/theming/ColorGenerator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -56,13 +55,13 @@ const ColorGenerator = (props: ComponentProps<'section'>) => {
>
<div className={styles.titleRow}>
<div className={styles.titleRowStart}>
<ColorDot color={formattedValue} />
<ColorDot color={value} />
{nameCap}
</div>
<div className={styles.titleRowEnd}>
<ColorInput
onClick={(event) => event.stopPropagation()}
color={formattedValue}
color={value}
setColor={(color) =>
setColors((colors) => {
colors[name] = generateColor(color);
Expand Down
4 changes: 2 additions & 2 deletions src/components/page/theming/_utils/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
3 changes: 2 additions & 1 deletion src/components/page/theming/_utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading