|
|
@ -5,15 +5,16 @@ import { |
|
|
|
parentSelectorLinter, |
|
|
|
StyleProvider, |
|
|
|
} from '@ant-design/cssinjs'; |
|
|
|
import { ConfigProvider, theme as antdTheme, App } from 'antd'; |
|
|
|
import { App, ConfigProvider, theme as antdTheme } from 'antd'; |
|
|
|
import type { DirectionType } from 'antd/es/config-provider'; |
|
|
|
import { createSearchParams, useOutlet, useSearchParams } from 'dumi'; |
|
|
|
import React, { startTransition, useCallback, useEffect, useMemo } from 'react'; |
|
|
|
import React, { useCallback, useEffect, useMemo } from 'react'; |
|
|
|
import useLocation from '../../hooks/useLocation'; |
|
|
|
import type { ThemeName } from '../common/ThemeSwitch'; |
|
|
|
import ThemeSwitch from '../common/ThemeSwitch'; |
|
|
|
import type { SiteContextProps } from '../slots/SiteContext'; |
|
|
|
import SiteContext from '../slots/SiteContext'; |
|
|
|
import useLayoutState from '../../hooks/useLayoutState'; |
|
|
|
|
|
|
|
type Entries<T> = { [K in keyof T]: [K, T[K]] }[keyof T][]; |
|
|
|
type SiteState = Partial<Omit<SiteContextProps, 'updateSiteContext'>>; |
|
|
@ -40,7 +41,7 @@ const GlobalLayout: React.FC = () => { |
|
|
|
const outlet = useOutlet(); |
|
|
|
const { pathname } = useLocation(); |
|
|
|
const [searchParams, setSearchParams] = useSearchParams(); |
|
|
|
const [{ theme, direction, isMobile }, setSiteState] = React.useState<SiteState>({ |
|
|
|
const [{ theme, direction, isMobile }, setSiteState] = useLayoutState<SiteState>({ |
|
|
|
isMobile: false, |
|
|
|
direction: 'ltr', |
|
|
|
theme: ['light'], |
|
|
@ -85,11 +86,9 @@ const GlobalLayout: React.FC = () => { |
|
|
|
const _theme = searchParams.getAll('theme') as ThemeName[]; |
|
|
|
const _direction = searchParams.get('direction') as DirectionType; |
|
|
|
|
|
|
|
startTransition(() => { |
|
|
|
setSiteState({ theme: _theme, direction: _direction === 'rtl' ? 'rtl' : 'ltr' }); |
|
|
|
// Handle isMobile
|
|
|
|
updateMobileMode(); |
|
|
|
}); |
|
|
|
setSiteState({ theme: _theme, direction: _direction === 'rtl' ? 'rtl' : 'ltr' }); |
|
|
|
// Handle isMobile
|
|
|
|
updateMobileMode(); |
|
|
|
|
|
|
|
window.addEventListener('resize', updateMobileMode); |
|
|
|
return () => { |
|
|
|