mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 17:55:17 -04:00
fix: replace dark mode hack with bootstrap's own dark mode
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
3f42798965
commit
0993372290
77 changed files with 244 additions and 365 deletions
|
@ -13,11 +13,16 @@ export const useApplyDarkModeStyle = (): void => {
|
|||
const darkMode = useDarkModeState()
|
||||
useEffect(() => {
|
||||
if (darkMode) {
|
||||
window.document.body.classList.add('dark')
|
||||
window.document.body.dataset.bsTheme = 'dark'
|
||||
} else {
|
||||
window.document.body.classList.remove('dark')
|
||||
window.document.body.dataset.bsTheme = 'light'
|
||||
}
|
||||
}, [darkMode])
|
||||
|
||||
useEffect(() => () => window.document.body.classList.remove('dark'), [])
|
||||
useEffect(
|
||||
() => () => {
|
||||
window.document.body.dataset.bsTheme = 'light'
|
||||
},
|
||||
[]
|
||||
)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import * as UseDarkModeStateModule from './use-dark-mode-state'
|
||||
import { useOutlineButtonVariant } from './use-outline-button-variant'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import React from 'react'
|
||||
|
||||
jest.mock('./use-dark-mode-state')
|
||||
|
||||
describe('useOutlineButtonVariant', () => {
|
||||
const TestComponent: React.FC = () => {
|
||||
return useOutlineButtonVariant()
|
||||
}
|
||||
|
||||
it('returns the correct variant for dark mode', async () => {
|
||||
jest.spyOn(UseDarkModeStateModule, 'useDarkModeState').mockReturnValue(true)
|
||||
render(<TestComponent />)
|
||||
await screen.findByText('outline-light')
|
||||
})
|
||||
|
||||
it('returns the correct variant for light mode', async () => {
|
||||
jest.spyOn(UseDarkModeStateModule, 'useDarkModeState').mockReturnValue(false)
|
||||
render(<TestComponent />)
|
||||
await screen.findByText('outline-dark')
|
||||
})
|
||||
})
|
10
frontend/src/hooks/dark-mode/use-outline-button-variant.ts
Normal file
10
frontend/src/hooks/dark-mode/use-outline-button-variant.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { useDarkModeState } from './use-dark-mode-state'
|
||||
|
||||
export const useOutlineButtonVariant = (): 'outline-light' | 'outline-dark' => {
|
||||
return useDarkModeState() ? 'outline-light' : 'outline-dark'
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue