70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
import type { HTMLAttributes, InputHTMLAttributes } from "react";
|
|
import { forwardRef } from "react";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
export interface CommandProps extends HTMLAttributes<HTMLDivElement> {
|
|
shouldFilter?: boolean;
|
|
}
|
|
|
|
export function Command({ className, shouldFilter, ...props }: CommandProps) {
|
|
return <div data-should-filter={shouldFilter} className={cn(className)} {...props} />;
|
|
}
|
|
|
|
export interface CommandInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "onValueChange"> {
|
|
onValueChange?: (value: string) => void;
|
|
}
|
|
|
|
export function CommandInput({ className, onValueChange, onChange, ...props }: CommandInputProps) {
|
|
return (
|
|
<input
|
|
className={cn(className)}
|
|
onChange={(e) => {
|
|
onValueChange?.(e.target.value);
|
|
onChange?.(e);
|
|
}}
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export const CommandList = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
|
|
function CommandList({ className, ...props }, ref) {
|
|
return <div ref={ref} className={cn(className)} {...props} />;
|
|
},
|
|
);
|
|
|
|
export function CommandEmpty({ className, ...props }: HTMLAttributes<HTMLDivElement>) {
|
|
return <div className={cn(className)} {...props} />;
|
|
}
|
|
|
|
export interface CommandGroupProps extends HTMLAttributes<HTMLDivElement> {
|
|
heading?: string;
|
|
}
|
|
|
|
export function CommandGroup({ className, heading, ...props }: CommandGroupProps) {
|
|
return <div data-heading={heading} className={cn(className)} {...props} />;
|
|
}
|
|
|
|
export interface CommandItemProps extends Omit<HTMLAttributes<HTMLDivElement>, "onSelect"> {
|
|
value?: string;
|
|
disabled?: boolean;
|
|
onSelect?: (value: string) => void;
|
|
}
|
|
|
|
export function CommandItem({ className, value, disabled, onSelect, ...props }: CommandItemProps) {
|
|
return (
|
|
<div
|
|
role="option"
|
|
data-value={value}
|
|
aria-disabled={disabled}
|
|
onClick={() => !disabled && onSelect?.(value ?? "")}
|
|
className={cn(className)}
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export function CommandSeparator({ className, ...props }: HTMLAttributes<HTMLDivElement>) {
|
|
return <div role="separator" className={cn(className)} {...props} />;
|
|
}
|