"use client" import type React from "react" import { useState, useRef, useEffect } from "react" import { useColorPalette } from "@/contexts/color-context" import { useMaterial } from "@/contexts/material-context" import { useDesign, availableFonts } from "@/contexts/design-context" import { useSidebar } from "@/contexts/sidebar-context" import { useView } from "@/contexts/view-context" import { HiMoon, HiSun } from "react-icons/hi" import { MdCheck, MdExpandMore } from "react-icons/md" import { RiSideBarFill } from "react-icons/ri" import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover" import { Button } from "@/components/ui/button" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu" import { useTheme } from "next-themes" // Preset colors for the color picker const presetColors = [ { name: "Slack Blue", value: "#1D9BD1" }, { name: "Discord Blurple", value: "#5865F2" }, { name: "Spotify Green", value: "#1DB954" }, { name: "Notion Red", value: "#E03E3E" }, { name: "Figma Purple", value: "#A259FF" }, { name: "Linear Pink", value: "#F687B3" }, { name: "GitHub Green", value: "#2DA44E" }, { name: "Vercel Cyan", value: "#00B8D9" }, { name: "Stripe Purple", value: "#635BFF" }, { name: "Raycast Orange", value: "#FF6363" }, { name: "Twitter Blue", value: "#1DA1F2" }, { name: "Tailwind Teal", value: "#0EA5E9" }, ] // Fixed border radius for UI components const UI_BORDER_RADIUS = "6px" export function TopBar() { const { primaryColor, setPrimaryColor } = useColorPalette() const { materials, selectedMaterial, setSelectedMaterial } = useMaterial() const { borderRadius, setBorderRadius, font, setFont } = useDesign() const { sidebarVisible, toggleSidebar } = useSidebar() const { viewMode, toggleViewMode } = useView() const [isColorPickerOpen, setIsColorPickerOpen] = useState(false) const [inputColor, setInputColor] = useState(primaryColor) const colorInputRef = useRef(null) const { setTheme, theme } = useTheme() const [mounted, setMounted] = useState(false) const [selectedFontName, setSelectedFontName] = useState(() => { // Find the font name based on the current font value const fontObj = availableFonts.find((f) => typeof f === "object" && f.value === font) return fontObj ? fontObj.name : "Inter" }) // Handle mounting for theme useEffect(() => { setMounted(true) }, []) // Update input color when primary color changes useEffect(() => { setInputColor(primaryColor) }, [primaryColor]) // Function to handle color change from the color picker const handleColorPickerChange = (e: React.ChangeEvent) => { const newColor = e.target.value setInputColor(newColor) setPrimaryColor(newColor) } // Function to handle color input change const handleColorInputChange = (e: React.ChangeEvent) => { const newColor = e.target.value setInputColor(newColor) // Validate if it's a valid hex color if (/^#([0-9A-F]{3}){1,2}$/i.test(newColor)) { setPrimaryColor(newColor) } } // Function to handle color input blur const handleColorInputBlur = () => { // Ensure the color is valid, if not revert to the current primary color if (!/^#([0-9A-F]{3}){1,2}$/i.test(inputColor)) { setInputColor(primaryColor) } else { setPrimaryColor(inputColor) } } // Function to handle preset color selection const handlePresetColorSelect = (color: string) => { setInputColor(color) setPrimaryColor(color) } // Function to handle font selection const handleFontSelect = (fontOption: any) => { if (typeof fontOption === "object") { setFont(fontOption.value) setSelectedFontName(fontOption.name) } else { setFont(fontOption) setSelectedFontName(fontOption) } } return (
{/* Sidebar toggle stays on the left */} {/* All other controls are centered in a grid layout */}
{/* Color Section */}
Color
Preset Colors
{presetColors.map((color) => ( ))}
{/* Separator */}
{/* Material Section */}
Material
{materials.slice(0, 3).map((material) => (
{/* Separator */}
{/* Roundedness Section - Direct visualization of border radius */}
Roundedness
{[0, 6, 12, 20].map((value) => (
{/* Separator */}
{/* Font Section - Using the default dropdown from styleguide */}
Font
{availableFonts.map((fontOption) => { const value = typeof fontOption === "object" ? fontOption.value : fontOption const name = typeof fontOption === "object" ? fontOption.name : fontOption return ( handleFontSelect(fontOption)} className="text-sm cursor-pointer fixed-font" > {name} ) })}
{/* Theme Toggle - Hidden in the mockup but keeping it accessible */}
{/* Sidebar Toggle */}
) } function cn(...classes: (string | boolean | undefined)[]) { return classes.filter(Boolean).join(" ") }