suggestion.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use client';
  2. import { Button } from '@/components/ui/button';
  3. import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area';
  4. import { cn } from '@/lib/utils';
  5. import type { ComponentProps } from 'react';
  6. export type SuggestionsProps = ComponentProps<typeof ScrollArea>;
  7. export const Suggestions = ({ className, children, ...props }: SuggestionsProps) => (
  8. <ScrollArea className="w-full overflow-x-auto whitespace-nowrap" {...props}>
  9. <div className={cn('flex w-max flex-nowrap items-center gap-2', className)}>{children}</div>
  10. <ScrollBar className="hidden" orientation="horizontal" />
  11. </ScrollArea>
  12. );
  13. export type SuggestionProps = Omit<ComponentProps<typeof Button>, 'onClick'> & {
  14. suggestion: string;
  15. onClick?: (suggestion: string) => void;
  16. };
  17. export const Suggestion = ({
  18. suggestion,
  19. onClick,
  20. className,
  21. variant = 'outline',
  22. size = 'sm',
  23. children,
  24. ...props
  25. }: SuggestionProps) => {
  26. const handleClick = () => {
  27. onClick?.(suggestion);
  28. };
  29. return (
  30. <Button
  31. className={cn('cursor-pointer rounded-full px-4', className)}
  32. onClick={handleClick}
  33. size={size}
  34. type="button"
  35. variant={variant}
  36. {...props}
  37. >
  38. {children || suggestion}
  39. </Button>
  40. );
  41. };