Tool.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import type { PropsWithChildren, ReactNode } from 'react'
  2. import { cn, Collapsible, CollapsibleContent, CollapsibleTrigger } from 'ui'
  3. type ToolProps = PropsWithChildren<{
  4. className?: string
  5. label: ReactNode
  6. icon?: ReactNode
  7. }>
  8. export function Tool({ className, label, icon, children }: ToolProps) {
  9. const isCollapsible = !!children
  10. return (
  11. <div
  12. className={cn(
  13. 'tool-item text-foreground-lighter flex items-center gap-2 py-2',
  14. '[&:not(.tool-item+.tool-item)]:mt-4 [&:not(:has(+.tool-item))]:mb-4',
  15. '[&:has(+.tool-item)]:border-b [&:has(+.tool-item)]:border-b-muted',
  16. 'first:mt-0! last:mb-0',
  17. className
  18. )}
  19. >
  20. <Collapsible>
  21. <CollapsibleTrigger
  22. className={cn('flex items-center gap-2 w-full text-left')}
  23. disabled={!children}
  24. >
  25. {icon}
  26. {typeof label === 'string' ? (
  27. <span className="text-foreground-lighter">{label}</span>
  28. ) : (
  29. label
  30. )}
  31. </CollapsibleTrigger>
  32. {isCollapsible && (
  33. <CollapsibleContent
  34. className={cn('pl-6 py-2 text-xs leading-normal', 'max-h-64 overflow-y-auto')}
  35. >
  36. {children}
  37. </CollapsibleContent>
  38. )}
  39. </Collapsible>
  40. </div>
  41. )
  42. }
  43. Tool.displayName = 'Tool'