Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[infra] Add support for automatic generation of data-attributes API #1022

Merged
merged 11 commits into from
Dec 11, 2024
5 changes: 5 additions & 0 deletions docs/reference/generated/collapsible-trigger.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@
"type": "React.ReactElement | (props, state) => React.ReactElement",
"description": "A function to customize rendering of the component."
}
},
"dataAttributes": {
"data-panel-open": {
"description": "Present when the collapsible panel is open."
}
}
}
10 changes: 5 additions & 5 deletions docs/reference/generated/dialog-backdrop.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
"description": "A function to customize rendering of the component."
}
},
"attributes": {
"[data-open]": {
"dataAttributes": {
"data-open": {
"description": "Present when the dialog is open."
},
"[data-closed]": {
"data-closed": {
"description": "Present when the dialog is closed."
},
"[data-starting-style]": {
"data-starting-style": {
"description": "Present when the dialog is animating in."
},
"[data-ending-style]": {
"data-ending-style": {
"description": "Present when the dialog is animating out."
}
}
Expand Down
14 changes: 7 additions & 7 deletions docs/reference/generated/dialog-popup.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@
"description": "A function to customize rendering of the component."
}
},
"attributes": {
"[data-open]": {
"dataAttributes": {
"data-open": {
"description": "Present when the dialog is open."
},
"[data-closed]": {
"data-closed": {
"description": "Present when the dialog is closed."
},
"[data-starting-style]": {
"data-starting-style": {
"description": "Present when the dialog is animating in."
},
"[data-ending-style]": {
"data-ending-style": {
"description": "Present when the dialog is animating out."
},
"[data-modal]": {
"data-modal": {
"description": "Present when the dialog is modal."
},
"[data-nested-dialogs]": {
"data-nested-dialogs": {
"type": "number",
"description": "Indicates how many dialogs are nested within."
}
Expand Down
6 changes: 3 additions & 3 deletions docs/reference/generated/dialog-trigger.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"description": "A function to customize rendering of the component."
}
},
"attributes": {
"[data-modal]": {
"dataAttributes": {
"data-modal": {
"description": "Present when the corresponding dialog is modal."
},
"[data-popup-open]": {
"data-popup-open": {
"description": "Present when the corresponding dialog is open."
}
}
Expand Down
10 changes: 5 additions & 5 deletions docs/reference/overrides/dialog-backdrop.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "DialogBackdrop",
"attributes": {
"[data-open]": {
"dataAttributes": {
"data-open": {
"description": "Present when the dialog is open."
},
"[data-closed]": {
"data-closed": {
"description": "Present when the dialog is closed."
},
"[data-starting-style]": {
"data-starting-style": {
"description": "Present when the dialog is animating in."
},
"[data-ending-style]": {
"data-ending-style": {
"description": "Present when the dialog is animating out."
}
}
Expand Down
14 changes: 7 additions & 7 deletions docs/reference/overrides/dialog-popup.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"name": "DialogPopup",
"attributes": {
"[data-open]": {
"dataAttributes": {
"data-open": {
"description": "Present when the dialog is open."
},
"[data-closed]": {
"data-closed": {
"description": "Present when the dialog is closed."
},
"[data-starting-style]": {
"data-starting-style": {
"description": "Present when the dialog is animating in."
},
"[data-ending-style]": {
"data-ending-style": {
"description": "Present when the dialog is animating out."
},
"[data-modal]": {
"data-modal": {
"description": "Present when the dialog is modal."
},
"[data-nested-dialogs]": {
"data-nested-dialogs": {
"type": "number",
"description": "Indicates how many dialogs are nested within."
}
Expand Down
6 changes: 3 additions & 3 deletions docs/reference/overrides/dialog-trigger.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "DialogTrigger",
"attributes": {
"[data-modal]": {
"dataAttributes": {
"data-modal": {
"description": "Present when the corresponding dialog is modal."
},
"[data-popup-open]": {
"data-popup-open": {
"description": "Present when the corresponding dialog is open."
}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/src/components/reference/rehypeReference.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ export function rehypeReference() {
}),
);

if (def.attributes) {
if (def.dataAttributes) {
subtree.push(
createMdxElement({
name: ATTRIBUTES_TABLE,
props: { data: def.attributes },
props: { data: def.dataAttributes },
}),
);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/reference/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export interface ComponentDef {
name: string;
description?: string;
props: Record<string, PropDef>;
attributes?: Record<string, AttributeDef>;
dataAttributes?: Record<string, AttributeDef>;
cssVariables?: Record<string, CssVariableDef>;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@mui/internal-markdown": "^1.0.22",
"@mui/internal-scripts": "^1.0.29",
"@mui/internal-test-utils": "https://pkg.csb.dev/mui/material-ui/commit/92c23999/@mui/internal-test-utils",
"@mui/monorepo": "github:mui/material-ui#817470c5a7c2ae721401e308b961005730cdf2ab",
"@mui/monorepo": "github:mui/material-ui#v6.2.0",
"@next/eslint-plugin-next": "^14.2.18",
"@octokit/rest": "^20.1.1",
"@playwright/test": "1.49.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum CollapsibleTriggerDataAttributes {
/**
* Present when the collapsible panel is open.
*/
panelOpen = 'data-panel-open',
}
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions scripts/buildApiDocs/buildReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,20 @@ export async function buildReference() {
console.warn(`Missing component description: ${componentData.name}`);
}

const attributes = componentOverrides?.attributes;
const dataAttributes =
!!componentData?.dataAttributes || !!componentOverrides?.dataAttributes
? { ...componentData?.dataAttributes, ...componentOverrides?.dataAttributes }
: undefined;
const cssVariables =
!!componentData?.cssVariables || componentOverrides?.cssVariables
!!componentData?.cssVariables || !!componentOverrides?.cssVariables
? { ...componentData?.cssVariables, ...componentOverrides?.cssVariables }
: undefined;

const json: ComponentDef = {
name: componentData.name,
description: descriptionData.componentDescription,
props,
attributes,
dataAttributes,
cssVariables,
};

Expand Down
Loading