/
githubmirror
/
gpt-runner
Обзор
Документация
Войти
/
githubmirror
/
gpt-runner
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
website/src/theme/ColorModeToggle.tsx
41 строка
1 KB
JinmingYang
docs: move doc site dir to website dir
27 июн 2023, 18:22
27 июн 2023, 18:22
87887ca
Код
Авторство
О чём код?
import React from 'react' import OriginalToggle from '@theme-original/ColorModeToggle' import { COLOR_SHADES, type ColorState, DARK_BACKGROUND_COLOR, DARK_PRIMARY_COLOR, LIGHT_BACKGROUND_COLOR, LIGHT_PRIMARY_COLOR, darkStorage, lightStorage, updateDOMColors, } from '@site/src/utils/colorUtils' import type { Props } from '@theme/ColorModeToggle' // The ColorGenerator modifies the DOM styles. The styles are persisted in // session storage, and we need to apply the same style when toggling modes even // when we are not on the styling-layout page. The only way to do this so far is // by hooking into the Toggle component. export default function ColorModeToggle(props: Props): JSX.Element { return ( <OriginalToggle {...props} onChange={(colorMode) => { props.onChange(colorMode) const isDarkMode = colorMode === 'dark' const storage = isDarkMode ? darkStorage : lightStorage const colorState = (JSON.parse( storage.get() ?? 'null', ) as ColorState | null) ?? { baseColor: isDarkMode ? DARK_PRIMARY_COLOR : LIGHT_PRIMARY_COLOR, background: isDarkMode ? DARK_BACKGROUND_COLOR : LIGHT_BACKGROUND_COLOR, shades: COLOR_SHADES, } updateDOMColors(colorState, isDarkMode) }} /> ) }