Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

4.3 KB
Raw Blame
/* eslint-disable @repo/no-style-props, @repo/no-margin-on-root-elements, @repo/component-file-structure */
"use client";

// Adapted command to be used as a form field with suggestions
// Find original shadcn/ui command component in /components/ui/command.tsx

import * as React from "react";
import { Command as CommandPrimitive } from "cmdk";
import { Search } from "@langfuse/icons";

import { cn } from "@/src/utils/tailwind";

const InputCommand = React.forwardRef<
  React.ComponentRef<typeof CommandPrimitive>,
  React.ComponentPropsWithoutRef<typeof CommandPrimitive>
>(({ className, ...props }, ref) => (
  <CommandPrimitive
    ref={ref}
    className={cn(
      "bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md",
      className,
    )}
    {...props}
  />
));
InputCommand.displayName = CommandPrimitive.displayName;

const InputCommandInput = React.forwardRef<
  React.ComponentRef<typeof CommandPrimitive.Input>,
  React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input> & {
    variant?: "default" | "bottom";
  }
>(({ className, variant = "default", ...props }, ref) => (
  <div
    className={cn(
      "flex items-center px-3",
      variant === "default" && "rounded border",
      variant === "bottom" && "border-b",
      "cmdk-input-wrapper",
    )}
  >
    <Search size="base" __rawClassName="mr-2 opacity-50" />
    <CommandPrimitive.Input
      ref={ref}
      className={cn(
        "placeholder:text-muted-foreground flex h-8 w-full rounded border-transparent bg-transparent py-3 font-mono text-xs outline-hidden focus:border-0 focus:border-none focus:border-transparent focus:ring-0 disabled:cursor-not-allowed disabled:opacity-50",
        className,
      )}
      {...props}
    />
  </div>
));

InputCommandInput.displayName = CommandPrimitive.Input.displayName;

const InputCommandList = React.forwardRef<
  React.ComponentRef<typeof CommandPrimitive.List>,
  React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>
>(({ className, ...props }, ref) => (
  <CommandPrimitive.List
    ref={ref}
    className={cn("max-h-[300px] overflow-x-hidden overflow-y-auto", className)}
    {...props}
  />
));

InputCommandList.displayName = CommandPrimitive.List.displayName;

const InputCommandEmpty = React.forwardRef<
  React.ComponentRef<typeof CommandPrimitive.Empty>,
  React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>
>((props, ref) => (
  <CommandPrimitive.Empty
    ref={ref}
    className="py-6 text-center text-sm"
    {...props}
  />
));

InputCommandEmpty.displayName = CommandPrimitive.Empty.displayName;

const InputCommandGroup = React.forwardRef<
  React.ComponentRef<typeof CommandPrimitive.Group>,
  React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>
>(({ className, ...props }, ref) => (
  <CommandPrimitive.Group
    ref={ref}
    className={cn(
      "text-foreground **:[[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 **:[[cmdk-group-heading]]:px-2 **:[[cmdk-group-heading]]:py-1.5 **:[[cmdk-group-heading]]:text-xs **:[[cmdk-group-heading]]:font-bold",
      className,
    )}
    {...props}
  />
));

InputCommandGroup.displayName = CommandPrimitive.Group.displayName;

const InputCommandSeparator = React.forwardRef<
  React.ComponentRef<typeof CommandPrimitive.Separator>,
  React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>
>(({ className, ...props }, ref) => (
  <CommandPrimitive.Separator
    ref={ref}
    className={cn("bg-border -mx-1 h-px", className)}
    {...props}
  />
));
InputCommandSeparator.displayName = CommandPrimitive.Separator.displayName;

const InputCommandItem = React.forwardRef<
  React.ComponentRef<typeof CommandPrimitive.Item>,
  React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>
>(({ className, ...props }, ref) => (
  <CommandPrimitive.Item
    ref={ref}
    className={cn(
      "aria-selected:bg-accent aria-selected:text-accent-foreground relative flex cursor-pointer items-center rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:cursor-not-allowed",
      className,
    )}
    {...props}
  />
));

InputCommandItem.displayName = CommandPrimitive.Item.displayName;

export {
  InputCommand,
  InputCommandInput,
  InputCommandList,
  InputCommandEmpty,
  InputCommandGroup,
  InputCommandItem,
  InputCommandSeparator,
};