2023-02-18 13:11:01 +03:00
|
|
|
import { faMoon, faSun } from '@fortawesome/free-solid-svg-icons';
|
2021-02-19 20:55:03 +03:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
2023-08-05 12:14:03 +03:00
|
|
|
import type { Theme } from '@shlinkio/shlink-frontend-kit';
|
2023-12-19 01:05:17 +03:00
|
|
|
import { getSystemPreferredTheme, SimpleCard, ToggleSwitch } from '@shlinkio/shlink-frontend-kit';
|
2023-02-18 13:11:01 +03:00
|
|
|
import type { FC } from 'react';
|
2023-12-19 01:05:17 +03:00
|
|
|
import { useMemo } from 'react';
|
2023-08-19 18:21:34 +03:00
|
|
|
import type { AppSettings, UiSettings } from './reducers/settings';
|
2021-12-25 12:49:12 +03:00
|
|
|
import './UserInterfaceSettings.scss';
|
2021-02-16 21:25:23 +03:00
|
|
|
|
|
|
|
interface UserInterfaceProps {
|
2023-08-19 18:21:34 +03:00
|
|
|
settings: AppSettings;
|
2021-02-16 21:25:23 +03:00
|
|
|
setUiSettings: (settings: UiSettings) => void;
|
2023-12-19 01:05:17 +03:00
|
|
|
|
|
|
|
/* Test seam */
|
|
|
|
_matchMedia?: typeof window.matchMedia;
|
2021-02-16 21:25:23 +03:00
|
|
|
}
|
|
|
|
|
2023-12-19 01:05:17 +03:00
|
|
|
export const UserInterfaceSettings: FC<UserInterfaceProps> = ({ settings: { ui }, setUiSettings, _matchMedia }) => {
|
|
|
|
const currentTheme = useMemo(() => ui?.theme ?? getSystemPreferredTheme(_matchMedia), [ui?.theme, _matchMedia]);
|
|
|
|
return (
|
|
|
|
<SimpleCard title="User interface" className="h-100">
|
|
|
|
<FontAwesomeIcon icon={currentTheme === 'dark' ? faMoon : faSun} className="user-interface__theme-icon" />
|
|
|
|
<ToggleSwitch
|
|
|
|
checked={currentTheme === 'dark'}
|
|
|
|
onChange={(useDarkTheme) => {
|
|
|
|
const theme: Theme = useDarkTheme ? 'dark' : 'light';
|
|
|
|
setUiSettings({ ...ui, theme });
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Use dark theme.
|
|
|
|
</ToggleSwitch>
|
|
|
|
</SimpleCard>
|
|
|
|
);
|
|
|
|
};
|