import React, { useMemo } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { useDispatch } from 'react-redux'; import { changeSetting } from 'soapbox/actions/settings'; import { Icon } from 'soapbox/components/ui'; import { useSettings } from 'soapbox/hooks'; const messages = defineMessages({ light: { id: 'theme_toggle.light', defaultMessage: 'Light' }, dark: { id: 'theme_toggle.dark', defaultMessage: 'Dark' }, system: { id: 'theme_toggle.system', defaultMessage: 'System' }, }); interface IThemeToggle { showLabel?: boolean, } const ThemeToggle = ({ showLabel }: IThemeToggle) => { const intl = useIntl(); const dispatch = useDispatch(); const themeMode = useSettings().get('themeMode'); const onToggle = (event: React.ChangeEvent) => { dispatch(changeSetting(['themeMode'], event.target.value)); }; const themeIconSrc = useMemo(() => { switch (themeMode) { case 'system': return require('@tabler/icons/icons/device-desktop.svg'); case 'light': return require('@tabler/icons/icons/sun.svg'); case 'dark': return require('@tabler/icons/icons/moon.svg'); default: return null; } }, [themeMode]); return ( ); }; export default ThemeToggle;