mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-23 03:27:05 -04:00
refactor: move dark-mode-state hook into other directory
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
cba8d917ed
commit
bcff03ef99
7 changed files with 8 additions and 8 deletions
20
frontend/src/hooks/dark-mode/use-dark-mode-state.ts
Normal file
20
frontend/src/hooks/dark-mode/use-dark-mode-state.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { DarkModePreference } from '../../redux/dark-mode/types'
|
||||
import { useApplicationState } from '../common/use-application-state'
|
||||
import useMediaQuery from '@restart/hooks/useMediaQuery'
|
||||
|
||||
/**
|
||||
* Uses the user settings and the browser preference to determine if dark mode should be used.
|
||||
*
|
||||
* @return The current state of the dark mode.
|
||||
*/
|
||||
export const useDarkModeState = (): boolean => {
|
||||
const preference = useApplicationState((state) => state.darkMode.darkModePreference)
|
||||
const isBrowserPreferringDark = useMediaQuery('(prefers-color-scheme: dark)')
|
||||
|
||||
return preference === DarkModePreference.DARK || (preference === DarkModePreference.AUTO && isBrowserPreferringDark)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue