Uecko_ERP/packages/shadcn-ui/src/components/command.tsx

194 lines
4.9 KiB
TypeScript
Raw Normal View History

2025-10-21 09:30:45 +00:00
import * as React from "react"
import { Command as CommandPrimitive } from "cmdk"
2025-05-05 17:11:44 +00:00
2025-10-21 09:30:45 +00:00
import { cn } from "@repo/shadcn-ui/lib/utils"
2025-05-05 17:11:44 +00:00
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
2025-10-21 09:30:45 +00:00
} from "@repo/shadcn-ui/components/dialog"
2026-03-17 17:49:54 +00:00
import {
InputGroup,
InputGroupAddon,
} from "@repo/shadcn-ui/components/input-group"
import { SearchIcon, CheckIcon } from "lucide-react"
2025-05-05 17:11:44 +00:00
2025-10-21 09:30:45 +00:00
function Command({
className,
...props
}: React.ComponentProps<typeof CommandPrimitive>) {
2025-05-05 17:11:44 +00:00
return (
<CommandPrimitive
2025-10-21 09:30:45 +00:00
data-slot="command"
2025-05-05 17:11:44 +00:00
className={cn(
2026-03-17 17:49:54 +00:00
"flex size-full flex-col overflow-hidden rounded-xl! bg-popover p-1 text-popover-foreground",
2025-05-05 17:11:44 +00:00
className
)}
{...props}
/>
2025-10-21 09:30:45 +00:00
)
2025-05-05 17:11:44 +00:00
}
function CommandDialog({
title = "Command Palette",
description = "Search for a command to run...",
children,
2025-10-21 09:30:45 +00:00
className,
2026-03-17 17:49:54 +00:00
showCloseButton = false,
2025-05-05 17:11:44 +00:00
...props
}: React.ComponentProps<typeof Dialog> & {
2025-10-21 09:30:45 +00:00
title?: string
description?: string
className?: string
showCloseButton?: boolean
2025-05-05 17:11:44 +00:00
}) {
return (
<Dialog {...props}>
2025-10-21 09:30:45 +00:00
<DialogHeader className="sr-only">
2025-05-05 17:11:44 +00:00
<DialogTitle>{title}</DialogTitle>
<DialogDescription>{description}</DialogDescription>
</DialogHeader>
2025-10-21 09:30:45 +00:00
<DialogContent
2026-03-17 17:49:54 +00:00
className={cn(
"top-1/3 translate-y-0 overflow-hidden rounded-xl! p-0",
className
)}
2025-10-21 09:30:45 +00:00
showCloseButton={showCloseButton}
>
2026-03-17 17:49:54 +00:00
{children}
2025-05-05 17:11:44 +00:00
</DialogContent>
</Dialog>
2025-10-21 09:30:45 +00:00
)
2025-05-05 17:11:44 +00:00
}
function CommandInput({
className,
...props
}: React.ComponentProps<typeof CommandPrimitive.Input>) {
return (
2026-03-17 17:49:54 +00:00
<div data-slot="command-input-wrapper" className="p-1 pb-0">
<InputGroup className="h-8! rounded-lg! border-input/30 bg-input/30 shadow-none! *:data-[slot=input-group-addon]:pl-2!">
<CommandPrimitive.Input
data-slot="command-input"
className={cn(
"w-full text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50",
className
)}
{...props}
/>
<InputGroupAddon>
<SearchIcon className="size-4 shrink-0 opacity-50" />
</InputGroupAddon>
</InputGroup>
2025-05-05 17:11:44 +00:00
</div>
2025-10-21 09:30:45 +00:00
)
2025-05-05 17:11:44 +00:00
}
2025-10-21 09:30:45 +00:00
function CommandList({
className,
...props
}: React.ComponentProps<typeof CommandPrimitive.List>) {
2025-05-05 17:11:44 +00:00
return (
<CommandPrimitive.List
2025-10-21 09:30:45 +00:00
data-slot="command-list"
className={cn(
2026-03-17 17:49:54 +00:00
"no-scrollbar max-h-72 scroll-py-1 overflow-x-hidden overflow-y-auto outline-none",
2025-10-21 09:30:45 +00:00
className
)}
2025-05-05 17:11:44 +00:00
{...props}
/>
2025-10-21 09:30:45 +00:00
)
2025-05-05 17:11:44 +00:00
}
2025-10-21 09:30:45 +00:00
function CommandEmpty({
2026-03-17 17:49:54 +00:00
className,
2025-10-21 09:30:45 +00:00
...props
}: React.ComponentProps<typeof CommandPrimitive.Empty>) {
2025-05-05 17:11:44 +00:00
return (
<CommandPrimitive.Empty
2025-10-21 09:30:45 +00:00
data-slot="command-empty"
2026-03-17 17:49:54 +00:00
className={cn("py-6 text-center text-sm", className)}
2025-05-05 17:11:44 +00:00
{...props}
/>
2025-10-21 09:30:45 +00:00
)
2025-05-05 17:11:44 +00:00
}
function CommandGroup({
className,
...props
}: React.ComponentProps<typeof CommandPrimitive.Group>) {
return (
<CommandPrimitive.Group
2025-10-21 09:30:45 +00:00
data-slot="command-group"
2025-05-05 17:11:44 +00:00
className={cn(
2026-03-17 17:49:54 +00:00
"overflow-hidden p-1 text-foreground **:[[cmdk-group-heading]]:px-2 **:[[cmdk-group-heading]]:py-1.5 **:[[cmdk-group-heading]]:text-xs **:[[cmdk-group-heading]]:font-medium **:[[cmdk-group-heading]]:text-muted-foreground",
2025-05-05 17:11:44 +00:00
className
)}
{...props}
/>
2025-10-21 09:30:45 +00:00
)
2025-05-05 17:11:44 +00:00
}
function CommandSeparator({
className,
...props
}: React.ComponentProps<typeof CommandPrimitive.Separator>) {
return (
<CommandPrimitive.Separator
2025-10-21 09:30:45 +00:00
data-slot="command-separator"
2026-03-17 17:49:54 +00:00
className={cn("-mx-1 h-px bg-border", className)}
2025-05-05 17:11:44 +00:00
{...props}
/>
2025-10-21 09:30:45 +00:00
)
2025-05-05 17:11:44 +00:00
}
2025-10-21 09:30:45 +00:00
function CommandItem({
className,
2026-03-17 17:49:54 +00:00
children,
2025-10-21 09:30:45 +00:00
...props
}: React.ComponentProps<typeof CommandPrimitive.Item>) {
2025-05-05 17:11:44 +00:00
return (
<CommandPrimitive.Item
2025-10-21 09:30:45 +00:00
data-slot="command-item"
2025-05-05 17:11:44 +00:00
className={cn(
2026-03-17 17:49:54 +00:00
"group/command-item relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none in-data-[slot=dialog-content]:rounded-lg! data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 data-selected:bg-muted data-selected:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-selected:*:[svg]:text-foreground",
2025-05-05 17:11:44 +00:00
className
)}
{...props}
2026-03-17 17:49:54 +00:00
>
{children}
<CheckIcon className="ml-auto opacity-0 group-has-data-[slot=command-shortcut]/command-item:hidden group-data-[checked=true]/command-item:opacity-100" />
</CommandPrimitive.Item>
2025-10-21 09:30:45 +00:00
)
2025-05-05 17:11:44 +00:00
}
2025-10-21 09:30:45 +00:00
function CommandShortcut({
className,
...props
}: React.ComponentProps<"span">) {
2025-05-05 17:11:44 +00:00
return (
<span
2025-10-21 09:30:45 +00:00
data-slot="command-shortcut"
className={cn(
2026-03-17 17:49:54 +00:00
"ml-auto text-xs tracking-widest text-muted-foreground group-data-selected/command-item:text-foreground",
2025-10-21 09:30:45 +00:00
className
)}
2025-05-05 17:11:44 +00:00
{...props}
/>
2025-10-21 09:30:45 +00:00
)
2025-05-05 17:11:44 +00:00
}
export {
Command,
CommandDialog,
2025-10-21 09:30:45 +00:00
CommandInput,
CommandList,
2025-05-05 17:11:44 +00:00
CommandEmpty,
CommandGroup,
CommandItem,
2025-07-17 08:50:28 +00:00
CommandShortcut,
2025-10-21 09:30:45 +00:00
CommandSeparator,
}