/** * @fileoverview 设计系统管理页面 * @description 展示和管理设计系统的所有令牌,包括颜色、字体、间距等 */ import React, { useState, useMemo } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { Palette, Type, Ruler, Shadow, Circle, Zap, Search, Filter, Grid, List, Download, Upload, Settings, Plus, Eye, EyeOff } from 'lucide-react'; import { Card, CardBody, CardHeader } from '../components/ui/Card'; import { Button, IconButton } from '../components/ui/Button'; import { TokenCard } from '../components/design-system/TokenCard'; import { ColorPalette } from '../components/design-system/ColorPalette'; import { useColors, useTypography, useSpacing, useShadows, useBorderRadius, useAnimations, useSelectedToken, useDesignSystemStore } from '../store/design-system-store'; import { clsx } from 'clsx'; // 令牌类型定义 type TokenType = 'all' | 'color' | 'typography' | 'spacing' | 'shadow' | 'border-radius' | 'animation'; // 令牌类别配置 const TOKEN_CATEGORIES = { all: { label: 'All Tokens', icon: Settings, color: 'neutral' }, color: { label: 'Colors', icon: Palette, color: 'primary' }, typography: { label: 'Typography', icon: Type, color: 'secondary' }, spacing: { label: 'Spacing', icon: Ruler, color: 'success' }, shadow: { label: 'Shadows', icon: Shadow, color: 'warning' }, 'border-radius': { label: 'Border Radius', icon: Circle, color: 'error' }, animation: { label: 'Animation', icon: Zap, color: 'info' }, } as const; /** * 设计系统主页面组件 */ const DesignSystem: React.FC = () => { const [activeCategory, setActiveCategory] = useState('all'); const [searchQuery, setSearchQuery] = useState(''); const [viewMode, setViewMode] = useState<'grid' | 'list'>('grid'); const [showDeprecated, setShowDeprecated] = useState(true); const [selectedToken, setSelectedToken] = useState(null); // 获取所有令牌数据 const colors = useColors(); const typography = useTypography(); const spacing = useSpacing(); const shadows = useShadows(); const borderRadius = useBorderRadius(); const animations = useAnimations(); // 合并所有令牌 const allTokens = useMemo(() => { return [ ...colors, ...typography, ...spacing, ...shadows, ...borderRadius, ...animations, ]; }, [colors, typography, spacing, shadows, borderRadius, animations]); // 过滤令牌 const filteredTokens = useMemo(() => { return allTokens.filter(token => { // 类别过滤 const matchesCategory = activeCategory === 'all' || token.category === activeCategory; // 搜索过滤 const matchesSearch = searchQuery === '' || token.name.toLowerCase().includes(searchQuery.toLowerCase()) || token.description?.toLowerCase().includes(searchQuery.toLowerCase()) || token.value.toString().toLowerCase().includes(searchQuery.toLowerCase()); // 废弃状态过滤 const matchesDeprecated = showDeprecated || !token.deprecated; return matchesCategory && matchesSearch && matchesDeprecated; }); }, [allTokens, activeCategory, searchQuery, showDeprecated]); // 渲染特定类别的内容 const renderCategoryContent = () => { switch (activeCategory) { case 'color': return ( ); case 'typography': return (
{typography.map((token, index) => ( ))}
); case 'spacing': return (
{spacing.map((token, index) => ( ))}
); case 'shadow': return (
{shadows.map((token, index) => ( ))}
); case 'border-radius': return (
{borderRadius.map((token, index) => ( ))}
); case 'animation': return (
{animations.map((token, index) => ( ))}
); default: return (
{filteredTokens.map((token, index) => ( ))}
); } }; // 获取类别统计 const getCategoryStats = (type: TokenType) => { switch (type) { case 'color': return colors.length; case 'typography': return typography.length; case 'spacing': return spacing.length; case 'shadow': return shadows.length; case 'border-radius': return borderRadius.length; case 'animation': return animations.length; default: return allTokens.length; } }; return (
{/* 页面头部 */}

Design System

Manage your design tokens, typography, colors, and component guidelines

{/* 控制面板 */}
{/* 搜索框 */}
setSearchQuery(e.target.value)} className="pl-10 pr-4 py-2 w-full border border-neutral-300 dark:border-neutral-600 rounded-md bg-white dark:bg-neutral-800 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500" data-component="Input" data-element="search-input" data-placeholder="search-tokens" />
{/* 视图模式切换 */}
View:
{/* 废弃令牌切换 */}
setShowDeprecated(!showDeprecated)} size="sm" data-component="IconButton" data-element="deprecated-toggle" data-action="toggle-deprecated" > {showDeprecated ? : } Show deprecated
{/* 类别选择器 */}
{Object.entries(TOKEN_CATEGORIES).map(([key, config]) => { const Icon = config.icon; const count = getCategoryStats(key as TokenType); const isActive = activeCategory === key; return ( ); })}
{/* 主要内容区域 */} {/* 空状态 */} {filteredTokens.length === 0 && activeCategory !== 'color' ? (

No tokens found

Try adjusting your search criteria or browse different categories.

) : ( {renderCategoryContent()} )}
{/* 统计信息 */}
{Object.entries(TOKEN_CATEGORIES).slice(1).map(([key, config]) => { const Icon = config.icon; const count = getCategoryStats(key as TokenType); return (
{count}
{config.label}
); })}
); }; export default DesignSystem;