2025-08-28 18:27:07 +02:00
|
|
|
import { Command as CommandPrimitive } from "cmdk";
|
|
|
|
|
import { SearchIcon } from "lucide-react";
|
|
|
|
|
import type * as React from "react";
|
2025-08-04 17:45:44 +02:00
|
|
|
import {
|
2025-08-28 18:27:07 +02:00
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogDescription,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
} from "~/components/ui/dialog";
|
|
|
|
|
import { cn } from "~/lib/utils";
|
2025-08-04 17:45:44 +02:00
|
|
|
|
|
|
|
|
function Command({
|
2025-08-28 18:27:07 +02:00
|
|
|
className,
|
|
|
|
|
...props
|
2025-08-04 17:45:44 +02:00
|
|
|
}: React.ComponentProps<typeof CommandPrimitive>) {
|
2025-08-28 18:27:07 +02:00
|
|
|
return (
|
|
|
|
|
<CommandPrimitive
|
|
|
|
|
className={cn(
|
2025-10-10 16:18:43 +02:00
|
|
|
"flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
|
2025-08-28 18:27:07 +02:00
|
|
|
className,
|
|
|
|
|
)}
|
2025-08-29 16:18:32 +02:00
|
|
|
data-slot="command"
|
2025-08-28 18:27:07 +02:00
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CommandDialog({
|
2025-08-28 18:27:07 +02:00
|
|
|
title = "Command Palette",
|
|
|
|
|
description = "Search for a command to run...",
|
|
|
|
|
children,
|
|
|
|
|
className,
|
|
|
|
|
showCloseButton = true,
|
|
|
|
|
...props
|
2025-08-04 17:45:44 +02:00
|
|
|
}: React.ComponentProps<typeof Dialog> & {
|
2025-08-28 18:27:07 +02:00
|
|
|
title?: string;
|
|
|
|
|
description?: string;
|
|
|
|
|
className?: string;
|
|
|
|
|
showCloseButton?: boolean;
|
2025-08-04 17:45:44 +02:00
|
|
|
}) {
|
2025-08-28 18:27:07 +02:00
|
|
|
return (
|
|
|
|
|
<Dialog {...props}>
|
|
|
|
|
<DialogHeader className="sr-only">
|
|
|
|
|
<DialogTitle>{title}</DialogTitle>
|
|
|
|
|
<DialogDescription>{description}</DialogDescription>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
<DialogContent
|
|
|
|
|
className={cn("overflow-hidden p-0", className)}
|
|
|
|
|
showCloseButton={showCloseButton}
|
|
|
|
|
>
|
2025-10-10 16:18:43 +02:00
|
|
|
<Command className="**:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">
|
2025-08-28 18:27:07 +02:00
|
|
|
{children}
|
|
|
|
|
</Command>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CommandInput({
|
2025-08-28 18:27:07 +02:00
|
|
|
className,
|
|
|
|
|
...props
|
2025-08-04 17:45:44 +02:00
|
|
|
}: React.ComponentProps<typeof CommandPrimitive.Input>) {
|
2025-08-28 18:27:07 +02:00
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className="flex h-9 items-center gap-2 border-b px-3"
|
2025-08-29 16:18:32 +02:00
|
|
|
data-slot="command-input-wrapper"
|
2025-08-28 18:27:07 +02:00
|
|
|
>
|
|
|
|
|
<SearchIcon className="size-4 shrink-0 opacity-50" />
|
|
|
|
|
<CommandPrimitive.Input
|
|
|
|
|
className={cn(
|
2025-10-10 16:18:43 +02:00
|
|
|
"flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
|
2025-08-28 18:27:07 +02:00
|
|
|
className,
|
|
|
|
|
)}
|
2025-08-29 16:18:32 +02:00
|
|
|
data-slot="command-input"
|
2025-08-28 18:27:07 +02:00
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CommandList({
|
2025-08-28 18:27:07 +02:00
|
|
|
className,
|
|
|
|
|
...props
|
2025-08-04 17:45:44 +02:00
|
|
|
}: React.ComponentProps<typeof CommandPrimitive.List>) {
|
2025-08-28 18:27:07 +02:00
|
|
|
return (
|
|
|
|
|
<CommandPrimitive.List
|
|
|
|
|
className={cn(
|
2025-10-10 16:18:43 +02:00
|
|
|
"max-h-[300px] scroll-py-1 overflow-y-auto overflow-x-hidden",
|
2025-08-28 18:27:07 +02:00
|
|
|
className,
|
|
|
|
|
)}
|
2025-08-29 16:18:32 +02:00
|
|
|
data-slot="command-list"
|
2025-08-28 18:27:07 +02:00
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CommandEmpty({
|
2025-08-28 18:27:07 +02:00
|
|
|
...props
|
2025-08-04 17:45:44 +02:00
|
|
|
}: React.ComponentProps<typeof CommandPrimitive.Empty>) {
|
2025-08-28 18:27:07 +02:00
|
|
|
return (
|
|
|
|
|
<CommandPrimitive.Empty
|
|
|
|
|
className="py-6 text-center text-sm"
|
2025-08-29 16:18:32 +02:00
|
|
|
data-slot="command-empty"
|
2025-08-28 18:27:07 +02:00
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CommandGroup({
|
2025-08-28 18:27:07 +02:00
|
|
|
className,
|
|
|
|
|
...props
|
2025-08-04 17:45:44 +02:00
|
|
|
}: React.ComponentProps<typeof CommandPrimitive.Group>) {
|
2025-08-28 18:27:07 +02:00
|
|
|
return (
|
|
|
|
|
<CommandPrimitive.Group
|
|
|
|
|
className={cn(
|
2025-10-10 16:18:43 +02:00
|
|
|
"overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:text-xs",
|
2025-08-28 18:27:07 +02:00
|
|
|
className,
|
|
|
|
|
)}
|
2025-08-29 16:18:32 +02:00
|
|
|
data-slot="command-group"
|
2025-08-28 18:27:07 +02:00
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CommandSeparator({
|
2025-08-28 18:27:07 +02:00
|
|
|
className,
|
|
|
|
|
...props
|
2025-08-04 17:45:44 +02:00
|
|
|
}: React.ComponentProps<typeof CommandPrimitive.Separator>) {
|
2025-08-28 18:27:07 +02:00
|
|
|
return (
|
|
|
|
|
<CommandPrimitive.Separator
|
2025-10-10 16:18:43 +02:00
|
|
|
className={cn("-mx-1 h-px bg-border", className)}
|
2025-08-29 16:18:32 +02:00
|
|
|
data-slot="command-separator"
|
2025-08-28 18:27:07 +02:00
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CommandItem({
|
2025-08-28 18:27:07 +02:00
|
|
|
className,
|
|
|
|
|
...props
|
2025-08-04 17:45:44 +02:00
|
|
|
}: React.ComponentProps<typeof CommandPrimitive.Item>) {
|
2025-08-28 18:27:07 +02:00
|
|
|
return (
|
|
|
|
|
<CommandPrimitive.Item
|
|
|
|
|
className={cn(
|
2025-10-10 16:18:43 +02:00
|
|
|
"relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden data-[disabled=true]:pointer-events-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
2025-08-28 18:27:07 +02:00
|
|
|
className,
|
|
|
|
|
)}
|
2025-08-29 16:18:32 +02:00
|
|
|
data-slot="command-item"
|
2025-08-28 18:27:07 +02:00
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CommandShortcut({
|
2025-08-28 18:27:07 +02:00
|
|
|
className,
|
|
|
|
|
...props
|
2025-08-04 17:45:44 +02:00
|
|
|
}: React.ComponentProps<"span">) {
|
2025-08-28 18:27:07 +02:00
|
|
|
return (
|
|
|
|
|
<span
|
|
|
|
|
className={cn(
|
2025-10-10 16:18:43 +02:00
|
|
|
"ml-auto text-muted-foreground text-xs tracking-widest",
|
2025-08-28 18:27:07 +02:00
|
|
|
className,
|
|
|
|
|
)}
|
2025-08-29 16:18:32 +02:00
|
|
|
data-slot="command-shortcut"
|
2025-08-28 18:27:07 +02:00
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export {
|
2025-08-28 18:27:07 +02:00
|
|
|
Command,
|
|
|
|
|
CommandDialog,
|
|
|
|
|
CommandInput,
|
|
|
|
|
CommandList,
|
|
|
|
|
CommandEmpty,
|
|
|
|
|
CommandGroup,
|
|
|
|
|
CommandItem,
|
|
|
|
|
CommandShortcut,
|
|
|
|
|
CommandSeparator,
|
|
|
|
|
};
|