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

[Dialog] Migrate DialogTitle to emotion #24623

Merged
merged 4 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
5 changes: 3 additions & 2 deletions docs/pages/api-docs/dialog-title.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"props": {
"children": { "type": { "name": "node" } },
"classes": { "type": { "name": "object" } },
"disableTypography": { "type": { "name": "bool" } }
"disableTypography": { "type": { "name": "bool" } },
"sx": { "type": { "name": "object" } }
},
"name": "DialogTitle",
"styles": { "classes": ["root"], "globalClasses": {}, "name": "MuiDialogTitle" },
Expand All @@ -11,6 +12,6 @@
"filename": "/packages/material-ui/src/DialogTitle/DialogTitle.js",
"inheritance": null,
"demos": "<ul><li><a href=\"/components/dialogs/\">Dialogs</a></li></ul>",
"styledComponent": false,
"styledComponent": true,
"cssComponent": false
}
3 changes: 2 additions & 1 deletion docs/translations/api-docs/dialog-title/dialog-title.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"propDescriptions": {
"children": "The content of the component.",
"classes": "Override or extend the styles applied to the component. See <a href=\"#css\">CSS API</a> below for more details.",
"disableTypography": "If <code>true</code>, the children won&#39;t be wrapped by a typography component. For instance, this can be useful to render an h4 instead of the default h2."
"disableTypography": "If <code>true</code>, the children won&#39;t be wrapped by a typography component. For instance, this can be useful to render an h4 instead of the default h2.",
"sx": "The system prop that allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/basics/#the-sx-prop\">`sx` page</a> for more details."
},
"classDescriptions": { "root": { "description": "Styles applied to the root element." } }
}
7 changes: 6 additions & 1 deletion packages/material-ui/src/DialogTitle/DialogTitle.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { InternalStandardProps as StandardProps } from '..';
import { SxProps } from '@material-ui/system';
import { InternalStandardProps as StandardProps, Theme } from '..';

export interface DialogTitleProps extends StandardProps<React.HTMLAttributes<HTMLDivElement>> {
/**
Expand All @@ -13,6 +14,10 @@ export interface DialogTitleProps extends StandardProps<React.HTMLAttributes<HTM
/** Styles applied to the root element. */
root?: string;
};
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx?: SxProps<Theme>;
/**
* If `true`, the children won't be wrapped by a typography component.
* For instance, this can be useful to render an h4 instead of the default h2.
Expand Down
61 changes: 50 additions & 11 deletions packages/material-ui/src/DialogTitle/DialogTitle.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,66 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import withStyles from '../styles/withStyles';
import { unstable_composeClasses as composeClasses } from '@material-ui/unstyled';
import Typography from '../Typography';
import experimentalStyled from '../styles/experimentalStyled';
import useThemeProps from '../styles/useThemeProps';
import { getDialogTitleUtilityClass } from './dialogTitleClasses';

export const styles = {
/* Styles applied to the root element. */
root: {
const overridesResolver = (props, styles) => styles.root || {};

const useUtilityClasses = (styleProps) => {
const { classes } = styleProps;

const slots = {
root: ['root'],
};

return composeClasses(slots, getDialogTitleUtilityClass, classes);
};

const DialogTitleRoot = experimentalStyled(
'div',
{},
{
name: 'MuiDialogTitle',
slot: 'Root',
overridesResolver,
},
)(() => {
return {
/* Styles applied to the root element. */
margin: 0,
padding: '16px 24px',
flex: '0 0 auto',
},
};
};
});

const DialogTitle = React.forwardRef(function DialogTitle(props, ref) {
const { children, classes, className, disableTypography = false, ...other } = props;
const DialogTitle = React.forwardRef(function DialogTitle(inProps, ref) {
const props = useThemeProps({
props: inProps,
name: 'MuiDialogTitle',
});

const { children, className, disableTypography = false, ...other } = props;
const styleProps = { ...props };
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
const classes = useUtilityClasses(styleProps);

return (
<div className={clsx(classes.root, className)} ref={ref} {...other}>
<DialogTitleRoot
className={clsx(classes.root, className)}
styleProps={styleProps}
ref={ref}
{...other}
>
{disableTypography ? (
children
) : (
<Typography component="h2" variant="h6">
{children}
</Typography>
)}
</div>
</DialogTitleRoot>
);
});

Expand All @@ -52,6 +87,10 @@ DialogTitle.propTypes = {
* @default false
*/
disableTypography: PropTypes.bool,
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: PropTypes.object,
};

export default withStyles(styles, { name: 'MuiDialogTitle' })(DialogTitle);
export default DialogTitle;
14 changes: 6 additions & 8 deletions packages/material-ui/src/DialogTitle/DialogTitle.test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import * as React from 'react';
import { getClasses, createMount, describeConformance, createClientRender } from 'test/utils';
import { createMount, describeConformanceV5, createClientRender } from 'test/utils';
import DialogTitle from './DialogTitle';
import classes from './dialogTitleClasses';

describe('<DialogTitle />', () => {
const mount = createMount();
const render = createClientRender();
let classes;

before(() => {
classes = getClasses(<DialogTitle>foo</DialogTitle>);
});

describeConformance(<DialogTitle>foo</DialogTitle>, () => ({
describeConformanceV5(<DialogTitle>foo</DialogTitle>, () => ({
classes,
inheritComponent: 'div',
mount,
muiName: 'MuiDialogTitle',
refInstanceof: window.HTMLDivElement,
skip: ['componentProp'],
testVariantProps: { disableTypography: true },
skip: ['componentProp', 'componentsProp'],
}));

it('should render JSX children', () => {
Expand Down
9 changes: 9 additions & 0 deletions packages/material-ui/src/DialogTitle/dialogTitleClasses.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface DialogTitleClasses {
root: string;
}

declare const dialogTitleClasses: DialogTitleClasses;

export function getDialogTitleUtilityClass(slot: string): string;

export default dialogTitleClasses;
9 changes: 9 additions & 0 deletions packages/material-ui/src/DialogTitle/dialogTitleClasses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { generateUtilityClass, generateUtilityClasses } from '@material-ui/unstyled';

export function getDialogTitleUtilityClass(slot) {
return generateUtilityClass('MuiDialogTitle', slot);
}

const dialogTitleClasses = generateUtilityClasses('MuiDialogTitle', ['root']);

export default dialogTitleClasses;
2 changes: 2 additions & 0 deletions packages/material-ui/src/DialogTitle/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export { default } from './DialogTitle';
export * from './DialogTitle';
export { default as dialogTitleClasses } from './dialogTitleClasses';
export * from './dialogTitleClasses';
2 changes: 2 additions & 0 deletions packages/material-ui/src/DialogTitle/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { default } from './DialogTitle';
export { default as dialogTitleClasses } from './dialogTitleClasses';
export * from './dialogTitleClasses';