Command
shadcn-lit-registry/commandFreeComponent
Fast, composable, unstyled command menu component. Features search/filtering, keyboard navigation, item grouping, and accessibility support. Based on the cmdk library pattern.
Install it
npx shadcn@latest add https://lit-registry.lloydrichards.dev/r/command.jsonSource
1import { css, html, LitElement, nothing, type PropertyValues } from "lit";2import { customElement, property, query, state } from "lit/decorators.js";3import { unsafeSVG } from "lit/directives/unsafe-svg.js";4import { Search } from "lucide-static";5import { TW } from "@/registry/lib/tailwindMixin";6import { cn } from "@/registry/lib/utils";78// Type definitions9export type FilterFunction = (10 value: string,11 search: string,12 keywords?: string[],13) => number;1415// Default filter function (similar to cmdk)16const defaultFilter: FilterFunction = (value, search, keywords = []) => {17 const searchLower = search.toLowerCase().trim();18 if (!searchLower) return 1;1920 const valueLower = value.toLowerCase();21 const keywordsLower = keywords.map((k) => k.toLowerCase());2223 // Exact match = highest score24 if (valueLower === searchLower) return 2;2526 // Starts with = high score27 if (valueLower.startsWith(searchLower)) return 1.5;2829 // Contains = medium score30 if (valueLower.includes(searchLower)) return 1;3132 // Check keywords33 for (const keyword of keywordsLower) {34 if (keyword.includes(searchLower)) return 0.8;35 }3637 return 0; // No match38};3940// Component properties interfaces41export interface CommandProperties {42 value?: string;43 filter?: FilterFunction;44 shouldFilter?: boolean;45 loop?: boolean;46 label?: string;47}4849export interface CommandInputProperties {50 value?: string;51 placeholder?: string;52}5354export interface CommandItemProperties {55 value?: string;56 keywords?: string[];57 disabled?: boolean;58 forceMount?: boolean;59}6061export interface CommandGroupProperties {62 heading?: string;63 forceMount?: boolean;64}6566// Helper type for items with internal state67export type CommandItemWithState = CommandItem & {68 _score: number;69 _highlighted: boolean;70};7172/**73 * Main Command component - root container74 */75@customElement("ui-command")76export class Command extends TW(LitElement) implements CommandProperties {77 static styles = css`78 :host {79 display: contents;80 }81 `;8283 @property({ type: String, reflect: true }) value = "";84 @property({ type: Boolean, attribute: "should-filter" }) shouldFilter = true;85 @property({ type: Boolean }) loop = false;86 @property({ type: String }) label = "Command Menu";87 @property({ attribute: false }) filter?: FilterFunction;8889 @state() private _search = "";90 @state() private _filteredCount = 0;91 @state() private _statusMessage = "";9293 // Store references to all items and groups for filtering94// … truncated
What it pulls in
npm packages
Files it writes
More from shadcn-lit-registry
All 26 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | shadcn-lit-registry | Components | Free | 1 dep · 2 files | |
| Avataravatar | shadcn-lit-registry | Components | Free | no deps · 2 files | |
| Badgebadge | shadcn-lit-registry | Components | Free | no deps · 2 files | |
| Buttonbutton | shadcn-lit-registry | Components | Free | 1 dep · 2 files | |
| Cardcard | shadcn-lit-registry | Components | Free | no deps · 2 files | |
| Checkboxcheckbox | shadcn-lit-registry | Components | Free | 1 dep · 2 files | |
| Collapsiblecollapsible | shadcn-lit-registry | Components | Free | 1 dep · 2 files | |
| Context Menucontext-menu | shadcn-lit-registry | Components | Free | 2 deps · 2 files |
