Skip to content

Commit 1637300

Browse files
committed
fix: add null/undefined guards to color resolution - add null check in hexToRgb, make resolveNoteColorVariants accept string | undefined, default to grey (#9ca3af) when colorValue is undefined, add ?? "grey" fallback in DisplayNote colorVariants computation
1 parent 5a971a6 commit 1637300

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

new-deepnotes/apps/web/src/features/spatial/DisplayNote.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const colorVariants = computed(() => {
6666
// When inheriting, resolve variants from the parent color directly
6767
return resolveNoteColorVariants(baseColor);
6868
}
69-
return resolveNoteColorVariants(c.value);
69+
return resolveNoteColorVariants(c.value ?? "grey");
7070
});
7171
7272
const headFrag = computed(() => props.model.head.value.value);

new-deepnotes/apps/web/src/features/spatial/color-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function lightenColor(hex: string, ratio: number): string {
4848
return rgbToHex(lightened.r, lightened.g, lightened.b);
4949
}
5050

51-
export function resolveNoteColorVariants(colorValue: string): ColorVariants {
51+
export function resolveNoteColorVariants(colorValue: string | undefined): ColorVariants {
5252
const colorMap: Record<string, string> = {
5353
grey: "#9ca3af",
5454
red: "#ef4444",
@@ -62,7 +62,7 @@ export function resolveNoteColorVariants(colorValue: string): ColorVariants {
6262
black: "#171717",
6363
white: "#f5f5f5",
6464
};
65-
const base = colorMap[colorValue] ?? colorValue;
65+
const base = (colorValue ? colorMap[colorValue] : undefined) ?? colorValue ?? "#9ca3af";
6666
return {
6767
base,
6868
light: lightenColor(base, 0.35),

0 commit comments

Comments
 (0)