From e96682f89e2c72b55025b7fe38bf10cfabad0ca7 Mon Sep 17 00:00:00 2001 From: karansingh21202 <131647871+karansingh21202@users.noreply.github.com> Date: Sat, 16 Aug 2025 11:09:32 +0530 Subject: [PATCH] fix: enable removing background color in text back to transparent and remember last selection (#510) --- .../properties-panel/text-properties.tsx | 44 +++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/apps/web/src/components/editor/properties-panel/text-properties.tsx b/apps/web/src/components/editor/properties-panel/text-properties.tsx index a06624eb..744c2be5 100644 --- a/apps/web/src/components/editor/properties-panel/text-properties.tsx +++ b/apps/web/src/components/editor/properties-panel/text-properties.tsx @@ -6,7 +6,8 @@ import { useTimelineStore } from "@/stores/timeline-store"; import { Slider } from "@/components/ui/slider"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; -import { useState } from "react"; +import { Switch } from "@/components/ui/switch"; // Add Switch import +import { useState, useRef } from "react"; import { PropertyItem, PropertyItemLabel, @@ -30,6 +31,9 @@ export function TextProperties({ Math.round(element.opacity * 100).toString() ); + // Track the last selected color for toggling + const lastSelectedColor = useRef("#000000"); + const parseAndValidateNumber = ( value: string, min: number, @@ -86,6 +90,20 @@ export function TextProperties({ updateTextElement(trackId, element.id, { opacity: opacityPercent / 100 }); }; + // Update last selected color when a new color is picked + const handleColorChange = (color: string) => { + if (color !== "transparent") { + lastSelectedColor.current = color; + } + updateTextElement(trackId, element.id, { backgroundColor: color }); + }; + + // Toggle between transparent and last selected color + const handleTransparentToggle = (isTransparent: boolean) => { + const newColor = isTransparent ? "transparent" : lastSelectedColor.current; + updateTextElement(trackId, element.id, { backgroundColor: newColor }); + }; + return (