Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

refactor(editor): use shared opaque hex normalization in config sidebar

Richie McIlroya3044a7c368d
diff --git a/apps/desktop/src/routes/editor/ConfigSidebar.tsx b/apps/desktop/src/routes/editor/ConfigSidebar.tsx
index 8f2a124a7..d59e5e657 100644
--- a/apps/desktop/src/routes/editor/ConfigSidebar.tsx
+++ b/apps/desktop/src/routes/editor/ConfigSidebar.tsx
@@ -40,6 +40,7 @@ import imageBg from "~/assets/illustrations/image.webp";
import transparentBg from "~/assets/illustrations/transparent.webp";
import { Toggle } from "~/components/Toggle";
import { generalSettingsStore } from "~/store";
+import { normalizeOpaqueHexColor } from "~/utils/hex-color";
import type {
BackgroundSource,
CameraShape,
@@ -2527,19 +2528,6 @@ function CornerStyleSelect(props: {
);
}
-const normalizeHexInput = (value: string, fallback: string) => {
- const trimmed = value.trim();
- const withHash = trimmed.startsWith("#") ? trimmed : `#${trimmed}`;
- const shortMatch = /^#[0-9A-Fa-f]{3}$/.test(withHash);
- if (shortMatch) {
- const [, r, g, b] = withHash;
- return `#${r}${r}${g}${g}${b}${b}`.toLowerCase();
- }
- const fullMatch = /^#[0-9A-Fa-f]{6}$/.test(withHash);
- if (fullMatch) return withHash.toLowerCase();
- return fallback;
-};
-
function HexColorInput(props: {
value: string;
onChange: (value: string) => void;
@@ -2585,7 +2573,8 @@ function HexColorInput(props: {
setText(e.currentTarget.value);
}}
onBlur={(e) => {
- const next = normalizeHexInput(e.currentTarget.value, prevColor);
+ const next =
+ normalizeOpaqueHexColor(e.currentTarget.value) ?? prevColor;
setText(next);
prevColor = next;
props.onChange(next);