sources.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use client';
  2. import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible';
  3. import { cn } from '@/lib/utils';
  4. import { BookIcon, ChevronDownIcon } from 'lucide-react';
  5. import type { ComponentProps } from 'react';
  6. export type SourcesProps = ComponentProps<'div'>;
  7. export const Sources = ({ className, ...props }: SourcesProps) => (
  8. <Collapsible className={cn('not-prose mb-4 text-primary text-xs', className)} {...props} />
  9. );
  10. export type SourcesTriggerProps = ComponentProps<typeof CollapsibleTrigger> & {
  11. count: number;
  12. };
  13. export const SourcesTrigger = ({ className, count, children, ...props }: SourcesTriggerProps) => (
  14. <CollapsibleTrigger className={cn('flex items-center gap-2', className)} {...props}>
  15. {children ?? (
  16. <>
  17. <p className="font-medium">Used {count} sources</p>
  18. <ChevronDownIcon className="h-4 w-4" />
  19. </>
  20. )}
  21. </CollapsibleTrigger>
  22. );
  23. export type SourcesContentProps = ComponentProps<typeof CollapsibleContent>;
  24. export const SourcesContent = ({ className, ...props }: SourcesContentProps) => (
  25. <CollapsibleContent
  26. className={cn(
  27. 'mt-3 flex w-fit flex-col gap-2',
  28. 'data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 outline-none data-[state=closed]:animate-out data-[state=open]:animate-in',
  29. className,
  30. )}
  31. {...props}
  32. />
  33. );
  34. export type SourceProps = ComponentProps<'a'>;
  35. export const Source = ({ href, title, children, ...props }: SourceProps) => (
  36. <a className="flex items-center gap-2" href={href} rel="noreferrer" target="_blank" {...props}>
  37. {children ?? (
  38. <>
  39. <BookIcon className="h-4 w-4" />
  40. <span className="block font-medium">{title}</span>
  41. </>
  42. )}
  43. </a>
  44. );