The user wants me to create a "Live Product Style Guide" tool. This is a sophisticated web application that needs to:
Let me build this as a single HTML file with all the necessary CSS and JS.
A sophisticated style guide management tool with diff tracking, drift detection, and approval workflows.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Style Guide — Live Product Documentation</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0a0a0f;
--bg-elevated: #12121a;
--bg-card: #1a1a24;
--fg: #e8e8ed;
--fg-muted: #6b6b7a;
--accent: #00d4aa;
--accent-dim: rgba(0, 212, 170, 0.15);
--warning: #ff9f43;
--warning-dim: rgba(255, 159, 67, 0.15);
--danger: #ff5757;
--danger-dim: rgba(255, 87, 87, 0.15);
--success: #00d4aa;
--border: #2a2a36;
--code-bg: #0f0f14;
}
* {
box-sizing: border-box;
}
body {
font-family: 'Space Grotesk', sans-serif;
background: var(--bg);
color: var(--fg);
min-height: 100vh;
}
.font-mono {
font-family: 'JetBrains Mono', monospace;
}
/* Custom scrollbar */
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
::-webkit-scrollbar-track {
background: var(--bg);
}
::-webkit-scrollbar-thumb {
background: var(--border);
border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
background: var(--fg-muted);
}
/* Background pattern */
.bg-grid {
background-image:
linear-gradient(rgba(42, 42, 54, 0.3) 1px, transparent 1px),
linear-gradient(90deg, rgba(42, 42, 54, 0.3) 1px, transparent 1px);
background-size: 32px 32px;
}
/* Glow effects */
.glow-accent {
box-shadow: 0 0 40px rgba(0, 212, 170, 0.2);
}
.glow-warning {
box-shadow: 0 0 20px rgba(255, 159, 67, 0.15);
}
/* Animations */
@keyframes fadeSlideUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateX(-10px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
.animate-fade-up {
animation: fadeSlideUp 0.5s ease-out forwards;
}
.animate-pulse-slow {
animation: pulse 2s ease-in-out infinite;
}
.animate-slide-in {
animation: slideIn 0.3s ease-out forwards;
}
.stagger-1 { animation-delay: 0.05s; }
.stagger-2 { animation-delay: 0.1s; }
.stagger-3 { animation-delay: 0.15s; }
.stagger-4 { animation-delay: 0.2s; }
.stagger-5 { animation-delay: 0.25s; }
@media (prefers-reduced-motion: reduce) {
.animate-fade-up,
.animate-pulse-slow,
.animate-slide-in {
animation: none;
opacity: 1;
transform: none;
}
}
/* Diff highlighting */
.diff-add {
background: rgba(0, 212, 170, 0.15);
border-left: 3px solid var(--accent);
}
.diff-remove {
background: rgba(255, 87, 87, 0.15);
border-left: 3px solid var(--danger);
}
/* Component snapshot frame */
.snapshot-frame {
background: linear-gradient(135deg, #1f1f2e 0%, #16161f 100%);
border: 1px solid var(--border);
border-radius: 12px;
padding: 24px;
position: relative;
overflow: hidden;
}
.snapshot-frame::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 1px;
background: linear-gradient(90deg, transparent, var(--accent), transparent);
opacity: 0.5;
}
/* Status badges */
.status-approved {
background: var(--accent-dim);
color: var(--accent);
border: 1px solid rgba(0, 212, 170, 0.3);
}
.status-pending {
background: var(--warning-dim);
color: var(--warning);
border: 1px solid rgba(255, 159, 67, 0.3);
}
.status-drift {
background: var(--danger-dim);
color: var(--danger);
border: 1px solid rgba(255, 87, 87, 0.3);
}
/* Interactive states */
.btn-primary {
background: var(--accent);
color: var(--bg);
transition: all 0.2s ease;
}
.btn-primary:hover {
transform: translateY(-1px);
box-shadow: 0 4px 20px rgba(0, 212, 170, 0.3);
}
.btn-primary:active {
transform: translateY(0);
}
.btn-secondary {
background: transparent;
border: 1px solid var(--border);
color: var(--fg);
transition: all 0.2s ease;
}
.btn-secondary:hover {
border-color: var(--accent);
color: var(--accent);
}
/* Nav item active */
.nav-item {
transition: all 0.2s ease;
position: relative;
}
.nav-item::before {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 3px;
height: 0;
background: var(--accent);
transition: height 0.2s ease;
border-radius: 2px;
}
.nav-item:hover,
.nav-item.active {
background: var(--accent-dim);
color: var(--accent);
}
.nav-item.active::before {
height: 60%;
}
/* Modal */
.modal-backdrop {
background: rgba(10, 10, 15, 0.9);
backdrop-filter: blur(4px);
}
/* Code block */
.code-block {
background: var(--code-bg);
border: 1px solid var(--border);
border-radius: 8px;
font-family: 'JetBrains Mono', monospace;
font-size: 13px;
line-height: 1.6;
}
/* Drift indicator */
.drift-line {
position: relative;
}
.drift-line::after {
content: '';
position: absolute;
right: -8px;
top: 50%;
transform: translateY(-50%);
width: 4px;
height: 4px;
background: var(--warning);
border-radius: 50%;
}
/* Focus states */
*:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
/* Hidden utility */
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}
</style>
</head>
<body class="bg-grid">
<!-- Header -->
<header class="fixed top-0 left-0 right-0 z-50 border-b border-[var(--border)] bg-[var(--bg-elevated)]" style="backdrop-filter: blur(12px);">
<div class="flex items-center justify-between px-6 h-16">
<div class="flex items-center gap-8">
<div class="flex items-center gap-3">
<div class="w-8 h-8 rounded-lg bg-[var(--accent)] flex items-center justify-center">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="var(--bg)" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 2L2 7l10 5 10-5-10-5z"/>
<path d="M2 17l10 5 10-5"/>
<path d="M2 12l10 5 10-5"/>
</svg>
</div>
<span class="font-semibold text-lg tracking-tight">StyleGuide</span>
</div>
<nav class="hidden md:flex items-center gap-1">
<button class="px-4 py-2 rounded-lg text-sm font-medium text-[var(--accent)] bg-[var(--accent-dim)]">Components</button>
<button class="px-4 py-2 rounded-lg text-sm font-medium text-[var(--fg-muted)] hover:text-[var(--fg)] transition-colors">Tokens</button>
<button class="px-4 py-2 rounded-lg text-sm font-medium text-[var(--fg-muted)] hover:text-[var(--fg)] transition-colors">Patterns</button>
</nav>
</div>
<div class="flex items-center gap-4">
<!-- Search -->
<div class="relative hidden md:block">
<input
type="text"
id="searchInput"
placeholder="Search components..."
class="w-64 h-10 pl-10 pr-4 rounded-lg bg-[var(--bg)] border border-[var(--border)] text-sm placeholder:text-[var(--fg-muted)] focus:border-[var(--accent)] transition-colors"
>
<svg class="absolute left-3 top-1/2 -translate-y-1/2 text-[var(--fg-muted)]" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="11" cy="11" r="8"/>
<path d="M21 21l-4.35-4.35"/>
</svg>
</div>
<!-- Drift Alert -->
<button
id="driftAlertBtn"
class="relative p-2 rounded-lg hover:bg-[var(--bg)] transition-colors"
aria-label="View drift alerts"
>
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/>
<line x1="12" y1="9" x2="12" y2="13"/>
<line x1="12" y1="17" x2="12.01" y2="17"/>
</svg>
<span id="driftBadge" class="absolute -top-1 -right-1 w-5 h-5 bg-[var(--danger)] rounded-full text-xs font-medium flex items-center justify-center">3</span>
</button>
<!-- Version -->
<div class="hidden md:flex items-center gap-2 px-3 py-1.5 rounded-lg bg-[var(--bg)] border border-[var(--border)]">
<span class="text-xs text-[var(--fg-muted)]">Release</span>
<span class="text-xs font-mono font-medium text-[var(--accent)]">v2.4.1</span>
</div>
</div>
</div>
</header>
<div class="flex pt-16">
<!-- Sidebar -->
<aside class="fixed left-0 top-16 bottom-0 w-64 border-r border-[var(--border)] bg-[var(--bg-elevated)] overflow-y-auto hidden md:block">
<div class="p-4">
<div class="mb-6">
<h3 class="text-xs font-semibold text-[var(--fg-muted)] uppercase tracking-wider mb-3 px-3">Categories</h3>
<div class="space-y-1" id="categoryNav">
<!-- Populated by JS -->
</div>
</div>
<div class="border-t border-[var(--border)] pt-6">
<h3 class="text-xs font-semibold text-[var(--fg-muted)] uppercase tracking-wider mb-3 px-3">Status Filter</h3>
<div class="space-y-1">
<button class="status-filter w-full flex items-center justify-between px-3 py-2 rounded-lg text-sm hover:bg-[var(--bg)] transition-colors" data-status="all">
<span>All Components</span>
<span class="text-[var(--fg-muted)]" id="countAll">12</span>
</button>
<button class="status-filter w-full flex items-center justify-between px-3 py-2 rounded-lg text-sm hover:bg-[var(--bg)] transition-colors" data-status="approved">
<span class="flex items-center gap-2">
<span class="w-2 h-2 rounded-full bg-[var(--accent)]"></span>
Approved
</span>
<span class="text-[var(--fg-muted)]" id="countApproved">8</span>
</button>
<button class="status-filter w-full flex items-center justify-between px-3 py-2 rounded-lg text-sm hover:bg-[var(--bg)] transition-colors" data-status="pending">
<span class="flex items-center gap-2">
<span class="w-2 h-2 rounded-full bg-[var(--warning)]"></span>
Pending Review
</span>
<span class="text-[var(--fg-muted)]" id="countPending">1</span>
</button>
<button class="status-filter w-full flex items-center justify-between px-3 py-2 rounded-lg text-sm hover:bg-[var(--bg)] transition-colors" data-status="drift">
<span class="flex items-center gap-2">
<span class="w-2 h-2 rounded-full bg-[var(--danger)]"></span>
Drift Detected
</span>
<span class="text-[var(--fg-muted)]" id="countDrift">3</span>
</button>
</div>
</div>
<div class="border-t border-[var(--border)] pt-6 mt-6">
<h3 class="text-xs font-semibold text-[var(--fg-muted)] uppercase tracking-wider mb-3 px-3">Recent Activity</h3>
<div class="space-y-3" id="activityFeed">
<!-- Populated by JS -->
</div>
</div>
</div>
</aside>
<!-- Main Content -->
<main class="flex-1 md:ml-64 min-h-screen">
<div class="max-w-6xl mx-auto p-6 md:p-8">
<!-- Page Header -->
<div class="mb-8 animate-fade-up opacity-0">
<div class="flex flex-col md:flex-row md:items-center justify-between gap-4 mb-4">
<div>
<h1 class="text-3xl md:text-4xl font-bold tracking-tight mb-2" id="componentTitle">Button</h1>
<p class="text-[var(--fg-muted)]" id="componentDescription">Interactive element for user actions</p>
</div>
<div class="flex items-center gap-3">
<span class="status-approved px-3 py-1.5 rounded-full text-sm font-medium" id="componentStatus">Approved</span>
<span class="text-sm text-[var(--fg-muted)] font-mono" id="componentVersion">v2.1.0</span>
</div>
</div>
<!-- Tabs -->
<div class="flex items-center gap-1 p-1 bg-[var(--bg-card)] rounded-lg w-fit" role="tablist">
<button role="tab" aria-selected="true" class="tab-btn px-4 py-2 rounded-md text-sm font-medium bg-[var(--bg)] text-[var(--fg)] shadow-sm" data-tab="snapshot">Snapshot</button>
<button role="tab" aria-selected="false" class="tab-btn px-4 py-2 rounded-md text-sm font-medium text-[var(--fg-muted)] hover:text-[var(--fg)]" data-tab="diff">Diff View</button>
<button role="tab" aria-selected="false" class="tab-btn px-4 py-2 rounded-md text-sm font-medium text-[var(--fg-muted)] hover:text-[var(--fg)]" data-tab="signoff">Sign-off</button>
<button role="tab" aria-selected="false" class="tab-btn px-4 py-2 rounded-md text-sm font-medium text-[var(--fg-muted)] hover:text-[var(--fg)]" data-tab="code">Code</button>
</div>
</div>
<!-- Tab Panels -->
<div id="tabContent">
<!-- Snapshot Panel -->
<div id="snapshotPanel" class="tab-panel animate-fade-up opacity-0 stagger-1">
<div class="snapshot-frame mb-6">
<div class="flex items-center gap-2 mb-6">
<div class="w-3 h-3 rounded-full bg-[#ff5f57]"></div>
<div class="w-3 h-3 rounded-full bg-[#febc2e]"></div>
<div class="w-3 h-3 rounded-full bg-[#28c840]"></div>
<span class="ml-4 text-xs text-[var(--fg-muted)] font-mono">Component Preview</span>
</div>
<div class="flex flex-wrap items-center gap-4" id="componentPreview">
<!-- Populated by JS -->
</div>
</div>
<!-- Variants -->
<div class="mb-8">
<h3 class="text-lg font-semibold mb-4">Variants</h3>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4" id="variantsGrid">
<!-- Populated by JS -->
</div>
</div>
<!-- Properties -->
<div>
<h3 class="text-lg font-semibold mb-4">Properties</h3>
<div class="code-block p-4 overflow-x-auto">
<pre class="text-[var(--fg-muted)]" id="propertiesCode"></pre>
</div>
</div>
</div>
<!-- Diff Panel -->
<div id="diffPanel" class="tab-panel hidden">
<div class="mb-6">
<div class="flex items-center justify-between mb-4">
<h3 class="text-lg font-semibold">Release Diff</h3>
<div class="flex items-center gap-2">
<select id="diffVersionSelect" class="h-9 px-3 rounded-lg bg-[var(--bg)] border border-[var(--border)] text-sm">
<option value="2.4.0-2.4.1">v2.4.0 → v2.4.1</option>
<option value="2.3.0-2.4.0">v2.3.0 → v2.4.0</option>
<option value="2.2.0-2.3.0">v2.2.0 → v2.3.0</option>
</select>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
<div class="p-3 rounded-lg bg-[var(--bg-card)] border border-[var(--border)]">
<div class="flex items-center justify-between mb-2">
<span class="text-sm font-medium text-[var(--fg-muted)]">Changes</span>
<span class="text-sm font-mono text-[var(--accent)]" id="diffChanges">+24 -8</span>
</div>
<div class="h-2 rounded-full bg-[var(--bg)] overflow-hidden flex">
<div class="h-full bg-[var(--accent)]" style="width: 60%"></div>
<div class="h-full bg-[var(--danger)]" style="width: 20%"></div>
</div>
</div>
<div class="p-3 rounded-lg bg-[var(--bg-card)] border border-[var(--border)]">
<div class="flex items-center justify-between mb-2">
<span class="text-sm font-medium text-[var(--fg-muted)]">Drift Score</span>
<span class="text-sm font-mono text-[var(--warning)]" id="driftScore">12%</span>
</div>
<div class="h-2 rounded-full bg-[var(--bg)] overflow-hidden">
<div class="h-full bg-[var(--warning)]" style="width: 12%"></div>
</div>
</div>
</div>
</div>
<div class="code-block overflow-hidden" id="diffContent">
<!-- Populated by JS -->
</div>
</div>
<!-- Sign-off Panel -->
<div id="signoffPanel" class="tab-panel hidden">
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<div>
<h3 class="text-lg font-semibold mb-4">Approval Status</h3>
<div class="space-y-3" id="approvalList">
<!-- Populated by JS -->
</div>
<div class="mt-6 p-4 rounded-lg bg-[var(--bg-card)] border border-[var(--border)]">
<h4 class="font-medium mb-3">Add Approval</h4>
<div class="space-y-3">
<input
type="text"
id="approverName"
placeholder="Your name"
class="w-full h-10 px-3 rounded-lg bg-[var(--bg)] border border-[var(--border)] text-sm"
>
<select id="approverRole" class="w-full h-10 px-3 rounded-lg bg-[var(--bg)] border border-[var(--border)] text-sm">
<option value="designer">Design Lead</option>
<option value="developer">Tech Lead</option>
<option value="pm">Product Manager</option>
<option value="qa">QA Engineer</option>
</select>
<button id="addApprovalBtn" class="btn-primary w-full h-10 rounded-lg font-medium text-sm">
Submit Approval
</button>
</div>
</div>
</div>
<div>
<h3 class="text-lg font-semibold mb-4">Sign-off History</h3>
<div class="space-y-3" id="signoffHistory">
<!-- Populated by JS -->
</div>
</div>
</div>
</div>
<!-- Code Panel -->
<div id="codePanel" class="tab-panel hidden">
<div class="flex items-center gap-2 mb-4">
<button class="code-tab px-3 py-1.5 rounded-md text-sm font-medium bg-[var(--accent-dim)] text-[var(--accent)]" data-lang="html">HTML</button>
<button class="code-tab px-3 py-1.5 rounded-md text-sm font-medium text-[var(--fg-muted)] hover:text-[var(--fg)]" data-lang="css">CSS</button>
<button class="code-tab px-3 py-1.5 rounded-md text-sm font-medium text-[var(--fg-muted)] hover:text-[var(--fg)]" data-lang="js">JS</button>
</div>
<div class="code-block p-4 overflow-x-auto">
<pre id="codeDisplay" class="text-sm"></pre>
</div>
<button id="copyCodeBtn" class="mt-4 btn-secondary px-4 py-2 rounded-lg text-sm font-medium flex items-center gap-2">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
</svg>
Copy Code
</button>
</div>
</div>
</div>
</main>
</div>
<!-- Drift Modal -->
<div id="driftModal" class="fixed inset-0 z-50 hidden">
<div class="modal-backdrop absolute inset-0" id="driftModalBackdrop"></div>
<div class="absolute right-0 top-0 bottom-0 w-full max-w-lg bg-[var(--bg-elevated)] border-l border-[var(--border)] overflow-y-auto animate-slide-in">
<div class="p-6">
<div class="flex items-center justify-between mb-6">
<h2 class="text-xl font-semibold">Drift Alerts</h2>
<button id="closeDriftModal" class="p-2 rounded-lg hover:bg-[var(--bg)] transition-colors" aria-label="Close">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="18" y1="6" x2="6" y2="18"/>
<line x1="6" y1="6" x2="18" y2="18"/>
</svg>
</button>
</div>
<div class="space-y-4" id="driftList">
<!-- Populated by JS -->
</div>
</div>
</div>
</div>
<!-- Toast -->
<div id="toast" class="fixed bottom-6 right-6 z-50 hidden">
<div class="px-4 py-3 rounded-lg bg-[var(--accent)] text-[var(--bg)] font-medium text-sm shadow-lg animate-slide-in">
<span id="toastMessage">Action completed</span>
</div>
</div>
<script>
// Data
const components = [
{
id: 'button',
name: 'Button',
category: 'Forms',
description: 'Interactive element for user actions',
status: 'approved',
version: '2.1.0',
variants: ['Primary', 'Secondary', 'Outline', 'Ghost', 'Destructive'],
properties: {
size: ['sm', 'md', 'lg'],
variant: ['primary', 'secondary', 'outline', 'ghost', 'destructive'],
disabled: 'boolean',
loading: 'boolean',
icon: 'boolean | ReactNode'
},
approvals: [
{ name: 'Sarah Chen', role: 'Design Lead', date: '2024-01-15', avatar: 'SC' },
{ name: 'Mike Ross', role: 'Tech Lead', date: '2024-01-15', avatar: 'MR' }
],
history: [
{ action: 'Approved', user: 'Sarah Chen', date: '2024-01-15' },
{ action: 'Changes requested', user: 'Mike Ross', date: '2024-01-14' },
{ action: 'Submitted for review', user: 'Alex Kim', date: '2024-01-12' }
]
},
{
id: 'input',
name: 'Input',
category: 'Forms',
description: 'Text input field for forms',
status: 'approved',
version: '1.8.0',
variants: ['Default', 'With Icon', 'With Label', 'Error State'],
properties: {
type: ['text', 'email', 'password', 'number'],
size: ['sm', 'md', 'lg'],
error: 'boolean | string',
disabled: 'boolean'
},
approvals: [
{ name: 'Sarah Chen', role: 'Design Lead', date: '2024-01-10', avatar: 'SC' }
],
history: [
{ action: 'Approved', user: 'Sarah Chen', date: '2024-01-10' }
]
},
{
id: 'card',
name: 'Card',
category: 'Layout',
description: 'Container for grouped content',
status: 'drift',
version: '3.2.0',
driftReason: 'Border radius mismatch detected',
variants: ['Default', 'Outlined', 'Elevated'],
properties: {
padding: ['sm', 'md', 'lg'],
shadow: 'boolean',
hoverable: 'boolean'
},
approvals: [],
history: [
{ action: 'Drift detected', user: 'System', date: '2024-01-18' }
]
},
{
id: 'modal',
name: 'Modal',
category: 'Overlay',
description: 'Dialog for focused content',
status: 'pending',
version: '2.0.0',
variants: ['Default', 'Full Screen', 'Side Panel'],
properties: {
size: ['sm', 'md', 'lg', 'xl'],
closeOnOverlay: 'boolean',
showClose: 'boolean'
},
approvals: [],
history: [
{ action: 'Submitted for review', user: 'Jane Doe', date: '2024-01-17' }
]
},
{
id: 'avatar',
name: 'Avatar',
category: 'Data Display',
description: 'User profile image or initials',
status: 'approved',
version: '1.5.0',
variants: ['Image', 'Initials', 'Icon'],
properties: {
size: ['xs', 'sm', 'md', 'lg', 'xl'],
shape: ['circle', 'square'],
status: 'boolean'
},
approvals: [
{ name: 'Sarah Chen', role: 'Design Lead', date: '2024-01-08', avatar: 'SC' }
],
history: []
},
{
id: 'badge',
name: 'Badge',
category: 'Data Display',
description: 'Status indicator and label',
status: 'drift',
version: '1.2.0',
driftReason: 'Color token mismatch: primary-500 vs primary-600',
variants: ['Solid', 'Outline', 'Dot'],
properties: {
size: ['sm', 'md', 'lg'],
variant: ['default', 'success', 'warning', 'danger']
},
approvals: [],
history: []
},
{
id: 'tabs',
name: 'Tabs',
category: 'Navigation',
description: 'Tabbed navigation component',
status: 'approved',
version: '2.3.0',
variants: ['Line', 'Contained', 'Pills'],
properties: {
orientation: ['horizontal', 'vertical'],
fullWidth: 'boolean',
icon: 'boolean'
},
approvals: [
{ name: 'Mike Ross', role: 'Tech Lead', date: '2024-01-05', avatar: 'MR' }
],
history: []
},
{
id: 'tooltip',
name: 'Tooltip',
category: 'Overlay',
description: 'Contextual information popup',
status: 'approved',
version: '1.4.0',
variants: ['Top', 'Right', 'Bottom', 'Left'],
properties: {
trigger: ['hover', 'click'],
delay: 'number',
arrow: 'boolean'
},
approvals: [],
history: []
},
{
id: 'toggle',
name: 'Toggle',
category: 'Forms',
description: 'Boolean switch control',
status: 'approved',
version: '1.6.0',
variants: ['Default', 'With Label', 'With Icons'],
properties: {
size: ['sm', 'md', 'lg'],
disabled: 'boolean',
icons: 'boolean'
},
approvals: [],
history: []
},
{
id: 'dropdown',
name: 'Dropdown',
category: 'Navigation',
description: 'Expandable menu selection',
status: 'drift',
version: '2.1.0',
driftReason: 'Animation duration differs from spec (200ms vs 150ms)',
variants: ['Default', 'Multi-select', 'Searchable'],
properties: {
size: ['sm', 'md', 'lg'],
searchable: 'boolean',
multi: 'boolean'
},
approvals: [],
history: []
},
{
id: 'table',
name: 'Table',
category: 'Data Display',
description: 'Structured data display',
status: 'approved',
version: '3.0.0',
variants: ['Default', 'Striped', 'Compact'],
properties: {
sortable: 'boolean',
selectable: 'boolean',
pagination: 'boolean'
},
approvals: [],
history: []
},
{
id: 'skeleton',
name: 'Skeleton',
category: 'Feedback',
description: 'Loading placeholder component',
status: 'approved',
version: '1.0.0',
variants: ['Text', 'Avatar', 'Card'],
properties: {
animate: 'boolean',
count: 'number',
width: 'string | number'
},
approvals: [],
history: []
}
];
const categories = [...new Set(components.map(c => c.category))];
let currentComponent = components[0];
let currentFilter = 'all';
let currentCategory = null;
// DOM Elements
const categoryNav = document.getElementById('categoryNav');
const componentTitle = document.getElementById('componentTitle');
const componentDescription = document.getElementById('componentDescription');
const componentStatus = document.getElementById('componentStatus');
const componentVersion = document.getElementById('componentVersion');
const componentPreview = document.getElementById('componentPreview');
const variantsGrid = document.getElementById('variantsGrid');
const propertiesCode = document.getElementById('propertiesCode');
const approvalList = document.getElementById('approvalList');
const signoffHistory = document.getElementById('signoffHistory');
const activityFeed = document.getElementById('activityFeed');
const driftModal = document.getElementById('driftModal');
const driftList = document.getElementById('driftList');
const toast = document.getElementById('toast');
const searchInput = document.getElementById('searchInput');
// Initialize
function init() {
renderCategoryNav();
renderComponent(currentComponent);
updateCounts();
renderActivityFeed();
renderDriftList();
setupEventListeners();
}
// Render category navigation
function renderCategoryNav() {
const allItem = `
<button class="nav-item w-full text-left px-3 py-2 rounded-lg text-sm active" data-category="all">
All Components
</button>
`;
const categoryItems = categories.map(cat => `
<button class="nav-item w-full text-left px-3 py-2 rounded-lg text-sm" data-category="${cat}">
${cat}
</button>
`).join('');
categoryNav.innerHTML = allItem + categoryItems;
}
// Render component details
function renderComponent(component) {
currentComponent = component;
// Header
componentTitle.textContent = component.name;
componentDescription.textContent = component.description;
componentVersion.textContent = `v${component.version}`;
// Status
const statusConfig = {
approved: { class: 'status-approved', text: 'Approved' },
pending: { class: 'status-pending', text: 'Pending Review' },
drift: { class: 'status-drift', text: 'Drift Detected' }
};
const status = statusConfig[component.status];
componentStatus.className = `${status.class} px-3 py-1.5 rounded-full text-sm font-medium`;
componentStatus.textContent = status.text;
// Preview
renderPreview(component);
// Variants
renderVariants(component);
// Properties
propertiesCode.textContent = JSON.stringify(component.properties, null, 2);
// Approvals
renderApprovals(component);
// History
renderHistory(component);
// Diff
renderDiff(component);
// Code
renderCode(component);
}
// Render preview based on component type
function renderPreview(component) {
let previewHTML = '';
switch(component.id) {
case 'button':
previewHTML = `
<button class="px-4 py-2 bg-[var(--accent)] text-[var(--bg)] rounded-lg font-medium text-sm">Primary Button</button>
<button class="px-4 py-2 bg-transparent border border-[var(--border)] text-[var(--fg)] rounded-lg font-medium text-sm hover:border-[var(--accent)]">Secondary Button</button>
<button class="px-4 py-2 bg-[var(--danger)] text-white rounded-lg font-medium text-sm">Destructive</button>
<button class="px-4 py-2 text-[var(--fg-muted)] rounded-lg font-medium text-sm hover:text-[var(--fg)]">Ghost</button>
`;
break;
case 'input':
previewHTML = `
<input type="text" placeholder="Enter text..." class="h-10 px-3 rounded-lg bg-[var(--bg)] border border-[var(--border)] text-sm w-64 focus:border-[var(--accent)]">
<input type="text" placeholder="With error" class="h-10 px-3 rounded-lg bg-[var(--bg)] border border-[var(--danger)] text-sm w-64">
`;
break;
case 'card':
previewHTML = `
<div class="p-4 rounded-xl bg-[var(--bg-card)] border border-[var(--border)] max-w-xs">
<h4 class="font-medium mb-2">Card Title</h4>
<p class="text-sm text-[var(--fg-muted)]">This is a sample card component with content.</p>
</div>
`;
break;
case 'avatar':
previewHTML = `
<div class="flex items-center gap-4">
<div class="w-10 h-10 rounded-full bg-[var(--accent)] flex items-center justify-center text-[var(--bg)] font-medium">SC</div>
<div class="w-10 h-10 rounded-full bg-[var(--warning)] flex items-center justify-center text-[var(--bg)] font-medium">MR</div>
<div class="w-10 h-10 rounded-full bg-[var(--danger)] flex items-center justify-center text-[var(--bg)] font-medium">AK</div>
</div>
`;
break;
case 'badge':
previewHTML = `
<span class="px-2 py-1 rounded-full text-xs font-medium status-approved">Active</span>
<span class="px-2 py-1 rounded-full text-xs font-medium status-pending">Pending</span>
<span class="px-2 py-1 rounded-full text-xs font-medium status-drift">Error</span>
`;
break;
case 'toggle':
previewHTML = `
<div class="flex items-center gap-3">
<button class="w-11 h-6 rounded-full bg-[var(--accent)] relative">
<span class="absolute right-1 top-1 w-4 h-4 rounded-full bg-white"></span>
</button>
<button class="w-11 h-6 rounded-full bg-[var(--border)] relative">
<span class="absolute left-1 top-1 w-4 h-4 rounded-full bg-[var(--fg-muted)]"></span>
</button>
</div>
`;
break;
default:
previewHTML = `
<div class="p-4 rounded-lg bg-[var(--bg)] border border-[var(--border)] text-[var(--fg-muted)] text-sm">
Preview for ${component.name}
</div>
`;
}
componentPreview.innerHTML = previewHTML;
}
// Render variants
function renderVariants(component) {
variantsGrid.innerHTML = component.variants.map((variant, i) => `
<div class="p-4 rounded-lg bg-[var(--bg-card)] border border-[var(--border)] hover:border-[var(--accent)] transition-colors cursor-pointer opacity-0 animate-fade-up stagger-${i + 1}">
<div class="h-20 flex items-center justify-center mb-3 bg-[var(--bg)] rounded-lg">
<span class="text-sm text-[var(--fg-muted)]">${variant}</span>
</div>
<span class="text-sm font-medium">${variant}</span>
</div>
`).join('');
}
// Render approvals
function renderApprovals(component) {
if (component.approvals.length === 0) {
approvalList.innerHTML = `
<div class="p-4 rounded-lg bg-[var(--bg-card)] border border-[var(--border)] border-dashed text-center">
<p class="text-sm text-[var(--fg-muted)]">No approvals yet</p>
</div>
`;
return;
}
approvalList.innerHTML = component.approvals.map(approval => `
<div class="flex items-center gap-3 p-3 rounded-lg bg-[var(--bg-card)] border border-[var(--border)]">
<div class="w-10 h-10 rounded-full bg-[var(--accent-dim)] flex items-center justify-center text-[var(--accent)] font-medium text-sm">
${approval.avatar}
</div>
<div class="flex-1">
<p class="text-sm font-medium">${approval.name}</p>
<p class="text-xs text-[var(--fg-muted)]">${approval.role}</p>
</div>
<div class="flex items-center gap-1 text-[var(--accent)]">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="20 6 9 17 4 12"/>
</svg>
</div>
</div>
`).join('');
}
// Render history
function renderHistory(component) {
if (component.history.length === 0) {
signoffHistory.innerHTML = `
<div class="p-4 rounded-lg bg-[var(--bg-card)] border border-[var(--border)] text-center">
<p class="text-sm text-[var(--fg-muted)]">No history available</p>
</div>
`;
return;
}
signoffHistory.innerHTML = component.history.map((item, i) => `
<div class="flex gap-3 ${i < component.history.length - 1 ? 'pb-3 border-b border-[var(--border)]' : ''}">
<div class="w-2 h-2 rounded-full bg-[var(--accent)] mt-2 flex-shrink-0"></div>
<div>
<p class="text-sm font-medium">${item.action}</p>
<p class="text-xs text-[var(--fg-muted)]">${item.user} · ${item.date}</p>
</div>
</div>
`).join('');
}
// Render diff
function renderDiff(component) {
const diffContent = document.getElementById('diffContent');
diffContent.innerHTML = `
<div class="p-4 border-b border-[var(--border)]">
<span class="text-xs text-[var(--fg-muted)] font-mono">components/${component.id}/${component.id}.tsx</span>
</div>
<div class="p-4 font-mono text-sm space-y-1">
<div class="diff-remove px-2 py-1 -mx-2">- const borderRadius = tokens.radius.md;</div>
<div class="diff-add px-2 py-1 -mx-2">+ const borderRadius = tokens.radius.lg;</div>
<div class="px-2 py-1 -mx-2 text-[var(--fg-muted)]"> </div>
<div class="diff-remove px-2 py-1 -mx-2">- transition: all 0.2s ease;</div>
<div class="diff-add px-2 py-1 -mx-2">+ transition: all 0.15s ease-out;</div>
<div class="px-2 py-1 -mx-2 text-[var(--fg-muted)]"> </div>
<div class="diff-add px-2 py-1 -mx-2">+ aria-describedby={hintId}</div>
<div class="px-2 py-1 -mx-2 text-[var(--fg-muted)]"> return (</div>
</div>
`;
}
// Render code samples
function renderCode(component) {
const codeDisplay = document.getElementById('codeDisplay');
const codeSamples = {
html: `<button class="btn btn-primary btn-md">
<span class="btn__icon">+</span>
<span class="btn__label">${component.name}</span>
</button>`,
css: `.${component.id} {
display: inline-flex;
align-items: center;
gap: 0.5rem;
padding: 0.625rem 1rem;
border-radius: var(--radius-md);
font-weight: 500;
transition: all 0.15s ease-out;
}
.${component.id}:hover {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}`,
js: `import { ${component.name.charAt(0).toUpperCase() + component.name.slice(1)} } from '@design-system/components';
function Example() {
return (
<${component.name.charAt(0).toUpperCase() + component.name.slice(1)}
variant="primary"
size="md"
onClick={() => console.log('clicked')}
>
Click me
</${component.name.charAt(0).toUpperCase() + component.name.slice(1)}>
);
}`
};
codeDisplay.innerHTML = `<code class="text-[var(--fg)]">${escapeHtml(codeSamples.html)}</code>`;
// Store for code tab switching
codeDisplay.dataset.samples = JSON.stringify(codeSamples);
}
// Escape HTML
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
// Update counts
function updateCounts() {
document.getElementById('countAll').textContent = components.length;
document.getElementById('countApproved').textContent = components.filter(c => c.status === 'approved').length;
document.getElementById('countPending').textContent = components.filter(c => c.status === 'pending').length;
document.getElementById('countDrift').textContent = components.filter(c => c.status === 'drift').length;
}
// Render activity feed
function renderActivityFeed() {
const activities = [
{ action: 'approved', component: 'Button', time: '2h ago' },
{ action: 'flagged drift', component: 'Card', time: '4h ago' },
{ action: 'submitted', component: 'Modal', time: '1d ago' }
];
activityFeed.innerHTML = activities.map(activity => `
<div class="px-3 py-2 rounded-lg hover:bg-[var(--bg)] transition-colors cursor-pointer">
<p class="text-sm truncate">
<span class="text-[var(--fg-muted)]">${activity.action}</span>
<span class="font-medium">${activity.component}</span>
</p>
<p class="text-xs text-[var(--fg-muted)]">${activity.time}</p>
</div>
`).join('');
}
// Render drift list
function renderDriftList() {
const driftComponents = components.filter(c => c.status === 'drift');
driftList.innerHTML = driftComponents.map(comp => `
<div class="p-4 rounded-lg bg-[var(--bg-card)] border border-[var(--border)] glow-warning">
<div class="flex items-start justify-between mb-2">
<h4 class="font-medium">${comp.name}</h4>
<span class="text-xs text-[var(--danger)] font-mono">v${comp.version}</span>
</div>
<p class="text-sm text-[var(--fg-muted)] mb-3">${comp.driftReason || 'Design specification mismatch detected'}</p>
<div class="flex items-center gap-2">
<button class="btn-secondary px-3 py-1.5 rounded-md text-xs font-medium" onclick="resolveDrift('${comp.id}')">
Resolve
</button>
<button class="text-xs text-[var(--fg-muted)] hover:text-[var(--fg)]" onclick="selectComponent('${comp.id}'); closeDriftModal();">
View Component
</button>
</div>
</div>
`).join('');
}
// Setup event listeners
function setupEventListeners() {
// Category navigation
categoryNav.addEventListener('click', (e) => {
const btn = e.target.closest('.nav-item');
if (btn) {
const category = btn.dataset.category;
currentCategory = category === 'all' ? null : category;
document.querySelectorAll('.nav-item').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
filterComponents();
}
});
// Status filter
document.querySelectorAll('.status-filter').forEach(btn => {
btn.addEventListener('click', () => {
currentFilter = btn.dataset.status;
filterComponents();
});
});
// Tabs
document.querySelectorAll('.tab-btn').forEach(btn => {
btn.addEventListener('click', () => {
switchTab(btn.dataset.tab);
});
});
// Code tabs
document.querySelectorAll('.code-tab').forEach(btn => {
btn.addEventListener('click', () => {
const lang = btn.dataset.lang;
const codeDisplay = document.getElementById('codeDisplay');
const samples = JSON.parse(codeDisplay.dataset.samples);
document.querySelectorAll('.code-tab').forEach(b => {
b.classList.remove('bg-[var(--accent-dim)]', 'text-[var(--accent)]');
b.classList.add('text-[var(--fg-muted)]');
});
btn.classList.add('bg-[var(--accent-dim)]', 'text-[var(--accent)]');
btn.classList.remove('text-[var(--fg-muted)]');
codeDisplay.innerHTML = `<code>${escapeHtml(samples[lang])}</code>`;
});
});
// Drift modal
document.getElementById('driftAlertBtn').addEventListener('click', () => {
driftModal.classList.remove('hidden');
});
document.getElementById('closeDriftModal').addEventListener('click', closeDriftModal);
document.getElementById('driftModalBackdrop').addEventListener('click', closeDriftModal);
// Add approval
document.getElementById('addApprovalBtn').addEventListener('click', addApproval);
// Copy code
document.getElementById('copyCodeBtn').addEventListener('click', () => {
const code = document.getElementById('codeDisplay').textContent;
navigator.clipboard.writeText(code);
showToast('Code copied to clipboard');
});
// Search
searchInput.addEventListener('input', (e) => {
const query = e.target.value.toLowerCase();
if (query) {
const results = components.filter(c =>
c.name.toLowerCase().includes(query) ||
c.description.toLowerCase().includes(query)
);
if (results.length > 0) {
renderComponent(results[0]);
}
}
});
// Keyboard navigation
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
closeDriftModal();
}
});
}
// Filter components
function filterComponents() {
let filtered = components;
if (currentCategory) {
filtered = filtered.filter(c => c.category === currentCategory);
}
if (currentFilter !== 'all') {
filtered = filtered.filter(c => c.status === currentFilter);
}
if (filtered.length > 0) {
renderComponent(filtered[0]);
}
}
// Select component
function selectComponent(id) {
const comp = components.find(c => c.id === id);
if (comp) {
renderComponent(comp);
}
}
// Switch tab
function switchTab(tabId) {
document.querySelectorAll('.tab-btn').forEach(btn => {
btn.classList.remove('bg-[var(--bg)]', 'text-[var(--fg)]', 'shadow-sm');
btn.classList.add('text-[var(--fg-muted)]');
btn.setAttribute('aria-selected', 'false');
});
const activeBtn = document.querySelector(`.tab-btn[data-tab="${tabId}"]`);
activeBtn.classList.add('bg-[var(--bg)]', 'text-[var(--fg)]', 'shadow-sm');
activeBtn.classList.remove('text-[var(--fg-muted)]');
activeBtn.setAttribute('aria-selected', 'true');
document.querySelectorAll('.tab-panel').forEach(panel => {
panel.classList.add('hidden');
});
const activePanel = document.getElementById(`${tabId}Panel`);
activePanel.classList.remove('hidden');
activePanel.classList.add('animate-fade-up');
}
// Close drift modal
function closeDriftModal() {
driftModal.classList.add('hidden');
}
// Add approval
function addApproval() {
const name = document.getElementById('approverName').value.trim();
const role = document.getElementById('approverRole').value;
if (!name) {
showToast('Please enter your name');
return;
}
const roleLabels = {
designer: 'Design Lead',
developer: 'Tech Lead',
pm: 'Product Manager',
qa: 'QA Engineer'
};
currentComponent.approvals.push({
name,
role: roleLabels[role],
date: new Date().toISOString().split('T')[0],
avatar: name.split(' ').map(n => n[0]).join('').toUpperCase().slice(0, 2)
});
currentComponent.history.unshift({
action: 'Approved',
user: name,
date: new Date().toISOString().split('T')[0]
});
renderApprovals(currentComponent);
renderHistory(currentComponent);
document.getElementById('approverName').value = '';
showToast('Approval added successfully');
}
// Resolve drift
function resolveDrift(id) {
const comp = components.find(c => c.id === id);
if (comp) {
comp.status = 'approved';
comp.driftReason = null;
// Update drift badge
const driftCount = components.filter(c => c.status === 'drift').length;
document.getElementById('driftBadge').textContent = driftCount;
updateCounts();
renderDriftList();
if (currentComponent.id === id) {
renderComponent(comp);
}
showToast(`Drift resolved for ${comp.name}`);
}
}
// Show toast
function showToast(message) {
const toastEl = document.getElementById('toast');
document.getElementById('toastMessage').textContent = message;
toastEl.classList.remove('hidden');
setTimeout(() => {
toastEl.classList.add('hidden');
}, 3000);
}
// Make functions available globally
window.selectComponent = selectComponent;
window.closeDriftModal = closeDriftModal;
window.resolveDrift = resolveDrift;
// Initialize on load
init();
</script>
</body>
</html>