We don't really use all of these exports, but we made it so that className gets passed properly to `styles` when we do
146 lines
3.7 KiB
TypeScript
146 lines
3.7 KiB
TypeScript
import { forwardRef } from 'react'
|
|
import classNames from 'classnames'
|
|
|
|
import { Command as CommandPrimitive } from 'cmdk'
|
|
import { Dialog } from '../Dialog'
|
|
import { DialogContent, DialogProps } from '@radix-ui/react-dialog'
|
|
|
|
import styles from './index.module.scss'
|
|
|
|
const Command = forwardRef<
|
|
React.ElementRef<typeof CommandPrimitive>,
|
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive>
|
|
>(({ className, ...props }, ref) => (
|
|
<CommandPrimitive ref={ref} className={className} {...props} />
|
|
))
|
|
Command.displayName = CommandPrimitive.displayName
|
|
|
|
interface CommandDialogProps extends DialogProps {}
|
|
|
|
const CommandDialog = ({ children, ...props }: CommandDialogProps) => {
|
|
return (
|
|
<Dialog {...props}>
|
|
<DialogContent className={styles.dialogContent}>
|
|
<Command>{children}</Command>
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|
|
|
|
const CommandInput = forwardRef<
|
|
React.ElementRef<typeof CommandPrimitive.Input>,
|
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>
|
|
>(({ className, ...props }, ref) => (
|
|
<div>
|
|
<CommandPrimitive.Input
|
|
ref={ref}
|
|
className={classNames(
|
|
{ CommandInput: true },
|
|
className?.split(' ').map((c) => styles[c])
|
|
)}
|
|
{...props}
|
|
/>
|
|
</div>
|
|
))
|
|
|
|
CommandInput.displayName = CommandPrimitive.Input.displayName
|
|
|
|
const CommandList = forwardRef<
|
|
React.ElementRef<typeof CommandPrimitive.List>,
|
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>
|
|
>(({ className, ...props }, ref) => (
|
|
<CommandPrimitive.List
|
|
ref={ref}
|
|
className={classNames(
|
|
{ CommandList: true },
|
|
className?.split(' ').map((c) => styles[c])
|
|
)}
|
|
{...props}
|
|
/>
|
|
))
|
|
|
|
CommandList.displayName = CommandPrimitive.List.displayName
|
|
|
|
const CommandEmpty = forwardRef<
|
|
React.ElementRef<typeof CommandPrimitive.Empty>,
|
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>
|
|
>((props, ref) => (
|
|
<CommandPrimitive.Empty ref={ref} className={styles.empty} {...props} />
|
|
))
|
|
|
|
CommandEmpty.displayName = CommandPrimitive.Empty.displayName
|
|
|
|
const CommandGroup = forwardRef<
|
|
React.ElementRef<typeof CommandPrimitive.Group>,
|
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>
|
|
>(({ className, ...props }, ref) => (
|
|
<CommandPrimitive.Group
|
|
ref={ref}
|
|
className={classNames(
|
|
{ CommandGroup: true },
|
|
className?.split(' ').map((c) => styles[c])
|
|
)}
|
|
{...props}
|
|
/>
|
|
))
|
|
|
|
CommandGroup.displayName = CommandPrimitive.Group.displayName
|
|
|
|
const CommandSeparator = forwardRef<
|
|
React.ElementRef<typeof CommandPrimitive.Separator>,
|
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>
|
|
>(({ className, ...props }, ref) => (
|
|
<CommandPrimitive.Separator
|
|
ref={ref}
|
|
className={classNames(
|
|
{ CommandSeparator: true },
|
|
className?.split(' ').map((c) => styles[c])
|
|
)}
|
|
{...props}
|
|
/>
|
|
))
|
|
CommandSeparator.displayName = CommandPrimitive.Separator.displayName
|
|
|
|
const CommandItem = forwardRef<
|
|
React.ElementRef<typeof CommandPrimitive.Item>,
|
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>
|
|
>(({ className, ...props }, ref) => (
|
|
<CommandPrimitive.Item
|
|
ref={ref}
|
|
className={classNames(
|
|
{ CommandItem: true },
|
|
className?.split(' ').map((c) => styles[c])
|
|
)}
|
|
{...props}
|
|
/>
|
|
))
|
|
|
|
CommandItem.displayName = CommandPrimitive.Item.displayName
|
|
|
|
const CommandShortcut = ({
|
|
className,
|
|
...props
|
|
}: React.HTMLAttributes<HTMLSpanElement>) => {
|
|
return (
|
|
<span
|
|
className={classNames(
|
|
{ CommandShortcut: true },
|
|
className?.split(' ').map((c) => styles[c])
|
|
)}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
CommandShortcut.displayName = 'CommandShortcut'
|
|
|
|
export {
|
|
Command,
|
|
CommandDialog,
|
|
CommandInput,
|
|
CommandList,
|
|
CommandEmpty,
|
|
CommandGroup,
|
|
CommandItem,
|
|
CommandShortcut,
|
|
CommandSeparator,
|
|
}
|