"use client"
import { useColorPalette } from "@/contexts/color-context"
import { useTheme } from "next-themes"
import { Copy, Check } from "lucide-react"
import { useState, useEffect } from "react"
import { SectionHeading } from "@/components/ui/section-heading"
import { semanticColors } from "@/utils/semantic-colors"
// Function to get computed CSS variable value
function getCssVariableValue(cssVar: string) {
return typeof window !== "undefined" ? getComputedStyle(document.documentElement).getPropertyValue(cssVar) : ""
}
// Percolate-aligned code field component for key-value pairs
interface CodeFieldProps {
variable: string
value: string
}
function CodeField({ variable, value }: CodeFieldProps) {
const [copiedVariable, setCopiedVariable] = useState(false)
const [copiedValue, setCopiedValue] = useState(false)
const copyToClipboard = (text: string, type: "variable" | "value") => {
navigator.clipboard.writeText(text).then(() => {
if (type === "variable") {
setCopiedVariable(true)
setTimeout(() => setCopiedVariable(false), 2000)
} else {
setCopiedValue(true)
setTimeout(() => setCopiedValue(false), 2000)
}
})
}
return (
{/* Variable */}
{variable}
copyToClipboard(variable, "variable")}
className="opacity-0 group-hover/var:opacity-100 transition-opacity duration-150 p-0.5 hover:bg-muted rounded"
title="Copy variable"
>
{copiedVariable ? (
) : (
)}
{/* Separator */}
:
{/* Value */}
{value}
copyToClipboard(value, "value")}
className="opacity-0 group-hover/val:opacity-100 transition-opacity duration-150 p-0.5 hover:bg-muted rounded flex-shrink-0"
title="Copy value"
>
{copiedValue ? (
) : (
)}
)
}
// Add minimal prop to the component
interface ColorSectionProps {
minimal?: boolean
}
export function ColorSection({ minimal = false }: ColorSectionProps) {
const [mounted, setMounted] = useState(false)
const { theme, resolvedTheme } = useTheme()
const [copiedColor, setCopiedColor] = useState(null)
// Use a try-catch to handle potential context errors
const colorContext = useColorPalette()
// Set mounted state after hydration
useEffect(() => {
setMounted(true)
}, [])
const copyToClipboard = (text: string, colorName: string) => {
if (typeof navigator !== "undefined") {
navigator.clipboard.writeText(text).then(() => {
setCopiedColor(colorName)
setTimeout(() => setCopiedColor(null), 2000)
})
}
}
// Get current theme for semantic colors
const currentTheme = (resolvedTheme || theme) as "light" | "dark"
const themeKey = currentTheme === "dark" ? "dark" : "light"
// If not mounted yet, show a loading state
if (!mounted) {
return Loading color section...
}
// If minimal is true, return a simplified version
if (minimal) {
return (
Color System
{["primary", "secondary", "accent", "success", "warning"].map((color) => (
{color.replace("-", " ")}
))}
)
}
return (
{/* Primary Color System */}
Primary Color System
The main brand color and its automatically generated palette of shades from 50 to 900
{/* Primary Color Swatch */}
copyToClipboard(colorContext.primaryColor, "primary")}
>
Primary
{colorContext.primaryColor}
{copiedColor === "primary" && (
Copied to clipboard
)}
{/* Primary Color Shades */}
Primary Color Shades
{[50, 100, 200, 300, 400, 500, 600, 700, 800, 900].map((shade) => (
copyToClipboard(`hsl(var(--primary-${shade}))`, `primary-${shade}`)}
>
{copiedColor === `primary-${shade}` && (
Copied!
)}
))}
Usage: Use these shades for consistent color variations.
Lighter shades (50-400) work well for backgrounds and subtle accents, while darker shades (600-900) are
ideal for text and prominent elements.
{/* CSS Variables */}
{/* Semantic Colors Section - Enhanced */}
Semantic Colors
Bold, vibrant colors for alerts, badges, and status indicators. Designed for maximum impact and clarity.
{/* Enhanced Grid of Semantic Colors */}
{(["success", "warning", "error", "info", "neutral"] as const).map((semantic) => {
const colors = semanticColors[semantic][themeKey]
return (
copyToClipboard(colors.background, semantic)}
>
{/* Icon/Accent Color Dot */}
{copiedColor === semantic && (
Copied!
)}
{semantic}
{semantic === "success" && "Positive feedback & confirmations"}
{semantic === "warning" && "Caution & important notices"}
{semantic === "error" && "Errors & critical alerts"}
{semantic === "info" && "Information & neutral updates"}
{semantic === "neutral" && "Default & secondary states"}
{/* Color Values */}
bg: {colors.background}
border: {colors.border}
)
})}
{/* Enhanced Usage Note */}
Usage Guidelines
Background: Use{" "}
--semantic-{"{color}"}-bg for card backgrounds and containers
Border: Use{" "}
--semantic-{"{color}"}-border for borders and dividers
Text: Use{" "}
--semantic-{"{color}"}-text for readable text content
Accent: Use{" "}
--semantic-{"{color}"}-fg for icons and highlights
)
}