Documentation menu
Getting Started
Components
Primitives
- Agent Thinking
- Alert
- Alert Dialog
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Checkbox
- Command
- Command Palette
- Context Menu
- Data Table
- Dialog
- Dropdown Menu
- Empty
- Field
- Glow Cloud
- Input
- Label
- Medication Schedule
- Period Tabs
- Popover
- Rainbow Button
- Scroll Area
- Select
- Selectable Card
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Tag
- Textarea
- Timeline
- Tooltip
- Use Count Up
Charts and metrics
Patterns
- Confirm Button
- Date Picker
- Embedded
- Empty State
- Entity Drawer
- Error Boundary
- Field Row
- File Dropzone
- Form Dialog
- Kv
- List Editor
- List Page
- Live Time
- Mini Table
- Money
- Note Field
- Note Text
- Page Card
- Page Header
- Page Tabs
- Page Toolbar
- Person Cell
- Picture Field
- Print Card
- Range Switcher
- Row Actions
- Search Input
- Search Select
- Selected Box
- Signature Pad
- Status Badge
- Sub Nav Layout
- Suggest Input
- Tab Icons
- Table Footer
- Theme Accent Picker
- Time Picker
- View All Link
Dashboard cards
Advanced
Device frames
Website widgets
Website screens
Website panels
Primitives
Command Palette
A Cmd+K palette with groups, rich items and shortcuts.
import { useState } from "react"
import { CalendarPlus, FileText, FlaskConical, Pill, UserPlus } from "lucide-react"
import { Button } from "@/registry/vcare/ui/button"
import { CommandPalette } from "@/registry/vcare/ui/command-palette"
export default function CommandPaletteDemo() {
const [open, setOpen] = useState(false)
return (
<>
<Button variant="outline" onClick={() => setOpen(true)}>
Search… <kbd className="ms-2 text-xs text-muted-foreground">⌘K</kbd>
</Button>
<CommandPalette
open={open}
onOpenChange={setOpen}
placeholder="Search patients, actions, pages"
groups={[
{
heading: "Actions",
items: [
{ id: "patient", label: "New patient", icon: <UserPlus />, shortcut: "N" },
{ id: "appt", label: "New appointment", icon: <CalendarPlus /> },
{ id: "lab", label: "New lab visit", icon: <FlaskConical /> },
],
},
{
heading: "Pages",
items: [
{ id: "rx", label: "Pharmacy today", description: "Dispense and bill", icon: <Pill /> },
{ id: "reports", label: "Lab reports", description: "Counts and turnaround", icon: <FileText /> },
],
},
]}
/>
</>
)
}Installation
npx shadcn@latest add @vcare/command-paletteOr install directly from the URL: https://ui.vcarehms.com/r/command-palette.json
- Install the dependencies:
npm i lucide-react - Add the registry items it uses: command, utils.
- Copy this file into your project and change the
@/registry/vcare/…imports to your own paths.
components/ui/command-palette.tsx
'use client';
import * as React from 'react';
import { CornerDownLeft } from 'lucide-react';
import { cn } from '@/registry/vcare/lib/utils';
import {
Command,
CommandDialog,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandSeparator,
CommandShortcut,
} from '@/registry/vcare/ui/command';
export interface CommandPaletteItem {
id: string;
label: string;
description?: string;
icon?: React.ReactNode;
/** Rich leading content such as a product thumbnail. */
media?: React.ReactNode;
/** Compact state or metadata aligned opposite the label. */
trailing?: React.ReactNode;
shortcut?: React.ReactNode;
keywords?: string[];
disabled?: boolean;
onSelect?: () => void;
}
export interface CommandPaletteGroup {
heading?: string;
items: CommandPaletteItem[];
}
export interface CommandPaletteProps {
groups: CommandPaletteGroup[];
variant?: 'dialog' | 'inline';
/** Arrange results as familiar command rows or as an app-launcher grid. */
layout?: 'list' | 'grid';
/** Tighten list rows for dense navigation menus. */
density?: 'compact' | 'default';
size?: 'compact' | 'default' | 'wide';
open?: boolean;
onOpenChange?: (open: boolean) => void;
placeholder?: string;
emptyLabel?: React.ReactNode;
title?: string;
description?: string;
footer?: React.ReactNode;
className?: string;
onSelect?: (item: CommandPaletteItem) => void;
/** Server-side search: called with the typed text, and the built-in filtering is switched off. */
onSearch?: (query: string) => void;
}
const sizeClasses = {
compact: 'sm:max-w-md',
default: 'sm:max-w-xl',
wide: 'sm:max-w-2xl',
};
/** Bind Command/Ctrl+K to a controlled command palette without stealing input shortcuts. */
function useCommandPaletteShortcut(onOpenChange: React.Dispatch<React.SetStateAction<boolean>>, enabled = true) {
React.useEffect(() => {
if (!enabled) return;
const onKeyDown = (event: KeyboardEvent) => {
if (!(event.metaKey || event.ctrlKey) || event.key.toLowerCase() !== 'k') return;
const target = event.target;
if (
target instanceof HTMLInputElement ||
target instanceof HTMLTextAreaElement ||
target instanceof HTMLSelectElement ||
(target instanceof HTMLElement && target.isContentEditable)
)
return;
event.preventDefault();
onOpenChange((open) => !open);
};
document.addEventListener('keydown', onKeyDown);
return () => document.removeEventListener('keydown', onKeyDown);
}, [enabled, onOpenChange]);
}
function CommandPaletteContent({
groups,
placeholder,
emptyLabel,
footer,
onSelect,
layout,
density,
onSearch,
}: Pick<CommandPaletteProps, 'groups' | 'placeholder' | 'emptyLabel' | 'footer' | 'onSelect' | 'layout' | 'density' | 'onSearch'>) {
return (
<>
<CommandInput placeholder={placeholder} {...(onSearch ? { onValueChange: onSearch } : {})} />
<CommandList className={cn('scroll-py-1', density === 'compact' ? 'max-h-[min(460px,64vh)]' : 'max-h-[min(420px,60vh)] scroll-py-2')}>
<CommandEmpty className="text-muted-foreground px-6 py-12 text-center text-sm">{emptyLabel}</CommandEmpty>
{groups.map((group, groupIndex) => (
<React.Fragment key={group.heading ?? groupIndex}>
{groupIndex > 0 ? <CommandSeparator /> : null}
<CommandGroup
heading={group.heading}
className={cn(
density === 'compact' &&
'p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1 [&_[cmdk-group-heading]]:text-[10.5px] [&_[cmdk-group-heading]]:font-semibold [&_[cmdk-group-heading]]:uppercase [&_[cmdk-group-heading]]:tracking-wide',
layout === 'grid' &&
'p-2 [&_[cmdk-group-items]]:grid [&_[cmdk-group-items]]:grid-cols-2 [&_[cmdk-group-items]]:gap-2 sm:[&_[cmdk-group-items]]:grid-cols-3',
)}
>
{group.items.map((item) => (
<CommandItem
key={item.id}
value={[item.label, item.description, ...(item.keywords ?? [])].filter(Boolean).join(' ')}
disabled={item.disabled}
onSelect={() => {
item.onSelect?.();
onSelect?.(item);
}}
className={cn(
'group/item',
density === 'compact' ? 'h-control-sm gap-2 px-2 py-0 text-[13px]' : 'gap-3 py-2.5',
layout === 'grid' &&
'h-auto min-h-28 flex-col items-start justify-between gap-4 rounded-lg border bg-card p-3 data-[selected=true]:border-ring data-[selected=true]:bg-accent',
)}
>
{item.media ? <span className={cn('flex shrink-0 items-center justify-center', density === 'compact' ? 'size-5' : 'size-10')}>{item.media}</span> : item.icon && density === 'compact' ? (
<span className="flex size-4 shrink-0 items-center justify-center [&>svg]:size-4">{item.icon}</span>
) : item.icon ? (
<span
className={cn(
'bg-muted group-data-[selected=true]/item:bg-background flex shrink-0 items-center justify-center rounded-md border [&>svg]:size-4',
density === 'compact' ? 'size-7' : 'size-8',
layout === 'grid' && 'size-9',
)}
>
{item.icon}
</span>
) : null}
{density === 'compact' ? (
<span className="flex min-w-0 flex-1 items-baseline gap-2">
<span className="truncate font-medium">{item.label}</span>
{item.description ? <span className="text-muted-foreground truncate text-xs">{item.description}</span> : null}
</span>
) : (
<span className="min-w-0 flex-1">
<span className="block truncate text-sm font-medium">{item.label}</span>
{item.description ? <span className="text-muted-foreground block truncate text-xs">{item.description}</span> : null}
</span>
)}
{item.trailing ? <span className="ms-auto shrink-0">{item.trailing}</span> : null}
{item.shortcut ? <CommandShortcut>{item.shortcut}</CommandShortcut> : null}
</CommandItem>
))}
</CommandGroup>
</React.Fragment>
))}
</CommandList>
{footer !== null ? (
<div className={cn('text-muted-foreground flex items-center justify-between gap-3 border-t bg-muted/30 px-3', density === 'compact' ? 'min-h-8 text-[11px]' : 'min-h-10 text-xs')}>{footer}</div>
) : null}
</>
);
}
/** A data-driven command menu that renders as a modal palette or an embedded search surface. */
function CommandPalette({
groups,
variant = 'dialog',
layout = 'list',
density = 'default',
size = 'default',
open,
onOpenChange,
placeholder = 'Type a command or search…',
emptyLabel = 'No commands found.',
title = 'Command palette',
description = 'Search for a command to run.',
footer = (
<span className="flex items-center gap-2">
<CommandPaletteKbd>
<CornerDownLeft />
</CommandPaletteKbd>
Select
</span>
),
className,
onSelect,
onSearch,
}: CommandPaletteProps) {
const content = (
<CommandPaletteContent
groups={groups}
placeholder={placeholder}
emptyLabel={emptyLabel}
footer={footer}
onSelect={onSelect}
layout={layout}
density={density}
onSearch={onSearch}
/>
);
if (variant === 'inline') {
return (
<Command data-slot="command-palette" shouldFilter={!onSearch} className={cn('h-auto rounded-xl border shadow-sm', className)}>
{content}
</Command>
);
}
return (
<CommandDialog
open={open}
onOpenChange={onOpenChange}
title={title}
description={description}
showCloseButton={false}
compact={density === 'compact'}
commandProps={onSearch ? { shouldFilter: false } : undefined}
className={cn('gap-0 overflow-hidden rounded-xl border bg-popover p-0 shadow-2xl', sizeClasses[size], className)}
>
{content}
</CommandDialog>
);
}
function CommandPaletteKbd({ className, ...props }: React.ComponentProps<'kbd'>) {
return (
<kbd
className={cn(
'bg-background text-muted-foreground inline-flex h-5 min-w-5 items-center justify-center rounded border px-1 font-sans text-[10px] font-medium shadow-xs [&_svg]:size-3',
className,
)}
{...props}
/>
);
}
function CommandPaletteShortcutKeys({ keys, label, className }: { keys: string[]; label?: string; className?: string }) {
return (
<span aria-label={label ?? keys.join(' then ')} className={cn('flex items-center gap-1', className)}>
{keys.map((key) => (
<CommandPaletteKbd key={key}>{key}</CommandPaletteKbd>
))}
</span>
);
}
export { CommandPalette, CommandPaletteKbd, CommandPaletteShortcutKeys, useCommandPaletteShortcut };Usage
import { CommandPalette, CommandPaletteKbd, CommandPaletteShortcutKeys, useCommandPaletteShortcut } from "@/components/ui/command-palette"Examples
Inline
import { CalendarPlus, FlaskConical, UserPlus } from "lucide-react"
import { CommandPalette } from "@/registry/vcare/ui/command-palette"
export default function CommandPaletteInline() {
return (
<CommandPalette
variant="inline"
className="mx-auto max-w-md"
groups={[
{
heading: "Quick actions",
items: [
{ id: "patient", label: "New patient", icon: <UserPlus /> },
{ id: "appt", label: "New appointment", icon: <CalendarPlus /> },
{ id: "lab", label: "New lab visit", icon: <FlaskConical /> },
],
},
]}
/>
)
}Exports
CommandPalette, CommandPaletteKbd, CommandPaletteShortcutKeys, useCommandPaletteShortcut
Dependencies
lucide-react@^1.80.0(npm)@vcare/command(registry)@vcare/utils(registry)
Raw item: /r/command-palette.json