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 5 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#73c04f191f6df3d0fbb18028aa0a23c440134d29",
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
"@mui/utils": "6.1.8",
"@next/eslint-plugin-next": "^14.2.17",
"@octokit/rest": "^20.1.1",
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/dialog/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * as Dialog from './index.parts';
export * from './popup/cssVars';
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 { cssVars } from './cssVars';

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, [cssVars.nestedDialogs]: nestedOpenDialogCount },
},
customStyleHookMapping,
});
Expand Down
11 changes: 11 additions & 0 deletions packages/react/src/dialog/popup/cssVars.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type DialogPopupCssVars = {
Copy link
Member Author

Choose a reason for hiding this comment

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

The convention here is tha the type with [ComponentName]CssVars exists. By default, the type is assumed string, if it is something else we can add the @type tag. The actual CSS variable in the docs is the kebab case of the key. I added support for the @deprecated tag too, in case we ever need it in the future.

/**
* Indicates how many dialogs are nested within.
* @type number
* */
nestedDialogs: string;
};

export const cssVars: DialogPopupCssVars = {
nestedDialogs: '--nested-dialogs',
};
90 changes: 45 additions & 45 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

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