The user wants a command palette (Cmd+K) for a SaaS platform. This is a complex UI component that needs:
- Fuzzy search - finding commands even with partial/typo-ridden queries
- Command side effects - showing what happens when you run a command (loading states, success/error feedback, undo capability)
- Plugin discovery - browsing and discovering available plugins/extensions
Let me design something that's visually striking and not generic. I'll think about:
Visual Direction:
- Dark theme with a sophisticated, technical aesthetic
- Glassmorphism for the palette overlay
- Smooth animations and transitions
- Clear visual hierarchy between different result types
Features to implement:
- Fuzzy search algorithm (simple implementation)
- Command categories: Actions, Navigation, Plugins
- Side effect indicators (shows what the command will do)
- Plugin discovery section with ratings, install status
- Keyboard navigation
- Recent commands
- Command preview panel
Color scheme:
- Deep dark background with subtle gradients
- Cyan/teal accent for highlights
- Warm orange/amber for warnings/actions
- Clean white/gray text hierarchy
Animations:
- Smooth palette open/close
- Staggered results reveal
- Hover states with subtle transforms
- Loading states for commands
- Toast notifications for feedback
Technical implementation:
- Fuzzy matching function
- Virtualized rendering for performance (though for demo just regular)
- Keyboard event handling
- CSS animations with reduced motion support
Let me create a polished, functional command palette that showcases all these features.
Command Palette Design for SaaS Platform
A sophisticated command palette featuring fuzzy search, real-time side effects visualization, and plugin discovery with a technical, high-end aesthetic.
<!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>
<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=JetBrains+Mono:wght@400;500;600&family=Space+Grotesk:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-deep: #0a0b0f;
--bg-surface: #12141a;
--bg-elevated: #1a1d26;
--fg-primary: #f0f2f5;
--fg-secondary: #8b919e;
--fg-muted: #4a5060;
--accent-cyan: #00d9ff;
--accent-cyan-dim: rgba(0, 217, 255, 0.15);
--accent-amber: #ffb347;
--accent-amber-dim: rgba(255, 179, 71, 0.15);
--accent-green: #00ff88;
--accent-red: #ff5f5f;
--border-subtle: rgba(255, 255, 255, 0.06);
--border-active: rgba(0, 217, 255, 0.3);
}
* {
box-sizing: border-box;
}
body {
font-family: 'Space Grotesk', sans-serif;
background: var(--bg-deep);
color: var(--fg-primary);
min-height: 100vh;
overflow: hidden;
}
.font-mono {
font-family: 'JetBrains Mono', monospace;
}
/* Background pattern */
.bg-pattern {
position: fixed;
inset: 0;
background-image:
radial-gradient(ellipse 80% 50% at 50% -20%, rgba(0, 217, 255, 0.08), transparent),
radial-gradient(ellipse 60% 40% at 80% 100%, rgba(255, 179, 71, 0.05), transparent),
linear-gradient(180deg, transparent 0%, var(--bg-deep) 100%);
pointer-events: none;
}
.grid-overlay {
position: fixed;
inset: 0;
background-image:
linear-gradient(var(--border-subtle) 1px, transparent 1px),
linear-gradient(90deg, var(--border-subtle) 1px, transparent 1px);
background-size: 60px 60px;
opacity: 0.3;
pointer-events: none;
}
/* Command Palette Modal */
.palette-backdrop {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.7);
backdrop-filter: blur(8px);
opacity: 0;
visibility: hidden;
transition: opacity 0.2s ease, visibility 0.2s ease;
z-index: 100;
}
.palette-backdrop.active {
opacity: 1;
visibility: visible;
}
.palette-container {
position: fixed;
top: 15%;
left: 50%;
transform: translateX(-50%) translateY(-20px) scale(0.98);
width: 640px;
max-width: 90vw;
max-height: 70vh;
background: var(--bg-surface);
border: 1px solid var(--border-subtle);
border-radius: 16px;
box-shadow:
0 0 0 1px rgba(255, 255, 255, 0.03),
0 25px 50px -12px rgba(0, 0, 0, 0.5),
0 0 100px -20px rgba(0, 217, 255, 0.15);
opacity: 0;
visibility: hidden;
transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
z-index: 101;
display: flex;
flex-direction: column;
overflow: hidden;
}
.palette-container.active {
opacity: 1;
visibility: visible;
transform: translateX(-50%) translateY(0) scale(1);
}
/* Search Input */
.search-wrapper {
display: flex;
align-items: center;
gap: 12px;
padding: 16px 20px;
border-bottom: 1px solid var(--border-subtle);
background: linear-gradient(180deg, rgba(255, 255, 255, 0.02) 0%, transparent 100%);
}
.search-icon {
width: 20px;
height: 20px;
color: var(--fg-muted);
flex-shrink: 0;
}
.search-input {
flex: 1;
background: none;
border: none;
outline: none;
font-size: 17px;
font-weight: 500;
color: var(--fg-primary);
font-family: inherit;
}
.search-input::placeholder {
color: var(--fg-muted);
}
.search-hint {
display: flex;
gap: 6px;
flex-shrink: 0;
}
.hint-key {
padding: 3px 7px;
background: var(--bg-elevated);
border: 1px solid var(--border-subtle);
border-radius: 5px;
font-size: 11px;
font-weight: 600;
color: var(--fg-muted);
font-family: 'JetBrains Mono', monospace;
}
/* Tabs */
.tabs-wrapper {
display: flex;
gap: 4px;
padding: 8px 12px;
border-bottom: 1px solid var(--border-subtle);
}
.tab-btn {
padding: 8px 14px;
background: none;
border: none;
border-radius: 8px;
font-size: 13px;
font-weight: 500;
color: var(--fg-secondary);
cursor: pointer;
transition: all 0.15s ease;
display: flex;
align-items: center;
gap: 6px;
}
.tab-btn:hover {
background: var(--bg-elevated);
color: var(--fg-primary);
}
.tab-btn.active {
background: var(--accent-cyan-dim);
color: var(--accent-cyan);
}
.tab-count {
padding: 2px 6px;
background: var(--bg-elevated);
border-radius: 4px;
font-size: 10px;
font-weight: 600;
color: var(--fg-muted);
}
.tab-btn.active .tab-count {
background: rgba(0, 217, 255, 0.2);
color: var(--accent-cyan);
}
/* Results */
.results-container {
flex: 1;
overflow-y: auto;
padding: 8px;
}
.results-container::-webkit-scrollbar {
width: 6px;
}
.results-container::-webkit-scrollbar-track {
background: transparent;
}
.results-container::-webkit-scrollbar-thumb {
background: var(--fg-muted);
border-radius: 3px;
}
.result-group {
margin-bottom: 8px;
}
.group-label {
padding: 8px 12px 6px;
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
color: var(--fg-muted);
}
.result-item {
display: flex;
align-items: center;
gap: 12px;
padding: 12px;
border-radius: 10px;
cursor: pointer;
transition: all 0.15s ease;
position: relative;
}
.result-item:hover,
.result-item.selected {
background: var(--bg-elevated);
}
.result-item.selected::before {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 3px;
height: 60%;
background: var(--accent-cyan);
border-radius: 0 2px 2px 0;
}
.result-icon {
width: 36px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
background: var(--bg-surface);
border: 1px solid var(--border-subtle);
border-radius: 8px;
flex-shrink: 0;
}
.result-icon svg {
width: 18px;
height: 18px;
}
.result-content {
flex: 1;
min-width: 0;
}
.result-title {
font-size: 14px;
font-weight: 500;
color: var(--fg-primary);
margin-bottom: 2px;
display: flex;
align-items: center;
gap: 8px;
}
.result-title .highlight {
color: var(--accent-cyan);
}
.result-description {
font-size: 12px;
color: var(--fg-secondary);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.result-meta {
display: flex;
align-items: center;
gap: 8px;
flex-shrink: 0;
}
.shortcut {
display: flex;
gap: 4px;
}
.shortcut kbd {
padding: 4px 8px;
background: var(--bg-surface);
border: 1px solid var(--border-subtle);
border-radius: 5px;
font-size: 11px;
font-weight: 500;
color: var(--fg-secondary);
font-family: 'JetBrains Mono', monospace;
}
/* Side Effect Badge */
.side-effect {
display: flex;
align-items: center;
gap: 4px;
padding: 4px 8px;
border-radius: 6px;
font-size: 11px;
font-weight: 500;
}
.side-effect.read {
background: var(--accent-cyan-dim);
color: var(--accent-cyan);
}
.side-effect.write {
background: var(--accent-amber-dim);
color: var(--accent-amber);
}
.side-effect.danger {
background: rgba(255, 95, 95, 0.15);
color: var(--accent-red);
}
.side-effect svg {
width: 12px;
height: 12px;
}
/* Plugin Card */
.plugin-card {
display: flex;
align-items: center;
gap: 12px;
padding: 12px;
border-radius: 10px;
cursor: pointer;
transition: all 0.15s ease;
}
.plugin-card:hover {
background: var(--bg-elevated);
}
.plugin-icon {
width: 40px;
height: 40px;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
flex-shrink: 0;
}
.plugin-info {
flex: 1;
min-width: 0;
}
.plugin-name {
font-size: 14px;
font-weight: 600;
color: var(--fg-primary);
margin-bottom: 2px;
}
.plugin-meta {
display: flex;
align-items: center;
gap: 8px;
font-size: 12px;
color: var(--fg-secondary);
}
.plugin-rating {
display: flex;
align-items: center;
gap: 3px;
color: var(--accent-amber);
}
.plugin-rating svg {
width: 12px;
height: 12px;
}
.plugin-status {
padding: 4px 10px;
border-radius: 6px;
font-size: 11px;
font-weight: 600;
}
.plugin-status.installed {
background: var(--accent-cyan-dim);
color: var(--accent-cyan);
}
.plugin-status.available {
background: var(--bg-elevated);
color: var(--fg-secondary);
border: 1px solid var(--border-subtle);
}
/* Empty State */
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 48px 24px;
text-align: center;
}
.empty-icon {
width: 48px;
height: 48px;
color: var(--fg-muted);
margin-bottom: 16px;
}
.empty-title {
font-size: 15px;
font-weight: 500;
color: var(--fg-primary);
margin-bottom: 4px;
}
.empty-description {
font-size: 13px;
color: var(--fg-secondary);
}
/* Footer */
.palette-footer {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 16px;
border-top: 1px solid var(--border-subtle);
background: rgba(0, 0, 0, 0.2);
}
.footer-hints {
display: flex;
gap: 16px;
}
.footer-hint {
display: flex;
align-items: center;
gap: 6px;
font-size: 12px;
color: var(--fg-muted);
}
.footer-hint kbd {
padding: 2px 6px;
background: var(--bg-elevated);
border: 1px solid var(--border-subtle);
border-radius: 4px;
font-size: 10px;
font-weight: 600;
font-family: 'JetBrains Mono', monospace;
}
/* Toast Notification */
.toast-container {
position: fixed;
bottom: 24px;
right: 24px;
z-index: 200;
display: flex;
flex-direction: column;
gap: 8px;
}
.toast {
display: flex;
align-items: center;
gap: 12px;
padding: 14px 18px;
background: var(--bg-surface);
border: 1px solid var(--border-subtle);
border-radius: 10px;
box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
transform: translateX(120%);
transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.show {
transform: translateX(0);
}
.toast-icon {
width: 20px;
height: 20px;
flex-shrink: 0;
}
.toast-icon.success {
color: var(--accent-green);
}
.toast-icon.info {
color: var(--accent-cyan);
}
.toast-message {
font-size: 13px;
font-weight: 500;
color: var(--fg-primary);
}
.toast-action {
padding: 6px 12px;
background: var(--accent-cyan-dim);
border: none;
border-radius: 6px;
font-size: 12px;
font-weight: 600;
color: var(--accent-cyan);
cursor: pointer;
transition: background 0.15s ease;
}
.toast-action:hover {
background: rgba(0, 217, 255, 0.25);
}
/* Demo Page Content */
.demo-content {
padding: 32px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
position: relative;
z-index: 1;
}
.demo-title {
font-size: 48px;
font-weight: 700;
color: var(--fg-primary);
margin-bottom: 12px;
letter-spacing: -1px;
}
.demo-subtitle {
font-size: 18px;
color: var(--fg-secondary);
margin-bottom: 32px;
}
.demo-trigger {
display: flex;
align-items: center;
gap: 12px;
padding: 14px 20px;
background: var(--bg-surface);
border: 1px solid var(--border-subtle);
border-radius: 12px;
cursor: pointer;
transition: all 0.2s ease;
}
.demo-trigger:hover {
background: var(--bg-elevated);
border-color: var(--border-active);
box-shadow: 0 0 20px -5px rgba(0, 217, 255, 0.2);
}
.demo-trigger-text {
font-size: 15px;
color: var(--fg-secondary);
}
.demo-trigger kbd {
padding: 4px 8px;
background: var(--bg-elevated);
border: 1px solid var(--border-subtle);
border-radius: 6px;
font-size: 12px;
font-weight: 600;
color: var(--fg-muted);
font-family: 'JetBrains Mono', monospace;
}
/* Loading spinner */
.spinner {
width: 16px;
height: 16px;
border: 2px solid var(--border-subtle);
border-top-color: var(--accent-cyan);
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
/* Animations */
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(8px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.result-item,
.plugin-card {
animation: fadeInUp 0.2s ease backwards;
}
.result-item:nth-child(1), .plugin-card:nth-child(1) { animation-delay: 0ms; }
.result-item:nth-child(2), .plugin-card:nth-child(2) { animation-delay: 30ms; }
.result-item:nth-child(3), .plugin-card:nth-child(3) { animation-delay: 60ms; }
.result-item:nth-child(4), .plugin-card:nth-child(4) { animation-delay: 90ms; }
.result-item:nth-child(5), .plugin-card:nth-child(5) { animation-delay: 120ms; }
.result-item:nth-child(6), .plugin-card:nth-child(6) { animation-delay: 150ms; }
/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
.palette-backdrop,
.palette-container,
.result-item,
.plugin-card,
.toast {
animation: none;
transition: opacity 0.15s ease;
}
}
/* Focus states */
.result-item:focus-visible,
.tab-btn:focus-visible,
.plugin-card:focus-visible {
outline: 2px solid var(--accent-cyan);
outline-offset: 2px;
}
.search-input:focus-visible {
outline: none;
}
</style>
</head>
<body>
<div class="bg-pattern"></div>
<div class="grid-overlay"></div>
<!-- Demo Page Content -->
<div class="demo-content">
<h1 class="demo-title">Nexus Platform</h1>
<p class="demo-subtitle">Your workspace, commanded.</p>
<button class="demo-trigger" id="openPalette" aria-label="Open command palette">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="11" cy="11" r="8"/>
<path d="m21 21-4.35-4.35"/>
</svg>
<span class="demo-trigger-text">Search commands...</span>
<kbd>Ctrl</kbd>
<kbd>K</kbd>
</button>
</div>
<!-- Command Palette -->
<div class="palette-backdrop" id="paletteBackdrop"></div>
<div class="palette-container" id="paletteContainer" role="dialog" aria-modal="true" aria-label="Command palette">
<div class="search-wrapper">
<svg class="search-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="11" cy="11" r="8"/>
<path d="m21 21-4.35-4.35"/>
</svg>
<input
type="text"
class="search-input"
id="searchInput"
placeholder="Search commands, plugins, or type '>' for actions..."
autocomplete="off"
aria-label="Search commands"
>
<div class="search-hint">
<span class="hint-key">ESC</span>
</div>
</div>
<div class="tabs-wrapper" role="tablist">
<button class="tab-btn active" role="tab" data-tab="all" aria-selected="true">
All
<span class="tab-count" id="allCount">12</span>
</button>
<button class="tab-btn" role="tab" data-tab="commands" aria-selected="false">
Commands
<span class="tab-count">8</span>
</button>
<button class="tab-btn" role="tab" data-tab="plugins" aria-selected="false">
Plugins
<span class="tab-count">4</span>
</button>
</div>
<div class="results-container" id="resultsContainer" role="listbox">
<!-- Results rendered by JS -->
</div>
<div class="palette-footer">
<div class="footer-hints">
<span class="footer-hint"><kbd>↑↓</kbd> Navigate</span>
<span class="footer-hint"><kbd>Enter</kbd> Select</span>
<span class="footer-hint"><kbd>Tab</kbd> Autocomplete</span>
</div>
<div class="footer-hints">
<span class="footer-hint"><kbd>Ctrl</kbd>+<kbd>N</kbd> New item</span>
</div>
</div>
</div>
<!-- Toast Container -->
<div class="toast-container" id="toastContainer"></div>
<script>
// Data
const commands = [
{
id: 'create-project',
title: 'Create new project',
description: 'Start a new project from scratch or template',
icon: 'plus',
category: 'actions',
sideEffect: 'write',
shortcut: ['Ctrl', 'N'],
keywords: ['new', 'project', 'create', 'add']
},
{
id: 'invite-member',
title: 'Invite team member',
description: 'Send an invitation to join your workspace',
icon: 'user-plus',
category: 'actions',
sideEffect: 'write',
shortcut: ['Ctrl', 'I'],
keywords: ['invite', 'team', 'member', 'add', 'user']
},
{
id: 'export-data',
title: 'Export workspace data',
description: 'Download all data as JSON or CSV',
icon: 'download',
category: 'actions',
sideEffect: 'read',
shortcut: [],
keywords: ['export', 'download', 'data', 'backup']
},
{
id: 'delete-project',
title: 'Delete current project',
description: 'Permanently remove this project and all data',
icon: 'trash',
category: 'actions',
sideEffect: 'danger',
shortcut: [],
keywords: ['delete', 'remove', 'project', 'destroy']
},
{
id: 'go-settings',
title: 'Open settings',
description: 'Manage your account and preferences',
icon: 'settings',
category: 'navigation',
sideEffect: null,
shortcut: ['Ctrl', ','],
keywords: ['settings', 'preferences', 'config', 'account']
},
{
id: 'go-dashboard',
title: 'Go to dashboard',
description: 'Return to the main overview',
icon: 'layout',
category: 'navigation',
sideEffect: null,
shortcut: ['Ctrl', 'D'],
keywords: ['dashboard', 'home', 'overview', 'main']
},
{
id: 'go-analytics',
title: 'View analytics',
description: 'See usage statistics and reports',
icon: 'chart',
category: 'navigation',
sideEffect: 'read',
shortcut: ['Ctrl', 'A'],
keywords: ['analytics', 'stats', 'reports', 'metrics']
},
{
id: 'toggle-theme',
title: 'Toggle dark mode',
description: 'Switch between light and dark themes',
icon: 'moon',
category: 'actions',
sideEffect: 'write',
shortcut: ['Ctrl', 'T'],
keywords: ['theme', 'dark', 'light', 'mode', 'toggle']
}
];
const plugins = [
{
id: 'plugin-analytics',
name: 'Advanced Analytics',
description: 'Deep insights with ML-powered predictions',
rating: 4.8,
reviews: 234,
installed: true,
color: '#00d9ff',
icon: '📊'
},
{
id: 'plugin-slack',
name: 'Slack Integration',
description: 'Sync notifications and updates to Slack',
rating: 4.6,
reviews: 512,
installed: true,
color: '#ffb347',
icon: '💬'
},
{
id: 'plugin-backup',
name: 'Auto Backup Pro',
description: 'Automated backups with cloud storage',
rating: 4.9,
reviews: 189,
installed: false,
color: '#00ff88',
icon: '☁️'
},
{
id: 'plugin-api',
name: 'API Gateway',
description: 'Custom endpoints and webhooks manager',
rating: 4.4,
reviews: 98,
installed: false,
color: '#ff5f5f',
icon: '⚡'
}
];
// State
let isOpen = false;
let selectedIndex = 0;
let currentTab = 'all';
let filteredResults = [];
let recentCommands = ['create-project', 'go-dashboard', 'invite-member'];
// DOM Elements
const backdrop = document.getElementById('paletteBackdrop');
const container = document.getElementById('paletteContainer');
const searchInput = document.getElementById('searchInput');
const resultsContainer = document.getElementById('resultsContainer');
const toastContainer = document.getElementById('toastContainer');
const openBtn = document.getElementById('openPalette');
const tabBtns = document.querySelectorAll('.tab-btn');
// Icons SVG
const icons = {
plus: '<path d="M12 5v14M5 12h14"/>',
'user-plus': '<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M19 8v6M22 11h-6"/>',
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"/>',
trash: '<polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>',
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"/>',
layout: '<rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="9" y1="21" x2="9" y2="9"/>',
chart: '<line x1="18" y1="20" x2="18" y2="10"/><line x1="12" y1="20" x2="12" y2="4"/><line x1="6" y1="20" x2="6" y2="14"/>',
moon: '<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>',
star: '<polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/>',
'check-circle': '<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/>'
};
function getIcon(name) {
return `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${icons[name] || ''}</svg>`;
}
// Fuzzy search
function fuzzyMatch(query, target) {
const queryLower = query.toLowerCase();
const targetLower = target.toLowerCase();
let queryIndex = 0;
let score = 0;
for (let i = 0; i < targetLower.length && queryIndex < queryLower.length; i++) {
if (targetLower[i] === queryLower[queryIndex]) {
score += (i === 0 || targetLower[i - 1] === ' ') ? 3 : 1;
queryIndex++;
}
}
return queryIndex === queryLower.length ? score : 0;
}
function searchCommands(query) {
const results = [];
commands.forEach(cmd => {
let score = 0;
// Check title
const titleScore = fuzzyMatch(query, cmd.title) * 2;
// Check keywords
const keywordScore = Math.max(...cmd.keywords.map(k => fuzzyMatch(query, k)));
score = Math.max(titleScore, keywordScore);
if (score > 0) {
results.push({ ...cmd, type: 'command', score });
}
});
plugins.forEach(plugin => {
let score = fuzzyMatch(query, plugin.name) * 2;
score = Math.max(score, fuzzyMatch(query, plugin.description));
if (score > 0) {
results.push({ ...plugin, type: 'plugin', score });
}
});
return results.sort((a, b) => b.score - a.score);
}
function highlightMatch(text, query) {
if (!query) return text;
const regex = new RegExp(`(${query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')})`, 'gi');
return text.replace(regex, '<span class="highlight">$1</span>');
}
function getSideEffectBadge(effect) {
if (!effect) return '';
const labels = {
read: 'Read-only',
write: 'Modifies data',
danger: 'Destructive'
};
const iconsMap = {
read: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>',
write: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"/></svg>',
danger: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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>'
};
return `<span class="side-effect ${effect}">${iconsMap[effect]}${labels[effect]}</span>`;
}
function renderResults(query = '') {
let results = [];
if (currentTab === 'all' || currentTab === 'commands') {
const cmdResults = query ? searchCommands(query).filter(r => r.type === 'command') : commands.map(c => ({ ...c, type: 'command' }));
results.push(...cmdResults);
}
if (currentTab === 'all' || currentTab === 'plugins') {
const pluginResults = query ? searchCommands(query).filter(r => r.type === 'plugin') : plugins.map(p => ({ ...p, type: 'plugin' }));
results.push(...pluginResults);
}
if (query) {
results = searchCommands(query);
if (currentTab === 'commands') results = results.filter(r => r.type === 'command');
if (currentTab === 'plugins') results = results.filter(r => r.type === 'plugin');
}
filteredResults = results;
selectedIndex = 0;
if (results.length === 0) {
resultsContainer.innerHTML = `
<div class="empty-state">
<svg class="empty-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="11" cy="11" r="8"/>
<path d="m21 21-4.35-4.35"/>
</svg>
<p class="empty-title">No results found</p>
<p class="empty-description">Try a different search term</p>
</div>
`;
return;
}
// Group by type
const commandResults = results.filter(r => r.type === 'command');
const pluginResults = results.filter(r => r.type === 'plugin');
let html = '';
let globalIndex = 0;
// Recent commands (only when no query and showing all/commands)
if (!query && currentTab !== 'plugins') {
const recent = recentCommands.map(id => commands.find(c => c.id === id)).filter(Boolean);
if (recent.length > 0) {
html += '<div class="result-group"><div class="group-label">Recent</div>';
recent.forEach((cmd, i) => {
html += renderCommandItem(cmd, globalIndex++, query);
});
html += '</div>';
}
}
// Commands
if (commandResults.length > 0 && (query || currentTab !== 'plugins')) {
const label = query ? 'Commands' : 'All Commands';
html += `<div class="result-group"><div class="group-label">${label}</div>`;
commandResults.forEach(cmd => {
html += renderCommandItem(cmd, globalIndex++, query);
});
html += '</div>';
}
// Plugins
if (pluginResults.length > 0 && (query || currentTab === 'all' || currentTab === 'plugins')) {
html += '<div class="result-group"><div class="group-label">Plugins</div>';
pluginResults.forEach(plugin => {
html += renderPluginItem(plugin, globalIndex++);
});
html += '</div>';
}
resultsContainer.innerHTML = html;
updateSelection();
}
function renderCommandItem(cmd, index, query) {
const title = query ? highlightMatch(cmd.title, query) : cmd.title;
const shortcut = cmd.shortcut.length > 0
? `<span class="shortcut">${cmd.shortcut.map(k => `<kbd>${k}</kbd>`).join('')}</span>`
: '';
const sideEffect = cmd.sideEffect ? getSideEffectBadge(cmd.sideEffect) : '';
return `
<div class="result-item" data-index="${index}" data-id="${cmd.id}" data-type="command" role="option" tabindex="-1">
<div class="result-icon">${getIcon(cmd.icon)}</div>
<div class="result-content">
<div class="result-title">${title}</div>
<div class="result-description">${cmd.description}</div>
</div>
<div class="result-meta">
${sideEffect}
${shortcut}
</div>
</div>
`;
}
function renderPluginItem(plugin, index) {
const statusClass = plugin.installed ? 'installed' : 'available';
const statusText = plugin.installed ? 'Installed' : 'Available';
return `
<div class="plugin-card" data-index="${index}" data-id="${plugin.id}" data-type="plugin" role="option" tabindex="-1">
<div class="plugin-icon" style="background: ${plugin.color}20; color: ${plugin.color};">
${plugin.icon}
</div>
<div class="plugin-info">
<div class="plugin-name">${plugin.name}</div>
<div class="plugin-meta">
<span class="plugin-rating">
${getIcon('star')}
${plugin.rating}
</span>
<span>${plugin.reviews} reviews</span>
</div>
</div>
<span class="plugin-status ${statusClass}">${statusText}</span>
</div>
`;
}
function updateSelection() {
const items = resultsContainer.querySelectorAll('.result-item, .plugin-card');
items.forEach((item, i) => {
item.classList.toggle('selected', i === selectedIndex);
item.setAttribute('aria-selected', i === selectedIndex);
});
}
function showToast(message, type = 'info', action = null) {
const toast = document.createElement('div');
toast.className = 'toast';
const iconType = type === 'success' ? 'check-circle' : 'chart';
const iconClass = type === 'success' ? 'success' : 'info';
let actionHtml = '';
if (action) {
actionHtml = `<button class="toast-action">${action.label}</button>`;
}
toast.innerHTML = `
<svg class="toast-icon ${iconClass}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
${icons[iconType]}
</svg>
<span class="toast-message">${message}</span>
${actionHtml}
`;
toastContainer.appendChild(toast);
// Trigger animation
requestAnimationFrame(() => {
toast.classList.add('show');
});
// Handle action click
if (action) {
toast.querySelector('.toast-action').addEventListener('click', () => {
action.callback();
toast.classList.remove('show');
setTimeout(() => toast.remove(), 300);
});
}
// Auto remove
setTimeout(() => {
toast.classList.remove('show');
setTimeout(() => toast.remove(), 300);
}, 4000);
}
function executeCommand(cmd) {
closePalette();
// Add to recent
recentCommands = [cmd.id, ...recentCommands.filter(id => id !== cmd.id)].slice(0, 3);
const messages = {
'create-project': { msg: 'Creating new project...', type: 'info' },
'invite-member': { msg: 'Opening invite dialog...', type: 'info' },
'export-data': { msg: 'Export started. Check your downloads.', type: 'success' },
'delete-project': { msg: 'Project deleted.', type: 'success', action: { label: 'Undo', callback: () => showToast('Project restored.', 'success') } },
'go-settings': { msg: 'Navigating to settings...', type: 'info' },
'go-dashboard': { msg: 'Navigating to dashboard...', type: 'info' },
'go-analytics': { msg: 'Loading analytics...', type: 'info' },
'toggle-theme': { msg: 'Theme toggled.', type: 'success' }
};
const config = messages[cmd.id] || { msg: `Executed: ${cmd.title}`, type: 'info' };
showToast(config.msg, config.type, config.action);
}
function installPlugin(plugin) {
showToast(`Installing ${plugin.name}...`, 'info');
// Simulate installation
setTimeout(() => {
plugin.installed = true;
showToast(`${plugin.name} installed successfully!`, 'success');
renderResults(searchInput.value);
}, 1500);
}
function openPalette() {
isOpen = true;
backdrop.classList.add('active');
container.classList.add('active');
searchInput.value = '';
searchInput.focus();
selectedIndex = 0;
renderResults();
}
function closePalette() {
isOpen = false;
backdrop.classList.remove('active');
container.classList.remove('active');
}
// Event Listeners
openBtn.addEventListener('click', openPalette);
backdrop.addEventListener('click', closePalette);
searchInput.addEventListener('input', (e) => {
renderResults(e.target.value);
});
tabBtns.forEach(btn => {
btn.addEventListener('click', () => {
tabBtns.forEach(b => {
b.classList.remove('active');
b.setAttribute('aria-selected', 'false');
});
btn.classList.add('active');
btn.setAttribute('aria-selected', 'true');
currentTab = btn.dataset.tab;
renderResults(searchInput.value);
});
});
resultsContainer.addEventListener('click', (e) => {
const item = e.target.closest('.result-item, .plugin-card');
if (!item) return;
const type = item.dataset.type;
const id = item.dataset.id;
if (type === 'command') {
const cmd = commands.find(c => c.id === id);
if (cmd) executeCommand(cmd);
} else if (type === 'plugin') {
const plugin = plugins.find(p => p.id === id);
if (plugin) {
if (plugin.installed) {
showToast(`${plugin.name} is already installed`, 'info');
} else {
installPlugin(plugin);
}
}
}
});
document.addEventListener('keydown', (e) => {
// Open palette
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
e.preventDefault();
if (isOpen) closePalette();
else openPalette();
return;
}
if (!isOpen) return;
// Close palette
if (e.key === 'Escape') {
closePalette();
return;
}
// Navigation
if (e.key === 'ArrowDown') {
e.preventDefault();
const items = resultsContainer.querySelectorAll('.result-item, .plugin-card');
if (items.length > 0) {
selectedIndex = (selectedIndex + 1) % items.length;
updateSelection();
items[selectedIndex].scrollIntoView({ block: 'nearest' });
}
return;
}
if (e.key === 'ArrowUp') {
e.preventDefault();
const items = resultsContainer.querySelectorAll('.result-item, .plugin-card');
if (items.length > 0) {
selectedIndex = (selectedIndex - 1 + items.length) % items.length;
updateSelection();
items[selectedIndex].scrollIntoView({ block: 'nearest' });
}
return;
}
// Execute
if (e.key === 'Enter') {
e.preventDefault();
const items = resultsContainer.querySelectorAll('.result-item, .plugin-card');
const selectedItem = items[selectedIndex];
if (selectedItem) {
selectedItem.click();
}
return;
}
// Tab autocomplete
if (e.key === 'Tab') {
e.preventDefault();
const items = resultsContainer.querySelectorAll('.result-item, .plugin-card');
const selectedItem = items[selectedIndex];
if (selectedItem && selectedItem.dataset.type === 'command') {
const cmd = commands.find(c => c.id === selectedItem.dataset.id);
if (cmd) {
searchInput.value = cmd.title;
renderResults(cmd.title);
}
}
return;
}
});
// Focus search on palette open
container.addEventListener('transitionend', () => {
if (isOpen) {
searchInput.focus();
}
});
// Initial render
renderResults();
</script>
</body>
</html>
Key Features Implemented
1. Fuzzy Search Algorithm
- Custom fuzzy matching that scores matches based on position and word boundaries
- Searches across command titles, descriptions, and keywords
- Real-time filtering as you type
2. Command Side Effects
Visual badges indicating the nature of each command:
- Read-only (cyan) — Safe operations that don't modify data
- Modifies data (amber) — Actions that change state
- Destructive (red) — Irreversible operations with built-in undo
3. Plugin Discovery
- Dedicated plugins tab with ratings and install status
- One-click install with loading states
- Visual distinction between installed/available plugins
4. Polish Details
- Staggered reveal animations on results
- Keyboard navigation with visual selection indicator
- Recent commands section for quick access
- Toast notifications with undo capability
- Responsive design (works on mobile)
- Reduced motion support
Interactions
- Press
Ctrl+K (or Cmd+K) to open
- Use
↑↓ to navigate, Enter to execute
Tab for autocomplete
Esc to close