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] Automatically get info for CSS variables #874

Merged
merged 26 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/data/api/dialog-popup.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
"imports": [
"import { Dialog } from '@base-ui-components/react/dialog';\nconst DialogPopup = Dialog.Popup;"
],
"cssVariables": {
"--nested-dialogs": {
"description": "Indicates how many dialogs are nested within.",
"type": "number"
}
},
"classes": [],
"spread": true,
"themeDefaultProps": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
},
"render": { "description": "A function to customize rendering of the component." }
},
"classDescriptions": {}
"classDescriptions": {},
"cssVariablesDescriptions": {
"--nested-dialogs": "Indicates how many dialogs are nested within."
}
}
4 changes: 2 additions & 2 deletions docs/reference/generated/dialog-popup.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
},
"cssVariables": {
"--nested-dialogs": {
"type": "number",
"description": "Indicates how many dialogs are nested within."
"description": "Indicates how many dialogs are nested within.",
"type": "number"
}
}
}
6 changes: 0 additions & 6 deletions docs/reference/overrides/dialog-popup.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,5 @@
"type": "number",
"description": "Indicates how many dialogs are nested within."
}
},
"cssVariables": {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for manually defining it 🎉

"--nested-dialogs": {
"type": "number",
"description": "Indicates how many dialogs are nested within."
}
}
}
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.20",
"@mui/internal-scripts": "^1.0.27",
"@mui/internal-test-utils": "https://pkg.csb.dev/mui/material-ui/commit/92c23999/@mui/internal-test-utils",
"@mui/monorepo": "github:mui/material-ui#v6.1.7",
"@mui/monorepo": "github:mui/material-ui#v6.1.10",
"@next/eslint-plugin-next": "^14.2.18",
"@octokit/rest": "^20.1.1",
"@playwright/test": "1.49.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/dialog/popup/DialogPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { type CustomStyleHookMapping } from '../../utils/getStyleHookProps';
import { popupOpenStateMapping as baseMapping } from '../../utils/popupOpenStateMapping';
import { useForkRef } from '../../utils/useForkRef';
import { InteractionType } from '../../utils/useEnhancedClickHandler';
import { DialogPopupCssVars } from './DialogPopupCssVars';

const customStyleHookMapping: CustomStyleHookMapping<DialogPopup.State> = {
...baseMapping,
Expand Down Expand Up @@ -103,7 +104,7 @@ const DialogPopup = React.forwardRef(function DialogPopup(
propGetter: getRootProps,
extraProps: {
...other,
style: { ...other.style, '--nested-dialogs': nestedOpenDialogCount },
style: { ...other.style, [DialogPopupCssVars.nestedDialogs]: nestedOpenDialogCount },
},
customStyleHookMapping,
});
Expand Down
7 changes: 7 additions & 0 deletions packages/react/src/dialog/popup/DialogPopupCssVars.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum DialogPopupCssVars {
/**
* Indicates how many dialogs are nested within.
* @type {number}
*/
nestedDialogs = '--nested-dialogs',
}
32 changes: 16 additions & 16 deletions pnpm-lock.yaml

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

5 changes: 4 additions & 1 deletion scripts/buildApiDocs/buildReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export async function buildReference() {
}

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

const json: ComponentDef = {
name: componentData.name,
Expand Down
2 changes: 1 addition & 1 deletion scripts/buildApiDocs/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import yargs, { ArgumentsCamelCase } from 'yargs';
import { buildApi } from '@mui-internal/api-docs-builder';
import { buildReference } from 'buildReference';
import { buildReference } from './buildReference';
import { projectSettings, newProjectSettings } from './config/projectSettings';

type CommandOptions = { grep?: string };
Expand Down
Loading