Skip to content

Commit

Permalink
Merge pull request #22 from ajnart/ajnart/issue21
Browse files Browse the repository at this point in the history
Add darkmode switch in settings menu #21
  • Loading branch information
ajnart authored May 9, 2022
2 parents cb3abbc + 43c0465 commit 7be2283
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
45 changes: 45 additions & 0 deletions components/ColorSchemeToggle/ColorSchemeSwitch.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Group>
<div className={classes.root}>
<Sun className={cx(classes.icon, classes.iconLight)} size={18} />
<MoonStars className={cx(classes.icon, classes.iconDark)} size={18} />
<Switch checked={colorScheme === 'dark'} onChange={() => toggleColorScheme()} size="md" />
</div>
Switch to {colorScheme === 'dark' ? 'light' : 'dark'} mode
</Group>
);
}
5 changes: 5 additions & 0 deletions components/Settings/SettingsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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=' },
Expand Down Expand Up @@ -46,6 +49,7 @@ function SettingsMenu(props: any) {
</Group>
<Group direction="column">
<Switch
size="md"
onChange={(e) =>
setConfig({
...config,
Expand All @@ -59,6 +63,7 @@ function SettingsMenu(props: any) {
label="Enable search bar"
/>
</Group>
<ColorSchemeSwitch />
<SaveConfigComponent />
<Text
style={{
Expand Down
2 changes: 0 additions & 2 deletions components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
import { useBooleanToggle } from '@mantine/hooks';
import { NextLink } from '@mantine/next';
import { Logo } from './Logo';
import { ColorSchemeToggle } from '../ColorSchemeToggle/ColorSchemeToggle';
import { SettingsMenuButton } from '../Settings/SettingsMenu';
import CalendarComponent from '../modules/calendar/CalendarModule';

Expand Down Expand Up @@ -119,7 +118,6 @@ export function Header({ links }: HeaderResponsiveProps) {
<Head height={HEADER_HEIGHT} mb={10} className={classes.root}>
<Container className={classes.header}>
<Group>
<ColorSchemeToggle />
<NextLink style={{ textDecoration: 'none' }} href="/">
<Logo style={{ fontSize: 22 }} />
</NextLink>
Expand Down

0 comments on commit 7be2283

Please sign in to comment.