The user wants a command palette interaction model. This is a complex UI component that requires:
- Keyboard-first flows - Full keyboard navigation without relying on mouse
- Fuzzy search - Smart matching that finds results even with partial/typo'd queries
- Contextual actions - Actions that change based on current context/state
Let me design a sophisticated command palette with:
Visual Design:
- Dark, sleek theme with high contrast
- Glowing accents (not purple - let's use cyan/teal or warm amber)
- Smooth animations and transitions
- Particle/glow effects in background for "alive" feeling
Features:
- Fuzzy search algorithm (implement myself)
- Keyboard shortcuts (Ctrl+K or Cmd+K to open)
- Arrow key navigation
- Enter to select
- Escape to close
- Context categories (Navigation, Actions, Settings, etc.)
- Dynamic actions based on "current context"
- Recent commands history
- Keyboard hints displayed
Technical Implementation:
- Custom fuzzy matching
- CSS animations
- Keyboard event handling
- Context state management
- Command grouping
Let me build this with a modern, professional aesthetic - maybe a dark slate theme with cyan/teal accents and some subtle animated background elements.
I'll create:
- A main command palette overlay
- Fuzzy search with highlighting
- Grouped results
- Keyboard navigation with visual feedback
- Context switching
- Action execution with feedback
- Animated background
- Recent commands section
Command Palette Design
I'll create a sophisticated command palette with:
- Fuzzy search with match highlighting
- Full keyboard navigation (arrows, enter, escape, shortcuts)
- Contextual actions that change based on selected context
- Recent commands tracking
- Animated visual feedback with a sleek dark theme
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Command Palette</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--bg-primary: #0d1117;
--bg-secondary: #161b22;
--bg-tertiary: #21262d;
--border-color: #30363d;
--text-primary: #e6edf3;
--text-secondary: #8b949e;
--text-muted: #6e7681;
--accent: #00d4aa;
--accent-dim: rgba(0, 212, 170, 0.15);
--accent-glow: rgba(0, 212, 170, 0.4);
--warning: #f0883e;
--danger: #f85149;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
background: var(--bg-primary);
color: var(--text-primary);
min-height: 100vh;
overflow: hidden;
}
/* Background animation */
.bg-canvas {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 0;
}
/* Demo interface */
.demo-interface {
position: relative;
z-index: 1;
padding: 40px;
height: 100vh;
display: flex;
flex-direction: column;
}
.demo-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30px;
}
.demo-title {
font-size: 24px;
font-weight: 600;
color: var(--text-primary);
}
.demo-hint {
display: flex;
align-items: center;
gap: 8px;
color: var(--text-secondary);
font-size: 14px;
}
.kbd {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 4px 8px;
background: var(--bg-tertiary);
border: 1px solid var(--border-color);
border-radius: 6px;
font-family: inherit;
font-size: 12px;
font-weight: 500;
color: var(--text-secondary);
min-width: 24px;
}
.demo-content {
flex: 1;
display: grid;
grid-template-columns: 250px 1fr;
gap: 20px;
}
.sidebar {
background: var(--bg-secondary);
border: 1px solid var(--border-color);
border-radius: 12px;
padding: 16px;
}
.sidebar-section {
margin-bottom: 24px;
}
.sidebar-title {
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
color: var(--text-muted);
margin-bottom: 12px;
}
.sidebar-item {
display: flex;
align-items: center;
gap: 10px;
padding: 8px 10px;
border-radius: 8px;
cursor: pointer;
transition: background 0.15s;
color: var(--text-secondary);
font-size: 14px;
}
.sidebar-item:hover {
background: var(--bg-tertiary);
color: var(--text-primary);
}
.sidebar-item.active {
background: var(--accent-dim);
color: var(--accent);
}
.main-content {
background: var(--bg-secondary);
border: 1px solid var(--border-color);
border-radius: 12px;
padding: 24px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.context-display {
text-align: center;
}
.context-label {
font-size: 12px;
color: var(--text-muted);
text-transform: uppercase;
letter-spacing: 1px;
margin-bottom: 8px;
}
.context-value {
font-size: 28px;
font-weight: 600;
color: var(--text-primary);
margin-bottom: 20px;
}
.context-actions {
display: flex;
gap: 12px;
margin-top: 20px;
}
.context-btn {
padding: 10px 20px;
background: var(--bg-tertiary);
border: 1px solid var(--border-color);
border-radius: 8px;
color: var(--text-secondary);
font-size: 14px;
cursor: pointer;
transition: all 0.15s;
}
.context-btn:hover {
background: var(--bg-primary);
border-color: var(--text-muted);
color: var(--text-primary);
}
/* Command Palette Overlay */
.palette-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.7);
backdrop-filter: blur(4px);
z-index: 1000;
display: flex;
align-items: flex-start;
justify-content: center;
padding-top: 15vh;
opacity: 0;
visibility: hidden;
transition: opacity 0.2s, visibility 0.2s;
}
.palette-overlay.active {
opacity: 1;
visibility: visible;
}
.palette-container {
width: 100%;
max-width: 640px;
background: var(--bg-secondary);
border: 1px solid var(--border-color);
border-radius: 16px;
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5),
0 0 0 1px rgba(0, 212, 170, 0.1);
overflow: hidden;
transform: scale(0.95) translateY(-20px);
transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.palette-overlay.active .palette-container {
transform: scale(1) translateY(0);
}
.palette-input-wrapper {
display: flex;
align-items: center;
padding: 16px 20px;
border-bottom: 1px solid var(--border-color);
background: var(--bg-tertiary);
}
.palette-icon {
width: 20px;
height: 20px;
color: var(--text-muted);
margin-right: 12px;
}
.palette-input {
flex: 1;
background: transparent;
border: none;
outline: none;
font-size: 18px;
color: var(--text-primary);
font-family: inherit;
}
.palette-input::placeholder {
color: var(--text-muted);
}
.palette-context-badge {
display: flex;
align-items: center;
gap: 6px;
padding: 4px 10px;
background: var(--accent-dim);
border-radius: 6px;
font-size: 12px;
color: var(--accent);
font-weight: 500;
}
.palette-results {
max-height: 400px;
overflow-y: auto;
padding: 8px;
}
.palette-results::-webkit-scrollbar {
width: 8px;
}
.palette-results::-webkit-scrollbar-track {
background: transparent;
}
.palette-results::-webkit-scrollbar-thumb {
background: var(--border-color);
border-radius: 4px;
}
.palette-group {
margin-bottom: 8px;
}
.palette-group:last-child {
margin-bottom: 0;
}
.palette-group-title {
display: flex;
align-items: center;
padding: 8px 12px 6px;
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
color: var(--text-muted);
}
.palette-item {
display: flex;
align-items: center;
padding: 10px 12px;
border-radius: 10px;
cursor: pointer;
transition: background 0.1s;
position: relative;
}
.palette-item:hover,
.palette-item.selected {
background: var(--bg-tertiary);
}
.palette-item.selected {
background: var(--accent-dim);
}
.palette-item.selected::before {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 3px;
height: 24px;
background: var(--accent);
border-radius: 0 2px 2px 0;
}
.palette-item-icon {
width: 36px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
background: var(--bg-primary);
border-radius: 8px;
margin-right: 12px;
color: var(--text-secondary);
flex-shrink: 0;
}
.palette-item.selected .palette-item-icon {
background: var(--accent);
color: var(--bg-primary);
}
.palette-item-content {
flex: 1;
min-width: 0;
}
.palette-item-title {
font-size: 14px;
font-weight: 500;
color: var(--text-primary);
margin-bottom: 2px;
display: flex;
align-items: center;
gap: 8px;
}
.palette-item-title .match {
color: var(--accent);
font-weight: 600;
}
.palette-item-description {
font-size: 12px;
color: var(--text-secondary);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.palette-item-shortcut {
display: flex;
gap: 4px;
margin-left: 12px;
}
.palette-footer {
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 16px;
border-top: 1px solid var(--border-color);
background: var(--bg-tertiary);
}
.palette-footer-hints {
display: flex;
gap: 16px;
}
.palette-footer-hint {
display: flex;
align-items: center;
gap: 6px;
font-size: 12px;
color: var(--text-muted);
}
.palette-footer-hint .kbd {
padding: 2px 6px;
font-size: 10px;
min-width: 20px;
}
.palette-empty {
padding: 40px 20px;
text-align: center;
color: var(--text-muted);
}
.palette-empty-icon {
font-size: 40px;
margin-bottom: 12px;
opacity: 0.5;
}
/* Toast notification */
.toast {
position: fixed;
bottom: 30px;
left: 50%;
transform: translateX(-50%) translateY(100px);
background: var(--bg-secondary);
border: 1px solid var(--border-color);
border-radius: 10px;
padding: 14px 20px;
display: flex;
align-items: center;
gap: 12px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
z-index: 2000;
opacity: 0;
transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s;
}
.toast.show {
transform: translateX(-50%) translateY(0);
opacity: 1;
}
.toast-icon {
width: 20px;
height: 20px;
color: var(--accent);
}
.toast-message {
font-size: 14px;
color: var(--text-primary);
}
/* Animations */
@keyframes pulse {
0%, 100% { opacity: 0.3; }
50% { opacity: 0.6; }
}
@keyframes float {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-10px); }
}
</style>
</head>
<body>
<canvas class="bg-canvas" id="bgCanvas"></canvas>
<div class="demo-interface">
<header class="demo-header">
<h1 class="demo-title">Project Dashboard</h1>
<div class="demo-hint">
Press <span class="kbd">Ctrl</span> + <span class="kbd">K</span> to open command palette
</div>
</header>
<div class="demo-content">
<aside class="sidebar">
<div class="sidebar-section">
<div class="sidebar-title">Navigation</div>
<div class="sidebar-item active" data-context="dashboard">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="3" y="3" width="7" height="7" rx="1"/>
<rect x="14" y="3" width="7" height="7" rx="1"/>
<rect x="3" y="14" width="7" height="7" rx="1"/>
<rect x="14" y="14" width="7" height="7" rx="1"/>
</svg>
Dashboard
</div>
<div class="sidebar-item" data-context="projects">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/>
</svg>
Projects
</div>
<div class="sidebar-item" data-context="tasks">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M9 11l3 3L22 4"/>
<path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"/>
</svg>
Tasks
</div>
<div class="sidebar-item" data-context="team">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/>
<circle cx="9" cy="7" r="4"/>
<path d="M23 21v-2a4 4 0 0 0-3-3.87"/>
<path d="M16 3.13a4 4 0 0 1 0 7.75"/>
</svg>
Team
</div>
</div>
<div class="sidebar-section">
<div class="sidebar-title">Account</div>
<div class="sidebar-item" data-context="settings">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="3"/>
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/>
</svg>
Settings
</div>
</div>
</aside>
<main class="main-content">
<div class="context-display">
<div class="context-label">Current Context</div>
<div class="context-value" id="currentContext">Dashboard</div>
<p style="color: var(--text-secondary); margin-bottom: 10px;">
Command palette actions adapt to your current context
</p>
<div class="context-actions">
<button class="context-btn" onclick="openPalette()">Open Palette</button>
<button class="context-btn" onclick="switchContext('projects')">Switch Context</button>
</div>
</div>
</main>
</div>
</div>
<!-- Command Palette -->
<div class="palette-overlay" id="paletteOverlay">
<div class="palette-container">
<div class="palette-input-wrapper">
<svg class="palette-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="11" cy="11" r="8"/>
<path d="M21 21l-4.35-4.35"/>
</svg>
<input type="text" class="palette-input" id="paletteInput" placeholder="Type a command or search..." autocomplete="off">
<div class="palette-context-badge" id="paletteContextBadge">
<svg width="12" height="12" viewBox="0 0 24 24" fill="currentColor">
<circle cx="12" cy="12" r="10"/>
</svg>
<span id="paletteContextName">Dashboard</span>
</div>
</div>
<div class="palette-results" id="paletteResults"></div>
<div class="palette-footer">
<div class="palette-footer-hints">
<div class="palette-footer-hint">
<span class="kbd">↑</span><span class="kbd">↓</span> Navigate
</div>
<div class="palette-footer-hint">
<span class="kbd">Enter</span> Select
</div>
<div class="palette-footer-hint">
<span class="kbd">Esc</span> Close
</div>
</div>
<div style="font-size: 12px; color: var(--text-muted);">
<span id="resultCount">0</span> commands
</div>
</div>
</div>
</div>
<!-- Toast -->
<div class="toast" id="toast">
<svg class="toast-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/>
<polyline points="22 4 12 14.01 9 11.01"/>
</svg>
<span class="toast-message" id="toastMessage">Action completed</span>
</div>
<script>
// Command definitions with context awareness
const commands = [
// Global commands
{ id: 'nav-dashboard', title: 'Go to Dashboard', description: 'Navigate to main dashboard', category: 'Navigation', shortcut: ['G', 'D'], icon: 'dashboard', global: true },
{ id: 'nav-projects', title: 'Go to Projects', description: 'View all projects', category: 'Navigation', shortcut: ['G', 'P'], icon: 'folder', global: true },
{ id: 'nav-tasks', title: 'Go to Tasks', description: 'View and manage tasks', category: 'Navigation', shortcut: ['G', 'T'], icon: 'check', global: true },
{ id: 'nav-team', title: 'Go to Team', description: 'View team members', category: 'Navigation', shortcut: ['G', 'M'], icon: 'users', global: true },
{ id: 'nav-settings', title: 'Open Settings', description: 'Application settings', category: 'Navigation', shortcut: ['Ctrl', ','], icon: 'settings', global: true },
// Dashboard context
{ id: 'dash-refresh', title: 'Refresh Dashboard', description: 'Reload dashboard data', category: 'Actions', context: 'dashboard', icon: 'refresh' },
{ id: 'dash-export', title: 'Export Report', description: 'Download dashboard report', category: 'Actions', context: 'dashboard', icon: 'download' },
{ id: 'dash-widgets', title: 'Customize Widgets', description: 'Arrange dashboard widgets', category: 'Actions', context: 'dashboard', icon: 'grid' },
// Projects context
{ id: 'proj-new', title: 'New Project', description: 'Create a new project', category: 'Actions', context: 'projects', shortcut: ['N'], icon: 'plus' },
{ id: 'proj-search', title: 'Search Projects', description: 'Find projects by name', category: 'Actions', context: 'projects', icon: 'search' },
{ id: 'proj-filter', title: 'Filter Projects', description: 'Filter by status or date', category: 'Actions', context: 'projects', icon: 'filter' },
{ id: 'proj-archive', title: 'View Archived', description: 'Show archived projects', category: 'Actions', context: 'projects', icon: 'archive' },
// Tasks context
{ id: 'task-new', title: 'New Task', description: 'Create a new task', category: 'Actions', context: 'tasks', shortcut: ['N'], icon: 'plus' },
{ id: 'task-complete', title: 'Mark Complete', description: 'Mark selected task done', category: 'Actions', context: 'tasks', shortcut: ['C'], icon: 'check' },
{ id: 'task-assign', title: 'Assign Task', description: 'Assign to team member', category: 'Actions', context: 'tasks', icon: 'user-plus' },
{ id: 'task-priority', title: 'Set Priority', description: 'Change task priority', category: 'Actions', context: 'tasks', icon: 'flag' },
{ id: 'task-due', title: 'Set Due Date', description: 'Schedule task deadline', category: 'Actions', context: 'tasks', icon: 'calendar' },
// Team context
{ id: 'team-invite', title: 'Invite Member', description: 'Send team invitation', category: 'Actions', context: 'team', icon: 'mail' },
{ id: 'team-roles', title: 'Manage Roles', description: 'Edit member permissions', category: 'Actions', context: 'team', icon: 'shield' },
// Settings context
{ id: 'set-theme', title: 'Change Theme', description: 'Switch appearance mode', category: 'Preferences', context: 'settings', icon: 'moon' },
{ id: 'set-notif', title: 'Notification Settings', description: 'Configure alerts', category: 'Preferences', context: 'settings', icon: 'bell' },
{ id: 'set-keyboard', title: 'Keyboard Shortcuts', description: 'View all shortcuts', category: 'Preferences', context: 'settings', shortcut: ['?'], icon: 'command' },
{ id: 'set-account', title: 'Account Settings', description: 'Manage your account', category: 'Preferences', context: 'settings', icon: 'user' },
];
// Icon SVG paths
const icons = {
dashboard: '<rect x="3" y="3" width="7" height="7" rx="1"/><rect x="14" y="3" width="7" height="7" rx="1"/><rect x="3" y="14" width="7" height="7" rx="1"/><rect x="14" y="14" width="7" height="7" rx="1"/>',
folder: '<path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/>',
check: '<path d="M9 11l3 3L22 4"/><path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"/>',
users: '<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/>',
settings: '<circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/>',
refresh: '<path d="M23 4v6h-6"/><path d="M1 20v-6h6"/><path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"/>',
download: '<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/>',
grid: '<rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/>',
plus: '<line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/>',
search: '<circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/>',
filter: '<polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"/>',
archive: '<polyline points="21 8 21 21 3 21 3 8"/><rect x="1" y="3" width="22" height="5"/><line x1="10" y1="12" x2="14" y2="12"/>',
'user-plus': '<path d="M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="8.5" cy="7" r="4"/><line x1="20" y1="8" x2="20" y2="14"/><line x1="23" y1="11" x2="17" y2="11"/>',
flag: '<path d="M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z"/><line x1="4" y1="22" x2="4" y2="15"/>',
calendar: '<rect x="3" y="4" width="18" height="18" rx="2" ry="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/>',
mail: '<path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"/><polyline points="22,6 12,13 2,6"/>',
shield: '<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>',
moon: '<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>',
bell: '<path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"/><path d="M13.73 21a2 2 0 0 1-3.46 0"/>',
command: '<path d="M18 3a3 3 0 0 0-3 3v12a3 3 0 0 0 3 3 3 3 0 0 0 3-3 3 3 0 0 0-3-3H6a3 3 0 0 0-3 3 3 3 0 0 0 3 3 3 3 0 0 0 3-3V6a3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3h12a3 3 0 0 0 3-3 3 3 0 0 0-3-3z"/>',
user: '<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/>'
};
// State
let currentContext = 'dashboard';
let recentCommands = [];
let paletteOpen = false;
let selectedIndex = 0;
let filteredCommands = [];
// DOM elements
const overlay = document.getElementById('paletteOverlay');
const input = document.getElementById('paletteInput');
const results = document.getElementById('paletteResults');
const contextDisplay = document.getElementById('currentContext');
const paletteContextName = document.getElementById('paletteContextName');
const resultCount = document.getElementById('resultCount');
const toast = document.getElementById('toast');
const toastMessage = document.getElementById('toastMessage');
// Background animation
const canvas = document.getElementById('bgCanvas');
const ctx = canvas.getContext('2d');
let particles = [];
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
function initParticles() {
particles = [];
const count = Math.floor((canvas.width * canvas.height) / 15000);
for (let i = 0; i < count; i++) {
particles.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
vx: (Math.random() - 0.5) * 0.3,
vy: (Math.random() - 0.5) * 0.3,
size: Math.random() * 2 + 1,
alpha: Math.random() * 0.3 + 0.1
});
}
}
function drawParticles() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
particles.forEach(p => {
p.x += p.vx;
p.y += p.vy;
if (p.x < 0) p.x = canvas.width;
if (p.x > canvas.width) p.x = 0;
if (p.y < 0) p.y = canvas.height;
if (p.y > canvas.height) p.y = 0;
ctx.beginPath();
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
ctx.fillStyle = `rgba(0, 212, 170, ${p.alpha})`;
ctx.fill();
});
// Draw connections
ctx.strokeStyle = 'rgba(0, 212, 170, 0.05)';
ctx.lineWidth = 1;
for (let i = 0; i < particles.length; i++) {
for (let j = i + 1; j < particles.length; j++) {
const dx = particles[i].x - particles[j].x;
const dy = particles[i].y - particles[j].y;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 120) {
ctx.beginPath();
ctx.moveTo(particles[i].x, particles[i].y);
ctx.lineTo(particles[j].x, particles[j].y);
ctx.stroke();
}
}
}
requestAnimationFrame(drawParticles);
}
resizeCanvas();
initParticles();
drawParticles();
window.addEventListener('resize', () => {
resizeCanvas();
initParticles();
});
// Fuzzy search implementation
function fuzzyMatch(text, query) {
const textLower = text.toLowerCase();
const queryLower = query.toLowerCase();
if (!query) return { match: true, score: 0, indices: [] };
let score = 0;
let indices = [];
let queryIndex = 0;
for (let i = 0; i < text.length && queryIndex < queryLower.length; i++) {
if (textLower[i] === queryLower[queryIndex]) {
indices.push(i);
score += (i === 0 || text[i - 1] === ' ') ? 15 : 10;
if (indices.length > 1 && indices[indices.length - 1] === indices[indices.length - 2] + 1) {
score += 5; // Bonus for consecutive matches
}
queryIndex++;
}
}
return {
match: queryIndex === queryLower.length,
score: score,
indices: indices
};
}
function highlightMatch(text, indices) {
if (!indices.length) return text;
let result = '';
let lastIndex = 0;
indices.forEach((idx, i) => {
result += text.slice(lastIndex, idx);
result += `<span class="match">${text[idx]}</span>`;
lastIndex = idx + 1;
});
result += text.slice(lastIndex);
return result;
}
// Filter commands
function getFilteredCommands(query) {
const queryTrimmed = query.trim().toLowerCase();
// Get commands available in current context
let available = commands.filter(cmd =>
cmd.global || cmd.context === currentContext || !cmd.context
);
if (!queryTrimmed) {
// Show recent commands first, then by category
const recent = recentCommands.map(id => available.find(c => c.id === id)).filter(Boolean);
const others = available.filter(c => !recentCommands.includes(c.id));
// Group by category
const grouped = {};
if (recent.length > 0) {
grouped['Recent'] = recent.slice(0, 3);
}
others.forEach(cmd => {
if (!grouped[cmd.category]) grouped[cmd.category] = [];
grouped[cmd.category].push(cmd);
});
return grouped;
}
// Fuzzy search
const scored = available.map(cmd => {
const titleMatch = fuzzyMatch(cmd.title, queryTrimmed);
const descMatch = fuzzyMatch(cmd.description, queryTrimmed);
const catMatch = fuzzyMatch(cmd.category, queryTrimmed);
if (titleMatch.match) {
return { ...cmd, score: titleMatch.score + 50, indices: titleMatch.indices };
}
if (descMatch.match) {
return { ...cmd, score: descMatch.score + 20, indices: descMatch.indices };
}
if (catMatch.match) {
return { ...cmd, score: catMatch.score, indices: [] };
}
return null;
}).filter(Boolean);
scored.sort((a, b) => b.score - a.score);
// Group results
const grouped = {};
scored.forEach(cmd => {
if (!grouped[cmd.category]) grouped[cmd.category] = [];
grouped[cmd.category].push(cmd);
});
return grouped;
}
// Render results
function renderResults(query) {
const grouped = getFilteredCommands(query);
const categories = Object.keys(grouped);
let totalCommands = 0;
categories.forEach(cat => totalCommands += grouped[cat].length);
resultCount.textContent = totalCommands;
if (totalCommands === 0) {
results.innerHTML = `
<div class="palette-empty">
<div class="palette-empty-icon">🔍</div>
<div>No commands found</div>
</div>
`;
filteredCommands = [];
return;
}
// Flatten for keyboard navigation
filteredCommands = [];
categories.forEach(cat => {
grouped[cat].forEach(cmd => filteredCommands.push(cmd));
});
let html = '';
categories.forEach(category => {
html += `<div class="palette-group">
<div class="palette-group-title">${category}</div>`;
grouped[category].forEach(cmd => {
const idx = filteredCommands.indexOf(cmd);
const isSelected = idx === selectedIndex;
const highlightedTitle = query ? highlightMatch(cmd.title, cmd.indices || []) : cmd.title;
html += `
<div class="palette-item ${isSelected ? 'selected' : ''}" data-index="${idx}">
<div class="palette-item-icon">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
${icons[cmd.icon] || ''}
</svg>
</div>
<div class="palette-item-content">
<div class="palette-item-title">${highlightedTitle}</div>
<div class="palette-item-description">${cmd.description}</div>
</div>
${cmd.shortcut ? `
<div class="palette-item-shortcut">
${cmd.shortcut.map(k => `<span class="kbd">${k}</span>`).join('')}
</div>
` : ''}
</div>
`;
});
html += '</div>';
});
results.innerHTML = html;
// Add click handlers
document.querySelectorAll('.palette-item').forEach(item => {
item.addEventListener('click', () => {
const idx = parseInt(item.dataset.index);
selectCommand(idx);
});
});
}
// Select command
function selectCommand(index) {
const cmd = filteredCommands[index];
if (!cmd) return;
// Add to recent
recentCommands = recentCommands.filter(id => id !== cmd.id);
recentCommands.unshift(cmd.id);
recentCommands = recentCommands.slice(0, 5);
closePalette();
// Handle navigation commands
if (cmd.id.startsWith('nav-')) {
const context = cmd.id.replace('nav-', '');
switchContext(context);
} else {
showToast(`Executed: ${cmd.title}`);
}
}
// Context switching
function switchContext(context) {
currentContext = context;
// Update UI
contextDisplay.textContent = context.charAt(0).toUpperCase() + context.slice(1);
paletteContextName.textContent = context.charAt(0).toUpperCase() + context.slice(1);
// Update sidebar
document.querySelectorAll('.sidebar-item').forEach(item => {
item.classList.toggle('active', item.dataset.context === context);
});
}
// Palette controls
function openPalette() {
paletteOpen = true;
selectedIndex = 0;
overlay.classList.add('active');
input.value = '';
input.focus();
renderResults('');
}
function closePalette() {
paletteOpen = false;
overlay.classList.remove('active');
input.blur();
}
// Toast
function showToast(message) {
toastMessage.textContent = message;
toast.classList.add('show');
setTimeout(() => toast.classList.remove('show'), 3000);
}
// Keyboard events
document.addEventListener('keydown', (e) => {
// Open palette
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
e.preventDefault();
if (paletteOpen) {
closePalette();
} else {
openPalette();
}
return;
}
if (!paletteOpen) return;
// Close on Escape
if (e.key === 'Escape') {
e.preventDefault();
closePalette();
return;
}
// Navigate
if (e.key === 'ArrowDown') {
e.preventDefault();
selectedIndex = Math.min(selectedIndex + 1, filteredCommands.length - 1);
renderResults(input.value);
scrollToSelected();
return;
}
if (e.key === 'ArrowUp') {
e.preventDefault();
selectedIndex = Math.max(selectedIndex - 1, 0);
renderResults(input.value);
scrollToSelected();
return;
}
// Select
if (e.key === 'Enter') {
e.preventDefault();
selectCommand(selectedIndex);
return;
}
});
function scrollToSelected() {
const selected = results.querySelector('.palette-item.selected');
if (selected) {
selected.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
}
}
// Input handling
input.addEventListener('input', () => {
selectedIndex = 0;
renderResults(input.value);
});
// Sidebar context switching
document.querySelectorAll('.sidebar-item').forEach(item => {
item.addEventListener('click', () => {
const context = item.dataset.context;
if (context) switchContext(context);
});
});
// Close on overlay click
overlay.addEventListener('click', (e) => {
if (e.target === overlay) closePalette();
});
// Initial render
renderResults('');
</script>
</body>
</html>
Key Features Implemented
1. Keyboard-First Design
Ctrl/Cmd + K to toggle palette
↑ / ↓ for navigation with visual selection
Enter to execute
Escape to close
- Full keyboard workflow without mouse dependency
2. Fuzzy Search Algorithm
- Matches characters in order but not necessarily consecutive
- Scores based on:
- Word boundary matches (higher score)
- Consecutive character matches (bonus)
- Title matches ranked higher than description
- Highlights matched characters in results
3. Contextual Actions
- Commands change based on current context (Dashboard, Projects, Tasks, Team, Settings)
- Global commands always available
- Context badge shows current mode
- Clicking sidebar items switches context
4. Visual Feedback
- Animated particle background
- Smooth palette open/close transitions
- Selection highlight with accent bar
- Toast notifications on action execution
- Recent commands section
5. Smart Organization
- Commands grouped by category
- Recent commands shown first when query is empty
- Keyboard shortcuts displayed inline
- Result count in footer