From 2627caebb45c7e0877078e1408fdae5388ea1260 Mon Sep 17 00:00:00 2001 From: cwg <1227646458@qq.com> Date: Fri, 15 Sep 2023 22:03:53 +0800 Subject: [PATCH] fix: site style conflict (#44899) * fix: site style conflict * chore: lint * feat: optimize code --- .dumi/theme/SiteThemeProvider.tsx | 1 + .dumi/theme/builtins/ComponentOverview/index.tsx | 7 +++++-- .dumi/theme/builtins/IconSearch/IconSearch.tsx | 9 +++++++-- .dumi/theme/layouts/GlobalLayout.tsx | 15 +++++++++------ .dumi/theme/slots/Header/index.tsx | 14 ++++++++++++++ .dumi/theme/slots/SiteContext.ts | 2 ++ 6 files changed, 38 insertions(+), 10 deletions(-) diff --git a/.dumi/theme/SiteThemeProvider.tsx b/.dumi/theme/SiteThemeProvider.tsx index 609f44f4a1ef..62bfb7dd09f6 100644 --- a/.dumi/theme/SiteThemeProvider.tsx +++ b/.dumi/theme/SiteThemeProvider.tsx @@ -41,6 +41,7 @@ const SiteThemeProvider: FC = ({ children, theme, ...rest }) theme={theme} customToken={{ headerHeight: 64, + bannerHeight: 38, menuItemBorder: 2, mobileMaxWidth: 767.99, siteMarkdownCodeBg: token.colorFillTertiary, diff --git a/.dumi/theme/builtins/ComponentOverview/index.tsx b/.dumi/theme/builtins/ComponentOverview/index.tsx index 6582b05f5bd4..58c9ea50d9c0 100644 --- a/.dumi/theme/builtins/ComponentOverview/index.tsx +++ b/.dumi/theme/builtins/ComponentOverview/index.tsx @@ -80,7 +80,7 @@ const { Title } = Typography; const Overview: React.FC = () => { const { styles } = useStyle(); - const { theme } = useContext(SiteContext); + const { theme, bannerVisible } = useContext(SiteContext); const data = useSidebarData(); const [searchBarAffixed, setSearchBarAffixed] = useState(false); @@ -143,7 +143,10 @@ const Overview: React.FC = () => { return (
- +
{ theme: ThemeType.Outlined, }); const token = useTheme(); + const { bannerVisible } = useContext(SiteContext); const newIconNames: string[] = []; @@ -124,7 +126,10 @@ const IconSearch: React.FC = () => { return (
- +
{ const { pathname } = useLocation(); const [searchParams, setSearchParams] = useSearchParams(); const [, , setPrefersColor] = usePrefersColor(); - const [{ theme = [], direction, isMobile }, setSiteState] = useLayoutState({ - isMobile: false, - direction: 'ltr', - theme: [], - }); + const [{ theme = [], direction, isMobile, bannerVisible = true }, setSiteState] = + useLayoutState({ + isMobile: false, + direction: 'ltr', + theme: [], + bannerVisible: true, + }); const updateSiteConfig = useCallback( (props: SiteState) => { @@ -121,8 +123,9 @@ const GlobalLayout: React.FC = () => { updateSiteConfig, theme: theme!, isMobile: isMobile!, + bannerVisible, }), - [isMobile, direction, updateSiteConfig, theme], + [isMobile, direction, updateSiteConfig, theme, bannerVisible], ); const [styleCache] = React.useState(() => createCache()); diff --git a/.dumi/theme/slots/Header/index.tsx b/.dumi/theme/slots/Header/index.tsx index 3b49f4036dfd..7bcd7faab70a 100644 --- a/.dumi/theme/slots/Header/index.tsx +++ b/.dumi/theme/slots/Header/index.tsx @@ -128,6 +128,11 @@ const useStyle = createStyles(({ token, css }) => { margin-left: 0; } `, + icon: css` + margin-right: 10px; + width: 22px; + height: 22px; + `, }; }); @@ -171,6 +176,9 @@ const Header: React.FC = () => { const onDirectionChange = () => { updateSiteConfig({ direction: direction !== 'rtl' ? 'rtl' : 'ltr' }); }; + const onBannerClose = () => { + updateSiteConfig({ bannerVisible: false }); + }; useEffect(() => { handleHideMenu(); @@ -349,6 +357,11 @@ const Header: React.FC = () => { className={styles.banner} message={ <> + yuque {isMobile ? locale.shortMessage : locale.message} { banner closable showIcon={false} + onClose={onBannerClose} /> )} diff --git a/.dumi/theme/slots/SiteContext.ts b/.dumi/theme/slots/SiteContext.ts index 179aa6dc3329..3878940d846f 100644 --- a/.dumi/theme/slots/SiteContext.ts +++ b/.dumi/theme/slots/SiteContext.ts @@ -4,6 +4,7 @@ import type { ThemeName } from '../common/ThemeSwitch'; export interface SiteContextProps { isMobile: boolean; + bannerVisible: boolean; direction: DirectionType; theme: ThemeName[]; updateSiteConfig: (props: Partial) => void; @@ -11,6 +12,7 @@ export interface SiteContextProps { const SiteContext = React.createContext({ isMobile: false, + bannerVisible: true, direction: 'ltr', theme: ['light'], updateSiteConfig: () => {},