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

[Accordion] Migrate AccordionDetails to emotion #24539

Merged
merged 2 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/accordion-details.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"props": {
"children": { "type": { "name": "node" } },
"classes": { "type": { "name": "object" } }
"classes": { "type": { "name": "object" } },
"sx": { "type": { "name": "object" } }
},
"name": "AccordionDetails",
"styles": { "classes": ["root"], "globalClasses": {}, "name": "MuiAccordionDetails" },
Expand All @@ -10,6 +11,6 @@
"filename": "/packages/material-ui/src/AccordionDetails/AccordionDetails.js",
"inheritance": null,
"demos": "<ul><li><a href=\"/components/accordion/\">Accordion</a></li></ul>",
"styledComponent": false,
"styledComponent": true,
"cssComponent": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"componentDescription": "",
"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."
"classes": "Override or extend the styles applied to the component. See <a href=\"#css\">CSS API</a> below for more details.",
"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." } }
}
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 AccordionDetailsProps extends StandardProps<React.HTMLAttributes<HTMLDivElement>> {
/**
Expand All @@ -13,6 +14,10 @@ export interface AccordionDetailsProps extends StandardProps<React.HTMLAttribute
/** 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>;
}

export type AccordionDetailsClassKey = keyof NonNullable<AccordionDetailsProps['classes']>;
Expand Down
59 changes: 49 additions & 10 deletions packages/material-ui/src/AccordionDetails/AccordionDetails.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,54 @@
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 { getAccordionDetailsUtilityClass } from './accordionDetailsClasses';

export const styles = (theme) => ({
/* Styles applied to the root element. */
root: {
padding: theme.spacing(1, 2, 2),
const overridesResolver = (props, styles) => {
queengooborg marked this conversation as resolved.
Show resolved Hide resolved
return deepmerge(styles.root || {}, {});
};

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

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

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

const AccordionDetailsRoot = experimentalStyled(
'div',
{},
{
name: 'MuiAccordionDetails',
slot: 'Root',
overridesResolver,
},
});
)(({ theme }) => ({
/* Styles applied to the root element. */
padding: theme.spacing(1, 2, 2),
}));

const AccordionDetails = React.forwardRef(function AccordionDetails(props, ref) {
const { classes, className, ...other } = props;
const AccordionDetails = React.forwardRef(function AccordionDetails(inProps, ref) {
const props = useThemeProps({ props: inProps, name: 'MuiAccordionDetails' });
const { className, ...other } = props;
const styleProps = { ...props };

return <div className={clsx(classes.root, className)} ref={ref} {...other} />;
const classes = useUtilityClasses(styleProps);

return (
<AccordionDetailsRoot
className={clsx(classes.root, className)}
ref={ref}
styleProps={styleProps}
{...other}
/>
);
});

AccordionDetails.propTypes = {
Expand All @@ -33,6 +68,10 @@ AccordionDetails.propTypes = {
* @ignore
*/
className: PropTypes.string,
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: PropTypes.object,
};

export default withStyles(styles, { name: 'MuiAccordionDetails' })(AccordionDetails);
export default AccordionDetails;
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import * as React from 'react';
import { expect } from 'chai';
import { createClientRender, getClasses, createMount, describeConformance } from 'test/utils';
import { createClientRender, createMount, describeConformanceV5 } from 'test/utils';
import AccordionDetails from './AccordionDetails';
import classes from './accordionDetailsClasses';

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

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

describeConformance(<AccordionDetails>Conformance</AccordionDetails>, () => ({
describeConformanceV5(<AccordionDetails>Conformance</AccordionDetails>, () => ({
classes,
inheritComponent: 'div',
mount,
refInstanceof: window.HTMLDivElement,
skip: ['componentProp'],
muiName: 'MuiAccordionDetails',
skip: ['componentProp', 'componentsProp', 'themeVariants'],
}));

it('should render a children element', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface AccordionDetailsClasses {
root: string;
}

declare const accordionDetailsClasses: AccordionDetailsClasses;

export function getAccordionDetailsUtilityClass(slot: string): string;

export default accordionDetailsClasses;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { generateUtilityClass, generateUtilityClasses } from '@material-ui/unstyled';

export function getAccordionDetailsUtilityClass(slot) {
return generateUtilityClass('MuiAccordionDetails', slot);
}

const accordionDetailsClasses = generateUtilityClasses('MuiAccordionDetails', ['root']);

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

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

export { default as accordionDetailsClasses } from './accordionDetailsClasses';
export * from './accordionDetailsClasses';