overall-theme-setting.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { useProjectSettingsContext } from '@/features/editor-left-menu/context/project-settings-context'
  2. import DropdownSetting from '../dropdown-setting'
  3. import getMeta from '@/utils/meta'
  4. import { useMemo } from 'react'
  5. import type { Option } from '../dropdown-setting'
  6. import { useTranslation } from 'react-i18next'
  7. import { OverallThemeMeta } from '@ol-types/project-settings'
  8. import { isIEEEBranded } from '@/utils/is-ieee-branded'
  9. import { useLayoutContext } from '@/shared/context/layout-context'
  10. import { OverallTheme } from '@/shared/utils/styles'
  11. export default function OverallThemeSetting() {
  12. const { t } = useTranslation()
  13. const overallThemes = getMeta('ol-overallThemes') as
  14. | OverallThemeMeta[]
  15. | undefined
  16. const { loadingStyleSheet } = useLayoutContext()
  17. const { overallTheme, setOverallTheme } = useProjectSettingsContext()
  18. const options: Array<Option<OverallTheme>> = useMemo(
  19. () =>
  20. overallThemes?.map(({ name, val }) => ({
  21. value: val,
  22. label: name,
  23. })) ?? [],
  24. [overallThemes]
  25. )
  26. if (!overallThemes || isIEEEBranded()) {
  27. return null
  28. }
  29. return (
  30. <DropdownSetting
  31. id="overallTheme"
  32. label={t('overall_theme')}
  33. description={t('the_overleaf_color_scheme')}
  34. options={options}
  35. onChange={setOverallTheme}
  36. value={overallTheme}
  37. loading={loadingStyleSheet}
  38. />
  39. )
  40. }