Skip to content

Commit

Permalink
feat: custom doc-layout components (#1611)
Browse files Browse the repository at this point in the history
  • Loading branch information
ap0nia authored Nov 20, 2024
1 parent c395518 commit 3460c70
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/document/docs/en/guide/advanced/custom-theme.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ const Layout = () => (
top={<div>top</div>}
/* Bottom of the entire page */
bottom={<div>bottom</div>}
/* Custom MDX components */
components={{ p: props => <p {...props} className="my-4 leading-7" /> }}
/>
);

Expand Down
2 changes: 2 additions & 0 deletions packages/document/docs/zh/guide/advanced/custom-theme.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ const Layout = () => (
top={<div>top</div>}
/* 整个页面最底部 */
bottom={<div>bottom</div>}
/* 自定义 MDX 组件 */
components={{ p: props => <p {...props} className="my-4 leading-7" /> }}
/>
);

Expand Down
6 changes: 5 additions & 1 deletion packages/theme-default/src/layout/DocLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface DocLayoutProps {
afterOutline?: React.ReactNode;
uiSwitch?: UISwitchResult;
navTitle?: React.ReactNode;
components?: Record<string, React.FC>;
}

export function DocLayout(props: DocLayoutProps) {
Expand All @@ -39,6 +40,7 @@ export function DocLayout(props: DocLayoutProps) {
afterSidebar,
uiSwitch,
navTitle,
components,
} = props;
const { siteData, page } = usePageData();
const { toc = [], frontmatter } = page;
Expand All @@ -52,9 +54,11 @@ export function DocLayout(props: DocLayoutProps) {
localesData?.outlineTitle || themeConfig?.outlineTitle || 'ON THIS PAGE';
const isOverviewPage = frontmatter?.overview ?? false;

const mdxComponents = { ...getCustomMDXComponent(), ...components };

const docContent = (
<TabDataContext.Provider value={{ tabData, setTabData }}>
<MDXProvider components={getCustomMDXComponent()}>
<MDXProvider components={mdxComponents}>
<Content />
</MDXProvider>
</TabDataContext.Provider>
Expand Down
2 changes: 2 additions & 0 deletions packages/theme-default/src/layout/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const Layout: React.FC<LayoutProps> = props => {
beforeFeatures,
afterFeatures,
afterNavMenu,
components,
} = props;
const docProps: DocLayoutProps = {
beforeDocFooter,
Expand All @@ -72,6 +73,7 @@ export const Layout: React.FC<LayoutProps> = props => {
afterSidebar,
beforeOutline,
afterOutline,
components,
};
const homeProps: HomeLayoutProps = {
beforeHero,
Expand Down

0 comments on commit 3460c70

Please sign in to comment.