Skip to content

Commit

Permalink
[infra] Automatically get info for CSS variables (#874)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnajdova authored Dec 4, 2024
1 parent e8d0f8c commit e7a245c
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 29 deletions.
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": {
"--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

0 comments on commit e7a245c

Please sign in to comment.