From 06580b0c9cce726a5a90179ce9bbc36de9936d94 Mon Sep 17 00:00:00 2001 From: xintaofei Date: Fri, 27 Mar 2026 14:13:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=90=AF=E5=8A=A8=E5=99=A8?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project-boot/project-boot-workspace.tsx | 2 +- .../shadcn/shadcn-config-panel.tsx | 2 +- .../project-boot/shadcn/shadcn-launcher.tsx | 79 ++++++++++++++++--- 3 files changed, 68 insertions(+), 15 deletions(-) diff --git a/src/components/project-boot/project-boot-workspace.tsx b/src/components/project-boot/project-boot-workspace.tsx index 199eed4..87c5424 100644 --- a/src/components/project-boot/project-boot-workspace.tsx +++ b/src/components/project-boot/project-boot-workspace.tsx @@ -13,7 +13,7 @@ export function ProjectBootWorkspace() { const t = useTranslations("ProjectBoot") return ( - +
{t("tabs.shadcn")} diff --git a/src/components/project-boot/shadcn/shadcn-config-panel.tsx b/src/components/project-boot/shadcn/shadcn-config-panel.tsx index 619a90f..f168273 100644 --- a/src/components/project-boot/shadcn/shadcn-config-panel.tsx +++ b/src/components/project-boot/shadcn/shadcn-config-panel.tsx @@ -85,7 +85,7 @@ export function ShadcnConfigPanel({ return (
- +
{CONFIG_FIELDS.map((field) => (
diff --git a/src/components/project-boot/shadcn/shadcn-launcher.tsx b/src/components/project-boot/shadcn/shadcn-launcher.tsx index 38a4c34..fcb5264 100644 --- a/src/components/project-boot/shadcn/shadcn-launcher.tsx +++ b/src/components/project-boot/shadcn/shadcn-launcher.tsx @@ -1,11 +1,7 @@ "use client" -import { useMemo, useState } from "react" -import { - ResizablePanelGroup, - ResizablePanel, - ResizableHandle, -} from "@/components/ui/resizable" +import { useMemo, useState, useCallback, useRef, useEffect } from "react" +import { cn } from "@/lib/utils" import { ShadcnConfigPanel } from "./shadcn-config-panel" import { ShadcnPreview } from "./shadcn-preview" import { @@ -15,10 +11,18 @@ import { type ShadcnPresetConfig, } from "./constants" +const MIN_WIDTH = 280 +const MAX_WIDTH = 480 +const DEFAULT_WIDTH = 360 + export function ShadcnLauncher() { const [config, setConfig] = useState( DEFAULT_PRESET_CONFIG ) + const [sidebarWidth, setSidebarWidth] = useState(DEFAULT_WIDTH) + const [isDragging, setIsDragging] = useState(false) + const startXRef = useRef(0) + const startWidthRef = useRef(0) const presetCode = useMemo(() => encodePreset(config), [config]) const previewUrl = useMemo( @@ -30,21 +34,70 @@ export function ShadcnLauncher() { setConfig((prev) => ({ ...prev, [key]: value })) } + const handleMouseDown = useCallback( + (e: React.MouseEvent) => { + e.preventDefault() + setIsDragging(true) + startXRef.current = e.clientX + startWidthRef.current = sidebarWidth + }, + [sidebarWidth] + ) + + useEffect(() => { + if (!isDragging) return + + const handleMouseMove = (e: MouseEvent) => { + const newWidth = Math.min( + MAX_WIDTH, + Math.max( + MIN_WIDTH, + startWidthRef.current + (e.clientX - startXRef.current) + ) + ) + setSidebarWidth(newWidth) + } + + const handleMouseUp = () => { + setIsDragging(false) + } + + document.addEventListener("mousemove", handleMouseMove) + document.addEventListener("mouseup", handleMouseUp) + + return () => { + document.removeEventListener("mousemove", handleMouseMove) + document.removeEventListener("mouseup", handleMouseUp) + } + }, [isDragging]) + return ( - - +
+
- +
- +
- +
- - +
+
) }