Skip to content

Commit

Permalink
custom default type
Browse files Browse the repository at this point in the history
  • Loading branch information
mnajdova committed Dec 10, 2024
1 parent 2f1c080 commit 0eafaa0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
6 changes: 5 additions & 1 deletion docs/pages/material-ui/api/accordion.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
5 changes: 4 additions & 1 deletion docs/translations/api-docs/accordion/accordion.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,8 @@
"heading": "The component that renders the heading.",
"transition": "The component that renders the transition. <a href=\"https://mui.com/material-ui/transitions/#transitioncomponent-prop\">Follow this guide</a> 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"
}
}
13 changes: 9 additions & 4 deletions packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 0eafaa0

Please sign in to comment.