'use client' import { Slot } from '@radix-ui/react-slot' import { IconCircle, IconSearch } from '@tabler/icons-react' import * as CommandPrimitive from 'cmdk' import { forwardRef } from 'react' import { tv } from 'tailwind-variants' import type { Merge } from 'type-fest' const command = tv({ slots: { root: 'flex h-full w-full flex-col overflow-hidden rounded-md', input: [ 'h-10 w-full text-sm outline-none bg-transparent', 'placeholder:text-fg-weaker', 'disabled:cursor-not-allowed disabled:opacity-50', ], inputWrapper: 'flex items-center border-b px-3', inputIcon: 'mr-2 size-4 shrink-0 text-fg-weaker', list: 'overflow-y-auto overflow-x-hidden', empty: 'py-6 text-center text-sm text-fg-weaker', group: [ 'overflow-hidden p-1', '[&_[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-fg-weaker', ], separator: '-mx-1 h-px bg-border', item: [ 'relative flex cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none', 'transition aria-selected:bg-bg--active', 'data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50', ], itemLeftIcon: 'size-[1.125rem] mr-2', itemShortcut: 'ml-auto text-xs tracking-widest text-fg-weaker', }, }) const CommandRoot = forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >((props, ref) => { const { root } = command() return ( ) }) CommandRoot.displayName = CommandPrimitive.Command.displayName const CommandInput = forwardRef< React.ElementRef, Merge< React.ComponentPropsWithoutRef, { wrapperProps?: React.ComponentProps<'div'> iconProps?: React.ComponentProps } > >(({ wrapperProps, iconProps, ...props }, ref) => { const { input, inputWrapper, inputIcon } = command() return (
) }) CommandInput.displayName = CommandPrimitive.Command.Input.displayName const CommandList = forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >((props, ref) => { const { list } = command() return ( ) }) CommandList.displayName = CommandPrimitive.Command.displayName const CommandEmpty = forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >((props, ref) => { const { empty } = command() return ( ) }) CommandEmpty.displayName = CommandPrimitive.Command.Empty.displayName const CommandGroup = forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >((props, ref) => { const { group } = command() return ( ) }) CommandGroup.displayName = CommandPrimitive.Command.Group.displayName const CommandSeparator = forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >((props, ref) => { const { separator } = command() return ( ) }) CommandSeparator.displayName = CommandPrimitive.Command.Separator.displayName const CommandItem = forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >((props, ref) => { const { item } = command() return ( ) }) CommandItem.displayName = CommandPrimitive.Command.Item.displayName const CommandItemLeftIcon = forwardRef< React.ComponentRef, React.ComponentPropsWithoutRef >((props, ref) => { const { itemLeftIcon } = command() return ( )} ref={ref as React.ForwardedRef} className={itemLeftIcon({ className: props.className })} > {props.children ?? } ) }) CommandItemLeftIcon.displayName = 'CommandItemLeftIcon' const CommandItemShortcut = forwardRef>( (props, ref) => { const { itemShortcut } = command() return }, ) CommandItemShortcut.displayName = 'CommandItemShortcut' const Command = Object.assign(CommandRoot, { Input: CommandInput, List: CommandList, Empty: CommandEmpty, Separator: CommandSeparator, Group: CommandGroup, Item: Object.assign(CommandItem, { LeftIcon: CommandItemLeftIcon, Shortcut: CommandItemShortcut, }), }) export default Command export { command, CommandPrimitive }