moai-lib-shadcn-ui
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseEnterprise shadcn/ui Component Library Expert v4.0.0
企业级shadcn/ui组件库专家 v4.0.0
Skill Metadata
技能元数据
| Field | Value |
|---|---|
| Skill Name | moai-lib-shadcn-ui |
| Version | 4.0.0 (2025-11-13) |
| Tier | Enterprise Component Library Expert |
| AI-Powered | ✅ Context7 Integration, Intelligent Architecture |
| Auto-load | On demand when shadcn/ui keywords detected |
| 字段 | 值 |
|---|---|
| Skill Name | moai-lib-shadcn-ui |
| Version | 4.0.0 (2025-11-13) |
| 等级 | 企业级组件库专家 |
| AI驱动 | ✅ Context7集成、智能架构 |
| 自动加载 | 检测到shadcn/ui关键词时按需加载 |
What It Does
功能介绍
Enterprise shadcn/ui Component Library expert with AI-powered design system architecture, Context7 integration, and intelligent component orchestration for modern React applications.
Revolutionary v4.0.0 capabilities:
- 🤖 AI-Powered Component Architecture using Context7 MCP for latest design patterns
- 📊 Intelligent Design System with automated theme customization and optimization
- 🚀 Advanced Component Orchestration with AI-driven accessibility and performance
- 🔗 Enterprise UI Framework with zero-configuration design tokens and branding
- 📈 Predictive Component Analytics with usage forecasting and optimization insights
面向现代React应用的企业级shadcn/ui组件库,具备AI驱动的设计系统架构、Context7集成以及智能组件编排能力。
突破性v4.0.0功能:
- 🤖 AI驱动的组件架构:借助Context7 MCP实现最新设计模式
- 📊 智能设计系统:支持自动主题定制与优化
- 🚀 高级组件编排:AI驱动的无障碍访问与性能优化
- 🔗 企业级UI框架:零配置设计令牌与品牌适配
- 📈 预测性组件分析:使用量预测与优化洞察
When to Use
使用场景
Automatic triggers:
- shadcn/ui component library and design system discussions
- React component architecture and UI framework planning
- Tailwind CSS integration and design token management
- Accessibility implementation and design customization
Manual invocation:
- Designing enterprise design systems with shadcn/ui
- Implementing comprehensive component libraries
- Planning theme customization and branding strategies
- Optimizing component performance and accessibility
自动触发场景:
- shadcn/ui组件库与设计系统讨论
- React组件架构与UI框架规划
- Tailwind CSS集成与设计令牌管理
- 无障碍访问实现与设计定制
手动调用场景:
- 基于shadcn/ui设计企业级设计系统
- 实现全面的组件库
- 规划主题定制与品牌策略
- 优化组件性能与无障碍访问
Quick Reference (Level 1)
快速参考(Level 1)
shadcn/ui Ecosystem (November 2025)
shadcn/ui生态系统(2025年11月)
Core Components
核心组件
- Form Components: Input, Select, Checkbox, Radio, Textarea
- Display Components: Card, Dialog, Sheet, Drawer, Popover
- Navigation Components: Navigation Menu, Breadcrumb, Tabs, Pagination
- Data Components: Table, Calendar, DatePicker, Chart Components
- Feedback Components: Alert, Toast, Progress, Badge, Avatar
- 表单组件:Input、Select、Checkbox、Radio、Textarea
- 展示组件:Card、Dialog、Sheet、Drawer、Popover
- 导航组件:Navigation Menu、Breadcrumb、Tabs、Pagination
- 数据组件:Table、Calendar、DatePicker、Chart Components
- 反馈组件:Alert、Toast、Progress、Badge、Avatar
Foundation Technologies
基础技术栈
- React 19: Latest React with server components and concurrent features
- TypeScript 5.5: Full type safety and enhanced developer experience
- Tailwind CSS 3.4: Utility-first CSS framework with JIT compilation
- Radix UI: Unstyled, accessible component primitives
- Framer Motion: Production-ready motion library for animations
- Lucide React: Beautifully designed icon library
- React 19:支持服务端组件与并发特性的最新版本React
- TypeScript 5.5:完整类型安全与增强的开发者体验
- Tailwind CSS 3.4:支持JIT编译的实用优先CSS框架
- Radix UI:无样式、无障碍的组件原语
- Framer Motion:生产就绪的动画库
- Lucide React:设计精美的图标库
Design System Features
设计系统特性
- Dark Mode: Comprehensive dark mode support with system detection
- Responsive Design: Mobile-first responsive components
- Accessibility: WCAG 2.1 AA compliance with proper ARIA support
- Theming: CSS variables for comprehensive theme customization
- Animation: Smooth animations and transitions with Framer Motion
- 深色模式:全面的深色模式支持与系统检测
- 响应式设计:移动端优先的响应式组件
- 无障碍访问:符合WCAG 2.1 AA标准,具备完善的ARIA支持
- 主题定制:通过CSS变量实现全面的主题定制
- 动画效果:基于Framer Motion的流畅动画与过渡
Integration Benefits
集成优势
- Developer Experience: Excellent DX with TypeScript and hot reloading
- Customization: Fully customizable with Tailwind CSS classes
- Performance: Optimized bundle size and runtime performance
- Accessibility: Built-in accessibility with Radix UI primitives
- Consistency: Design system ensures consistent UI across applications
- 开发者体验:TypeScript与热重载带来的优秀DX
- 可定制性:通过Tailwind CSS类实现完全定制
- 性能表现:优化的包体积与运行时性能
- 无障碍访问:基于Radix UI原语的内置无障碍支持
- 一致性:设计系统确保跨应用的UI一致性
Core Implementation (Level 2)
核心实现方案(Level 2)
shadcn/ui Architecture Intelligence
shadcn/ui架构智能优化
python
undefinedpython
undefinedAI-powered shadcn/ui architecture optimization with Context7
AI-powered shadcn/ui architecture optimization with Context7
class ShadcnUIArchitectOptimizer:
def init(self):
self.context7_client = Context7Client()
self.component_analyzer = ComponentAnalyzer()
self.theme_optimizer = ThemeOptimizer()
async def design_optimal_shadcn_architecture(self,
requirements: DesignSystemRequirements) -> ShadcnUIArchitecture:
"""Design optimal shadcn/ui architecture using AI analysis."""
# Get latest shadcn/ui and React documentation via Context7
shadcn_docs = await self.context7_client.get_library_docs(
context7_library_id='/shadcn-ui/docs',
topic="component library design system theming accessibility 2025",
tokens=3000
)
react_docs = await self.context7_client.get_library_docs(
context7_library_id='/react/docs',
topic="hooks server-components performance optimization 2025",
tokens=2000
)
# Optimize component selection
component_selection = self.component_analyzer.optimize_component_selection(
requirements.ui_components,
requirements.user_needs,
shadcn_docs
)
# Optimize theme configuration
theme_configuration = self.theme_optimizer.optimize_theme_system(
requirements.brand_guidelines,
requirements.accessibility_requirements,
shadcn_docs
)
return ShadcnUIArchitecture(
component_library=component_selection,
theme_system=theme_configuration,
accessibility_compliance=self._ensure_accessibility_compliance(
requirements.accessibility_requirements
),
performance_optimization=self._optimize_component_performance(
component_selection
),
integration_patterns=self._design_integration_patterns(
requirements.framework_stack
),
customization_strategy=self._plan_customization_strategy(
requirements.customization_needs
)
)undefinedclass ShadcnUIArchitectOptimizer:
def init(self):
self.context7_client = Context7Client()
self.component_analyzer = ComponentAnalyzer()
self.theme_optimizer = ThemeOptimizer()
async def design_optimal_shadcn_architecture(self,
requirements: DesignSystemRequirements) -> ShadcnUIArchitecture:
"""Design optimal shadcn/ui architecture using AI analysis."""
# Get latest shadcn/ui and React documentation via Context7
shadcn_docs = await self.context7_client.get_library_docs(
context7_library_id='/shadcn-ui/docs',
topic="component library design system theming accessibility 2025",
tokens=3000
)
react_docs = await self.context7_client.get_library_docs(
context7_library_id='/react/docs',
topic="hooks server-components performance optimization 2025",
tokens=2000
)
# Optimize component selection
component_selection = self.component_analyzer.optimize_component_selection(
requirements.ui_components,
requirements.user_needs,
shadcn_docs
)
# Optimize theme configuration
theme_configuration = self.theme_optimizer.optimize_theme_system(
requirements.brand_guidelines,
requirements.accessibility_requirements,
shadcn_docs
)
return ShadcnUIArchitecture(
component_library=component_selection,
theme_system=theme_configuration,
accessibility_compliance=self._ensure_accessibility_compliance(
requirements.accessibility_requirements
),
performance_optimization=self._optimize_component_performance(
component_selection
),
integration_patterns=self._design_integration_patterns(
requirements.framework_stack
),
customization_strategy=self._plan_customization_strategy(
requirements.customization_needs
)
)undefinedComponent System Implementation
组件系统实现
typescript
// Advanced shadcn/ui component with TypeScript and modern patterns
import * as React from "react";
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";
// Component variants using class-variance-authority
const buttonVariants = cva(
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
ghost: "hover:bg-accent hover:text-accent-foreground",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
default: "h-9 px-4 py-2",
sm: "h-8 rounded-md px-3 text-xs",
lg: "h-10 rounded-md px-8",
icon: "h-9 w-9",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
);
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean;
loading?: boolean;
loadingText?: string;
}
// Enhanced button component with loading state and accessibility
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, loading, loadingText, children, disabled, ...props }, ref) => {
const Comp = asChild ? Slot : "button";
return (
<Comp
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
disabled={disabled || loading}
aria-disabled={disabled || loading}
aria-describedby={loading ? "loading-description" : undefined}
{...props}
>
{loading && (
<div className="mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent" />
)}
{loading && loadingText ? (
<span id="loading-description" className="sr-only">
{loadingText}
</span>
) : null}
{loading ? loadingText || children : children}
</Comp>
);
}
);
Button.displayName = "Button";
export { Button, buttonVariants };
// Advanced form component with validation
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
const formSchema = z.object({
username: z.string().min(2, {
message: "Username must be at least 2 characters.",
}),
email: z.string().email({
message: "Please enter a valid email address.",
}),
password: z.string().min(8, {
message: "Password must be at least 8 characters.",
}),
});
type FormValues = z.infer<typeof formSchema>;
export function UserForm() {
const form = useForm<FormValues>({
resolver: zodResolver(formSchema),
defaultValues: {
username: "",
email: "",
password: "",
},
});
const onSubmit = async (data: FormValues) => {
try {
// Handle form submission
console.log("Form data:", data);
} catch (error) {
console.error("Submission error:", error);
}
};
return (
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
<div className="space-y-2">
<Label htmlFor="username">Username</Label>
<Input
id="username"
type="text"
placeholder="Enter your username"
{...form.register("username")}
aria-invalid={form.formState.errors.username ? "true" : "false"}
aria-describedby={form.formState.errors.username ? "username-error" : undefined}
/>
{form.formState.errors.username && (
<p id="username-error" className="text-sm text-destructive">
{form.formState.errors.username.message}
</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="email">Email</Label>
<Input
id="email"
type="email"
placeholder="Enter your email"
{...form.register("email")}
aria-invalid={form.formState.errors.email ? "true" : "false"}
aria-describedby={form.formState.errors.email ? "email-error" : undefined}
/>
{form.formState.errors.email && (
<p id="email-error" className="text-sm text-destructive">
{form.formState.errors.email.message}
</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="password">Password</Label>
<Input
id="password"
type="password"
placeholder="Enter your password"
{...form.register("password")}
aria-invalid={form.formState.errors.password ? "true" : "false"}
aria-describedby={form.formState.errors.password ? "password-error" : undefined}
/>
{form.formState.errors.password && (
<p id="password-error" className="text-sm text-destructive">
{form.formState.errors.password.message}
</p>
)}
</div>
<Button type="submit" className="w-full" disabled={form.formState.isSubmitting}>
{form.formState.isSubmitting ? "Creating account..." : "Create account"}
</Button>
</form>
);
}typescript
// Advanced shadcn/ui component with TypeScript and modern patterns
import * as React from "react";
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";
// Component variants using class-variance-authority
const buttonVariants = cva(
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
ghost: "hover:bg-accent hover:text-accent-foreground",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
default: "h-9 px-4 py-2",
sm: "h-8 rounded-md px-3 text-xs",
lg: "h-10 rounded-md px-8",
icon: "h-9 w-9",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
);
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean;
loading?: boolean;
loadingText?: string;
}
// Enhanced button component with loading state and accessibility
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, loading, loadingText, children, disabled, ...props }, ref) => {
const Comp = asChild ? Slot : "button";
return (
<Comp
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
disabled={disabled || loading}
aria-disabled={disabled || loading}
aria-describedby={loading ? "loading-description" : undefined}
{...props}
>
{loading && (
<div className="mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent" />
)}
{loading && loadingText ? (
<span id="loading-description" className="sr-only">
{loadingText}
</span>
) : null}
{loading ? loadingText || children : children}
</Comp>
);
}
);
Button.displayName = "Button";
export { Button, buttonVariants };
// Advanced form component with validation
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
export function UserForm() {
const form = useForm<FormValues>({
resolver: zodResolver(formSchema),
defaultValues: {
username: "",
email: "",
password: "",
},
});
const onSubmit = async (data: FormValues) => {
try {
// Handle form submission
console.log("Form data:", data);
} catch (error) {
console.error("Submission error:", error);
}
};
return (
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
<div className="space-y-2">
<Label htmlFor="username">Username</Label>
<Input
id="username"
type="text"
placeholder="Enter your username"
{...form.register("username")}
aria-invalid={form.formState.errors.username ? "true" : "false"}
aria-describedby={form.formState.errors.username ? "username-error" : undefined}
/>
{form.formState.errors.username && (
<p id="username-error" className="text-sm text-destructive">
{form.formState.errors.username.message}
</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="email">Email</Label>
<Input
id="email"
type="email"
placeholder="Enter your email"
{...form.register("email")}
aria-invalid={form.formState.errors.email ? "true" : "false"}
aria-describedby={form.formState.errors.email ? "email-error" : undefined}
/>
{form.formState.errors.email && (
<p id="email-error" className="text-sm text-destructive">
{form.formState.errors.email.message}
</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="password">Password</Label>
<Input
id="password"
type="password"
placeholder="Enter your password"
{...form.register("password")}
aria-invalid={form.formState.errors.password ? "true" : "false"}
aria-describedby={form.formState.errors.password ? "password-error" : undefined}
/>
{form.formState.errors.password && (
<p id="password-error" className="text-sm text-destructive">
{form.formState.errors.password.message}
</p>
)}
</div>
<Button type="submit" className="w-full" disabled={form.formState.isSubmitting}>
{form.formState.isSubmitting ? "Creating account..." : "Create account"}
</Button>
</form>
);
}Theme System Implementation
主题系统实现
typescript
// Advanced theme system with CSS variables and dark mode
import { createContext, useContext, useEffect, useState } from "react";
type Theme = "dark" | "light" | "system";
interface ThemeProviderProps {
children: React.ReactNode;
defaultTheme?: Theme;
storageKey?: string;
attribute?: string;
enableSystem?: boolean;
}
interface ThemeProviderState {
theme: Theme;
setTheme: (theme: Theme) => void;
}
const ThemeProviderContext = createContext<ThemeProviderState | undefined>(undefined);
export function ThemeProvider({
children,
defaultTheme = "system",
storageKey = "ui-theme",
attribute = "class",
enableSystem = true,
...props
}: ThemeProviderProps) {
const [theme, setTheme] = useState<Theme>(() => {
if (typeof window !== "undefined") {
return (localStorage.getItem(storageKey) as Theme) || defaultTheme;
}
return defaultTheme;
});
useEffect(() => {
const root = window.document.documentElement;
root.classList.remove("light", "dark");
if (theme === "system" && enableSystem) {
const systemTheme = window.matchMedia("(prefers-color-scheme: dark)")
.matches
? "dark"
: "light";
root.classList.add(systemTheme);
return;
}
root.classList.add(theme);
}, [theme, enableSystem, attribute]);
const value = {
theme,
setTheme: (theme: Theme) => {
localStorage.setItem(storageKey, theme);
setTheme(theme);
},
};
return (
<ThemeProviderContext.Provider {...props} value={value}>
{children}
</ThemeProviderContext.Provider>
);
}
export const useTheme = () => {
const context = useContext(ThemeProviderContext);
if (context === undefined)
throw new Error("useTheme must be used within a ThemeProvider");
return context;
};
// Theme configuration with design tokens
export const theme = {
light: {
background: "hsl(0 0% 100%)",
foreground: "hsl(240 10% 3.9%)",
card: "hsl(0 0% 100%)",
cardForeground: "hsl(240 10% 3.9%)",
popover: "hsl(0 0% 100%)",
popoverForeground: "hsl(240 10% 3.9%)",
primary: "hsl(240 9% 10%)",
primaryForeground: "hsl(0 0% 98%)",
secondary: "hsl(240 4.8% 95.9%)",
secondaryForeground: "hsl(240 3.8% 46.1%)",
muted: "hsl(240 4.8% 95.9%)",
mutedForeground: "hsl(240 3.8% 46.1%)",
accent: "hsl(240 4.8% 95.9%)",
accentForeground: "hsl(240 5.9% 10%)",
destructive: "hsl(0 72.22% 50.59%)",
destructiveForeground: "hsl(0 0% 98%)",
border: "hsl(240 5.9% 90%)",
input: "hsl(240 5.9% 90%)",
ring: "hsl(240 5.9% 10%)",
},
dark: {
background: "hsl(240 10% 3.9%)",
foreground: "hsl(0 0% 98%)",
card: "hsl(240 10% 3.9%)",
cardForeground: "hsl(0 0% 98%)",
popover: "hsl(240 10% 3.9%)",
popoverForeground: "hsl(0 0% 98%)",
primary: "hsl(0 0% 98%)",
primaryForeground: "hsl(240 9% 10%)",
secondary: "hsl(240 3.7% 15.9%)",
secondaryForeground: "hsl(0 0% 98%)",
muted: "hsl(240 3.7% 15.9%)",
mutedForeground: "hsl(240 5% 64.9%)",
accent: "hsl(240 3.7% 15.9%)",
accentForeground: "hsl(0 0% 98%)",
destructive: "hsl(0 62.8% 30.6%)",
destructiveForeground: "hsl(0 0% 98%)",
border: "hsl(240 3.7% 15.9%)",
input: "hsl(240 3.7% 15.9%)",
ring: "hsl(240 4.9% 83.9%)",
},
};
// Apply theme CSS variables
export function applyThemeCSS() {
const root = document.documentElement;
Object.entries(theme.light).forEach(([key, value]) => {
root.style.setProperty(`--${key}`, value);
});
}typescript
// Advanced theme system with CSS variables and dark mode
import { createContext, useContext, useEffect, useState } from "react";
type Theme = "dark" | "light" | "system";
interface ThemeProviderProps {
children: React.ReactNode;
defaultTheme?: Theme;
storageKey?: string;
attribute?: string;
enableSystem?: boolean;
}
interface ThemeProviderState {
theme: Theme;
setTheme: (theme: Theme) => void;
}
const ThemeProviderContext = createContext<ThemeProviderState | undefined>(undefined);
export function ThemeProvider({
children,
defaultTheme = "system",
storageKey = "ui-theme",
attribute = "class",
enableSystem = true,
...props
}: ThemeProviderProps) {
const [theme, setTheme] = useState<Theme>(() => {
if (typeof window !== "undefined") {
return (localStorage.getItem(storageKey) as Theme) || defaultTheme;
}
return defaultTheme;
});
useEffect(() => {
const root = window.document.documentElement;
root.classList.remove("light", "dark");
if (theme === "system" && enableSystem) {
const systemTheme = window.matchMedia("(prefers-color-scheme: dark)")
.matches
? "dark"
: "light";
root.classList.add(systemTheme);
return;
}
root.classList.add(theme);
}, [theme, enableSystem, attribute]);
const value = {
theme,
setTheme: (theme: Theme) => {
localStorage.setItem(storageKey, theme);
setTheme(theme);
},
};
return (
<ThemeProviderContext.Provider {...props} value={value}>
{children}
</ThemeProviderContext.Provider>
);
}
export const useTheme = () => {
const context = useContext(ThemeProviderContext);
if (context === undefined)
throw new Error("useTheme must be used within a ThemeProvider");
return context;
};
// Theme configuration with design tokens
export const theme = {
light: {
background: "hsl(0 0% 100%)",
foreground: "hsl(240 10% 3.9%)",
card: "hsl(0 0% 100%)",
cardForeground: "hsl(240 10% 3.9%)",
popover: "hsl(0 0% 100%)",
popoverForeground: "hsl(240 10% 3.9%)",
primary: "hsl(240 9% 10%)",
primaryForeground: "hsl(0 0% 98%)",
secondary: "hsl(240 4.8% 95.9%)",
secondaryForeground: "hsl(240 3.8% 46.1%)",
muted: "hsl(240 4.8% 95.9%)",
mutedForeground: "hsl(240 3.8% 46.1%)",
accent: "hsl(240 4.8% 95.9%)",
accentForeground: "hsl(240 5.9% 10%)",
destructive: "hsl(0 72.22% 50.59%)",
destructiveForeground: "hsl(0 0% 98%)",
border: "hsl(240 5.9% 90%)",
input: "hsl(240 5.9% 90%)",
ring: "hsl(240 5.9% 10%)",
},
dark: {
background: "hsl(240 10% 3.9%)",
foreground: "hsl(0 0% 98%)",
card: "hsl(240 10% 3.9%)",
cardForeground: "hsl(0 0% 98%)",
popover: "hsl(240 10% 3.9%)",
popoverForeground: "hsl(0 0% 98%)",
primary: "hsl(0 0% 98%)",
primaryForeground: "hsl(240 9% 10%)",
secondary: "hsl(240 3.7% 15.9%)",
secondaryForeground: "hsl(0 0% 98%)",
muted: "hsl(240 3.7% 15.9%)",
mutedForeground: "hsl(240 5% 64.9%)",
accent: "hsl(240 3.7% 15.9%)",
accentForeground: "hsl(0 0% 98%)",
destructive: "hsl(0 62.8% 30.6%)",
destructiveForeground: "hsl(0 0% 98%)",
border: "hsl(240 3.7% 15.9%)",
input: "hsl(240 3.7% 15.9%)",
ring: "hsl(240 4.9% 83.9%)",
},
};
// Apply theme CSS variables
export function applyThemeCSS() {
const root = document.documentElement;
Object.entries(theme.light).forEach(([key, value]) => {
root.style.setProperty(`--${key}`, value);
});
}Advanced Implementation (Level 3)
高级实现方案(Level 3)
Advanced Component Patterns
高级组件模式
typescript
// Complex data table with shadcn/ui components
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import {
ColumnDef,
flexRender,
getCoreRowModel,
getPaginationRowModel,
useReactTable,
} from "@tanstack/react-table";
interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[];
data: TData[];
searchKey?: string;
filterableColumns?: string[];
}
export function DataTable<TData, TValue>({
columns,
data,
searchKey,
filterableColumns = [],
}: DataTableProps<TData, TValue>) {
const [globalFilter, setGlobalFilter] = useState("");
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
onGlobalFilterChange: setGlobalFilter,
onColumnFiltersChange: setColumnFilters,
state: {
globalFilter,
columnFilters,
},
});
return (
<div className="space-y-4">
{/* Search and Filters */}
<div className="flex items-center gap-4">
<Input
placeholder={`Filter ${searchKey}...`}
value={(globalFilter ?? "") as string}
onChange={(event) => setGlobalFilter(String(event.target.value))}
className="max-w-sm"
/>
{/* Column Filters */}
{filterableColumns.map((column) => (
<DataTableColumnFilter
key={column}
column={table.getColumn(column)}
title={column}
/>
))}
</div>
{/* Data Table */}
<div className="rounded-md border">
<Table>
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id}>
{headerGroup.headers.map((header) => (
<TableHead key={header.id}>
{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext()
)}
</TableHead>
))}
</TableRow>
))}
</TableHeader>
<TableBody>
{table.getRowModel().rows?.length ? (
table.getRowModel().rows.map((row) => (
<TableRow
key={row.id}
data-state={row.getIsSelected() && "selected"}
>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id}>
{flexRender(
cell.column.columnDef.cell,
cell.getContext()
)}
</TableCell>
))}
</TableRow>
))
) : (
<TableRow>
<TableCell
colSpan={columns.length}
className="h-24 text-center"
>
No results.
</TableCell>
</TableRow>
)}
</TableBody>
</Table>
</div>
{/* Pagination */}
<div className="flex items-center justify-end space-x-2 py-4">
<Button
variant="outline"
size="sm"
onClick={() => table.previousPage()}
disabled={!table.getCanPreviousPage()}
>
Previous
</Button>
<Button
variant="outline"
size="sm"
onClick={() => table.nextPage()}
disabled={!table.getCanNextPage()}
>
Next
</Button>
</div>
</div>
);
}
// Advanced form with multi-step validation
import { useState } from "react";
import { useForm, FormProvider } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
import { Button } from "@/components/ui/button";
import { Progress } from "@/components/ui/progress";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
const multiStepSchema = z.object({
// Step 1: Personal Information
personalInfo: z.object({
firstName: z.string().min(2),
lastName: z.string().min(2),
email: z.string().email(),
phone: z.string().optional(),
}),
// Step 2: Address
address: z.object({
street: z.string().min(5),
city: z.string().min(2),
state: z.string().min(2),
zipCode: z.string().regex(/^\d{5}(-\d{4})?$/),
country: z.string().min(2),
}),
// Step 3: Preferences
preferences: z.object({
newsletter: z.boolean(),
notifications: z.boolean(),
theme: z.enum(["light", "dark", "system"]),
}),
});
type MultiStepFormValues = z.infer<typeof multiStepSchema>;
export function MultiStepForm() {
const [currentStep, setCurrentStep] = useState(0);
const [isSubmitting, setIsSubmitting] = useState(false);
const methods = useForm<MultiStepFormValues>({
resolver: zodResolver(multiStepSchema),
defaultValues: {
personalInfo: {
firstName: "",
lastName: "",
email: "",
phone: "",
},
address: {
street: "",
city: "",
state: "",
zipCode: "",
country: "",
},
preferences: {
newsletter: false,
notifications: true,
theme: "system",
},
},
});
const steps = [
{ title: "Personal Info", component: PersonalInfoStep },
{ title: "Address", component: AddressStep },
{ title: "Preferences", component: PreferencesStep },
];
const handleNext = async () => {
const currentStepName = ["personalInfo", "address", "preferences"][currentStep];
const isValid = await methods.trigger(currentStepName as any);
if (isValid && currentStep < steps.length - 1) {
setCurrentStep(currentStep + 1);
}
};
const handlePrevious = () => {
if (currentStep > 0) {
setCurrentStep(currentStep - 1);
}
};
const onSubmit = async (data: MultiStepFormValues) => {
setIsSubmitting(true);
try {
// Handle form submission
console.log("Form submitted:", data);
await new Promise(resolve => setTimeout(resolve, 2000)); // Simulate API call
} catch (error) {
console.error("Submission error:", error);
} finally {
setIsSubmitting(false);
}
};
const progress = ((currentStep + 1) / steps.length) * 100;
const CurrentStepComponent = steps[currentStep].component;
return (
<div className="w-full max-w-2xl mx-auto p-6">
<div className="mb-8">
<h1 className="text-2xl font-bold mb-4">Multi-Step Form</h1>
<Progress value={progress} className="mb-2" />
<p className="text-sm text-muted-foreground">
Step {currentStep + 1} of {steps.length}: {steps[currentStep].title}
</p>
</div>
<FormProvider {...methods}>
<form onSubmit={methods.handleSubmit(onSubmit)}>
<div className="mb-8">
<CurrentStepComponent />
</div>
<div className="flex justify-between">
<Button
type="button"
variant="outline"
onClick={handlePrevious}
disabled={currentStep === 0}
>
Previous
</Button>
{currentStep === steps.length - 1 ? (
<Button type="submit" disabled={isSubmitting}>
{isSubmitting ? "Submitting..." : "Submit"}
</Button>
) : (
<Button type="button" onClick={handleNext}>
Next
</Button>
)}
</div>
</form>
</FormProvider>
</div>
);
}typescript
// Complex data table with shadcn/ui components
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import {
ColumnDef,
flexRender,
getCoreRowModel,
getPaginationRowModel,
useReactTable,
} from "@tanstack/react-table";
interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[];
data: TData[];
searchKey?: string;
filterableColumns?: string[];
}
export function DataTable<TData, TValue>({
columns,
data,
searchKey,
filterableColumns = [],
}: DataTableProps<TData, TValue>) {
const [globalFilter, setGlobalFilter] = useState("");
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
onGlobalFilterChange: setGlobalFilter,
onColumnFiltersChange: setColumnFilters,
state: {
globalFilter,
columnFilters,
},
});
return (
<div className="space-y-4">
{/* Search and Filters */}
<div className="flex items-center gap-4">
<Input
placeholder={`Filter ${searchKey}...`}
value={(globalFilter ?? "") as string}
onChange={(event) => setGlobalFilter(String(event.target.value))}
className="max-w-sm"
/>
{/* Column Filters */}
{filterableColumns.map((column) => (
<DataTableColumnFilter
key={column}
column={table.getColumn(column)}
title={column}
/>
))}
</div>
{/* Data Table */}
<div className="rounded-md border">
<Table>
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id}>
{headerGroup.headers.map((header) => (
<TableHead key={header.id}>
{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext()
)}
</TableHead>
))}
</TableRow>
))}
</TableHeader>
<TableBody>
{table.getRowModel().rows?.length ? (
table.getRowModel().rows.map((row) => (
<TableRow
key={row.id}
data-state={row.getIsSelected() && "selected"}
>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id}>
{flexRender(
cell.column.columnDef.cell,
cell.getContext()
)}
</TableCell>
))}
</TableRow>
))
) : (
<TableRow>
<TableCell
colSpan={columns.length}
className="h-24 text-center"
>
No results.
</TableCell>
</TableRow>
)}
</TableBody>
</Table>
</div>
{/* Pagination */}
<div className="flex items-center justify-end space-x-2 py-4">
<Button
variant="outline"
size="sm"
onClick={() => table.previousPage()}
disabled={!table.getCanPreviousPage()}
>
Previous
</Button>
<Button
variant="outline"
size="sm"
onClick={() => table.nextPage()}
disabled={!table.getCanNextPage()}
>
Next
</Button>
</div>
</div>
);
}
// Advanced form with multi-step validation
import { useState } from "react";
import { useForm, FormProvider } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
import { Button } from "@/components/ui/button";
import { Progress } from "@/components/ui/progress";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
const multiStepSchema = z.object({
// Step 1: Personal Information
personalInfo: z.object({
firstName: z.string().min(2),
lastName: z.string().min(2),
email: z.string().email(),
phone: z.string().optional(),
}),
// Step 2: Address
address: z.object({
street: z.string().min(5),
city: z.string().min(2),
state: z.string().min(2),
zipCode: z.string().regex(/^\d{5}(-\d{4})?$/),
country: z.string().min(2),
}),
// Step 3: Preferences
preferences: z.object({
newsletter: z.boolean(),
notifications: z.boolean(),
theme: z.enum(["light", "dark", "system"]),
}),
});
type MultiStepFormValues = z.infer<typeof multiStepSchema>;
export function MultiStepForm() {
const [currentStep, setCurrentStep] = useState(0);
const [isSubmitting, setIsSubmitting] = useState(false);
const methods = useForm<MultiStepFormValues>({
resolver: zodResolver(multiStepSchema),
defaultValues: {
personalInfo: {
firstName: "",
lastName: "",
email: "",
phone: "",
},
address: {
street: "",
city: "",
state: "",
zipCode: "",
country: "",
},
preferences: {
newsletter: false,
notifications: true,
theme: "system",
},
},
});
const steps = [
{ title: "Personal Info", component: PersonalInfoStep },
{ title: "Address", component: AddressStep },
{ title: "Preferences", component: PreferencesStep },
];
const handleNext = async () => {
const currentStepName = ["personalInfo", "address", "preferences"][currentStep];
const isValid = await methods.trigger(currentStepName as any);
if (isValid && currentStep < steps.length - 1) {
setCurrentStep(currentStep + 1);
}
};
const handlePrevious = () => {
if (currentStep > 0) {
setCurrentStep(currentStep - 1);
}
};
const onSubmit = async (data: MultiStepFormValues) => {
setIsSubmitting(true);
try {
// Handle form submission
console.log("Form submitted:", data);
await new Promise(resolve => setTimeout(resolve, 2000)); // Simulate API call
} catch (error) {
console.error("Submission error:", error);
} finally {
setIsSubmitting(false);
}
};
const progress = ((currentStep + 1) / steps.length) * 100;
const CurrentStepComponent = steps[currentStep].component;
return (
<div className="w-full max-w-2xl mx-auto p-6">
<div className="mb-8">
<h1 className="text-2xl font-bold mb-4">Multi-Step Form</h1>
<Progress value={progress} className="mb-2" />
<p className="text-sm text-muted-foreground">
Step {currentStep + 1} of {steps.length}: {steps[currentStep].title}
</p>
</div>
<FormProvider {...methods}>
<form onSubmit={methods.handleSubmit(onSubmit)}>
<div className="mb-8">
<CurrentStepComponent />
</div>
<div className="flex justify-between">
<Button
type="button"
variant="outline"
onClick={handlePrevious}
disabled={currentStep === 0}
>
Previous
</Button>
{currentStep === steps.length - 1 ? (
<Button type="submit" disabled={isSubmitting}>
{isSubmitting ? "Submitting..." : "Submit"}
</Button>
) : (
<Button type="button" onClick={handleNext}>
Next
</Button>
)}
</div>
</form>
</FormProvider>
</div>
);
}Performance Optimization
性能优化
typescript
// Performance optimization for shadcn/ui components
export class ComponentPerformanceOptimizer {
// Lazy loading components with React.lazy
static createLazyComponent(importFn: () => Promise<{ default: React.ComponentType<any> }>) {
return React.lazy(importFn);
}
// Component memoization with React.memo
static createMemoizedComponent<P extends object>(
Component: React.ComponentType<P>,
areEqual?: (prevProps: P, nextProps: P) => boolean
) {
return React.memo(Component, areEqual);
}
// Hook for performance monitoring
static usePerformanceMonitor(componentName: string) {
const [renderCount, setRenderCount] = useState(0);
const [renderTime, setRenderTime] = useState(0);
useEffect(() => {
const startTime = performance.now();
setRenderCount(prev => prev + 1);
return () => {
const endTime = performance.now();
setRenderTime(endTime - startTime);
if (process.env.NODE_ENV === 'development') {
console.log(
`${componentName} render #${renderCount}: ${renderTime.toFixed(2)}ms`
);
}
};
});
return { renderCount, renderTime };
}
// Bundle size optimization
static optimizeBundleSize() {
return {
treeShaking: {
enabled: true,
description: "Remove unused components and utilities",
},
codeSplitting: {
enabled: true,
description: "Split components into separate chunks",
},
compression: {
enabled: true,
description: "Compress bundle with gzip/brotli",
},
};
}
// Runtime performance optimization
static optimizeRuntimePerformance() {
return {
virtualScrolling: {
enabled: true,
description: "Virtual scrolling for large data sets",
},
memoization: {
enabled: true,
description: "Memoize expensive computations",
},
debouncing: {
enabled: true,
description: "Debounce user interactions",
},
};
}
}typescript
// Performance optimization for shadcn/ui components
export class ComponentPerformanceOptimizer {
// Lazy loading components with React.lazy
static createLazyComponent(importFn: () => Promise<{ default: React.ComponentType<any> }>) {
return React.lazy(importFn);
}
// Component memoization with React.memo
static createMemoizedComponent<P extends object>(
Component: React.ComponentType<P>,
areEqual?: (prevProps: P, nextProps: P) => boolean
) {
return React.memo(Component, areEqual);
}
// Hook for performance monitoring
static usePerformanceMonitor(componentName: string) {
const [renderCount, setRenderCount] = useState(0);
const [renderTime, setRenderTime] = useState(0);
useEffect(() => {
const startTime = performance.now();
setRenderCount(prev => prev + 1);
return () => {
const endTime = performance.now();
setRenderTime(endTime - startTime);
if (process.env.NODE_ENV === 'development') {
console.log(
`${componentName} render #${renderCount}: ${renderTime.toFixed(2)}ms`
);
}
};
});
return { renderCount, renderTime };
}
// Bundle size optimization
static optimizeBundleSize() {
return {
treeShaking: {
enabled: true,
description: "Remove unused components and utilities",
},
codeSplitting: {
enabled: true,
description: "Split components into separate chunks",
},
compression: {
enabled: true,
description: "Compress bundle with gzip/brotli",
},
};
}
// Runtime performance optimization
static optimizeRuntimePerformance() {
return {
virtualScrolling: {
enabled: true,
description: "Virtual scrolling for large data sets",
},
memoization: {
enabled: true,
description: "Memoize expensive computations",
},
debouncing: {
enabled: true,
description: "Debounce user interactions",
},
};
}
}Reference & Integration (Level 4)
参考与集成(Level 4)
API Reference
API参考
Core shadcn/ui Operations
核心shadcn/ui操作
- - Create new component
create_component(variant_config, props) - - Customize theme
customize_theme(theme_config, colors) - - Install new component
install_component(component_name) - - Set up design system
setup_design_system(tokens, branding) - - Optimize component performance
optimize_components(performance_config)
- - 创建新组件
create_component(variant_config, props) - - 定制主题
customize_theme(theme_config, colors) - - 安装新组件
install_component(component_name) - - 搭建设计系统
setup_design_system(tokens, branding) - - 优化组件性能
optimize_components(performance_config)
Context7 Integration
Context7集成
- - shadcn/ui docs via Context7
get_latest_shadcn_docs() - - Component patterns via Context7
analyze_component_patterns() - - Theme optimization via Context7
optimize_theme_system()
- - 通过Context7获取shadcn/ui文档
get_latest_shadcn_docs() - - 通过Context7分析组件模式
analyze_component_patterns() - - 通过Context7优化主题系统
optimize_theme_system()
Best Practices (November 2025)
最佳实践(2025年11月)
DO
建议
- Use TypeScript for type safety and better developer experience
- Implement proper accessibility with ARIA attributes
- Customize themes using CSS variables for consistency
- Optimize component performance with memoization and lazy loading
- Use form validation with proper error handling
- Implement responsive design with Tailwind CSS
- Use Radix UI primitives for accessible components
- Test components across different browsers and devices
- 使用TypeScript确保类型安全与更好的开发者体验
- 借助ARIA属性实现完善的无障碍访问
- 使用CSS变量定制主题以保证一致性
- 通过 memoization 与懒加载优化组件性能
- 实现带完善错误处理的表单验证
- 基于Tailwind CSS实现响应式设计
- 使用Radix UI原语构建无障碍组件
- 在不同浏览器与设备上测试组件
DON'T
避免
- Skip TypeScript type definitions and validations
- Ignore accessibility requirements and WCAG compliance
- Override component styles without understanding the CSS structure
- Forget to implement proper error handling and validation
- Skip performance optimization for large datasets
- Use inline styles instead of Tailwind CSS classes
- Forget to implement proper keyboard navigation
- Skip component testing and user experience validation
- 跳过TypeScript类型定义与验证
- 忽略无障碍访问要求与WCAG合规性
- 在不了解CSS结构的情况下覆盖组件样式
- 忽略错误处理与验证实现
- 不为大型数据集做性能优化
- 使用内联样式而非Tailwind CSS类
- 忽略键盘导航实现
- 跳过组件测试与用户体验验证
Works Well With
兼容技能
- (Frontend development patterns)
moai-domain-frontend - (Enterprise UI architecture)
moai-baas-foundation - (UI security implementation)
moai-security-api - (Performance optimization)
moai-essentials-perf - (Accessibility and compliance)
moai-foundation-trust - (Backend integration)
moai-domain-backend - (Frontend deployment)
moai-baas-vercel-ext - (Component testing strategies)
moai-domain-testing
- (前端开发模式)
moai-domain-frontend - (企业级UI架构)
moai-baas-foundation - (UI安全实现)
moai-security-api - (性能优化)
moai-essentials-perf - (无障碍访问与合规性)
moai-foundation-trust - (后端集成)
moai-domain-backend - (前端部署)
moai-baas-vercel-ext - (组件测试策略)
moai-domain-testing
Changelog
更新日志
- v4.0.0 (2025-11-13): Complete Enterprise v4.0 rewrite with 40% content reduction, 4-layer Progressive Disclosure structure, Context7 integration, November 2025 shadcn/ui ecosystem updates, and advanced component patterns
- v2.0.0 (2025-11-11): Complete metadata structure, component patterns, theme system
- v1.0.0 (2025-11-11): Initial shadcn/ui component library
End of Skill | Updated 2025-11-13
- v4.0.0(2025-11-13):企业级v4.0完整重写,内容精简40%,采用4层渐进式披露结构,集成Context7,更新2025年11月shadcn/ui生态系统,新增高级组件模式
- v2.0.0(2025-11-11):完善元数据结构、组件模式与主题系统
- v1.0.0(2025-11-11):初始shadcn/ui组件库版本
技能结束 | 更新于2025-11-13
Design System Integration
设计系统集成
Enterprise Features
企业级特性
- Comprehensive component library with enterprise-grade features
- Advanced theming system with brand customization
- Performance optimization for large-scale applications
- Accessibility compliance with WCAG 2.1 AA standards
- 具备企业级功能的全面组件库
- 支持品牌定制的高级主题系统
- 面向大规模应用的性能优化
- 符合WCAG 2.1 AA标准的无障碍访问合规性
Modern Development
现代开发
- TypeScript-first development with full type safety
- Modern React patterns with hooks and server components
- Tailwind CSS integration for consistent styling
- Framer Motion for smooth animations and transitions
End of Enterprise shadcn/ui Component Library Expert v4.0.0
- 优先使用TypeScript,具备完整类型安全
- 采用包含Hooks与服务端组件的现代React模式
- Tailwind CSS集成确保样式一致性
- Framer Motion实现流畅动画与过渡
企业级shadcn/ui组件库专家 v4.0.0 结束