Skip to content

Commit

Permalink
[docs-infra] New way of providing API layout config (#41106)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette authored Feb 19, 2024
1 parent 1476da5 commit dd82af7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ const generateApiPage = async (
reactApi: ReactApi,
sortingStrategies?: SortingStrategiesType,
onlyJsonFile: boolean = false,
layoutConfigPath: string = '',
) => {
const normalizedApiPathname = reactApi.apiPathname.replace(/\\/g, '/');
/**
Expand Down Expand Up @@ -422,12 +423,17 @@ const generateApiPage = async (
path.resolve(apiPagesDirectory, `${kebabCase(reactApi.name)}.js`),
`import * as React from 'react';
import ApiPage from 'docs/src/modules/components/ApiPage';
import mapApiPageTranslations from 'docs/src/modules/utils/mapApiPageTranslations';
import mapApiPageTranslations from 'docs/src/modules/utils/mapApiPageTranslations';${
layoutConfigPath === ''
? ''
: `
import layoutConfig from '${layoutConfigPath}';`
}
import jsonPageContent from './${kebabCase(reactApi.name)}.json';
export default function Page(props) {
const { descriptions, pageContent } = props;
return <ApiPage descriptions={descriptions} pageContent={pageContent} />;
return <ApiPage ${layoutConfigPath === '' ? '' : '{...layoutConfig} '}descriptions={descriptions} pageContent={pageContent} />;
}
Page.getInitialProps = () => {
Expand Down Expand Up @@ -802,6 +808,7 @@ export default async function generateComponentApi(
reactApi,
projectSettings.sortingStrategies,
generateJsonFileOnly,
componentInfo.layoutConfigPath,
);

if (
Expand Down
4 changes: 4 additions & 0 deletions packages/api-docs-builder/buildApiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ export type ComponentInfo = {
};
getDemos: () => Array<{ demoPageTitle: string; demoPathname: string }>;
apiPagesDirectory: string;
/**
* The path to import specific layout config of the page if needed.
*/
layoutConfigPath?: string;
skipApiGeneration?: boolean;
/**
* If `true`, the component's name match one of the MUI System components.
Expand Down

0 comments on commit dd82af7

Please sign in to comment.