Completely updated React, fixed #11, (hopefully)

This commit is contained in:
2018-03-04 19:11:49 -05:00
parent 6e0afd6e2a
commit 34e5f5139a
13674 changed files with 333464 additions and 473223 deletions

View File

@@ -1,22 +1,25 @@
// @flow
// @inheritedComponent CardContent
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import Typography from '../Typography';
import CardContent from './CardContent';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
display: 'flex',
alignItems: 'center',
padding: theme.spacing.unit * 2,
},
avatar: {
flex: '0 0 auto',
marginRight: theme.spacing.unit * 2,
},
action: {
flex: '0 0 auto',
alignSelf: 'flex-start',
marginTop: theme.spacing.unit * -1,
marginRight: theme.spacing.unit * -2,
},
content: {
flex: '1 1 auto',
},
@@ -24,60 +27,79 @@ export const styles = (theme: Object) => ({
subheader: {},
});
type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* The Avatar for the Card Header.
*/
avatar?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* The content of the component.
*/
subheader?: Node,
/**
* The content of the Card Title.
*/
title?: Node,
};
function CardHeader(props: ProvidedProps & Props) {
const { avatar, classes, className: classNameProp, subheader, title, ...other } = props;
const className = classNames(classes.root, classNameProp);
// Adjustments that depend on the presence of an avatar
const titleType = avatar ? 'body2' : 'headline';
const subheaderType = avatar ? 'body2' : 'body1';
function CardHeader(props) {
const {
action,
avatar,
classes,
className: classNameProp,
component: Component,
subheader,
title,
...other
} = props;
return (
<CardContent className={className} {...other}>
<Component className={classNames(classes.root, classNameProp)} {...other}>
{avatar && <div className={classes.avatar}>{avatar}</div>}
<div className={classes.content}>
<Typography type={titleType} component="span" className={classes.title}>
<Typography
variant={avatar ? 'body2' : 'headline'}
component="span"
className={classes.title}
>
{title}
</Typography>
<Typography
type={subheaderType}
component="span"
color="secondary"
className={classes.subheader}
>
{subheader}
</Typography>
{subheader && (
<Typography
variant={avatar ? 'body2' : 'body1'}
component="span"
color="textSecondary"
className={classes.subheader}
>
{subheader}
</Typography>
)}
</div>
</CardContent>
{action && <div className={classes.action}>{action}</div>}
</Component>
);
}
CardHeader.propTypes = {
/**
* The action to display in the card header.
*/
action: PropTypes.node,
/**
* The Avatar for the Card Header.
*/
avatar: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
/**
* The content of the component.
*/
subheader: PropTypes.node,
/**
* The content of the Card Title.
*/
title: PropTypes.node,
};
CardHeader.defaultProps = {
component: 'div',
};
export default withStyles(styles, { name: 'MuiCardHeader' })(CardHeader);