Skip to content

Commit

Permalink
Update interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjORbj committed Feb 10, 2023
1 parent 032dc3b commit a3f50f9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { defaultHandlers, parse as docgenParse, ReactDocgenApi } from 'react-doc
import { unstable_generateUtilityClass as generateUtilityClass } from '@mui/utils';
import { renderInline as renderMarkdownInline } from '@mui/markdown';
import { LANGUAGES } from 'docs/config';

import muiDefaultPropsHandler from '../utils/defaultPropsHandler';
import parseTest from '../utils/parseTest';
import generatePropTypeDescription, { getChained } from '../utils/generatePropTypeDescription';
Expand All @@ -24,6 +23,7 @@ import generatePropDescription from '../utils/generatePropDescription';
import parseStyles, { Styles } from '../utils/parseStyles';
import { ComponentInfo } from '../buildApiUtils';
import { TypeScriptProject } from '../utils/createTypeScriptProject';
import parseSlots, { Slot } from '../utils/parseSlots';

const DEFAULT_PRETTIER_CONFIG_PATH = path.join(process.cwd(), 'prettier.config.js');

Expand All @@ -47,6 +47,7 @@ export interface ReactApi extends ReactDocgenApi {
*/
src: string;
styles: Styles;
slots: Slot[];
propsTable: _.Dictionary<{
default: string | undefined;
required: boolean | undefined;
Expand All @@ -58,6 +59,7 @@ export interface ReactApi extends ReactDocgenApi {
componentDescription: string;
propDescriptions: { [key: string]: string | undefined };
classDescriptions: { [key: string]: { description: string; conditions?: string } };
slotDescriptions: { [key: string]: string | undefined };
};
}

Expand Down Expand Up @@ -350,6 +352,7 @@ const generateApiPage = (outputDirectory: string, reactApi: ReactApi) => {
),
name: reactApi.styles.name,
},
slots: reactApi.slots,
spread: reactApi.spread,
forwardsRefTo: reactApi.forwardsRefTo,
filename: toGitHubPath(reactApi.filename),
Expand Down Expand Up @@ -404,6 +407,7 @@ const attachTranslations = (reactApi: ReactApi) => {
componentDescription: reactApi.description,
propDescriptions: {},
classDescriptions: {},
slotDescriptions: {},
};
Object.entries(reactApi.props!).forEach(([propName, propDescriptor]) => {
let prop: DescribeablePropDescriptor | null;
Expand All @@ -418,6 +422,8 @@ const attachTranslations = (reactApi: ReactApi) => {

if (propName === 'classes') {
description += ' See <a href="#css">CSS API</a> below for more details.';
} else if (propName === 'slots') {
description += ' See <a href="#slots">Slots API</a> below for more details.';
} else if (propName === 'sx') {
description +=
' See the <a href="/system/getting-started/the-sx-prop/">`sx` page</a> for more details.';
Expand All @@ -427,9 +433,10 @@ const attachTranslations = (reactApi: ReactApi) => {
});

/**
* CSS class descriptiohs.
* CSS class descriptions.
*/
translations.classDescriptions = extractClassConditions(reactApi.styles.descriptions);
// translations.slotDescriptions = generateSlotDescriptions(reactApi.slots.descriptions);

reactApi.translations = translations;
};
Expand Down Expand Up @@ -597,7 +604,7 @@ const generateComponentApi = async (componentInfo: ComponentInfo, project: TypeS
reactApi.spread = testInfo.spread ?? spread;
reactApi.inheritance = getInheritance(testInfo.inheritComponent);
reactApi.styles = await parseStyles({ project, componentName: reactApi.name });

reactApi.slots = parseSlots({ project, componentName: reactApi.name });
if (reactApi.styles.classes.length > 0 && !reactApi.name.endsWith('Unstyled')) {
reactApi.styles.name = reactApi.muiName;
}
Expand Down

0 comments on commit a3f50f9

Please sign in to comment.