MarkdownContent.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { motion } from 'framer-motion'
  2. import { useEffect, useState } from 'react'
  3. import { cn } from 'ui'
  4. import { Markdown } from '@/components/interfaces/Markdown'
  5. const CHAR_LIMIT = 500 // Adjust this number as needed
  6. export const MarkdownContent = ({
  7. integrationId,
  8. initiallyExpanded,
  9. }: {
  10. integrationId: string
  11. initiallyExpanded?: boolean
  12. }) => {
  13. const [content, setContent] = useState<string>('')
  14. const [isExpanded, setIsExpanded] = useState(initiallyExpanded ?? false)
  15. useEffect(() => {
  16. import(`@/static-data/integrations/${integrationId}/overview.md`)
  17. .then((module) => setContent(String(module.default)))
  18. .catch((error) => console.error('Error loading markdown:', error))
  19. }, [integrationId])
  20. const displayContent = isExpanded ? content : content.slice(0, CHAR_LIMIT)
  21. const supportExpanding = content.length > CHAR_LIMIT || (content.match(/\n/g) || []).length > 1
  22. if (displayContent.length === 0) return null
  23. return (
  24. <div className="px-10">
  25. <div className="relative">
  26. <motion.div
  27. initial={false}
  28. animate={{ height: isExpanded ? 'auto' : 80 }}
  29. className="overflow-hidden"
  30. transition={{ duration: 0.4 }}
  31. >
  32. <Markdown content={displayContent} className="max-w-3xl!" />
  33. </motion.div>
  34. {!isExpanded && (
  35. <div
  36. className={cn(
  37. 'bottom-0 left-0 right-0 h-24',
  38. supportExpanding && 'bg-linear-to-t from-background-200 to-transparent',
  39. !isExpanded ? 'absolute' : 'relative'
  40. )}
  41. />
  42. )}
  43. {supportExpanding && (
  44. <div className={cn('bottom-0', !isExpanded ? 'absolute' : 'relative mt-3')}>
  45. <button
  46. className="text-foreground-light hover:text-foreground underline text-sm"
  47. onClick={() => setIsExpanded(!isExpanded)}
  48. >
  49. {isExpanded ? 'Show less' : 'Read more'}
  50. </button>
  51. </div>
  52. )}
  53. </div>
  54. </div>
  55. )
  56. }