pdf-log-entry-content.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { useTranslation } from 'react-i18next'
  2. import PdfLogEntryRawContent from './pdf-log-entry-raw-content'
  3. import importOverleafModules from '../../../../macros/import-overleaf-module.macro'
  4. import { LogEntry } from '../util/types'
  5. import { ElementType } from 'react'
  6. import classNames from 'classnames'
  7. const pdfLogEntryComponents = importOverleafModules(
  8. 'pdfLogEntryComponents'
  9. ) as {
  10. import: { default: ElementType }
  11. path: string
  12. }[]
  13. export default function PdfLogEntryContent({
  14. rawContent,
  15. formattedContent,
  16. extraInfoURL,
  17. index,
  18. logEntry,
  19. alwaysExpandRawContent = false,
  20. className,
  21. }: {
  22. rawContent?: string
  23. formattedContent?: React.ReactNode
  24. extraInfoURL?: string | null
  25. index?: number
  26. logEntry?: LogEntry
  27. alwaysExpandRawContent?: boolean
  28. className?: string
  29. }) {
  30. const { t } = useTranslation()
  31. return (
  32. <div className={classNames('log-entry-content', className)}>
  33. {formattedContent && (
  34. <div className="log-entry-formatted-content">{formattedContent}</div>
  35. )}
  36. {extraInfoURL && (
  37. <div className="log-entry-content-link">
  38. <a href={extraInfoURL} target="_blank" rel="noopener">
  39. {t('log_hint_extra_info')}
  40. </a>
  41. </div>
  42. )}
  43. {logEntry &&
  44. pdfLogEntryComponents.map(
  45. ({ import: { default: Component }, path }) => (
  46. <Component key={path} index={index} logEntry={logEntry} />
  47. )
  48. )}
  49. {rawContent && (
  50. <PdfLogEntryRawContent
  51. rawContent={rawContent}
  52. collapsedSize={150}
  53. alwaysExpanded={alwaysExpandRawContent}
  54. />
  55. )}
  56. </div>
  57. )
  58. }