From 0eafaa04fa68500cc820076fcf9f7299f28ece5d Mon Sep 17 00:00:00 2001 From: mnajdova Date: Tue, 10 Dec 2024 10:25:52 +0100 Subject: [PATCH] custom default type --- docs/pages/material-ui/api/accordion.json | 6 +++++- docs/translations/api-docs/accordion/accordion.json | 5 ++++- .../ApiBuilders/ComponentApiBuilder.ts | 13 +++++++++---- .../src/Accordion/AccordionDataAttributes.ts | 8 ++++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/docs/pages/material-ui/api/accordion.json b/docs/pages/material-ui/api/accordion.json index 02ab397c69e630..28d48591acc21e 100644 --- a/docs/pages/material-ui/api/accordion.json +++ b/docs/pages/material-ui/api/accordion.json @@ -66,7 +66,11 @@ } ], "dataAttributes": { - "data-panel-open": { "description": "Indicates whether the panel is opened", "type": "boolean" } + "[data-nested-dialogs]": { + "description": "Indicates how many dialogs are nested within.", + "type": "number" + }, + "[data-panel-open]": { "description": "Indicates whether the panel is opened" } }, "classes": [ { diff --git a/docs/translations/api-docs/accordion/accordion.json b/docs/translations/api-docs/accordion/accordion.json index 6e078a62ca1c26..bcc53d61b99432 100644 --- a/docs/translations/api-docs/accordion/accordion.json +++ b/docs/translations/api-docs/accordion/accordion.json @@ -63,5 +63,8 @@ "heading": "The component that renders the heading.", "transition": "The component that renders the transition. Follow this guide to learn more about the requirements for this component." }, - "dataAttributesDescriptions": { "data-panel-open": "Indicates whether the panel is opened" } + "dataAttributesDescriptions": { + "[data-nested-dialogs]": "Indicates how many dialogs are nested within.", + "[data-panel-open]": "Indicates whether the panel is opened" + } } diff --git a/packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts b/packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts index a1cfd6fb82f4a3..6d2884c4a08e0a 100644 --- a/packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts +++ b/packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts @@ -488,8 +488,8 @@ const attachTranslations = ( [...Object.keys(reactApi.dataAttributes)] .sort() // Sort to ensure consistency of object key order .forEach((dataAttributeName: string) => { - const cssVariable = reactApi.dataAttributes[dataAttributeName]; - const { description } = cssVariable; + const dataAttribute = reactApi.dataAttributes[dataAttributeName]; + const { description } = dataAttribute; translations.dataAttributesDescriptions![dataAttributeName] = renderMarkdown(description); }); } @@ -645,6 +645,7 @@ const attachTable = ( reactApi: ComponentReactApi, params: ParsedProperty[], attribute: 'cssVariables' | 'dataAttributes', + defaultType: any = undefined, ) => { const errors: Array<[propName: string, error: Error]> = []; const data: { [key: string]: ApiItemDescription } = params @@ -666,7 +667,11 @@ const attachTable = ( const deprecation = deprecationTag?.text?.[0]?.text; const typeTag = propDescriptor.tags?.type; - const type = (typeTag?.text?.[0]?.text ?? 'string').replace(/{|}/g, ''); + + let type = (typeTag?.text?.[0]?.text ?? defaultType) + if (typeof type === 'string') { + type = type.replace(/{|}/g, ''); + } return { name: propName, @@ -854,7 +859,7 @@ export default async function generateComponentApi( ); attachPropsTable(reactApi, projectSettings.propsSettings); - attachTable(reactApi, cssVars, 'cssVariables'); + attachTable(reactApi, cssVars, 'cssVariables', 'string'); attachTable(reactApi, dataAttributes, 'dataAttributes'); attachTranslations(reactApi, deprecationInfo, projectSettings.propsSettings); diff --git a/packages/mui-material/src/Accordion/AccordionDataAttributes.ts b/packages/mui-material/src/Accordion/AccordionDataAttributes.ts index 6433c1e6b5de2a..e912784c236e0a 100644 --- a/packages/mui-material/src/Accordion/AccordionDataAttributes.ts +++ b/packages/mui-material/src/Accordion/AccordionDataAttributes.ts @@ -1,9 +1,13 @@ enum AccordionDataAttributes { /** * Indicates whether the panel is opened - * @type {boolean} */ - panelOpen = 'data-panel-open', + panelOpen = '[data-panel-open]', + /** + * Indicates how many dialogs are nested within. + * @type {number} + */ + nestedDialogs = '[data-nested-dialogs]', } export default AccordionDataAttributes;