From df207e0f836770ebbe95e5d2b754d12e57e68768 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Sun, 29 Mar 2026 21:18:07 +0200 Subject: [PATCH] refactor: name magic numbers and rename el in landing handlebars --- .../web/src/components/landing/handlebars.tsx | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/apps/web/src/components/landing/handlebars.tsx b/apps/web/src/components/landing/handlebars.tsx index cfc688ce..4a81cdba 100644 --- a/apps/web/src/components/landing/handlebars.tsx +++ b/apps/web/src/components/landing/handlebars.tsx @@ -10,6 +10,11 @@ import { type HandlebarsProps = PropsWithChildren; +const MIN_HANDLE_SEPARATION_PX = 60; +const MASK_GRADIENT_EDGE_PADDING_PX = 10; +const HANDLEBARS_ROTATE_DEG = 2.76; +const RIGHT_HANDLE_LEFT_OFFSET_PX = -30; + export function Handlebars({ children }: HandlebarsProps) { const containerRef = useRef(null); const leftHandleRef = useRef(null); @@ -38,17 +43,17 @@ export function Handlebars({ children }: HandlebarsProps) { }); useLayoutEffect(() => { - const el = containerRef.current; - if (!el) return; + const container = containerRef.current; + if (!container) return; const updateWidth = () => { - const newWidth = el.offsetWidth; + const newWidth = container.offsetWidth; setWidth(newWidth); setRightHandle(newWidth); }; const observer = new ResizeObserver(updateWidth); - observer.observe(el); + observer.observe(container); updateWidth(); return () => observer.disconnect(); @@ -72,7 +77,10 @@ export function Handlebars({ children }: HandlebarsProps) { const deltaX = event.clientX - startX; if (side === "left") { - const maxLeft = Math.max(0, rightHandlePositionRef.current - 60); + const maxLeft = Math.max( + 0, + rightHandlePositionRef.current - MIN_HANDLE_SEPARATION_PX, + ); const nextLeftHandle = Math.max( 0, Math.min(maxLeft, initialPosition + deltaX), @@ -83,7 +91,7 @@ export function Handlebars({ children }: HandlebarsProps) { const minRight = Math.min( widthRef.current, - leftHandlePositionRef.current + 60, + leftHandlePositionRef.current + MIN_HANDLE_SEPARATION_PX, ); const nextRightHandle = Math.max( minRight, @@ -114,10 +122,10 @@ export function Handlebars({ children }: HandlebarsProps) { const hasMeasuredWidth = width > 0; const leftGradientPercent = hasMeasuredWidth - ? (leftHandle / (width - 10)) * 100 + ? (leftHandle / (width - MASK_GRADIENT_EDGE_PADDING_PX)) * 100 : 0; const rightGradientPercent = hasMeasuredWidth - ? (rightHandle / (width + 10)) * 100 + ? (rightHandle / (width + MASK_GRADIENT_EDGE_PADDING_PX)) * 100 : 100; const textMask = hasMeasuredWidth ? `linear-gradient(90deg, @@ -131,7 +139,11 @@ export function Handlebars({ children }: HandlebarsProps) { return (
-
+