dashboard-patterns by yonatangross/orchestkit
npx skills add https://github.com/yonatangross/orchestkit --skill dashboard-patterns使用 React 构建管理面板、分析仪表板和数据驱动界面的仪表板 UI 模式。
function DashboardLayout({ children }: { children: React.ReactNode }) {
return (
<div className="min-h-screen bg-muted/40">
<aside className="fixed inset-y-0 left-0 z-10 w-64 border-r bg-background">
<Sidebar />
</aside>
<main className="pl-64">
<header className="sticky top-0 z-10 border-b bg-background px-6 py-4">
<DashboardHeader />
</header>
<div className="p-6">
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-4">{children}</div>
</div>
</main>
</div>
);
}
function DashboardGrid() {
return (
<div className="grid gap-4 grid-cols-1 sm:grid-cols-2 lg:grid-cols-4">
<StatCard title="Revenue" value="$45,231" change="+12%" />
<StatCard title="Users" value="2,350" change="+5.2%" />
<StatCard title="Orders" value="1,245" change="+18%" />
<StatCard title="Conversion" value="3.2%" change="-0.4%" />
<div className="col-span-1 sm:col-span-2"><RevenueChart /></div>
<div className="col-span-1 sm:col-span-2"><TrafficChart /></div>
<div className="col-span-full"><RecentOrdersTable /></div>
</div>
);
}
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
import { TrendingUp, TrendingDown } from 'lucide-react';
interface StatCardProps {
title: string;
value: string | number;
change?: string;
changeType?: 'positive' | 'negative' | 'neutral';
icon?: React.ReactNode;
}
function StatCard({ title, value, change, changeType = 'neutral', icon }: StatCardProps) {
return (
<div className="rounded-xl border bg-card p-6">
<div className="flex items-center justify-between">
<p className="text-sm font-medium text-muted-foreground">{title}</p>
{icon && <div className="text-muted-foreground">{icon}</div>}
</div>
<div className="mt-2 flex items-baseline gap-2">
<p className="text-3xl font-bold">{value}</p>
{change && (
<span className={cn(
'flex items-center text-sm font-medium',
changeType === 'positive' && 'text-green-600',
changeType === 'negative' && 'text-red-600',
)}>
{changeType === 'positive' && <TrendingUp className="h-4 w-4" />}
{changeType === 'negative' && <TrendingDown className="h-4 w-4" />}
{change}
</span>
)}
</div>
</div>
);
}
type WidgetType = 'stat' | 'chart' | 'table' | 'list';
interface WidgetConfig {
id: string;
type: WidgetType;
title: string;
span?: number;
props: Record<string, unknown>;
}
const widgetRegistry: Record<WidgetType, React.ComponentType<any>> = {
stat: StatCard,
chart: ChartCard,
table: DataTable,
list: ListWidget,
};
function DashboardWidget({ config }: { config: WidgetConfig }) {
const Component = widgetRegistry[config.type];
if (!Component) return null;
return (
<div style={{ gridColumn: config.span ? `span ${config.span}` : undefined }}>
<Component title={config.title} {...config.props} />
</div>
);
}
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { useEffect } from 'react';
function useRealtimeMetrics() {
const queryClient = useQueryClient();
const { data, isLoading } = useQuery({
queryKey: ['metrics'],
queryFn: fetchMetrics,
});
useEffect(() => {
const eventSource = new EventSource('/api/metrics/stream');
eventSource.onmessage = (event) => {
const update = JSON.parse(event.data);
queryClient.setQueryData(['metrics'], (old: Metrics | undefined) => ({
...old,
...update,
}));
};
eventSource.onerror = () => {
eventSource.close();
queryClient.invalidateQueries({ queryKey: ['metrics'] });
};
return () => eventSource.close();
}, [queryClient]);
return { data, isLoading };
}
import {
useReactTable,
getCoreRowModel,
getSortedRowModel,
getFilteredRowModel,
getPaginationRowModel,
flexRender,
type ColumnDef,
type SortingState,
} from '@tanstack/react-table';
const columns: ColumnDef<Order>[] = [
{ accessorKey: 'id', header: 'Order ID' },
{ accessorKey: 'customer', header: 'Customer' },
{ accessorKey: 'amount', header: 'Amount', cell: ({ getValue }) => `$${getValue<number>().toLocaleString()}` },
{ accessorKey: 'status', header: 'Status', cell: ({ getValue }) => <StatusBadge status={getValue()} /> },
];
function OrdersTable({ data }: { data: Order[] }) {
const [sorting, setSorting] = useState<SortingState>([]);
const [globalFilter, setGlobalFilter] = useState('');
const table = useReactTable({
data,
columns,
state: { sorting, globalFilter },
onSortingChange: setSorting,
onGlobalFilterChange: setGlobalFilter,
getCoreRowModel: getCoreRowModel(),
getSortedRowModel: getSortedRowModel(),
getFilteredRowModel: getFilteredRowModel(),
getPaginationRowModel: getPaginationRowModel(),
});
return (
<div>
<input
value={globalFilter}
onChange={(e) => setGlobalFilter(e.target.value)}
placeholder="Search orders..."
className="mb-4 rounded border px-3 py-2"
/>
<table className="w-full">
<thead>
{table.getHeaderGroups().map((headerGroup) => (
<tr key={headerGroup.id}>
{headerGroup.headers.map((header) => (
<th key={header.id} onClick={header.column.getToggleSortingHandler()} className="cursor-pointer px-4 py-2 text-left">
{flexRender(header.column.columnDef.header, header.getContext())}
{header.column.getIsSorted() === 'asc' && ' ↑'}
{header.column.getIsSorted() === 'desc' && ' ↓'}
</th>
))}
</tr>
))}
</thead>
<tbody>
{table.getRowModel().rows.map((row) => (
<tr key={row.id} className="border-t">
{row.getVisibleCells().map((cell) => (
<td key={cell.id} className="px-4 py-2">
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</td>
))}
</tr>
))}
</tbody>
</table>
<div className="mt-4 flex items-center gap-2">
<button onClick={() => table.previousPage()} disabled={!table.getCanPreviousPage()}>Previous</button>
<span>Page {table.getState().pagination.pageIndex + 1} of {table.getPageCount()}</span>
<button onClick={() => table.nextPage()} disabled={!table.getCanNextPage()}>Next</button>
</div>
</div>
);
}
function DashboardSkeleton() {
return (
<div className="grid gap-4 grid-cols-1 md:grid-cols-2 lg:grid-cols-4">
{[...Array(4)].map((_, i) => (
<div key={i} className="rounded-xl border bg-card p-6">
<div className="h-4 w-24 animate-pulse rounded bg-muted" />
<div className="mt-2 h-8 w-32 animate-pulse rounded bg-muted" />
</div>
))}
<div className="col-span-full rounded-xl border bg-card p-6">
<div className="mt-4 space-y-2">
{[...Array(5)].map((_, i) => (
<div key={i} className="h-12 animate-pulse rounded bg-muted" />
))}
</div>
</div>
</div>
);
}
// 绝对禁止:在每个部件中独立获取数据(重复查询)
// 绝对禁止:单个指标变化时重新渲染整个仪表板
// 绝对禁止:硬编码仪表板布局(非响应式)
// 绝对禁止:无间隔轮询(无限循环)
// 绝对禁止:缺少加载状态(空状态闪烁)
// 绝对禁止:无防抖的实时更新(每秒100次重新渲染)
| 决策 | 推荐方案 |
|---|---|
| 布局 | CSS Grid 用于二维仪表板布局 |
| 实时性 | SSE 用于服务器到客户端,WebSocket 用于双向通信 |
| 数据表格 | TanStack Table 用于功能丰富的表格 |
| 状态管理 | TanStack Query 配合细粒度键 |
| 加载状态 | 骨架屏 用于内容区域 |
recharts-patterns - 仪表板图表组件tanstack-query-advanced - 数据获取模式streaming-api-patterns - SSE 和 WebSocket 实现每周安装量
120
代码仓库
GitHub 星标数
132
首次出现
2026年1月22日
安全审计
已安装于
opencode99
claude-code98
codex88
gemini-cli87
cursor86
antigravity76
Dashboard UI patterns for building admin panels, analytics dashboards, and data-driven interfaces with React.
function DashboardLayout({ children }: { children: React.ReactNode }) {
return (
<div className="min-h-screen bg-muted/40">
<aside className="fixed inset-y-0 left-0 z-10 w-64 border-r bg-background">
<Sidebar />
</aside>
<main className="pl-64">
<header className="sticky top-0 z-10 border-b bg-background px-6 py-4">
<DashboardHeader />
</header>
<div className="p-6">
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-4">{children}</div>
</div>
</main>
</div>
);
}
function DashboardGrid() {
return (
<div className="grid gap-4 grid-cols-1 sm:grid-cols-2 lg:grid-cols-4">
<StatCard title="Revenue" value="$45,231" change="+12%" />
<StatCard title="Users" value="2,350" change="+5.2%" />
<StatCard title="Orders" value="1,245" change="+18%" />
<StatCard title="Conversion" value="3.2%" change="-0.4%" />
<div className="col-span-1 sm:col-span-2"><RevenueChart /></div>
<div className="col-span-1 sm:col-span-2"><TrafficChart /></div>
<div className="col-span-full"><RecentOrdersTable /></div>
</div>
);
}
import { TrendingUp, TrendingDown } from 'lucide-react';
interface StatCardProps {
title: string;
value: string | number;
change?: string;
changeType?: 'positive' | 'negative' | 'neutral';
icon?: React.ReactNode;
}
function StatCard({ title, value, change, changeType = 'neutral', icon }: StatCardProps) {
return (
<div className="rounded-xl border bg-card p-6">
<div className="flex items-center justify-between">
<p className="text-sm font-medium text-muted-foreground">{title}</p>
{icon && <div className="text-muted-foreground">{icon}</div>}
</div>
<div className="mt-2 flex items-baseline gap-2">
<p className="text-3xl font-bold">{value}</p>
{change && (
<span className={cn(
'flex items-center text-sm font-medium',
changeType === 'positive' && 'text-green-600',
changeType === 'negative' && 'text-red-600',
)}>
{changeType === 'positive' && <TrendingUp className="h-4 w-4" />}
{changeType === 'negative' && <TrendingDown className="h-4 w-4" />}
{change}
</span>
)}
</div>
</div>
);
}
type WidgetType = 'stat' | 'chart' | 'table' | 'list';
interface WidgetConfig {
id: string;
type: WidgetType;
title: string;
span?: number;
props: Record<string, unknown>;
}
const widgetRegistry: Record<WidgetType, React.ComponentType<any>> = {
stat: StatCard,
chart: ChartCard,
table: DataTable,
list: ListWidget,
};
function DashboardWidget({ config }: { config: WidgetConfig }) {
const Component = widgetRegistry[config.type];
if (!Component) return null;
return (
<div style={{ gridColumn: config.span ? `span ${config.span}` : undefined }}>
<Component title={config.title} {...config.props} />
</div>
);
}
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { useEffect } from 'react';
function useRealtimeMetrics() {
const queryClient = useQueryClient();
const { data, isLoading } = useQuery({
queryKey: ['metrics'],
queryFn: fetchMetrics,
});
useEffect(() => {
const eventSource = new EventSource('/api/metrics/stream');
eventSource.onmessage = (event) => {
const update = JSON.parse(event.data);
queryClient.setQueryData(['metrics'], (old: Metrics | undefined) => ({
...old,
...update,
}));
};
eventSource.onerror = () => {
eventSource.close();
queryClient.invalidateQueries({ queryKey: ['metrics'] });
};
return () => eventSource.close();
}, [queryClient]);
return { data, isLoading };
}
import {
useReactTable,
getCoreRowModel,
getSortedRowModel,
getFilteredRowModel,
getPaginationRowModel,
flexRender,
type ColumnDef,
type SortingState,
} from '@tanstack/react-table';
const columns: ColumnDef<Order>[] = [
{ accessorKey: 'id', header: 'Order ID' },
{ accessorKey: 'customer', header: 'Customer' },
{ accessorKey: 'amount', header: 'Amount', cell: ({ getValue }) => `$${getValue<number>().toLocaleString()}` },
{ accessorKey: 'status', header: 'Status', cell: ({ getValue }) => <StatusBadge status={getValue()} /> },
];
function OrdersTable({ data }: { data: Order[] }) {
const [sorting, setSorting] = useState<SortingState>([]);
const [globalFilter, setGlobalFilter] = useState('');
const table = useReactTable({
data,
columns,
state: { sorting, globalFilter },
onSortingChange: setSorting,
onGlobalFilterChange: setGlobalFilter,
getCoreRowModel: getCoreRowModel(),
getSortedRowModel: getSortedRowModel(),
getFilteredRowModel: getFilteredRowModel(),
getPaginationRowModel: getPaginationRowModel(),
});
return (
<div>
<input
value={globalFilter}
onChange={(e) => setGlobalFilter(e.target.value)}
placeholder="Search orders..."
className="mb-4 rounded border px-3 py-2"
/>
<table className="w-full">
<thead>
{table.getHeaderGroups().map((headerGroup) => (
<tr key={headerGroup.id}>
{headerGroup.headers.map((header) => (
<th key={header.id} onClick={header.column.getToggleSortingHandler()} className="cursor-pointer px-4 py-2 text-left">
{flexRender(header.column.columnDef.header, header.getContext())}
{header.column.getIsSorted() === 'asc' && ' ↑'}
{header.column.getIsSorted() === 'desc' && ' ↓'}
</th>
))}
</tr>
))}
</thead>
<tbody>
{table.getRowModel().rows.map((row) => (
<tr key={row.id} className="border-t">
{row.getVisibleCells().map((cell) => (
<td key={cell.id} className="px-4 py-2">
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</td>
))}
</tr>
))}
</tbody>
</table>
<div className="mt-4 flex items-center gap-2">
<button onClick={() => table.previousPage()} disabled={!table.getCanPreviousPage()}>Previous</button>
<span>Page {table.getState().pagination.pageIndex + 1} of {table.getPageCount()}</span>
<button onClick={() => table.nextPage()} disabled={!table.getCanNextPage()}>Next</button>
</div>
</div>
);
}
function DashboardSkeleton() {
return (
<div className="grid gap-4 grid-cols-1 md:grid-cols-2 lg:grid-cols-4">
{[...Array(4)].map((_, i) => (
<div key={i} className="rounded-xl border bg-card p-6">
<div className="h-4 w-24 animate-pulse rounded bg-muted" />
<div className="mt-2 h-8 w-32 animate-pulse rounded bg-muted" />
</div>
))}
<div className="col-span-full rounded-xl border bg-card p-6">
<div className="mt-4 space-y-2">
{[...Array(5)].map((_, i) => (
<div key={i} className="h-12 animate-pulse rounded bg-muted" />
))}
</div>
</div>
</div>
);
}
// NEVER: Fetch data in every widget independently (duplicated queries)
// NEVER: Re-render entire dashboard on single metric change
// NEVER: Hardcoded dashboard layout (not responsive)
// NEVER: Polling without intervals (infinite loop)
// NEVER: Missing loading states (flash of empty state)
// NEVER: Real-time updates without debounce (100 re-renders/sec)
| Decision | Recommendation |
|---|---|
| Layout | CSS Grid for 2D dashboard layouts |
| Real-time | SSE for server->client, WebSocket for bidirectional |
| Data table | TanStack Table for features |
| State | TanStack Query with granular keys |
| Loading | Skeleton for content areas |
recharts-patterns - Chart components for dashboardstanstack-query-advanced - Data fetching patternsstreaming-api-patterns - SSE and WebSocket implementationWeekly Installs
120
Repository
GitHub Stars
132
First Seen
Jan 22, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode99
claude-code98
codex88
gemini-cli87
cursor86
antigravity76
TanStack Query v5 完全指南:React 数据管理、乐观更新、离线支持
2,500 周安装
GTM市场进入策略指南:产品发布、新市场、重新定位与功能发布的完整蓝图
338 周安装
Cloudflare D1数据库迁移指南 - Drizzle ORM工作流与问题解决方案
335 周安装
Claude API 结构化输出与错误预防指南 - 保证JSON模式一致性,提升AI应用开发效率
325 周安装
Go 代码风格核心原则与最佳实践 | Google/Uber 权威指南
331 周安装
Cloudflare Vectorize 完整指南:全球分布式向量数据库,实现语义搜索与RAG应用
326 周安装
Cloudflare Agents SDK:构建AI驱动的自主智能体,支持可恢复流式传输与持久化状态
326 周安装