spell-check-setting.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { useProjectSettingsContext } from '@/features/editor-left-menu/context/project-settings-context'
  2. import { useTranslation } from 'react-i18next'
  3. import DropdownSetting, { Optgroup } from '../dropdown-setting'
  4. import { useMemo } from 'react'
  5. import getMeta from '@/utils/meta'
  6. import { supportsWebAssembly } from '@/utils/wasm'
  7. // TODO: Split this into separate setttings for spell check
  8. // language and spell check on/off
  9. export default function SpellCheckSetting() {
  10. const { spellCheckLanguage, setSpellCheckLanguage } =
  11. useProjectSettingsContext()
  12. const { t } = useTranslation()
  13. const optgroup: Optgroup = useMemo(() => {
  14. const options = (getMeta('ol-languages') ?? [])
  15. // only include spell-check languages that are available in the client
  16. .filter(language => language.dic !== undefined)
  17. return {
  18. label: 'Language',
  19. options: options.map(language => ({
  20. value: language.code,
  21. label: language.name,
  22. })),
  23. }
  24. }, [])
  25. return (
  26. <DropdownSetting
  27. id="spellCheckLanguage"
  28. label={t('spellcheck_language')}
  29. options={[{ value: '', label: t('off') }]}
  30. optgroups={[optgroup]}
  31. onChange={setSpellCheckLanguage}
  32. value={supportsWebAssembly() ? spellCheckLanguage : ''}
  33. width="wide"
  34. />
  35. )
  36. }