Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect OS color scheme #437

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions client/src/app/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React from 'react'
import { Button, createTheme, MantineProvider } from '@mantine/core'
import { Notifications } from '@mantine/notifications'
import '../../public/favicon.svg'
import AppRoutes from './Routes'
import AuthenticationProvider from '../providers/AuthenticationContext/AuthenticationProvider'
import AppRoutes from './Routes'

import '@mantine/core/styles.layer.css'
import '@mantine/dates/styles.layer.css'
import '@mantine/dropzone/styles.css'
import '@mantine/notifications/styles.css'
import '@mantine/tiptap/styles.css'
import '@mantine/dropzone/styles.css'
import 'mantine-datatable/styles.layer.css'

import * as buttonClasses from './styles/Buttons.module.css'
Expand Down Expand Up @@ -41,7 +40,7 @@ const theme = createTheme({

const App = () => {
return (
<MantineProvider defaultColorScheme='dark' theme={theme}>
<MantineProvider defaultColorScheme='auto' theme={theme}>
<AuthenticationProvider>
<AppRoutes />
<Notifications limit={5} position='top-right' />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
import { Moon, Sun } from 'phosphor-react'
import { ActionIcon, useMantineColorScheme } from '@mantine/core'
import React from 'react'
import { BoxProps } from '@mantine/core/lib/core'
import { useMediaQuery } from '@mantine/hooks'
import { Moon, Sun } from 'phosphor-react'

const ColorSchemeToggleButton = (props: BoxProps) => {
const { colorScheme, toggleColorScheme } = useMantineColorScheme()
const { colorScheme, toggleColorScheme, clearColorScheme } = useMantineColorScheme()
const prefersDarkColorScheme = useMediaQuery('(prefers-color-scheme: dark)')

const showSunIcon = (colorScheme === 'auto' && prefersDarkColorScheme) || colorScheme === 'dark'

return (
<ActionIcon
variant='outline'
color={colorScheme === 'dark' ? 'yellow' : 'pale-purple'}
onClick={() => toggleColorScheme()}
onClick={() => {
// Reset to "auto" if the preferred value is reached again
if (
(colorScheme === 'dark' && !prefersDarkColorScheme) ||
(colorScheme === 'light' && prefersDarkColorScheme)
) {
clearColorScheme()
} else {
toggleColorScheme()
}
}}
title='Toggle color scheme'
{...props}
>
{colorScheme === 'dark' ? <Sun size='1.1rem' /> : <Moon size='1.1rem' />}
{showSunIcon ? <Sun size='1.1rem' /> : <Moon size='1.1rem' />}
</ActionIcon>
)
}
Expand Down