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 DialogActions to emotion #24613

Merged
merged 5 commits into from Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/pages/api-docs/dialog-actions.json
Expand Up @@ -2,7 +2,8 @@
"props": {
"children": { "type": { "name": "node" } },
"classes": { "type": { "name": "object" } },
"disableSpacing": { "type": { "name": "bool" } }
"disableSpacing": { "type": { "name": "bool" } },
"sx": { "type": { "name": "object" } }
},
"name": "DialogActions",
"styles": { "classes": ["root", "spacing"], "globalClasses": {}, "name": "MuiDialogActions" },
Expand All @@ -11,6 +12,6 @@
"filename": "/packages/material-ui/src/DialogActions/DialogActions.js",
"inheritance": null,
"demos": "<ul><li><a href=\"/components/dialogs/\">Dialogs</a></li></ul>",
"styledComponent": false,
"styledComponent": true,
"cssComponent": false
}
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.",
"disableSpacing": "If <code>true</code>, the actions do not have additional margin."
"disableSpacing": "If <code>true</code>, the actions do not have additional margin.",
"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." },
Expand Down
7 changes: 6 additions & 1 deletion packages/material-ui/src/DialogActions/DialogActions.d.ts
@@ -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 DialogActionsProps extends StandardProps<React.HTMLAttributes<HTMLDivElement>> {
/**
Expand All @@ -15,6 +16,10 @@ export interface DialogActionsProps extends StandardProps<React.HTMLAttributes<H
/** Styles applied to the root element unless `disableSpacing={true}`. */
spacing?: string;
};
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx?: SxProps<Theme>;
/**
* If `true`, the actions do not have additional margin.
* @default false
Expand Down
76 changes: 58 additions & 18 deletions packages/material-ui/src/DialogActions/DialogActions.js
@@ -1,31 +1,67 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import withStyles from '../styles/withStyles';
import { deepmerge } from '@material-ui/utils';
import { unstable_composeClasses as composeClasses } from '@material-ui/unstyled';
import experimentalStyled from '../styles/experimentalStyled';
import useThemeProps from '../styles/useThemeProps';
import { getDialogActionsUtilityClass } from './dialogActionsClasses';

export const styles = {
/* Styles applied to the root element. */
root: {
display: 'flex',
alignItems: 'center',
padding: 8,
justifyContent: 'flex-end',
flex: '0 0 auto',
const overridesResolver = (props, styles) => {
const { styleProps } = props;

return deepmerge(styles.root || {}, {
...(!styleProps.disableSpacing && styles.spacing),
});
};

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

const slots = {
root: ['root', !disableSpacing && 'spacing'],
};

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

const DialogActionsRoot = experimentalStyled(
'div',
{},
{
name: 'MuiDialogActions',
slot: 'Root',
overridesResolver,
},
)(({ styleProps }) => ({
/* Styles applied to the root element. */
display: 'flex',
alignItems: 'center',
padding: 8,
justifyContent: 'flex-end',
flex: '0 0 auto',
/* Styles applied to the root element unless `disableSpacing={true}`. */
spacing: {
'& > :not(:first-child)': {
...(!styleProps.disableSpacing && {
'& > :not(:first-of-type)': {
marginLeft: 8,
},
},
};
}),
}));

const DialogActions = React.forwardRef(function DialogActions(props, ref) {
const { disableSpacing = false, classes, className, ...other } = props;
const DialogActions = React.forwardRef(function DialogActions(inProps, ref) {
const props = useThemeProps({
props: inProps,
name: 'MuiDialogActions',
});

const { className, disableSpacing = false, ...other } = props;
const styleProps = { ...props, disableSpacing };
const classes = useUtilityClasses(styleProps);

return (
<div
className={clsx(classes.root, { [classes.spacing]: !disableSpacing }, className)}
<DialogActionsRoot
className={clsx(classes.root, className)}
styleProps={styleProps}
ref={ref}
{...other}
/>
Expand Down Expand Up @@ -54,6 +90,10 @@ DialogActions.propTypes = {
* @default false
*/
disableSpacing: PropTypes.bool,
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: PropTypes.object,
};

export default withStyles(styles, { name: 'MuiDialogActions' })(DialogActions);
export default DialogActions;
14 changes: 6 additions & 8 deletions packages/material-ui/src/DialogActions/DialogActions.test.js
@@ -1,20 +1,18 @@
import * as React from 'react';
import { getClasses, createMount, describeConformance } from 'test/utils';
import { createMount, describeConformanceV5 } from 'test/utils';
import DialogActions from './DialogActions';
import classes from './dialogActionsClasses';

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

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

describeConformance(<DialogActions />, () => ({
describeConformanceV5(<DialogActions />, () => ({
classes,
inheritComponent: 'div',
mount,
refInstanceof: window.HTMLDivElement,
skip: ['componentProp'],
muiName: 'MuiDialogActions',
testVariantProps: { disableSpacing: true },
skip: ['componentProp', 'componentsProp'],
}));
});
10 changes: 10 additions & 0 deletions packages/material-ui/src/DialogActions/dialogActionsClasses.d.ts
@@ -0,0 +1,10 @@
export interface DialogActionsClasses {
root: string;
spacing: string;
}

declare const dialogActionsClasses: DialogActionsClasses;

export function getDialogActionsUtilityClass(slot: string): string;

export default dialogActionsClasses;
@@ -0,0 +1,9 @@
import { generateUtilityClass, generateUtilityClasses } from '@material-ui/unstyled';

export function getDialogActionsUtilityClass(slot) {
return generateUtilityClass('MuiDialogActions', slot);
}

const dialogActionsClasses = generateUtilityClasses('MuiDialogActions', ['root', 'spacing']);

export default dialogActionsClasses;
2 changes: 2 additions & 0 deletions packages/material-ui/src/DialogActions/index.d.ts
@@ -1,2 +1,4 @@
export { default } from './DialogActions';
export * from './DialogActions';
export { default as dialogActionsClasses } from './dialogActionsClasses';
export * from './dialogActionsClasses';
2 changes: 2 additions & 0 deletions packages/material-ui/src/DialogActions/index.js
@@ -1 +1,3 @@
export { default } from './DialogActions';
export { default as dialogActionsClasses } from './dialogActionsClasses';
export * from './dialogActionsClasses';