DocsLink.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { type DocsSearchResult as Page, type DocsSearchResultSection as PageSection } from 'common'
  2. import { ChevronRight } from 'lucide-react'
  3. import Link from 'next/link'
  4. import { cn } from 'ui'
  5. import { TextHighlighterBase as TextHighlighter } from 'ui-patterns/CommandMenu'
  6. import { formatSectionUrl, generateLink, getPageIcon } from './SupportForm.utils'
  7. const cardBaseClasses =
  8. 'bg-200 rounded-lg hover:bg-surface-200 p-3 transition-colors hover:border-overlay hover:shadow-xs flex items-center justify-between'
  9. interface DocsLinkGroup {
  10. page: Page
  11. }
  12. export const DocsLinkGroup = ({ page }: DocsLinkGroup) => {
  13. const link = generateLink(page.type, page.path)
  14. return (
  15. <ul key={page.id} className="grid gap-2">
  16. <li key={`${page.path}-group`} className="px-2">
  17. <Link
  18. target="_blank"
  19. rel="noreferrer"
  20. href={link}
  21. className={cn(cardBaseClasses, 'flex items-center justify-between pr-5')}
  22. >
  23. <div className="grow flex gap-3 items-center">
  24. <div>{getPageIcon(page)}</div>
  25. <div className="flex flex-col gap-0 pr-6">
  26. <span className="text-sm">
  27. <TextHighlighter text={page.title} query="test" />
  28. </span>
  29. {(page.description || page.subtitle) && (
  30. <div className="text-xs text">
  31. <TextHighlighter text={page.description || page.subtitle || ''} query="test" />
  32. </div>
  33. )}
  34. </div>
  35. </div>
  36. <ChevronRight size={18} />
  37. </Link>
  38. {page.sections.length > 0 && (
  39. <ul className="border-l border-default ml-3 pt-3 grid gap-2">
  40. {page.sections.map((section: PageSection, i) => (
  41. <DocsLinkSection
  42. key={`${page.path}__${section.heading}-item-${i}`}
  43. page={page}
  44. section={section}
  45. />
  46. ))}
  47. </ul>
  48. )}
  49. </li>
  50. </ul>
  51. )
  52. }
  53. interface DocsLinkSection {
  54. page: Page
  55. section: PageSection
  56. }
  57. const DocsLinkSection = ({ page, section }: DocsLinkSection) => {
  58. const sectionLink = formatSectionUrl(page, section)
  59. return (
  60. <ul key={`${section.heading}-group`} className="grid gap-2">
  61. <li key={`${section.heading}-item`} className="p-2 mb-2">
  62. <Link target="_blank" href={sectionLink} className={cn(cardBaseClasses)}>
  63. <div className="grow flex gap-3 items-center">
  64. <div>{getPageIcon(page)}</div>
  65. <div className="grid gap-1.5">
  66. {page.type !== 'github-discussions' && (
  67. <span>
  68. <TextHighlighter
  69. className="not-italic text-xs rounded-full px-3 py-1 bg-surface-300 "
  70. text={section.heading}
  71. query="test"
  72. />
  73. </span>
  74. )}
  75. {section.heading && (
  76. <div className="text text-xs ">
  77. <TextHighlighter text={section.heading} query="test" />
  78. </div>
  79. )}
  80. </div>
  81. </div>
  82. <ChevronRight size={18} />
  83. </Link>
  84. </li>
  85. </ul>
  86. )
  87. }