ds-nav-page-switcher.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { useTranslation } from 'react-i18next'
  2. import { BookBookmark, Folder } from '@phosphor-icons/react'
  3. import { useActiveOverallTheme } from '@/shared/hooks/use-active-overall-theme'
  4. import getMeta from '@/utils/meta'
  5. import overleafLogo from '@/shared/svgs/overleaf-a-ds-solution-mallard.svg'
  6. import overleafLogoDark from '@/shared/svgs/overleaf-a-ds-solution-mallard-dark.svg'
  7. type ActivePage = 'library' | 'projects'
  8. export function DsNavPageSwitcher({
  9. activePage,
  10. showLogo = true,
  11. onLibraryClick,
  12. onProjectsClick,
  13. }: {
  14. activePage: ActivePage
  15. showLogo?: boolean
  16. onLibraryClick?: React.MouseEventHandler
  17. onProjectsClick?: React.MouseEventHandler
  18. }) {
  19. const { t } = useTranslation()
  20. const appName = getMeta('ol-ExposedSettings')?.appName ?? 'Overleaf'
  21. const activeOverallTheme = useActiveOverallTheme()
  22. return (
  23. <>
  24. {showLogo && (
  25. <div className="ds-nav-page-switcher-logo">
  26. <a href="/" aria-label={appName}>
  27. <img
  28. src={
  29. activeOverallTheme === 'dark' ? overleafLogoDark : overleafLogo
  30. }
  31. alt="Overleaf, A Digital Science Solution"
  32. height="59"
  33. width="130"
  34. />
  35. </a>
  36. </div>
  37. )}
  38. <ul
  39. className={`list-unstyled ds-nav-page-switcher-items${!showLogo ? ' ds-nav-page-switcher-items--no-logo' : ''}`}
  40. >
  41. <li>
  42. <a
  43. href="/library"
  44. className={`ds-nav-page-switcher-item${activePage === 'library' ? ' active' : ''}`}
  45. aria-current={activePage === 'library' ? 'page' : undefined}
  46. onClick={
  47. onLibraryClick
  48. ? e => {
  49. e.preventDefault()
  50. onLibraryClick(e)
  51. }
  52. : undefined
  53. }
  54. >
  55. <BookBookmark size={24} />
  56. <span>{t('library')}</span>
  57. </a>
  58. </li>
  59. <li>
  60. <a
  61. href="/project"
  62. className={`ds-nav-page-switcher-item${activePage === 'projects' ? ' active' : ''}`}
  63. aria-current={activePage === 'projects' ? 'page' : undefined}
  64. onClick={
  65. onProjectsClick
  66. ? e => {
  67. e.preventDefault()
  68. onProjectsClick(e)
  69. }
  70. : undefined
  71. }
  72. >
  73. <Folder size={24} />
  74. <span>{t('projects')}</span>
  75. </a>
  76. </li>
  77. </ul>
  78. </>
  79. )
  80. }