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

[Card] Migrate CardContent to emotion #24600

Merged
merged 6 commits into from
Jan 25, 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.
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/card-content.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" } },
"component": { "type": { "name": "elementType" } }
"component": { "type": { "name": "elementType" } },
"sx": { "type": { "name": "object" } }
},
"name": "CardContent",
"styles": { "classes": ["root"], "globalClasses": {}, "name": "MuiCardContent" },
Expand All @@ -11,6 +12,6 @@
"filename": "/packages/material-ui/src/CardContent/CardContent.js",
"inheritance": null,
"demos": "<ul><li><a href=\"/components/cards/\">Cards</a></li></ul>",
"styledComponent": false,
"styledComponent": true,
"cssComponent": false
}
3 changes: 2 additions & 1 deletion docs/translations/api-docs/card-content/card-content.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.",
"component": "The component used for the root node. Either a string to use a HTML element or a component."
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"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." } }
}
6 changes: 6 additions & 0 deletions packages/material-ui/src/CardContent/CardContent.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as React from 'react';
import { SxProps } from '@material-ui/system';
import { OverridableComponent, OverrideProps } from '../OverridableComponent';
import { Theme } from '..';

export interface CardContentTypeMap<P = {}, D extends React.ElementType = 'div'> {
props: P & {
Expand All @@ -14,6 +16,10 @@ export interface CardContentTypeMap<P = {}, D extends React.ElementType = 'div'>
/** 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>;
};
defaultComponent: D;
}
Expand Down
62 changes: 53 additions & 9 deletions packages/material-ui/src/CardContent/CardContent.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,62 @@
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 experimentalStyled from '../styles/experimentalStyled';
import useThemeProps from '../styles/useThemeProps';
import { getCardContentUtilityClass } from './cardContentClasses';

export const styles = {
const overridesResolver = (props, styles) => styles.root || {};

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

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

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

const CardContentRoot = experimentalStyled(
'div',
{},
{
name: 'MuiCardContent',
slot: 'Root',
overridesResolver,
},
)(() => {
/* Styles applied to the root element. */
root: {
return {
padding: 16,
'&:last-child': {
paddingBottom: 24,
},
},
};
};
});

const CardContent = React.forwardRef(function CardContent(inProps, ref) {
const props = useThemeProps({
props: inProps,
name: 'MuiCardContent',
});

const { className, component = 'div', ...other } = props;

const CardContent = React.forwardRef(function CardContent(props, ref) {
const { classes, className, component: Component = 'div', ...other } = props;
const styleProps = { ...props, component };

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

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

CardContent.propTypes = {
Expand All @@ -41,6 +81,10 @@ CardContent.propTypes = {
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: PropTypes.object,
};

export default withStyles(styles, { name: 'MuiCardContent' })(CardContent);
export default CardContent;
12 changes: 5 additions & 7 deletions packages/material-ui/src/CardContent/CardContent.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import * as React from 'react';
import { getClasses, createMount, describeConformance } from 'test/utils';
import { createMount, describeConformanceV5 } from 'test/utils';
import CardContent from './CardContent';
import classes from './cardContentClasses';

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

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

describeConformance(<CardContent />, () => ({
describeConformanceV5(<CardContent />, () => ({
classes,
inheritComponent: 'div',
mount,
muiName: 'MuiCardContent',
refInstanceof: window.HTMLDivElement,
skip: ['componentsProp', 'themeVariants'],
testComponentPropWith: 'span',
}));
});
9 changes: 9 additions & 0 deletions packages/material-ui/src/CardContent/cardContentClasses.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface CardContentClasses {
root: string;
}

declare const cardContentClasses: CardContentClasses;

export function getCardContentUtilityClass(slot: string): string;

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

export function getCardContentUtilityClass(slot) {
return generateUtilityClass('MuiCardContent', slot);
}

const cardContentClasses = generateUtilityClasses('MuiCardContent', ['root']);

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