Skip to content

Commit

Permalink
feat: add new context field to support embedded rsdoctor to other page (
Browse files Browse the repository at this point in the history
  • Loading branch information
zllkjc authored Sep 27, 2024
1 parent b0cd547 commit c791b79
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 11 additions & 4 deletions packages/components/src/components/Layout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { PropsWithChildren, useEffect } from 'react';
import { PropsWithChildren, useContext, useEffect } from 'react';
import { FloatButton, Layout as L } from 'antd';
import { MAIN_BG, Size } from '../../constants';
import { Header } from './header';
import { useLocale, useI18n } from '../../utils';
import { Progress } from './progress';
import { ConfigContext } from '../../config';

export interface LayoutProps {
children: JSX.Element;
Expand All @@ -14,19 +15,25 @@ export const Layout = (props: PropsWithChildren<LayoutProps>): JSX.Element => {
const { i18n } = useI18n();
const { children } = props;


useEffect(() => {
if (i18n.language !== locale) {
i18n.changeLanguage(locale);
}
}, [locale]);

const ctx = useContext(ConfigContext);
return (
<L>
<Header />
{!ctx.embedded ? <Header /> : null}
<Progress />
<L.Content
style={{ height: '100%', minHeight: '100vh', padding: Size.BasePadding, marginTop: Size.NavBarHeight, background: MAIN_BG }}
style={{
height: '100%',
minHeight: '100vh',
padding: Size.BasePadding,
marginTop: !ctx.embedded ? Size.NavBarHeight : 0,
background: MAIN_BG,
}}
>
{children}
<FloatButton.BackTop />
Expand Down
8 changes: 7 additions & 1 deletion packages/components/src/config.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { createContext } from 'react';
import { Manifest } from '@rsdoctor/types';
import { getLocaleFromStorage, getThemeFromStorage, getViewModeFromStorage } from './utils/storage';
import {
getLocaleFromStorage,
getThemeFromStorage,
getViewModeFromStorage,
} from './utils/storage';
import { PageState, ViewMode, Language, Theme } from './constants';

export interface Config {
Expand All @@ -16,6 +20,8 @@ export interface Config {
setManifest(json: Manifest.RsdoctorManifest): void;
setPageState(state: PageState): void;
setViewMode(mode: Partial<Config['viewMode']>, saveStorage?: boolean): void;
// whether the page is embedded in another page
embedded?: boolean;
}

export const defaultConfig: Config = {
Expand Down

0 comments on commit c791b79

Please sign in to comment.