diff --git a/components/ColorSchemeToggle/ColorSchemeSwitch.tsx b/components/ColorSchemeToggle/ColorSchemeSwitch.tsx new file mode 100644 index 000000000..b8fb15488 --- /dev/null +++ b/components/ColorSchemeToggle/ColorSchemeSwitch.tsx @@ -0,0 +1,45 @@ +import React from 'react'; +import { createStyles, Switch, Group, useMantineColorScheme } from '@mantine/core'; +import { Sun, MoonStars } from 'tabler-icons-react'; + +const useStyles = createStyles((theme) => ({ + root: { + position: 'relative', + '& *': { + cursor: 'pointer', + }, + }, + + icon: { + pointerEvents: 'none', + position: 'absolute', + zIndex: 1, + top: 3, + }, + + iconLight: { + left: 4, + color: theme.white, + }, + + iconDark: { + right: 4, + color: theme.colors.gray[6], + }, +})); + +export function ColorSchemeSwitch() { + const { colorScheme, toggleColorScheme } = useMantineColorScheme(); + const { classes, cx } = useStyles(); + + return ( + +
+ + + toggleColorScheme()} size="md" /> +
+ Switch to {colorScheme === 'dark' ? 'light' : 'dark'} mode +
+ ); +} diff --git a/components/Settings/SettingsMenu.tsx b/components/Settings/SettingsMenu.tsx index 3da9f5e7d..70b7c48cd 100644 --- a/components/Settings/SettingsMenu.tsx +++ b/components/Settings/SettingsMenu.tsx @@ -8,13 +8,16 @@ import { Tooltip, SegmentedControl, } from '@mantine/core'; +import { useColorScheme } from '@mantine/hooks'; import { useState } from 'react'; import { Settings as SettingsIcon } from 'tabler-icons-react'; import { useConfig } from '../../tools/state'; +import { ColorSchemeSwitch } from '../ColorSchemeToggle/ColorSchemeSwitch'; import SaveConfigComponent from '../Config/SaveConfig'; function SettingsMenu(props: any) { const { config, setConfig } = useConfig(); + const colorScheme = useColorScheme(); const matches = [ { label: 'Google', value: 'https://google.com/search?q=' }, { label: 'DuckDuckGo', value: 'https://duckduckgo.com/?q=' }, @@ -46,6 +49,7 @@ function SettingsMenu(props: any) { setConfig({ ...config, @@ -59,6 +63,7 @@ function SettingsMenu(props: any) { label="Enable search bar" /> + -