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,9 +1,7 @@
// @flow
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import warning from 'warning';
import type { ElementType } from 'react';
import withStyles from '../styles/withStyles';
export const styles = {
@@ -17,53 +15,17 @@ export const styles = {
},
};
const mediaComponents = ['video', 'audio', 'picture', 'iframe', 'img'];
const MEDIA_COMPONENTS = ['video', 'audio', 'picture', 'iframe', 'img'];
type ProvidedProps = {
classes: Object,
component: ElementType,
};
export type Props = {
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* Image to be displayed as a background image.
* Either `image` or `src` prop must be specified.
* Note that caller must specify height otherwise the image will not be visible.
*/
image?: string,
/**
* An alias for `image` property.
* Available only with media components.
* Media components: `video`, `audio`, `picture`, `iframe`, `img`.
*/
src?: string,
/**
* @ignore
*/
style?: Object,
/**
* Component for rendering image.
*/
component?: ElementType,
};
function CardMedia(props: ProvidedProps & Props) {
const { classes, className, image, style, src, component: ComponentProp, ...other } = props;
function CardMedia(props) {
const { classes, className, component: Component, image, src, style, ...other } = props;
warning(
Boolean(image || src),
'Material-UI: either `image` or `src` property must be specified.',
);
const isMediaComponent = mediaComponents.indexOf(ComponentProp) !== -1;
const isMediaComponent = MEDIA_COMPONENTS.indexOf(Component) !== -1;
const composedStyle =
!isMediaComponent && image ? { backgroundImage: `url(${image})`, ...style } : style;
const composedClassName = classNames(
@@ -75,7 +37,7 @@ function CardMedia(props: ProvidedProps & Props) {
);
return (
<ComponentProp
<Component
className={composedClassName}
style={composedStyle}
src={isMediaComponent ? image || src : undefined}
@@ -84,6 +46,38 @@ function CardMedia(props: ProvidedProps & Props) {
);
}
CardMedia.propTypes = {
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* Component for rendering image.
* Either a string to use a DOM element or a component.
*/
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
/**
* Image to be displayed as a background image.
* Either `image` or `src` prop must be specified.
* Note that caller must specify height otherwise the image will not be visible.
*/
image: PropTypes.string,
/**
* An alias for `image` property.
* Available only with media components.
* Media components: `video`, `audio`, `picture`, `iframe`, `img`.
*/
src: PropTypes.string,
/**
* @ignore
*/
style: PropTypes.object,
};
CardMedia.defaultProps = {
component: 'div',
};