1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
3 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
4 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
5 | import _inherits from 'babel-runtime/helpers/inherits';
|
6 |
|
7 | var _class, _temp;
|
8 |
|
9 | import React, { Component } from 'react';
|
10 | import PropTypes from 'prop-types';
|
11 | import classNames from 'classnames';
|
12 | import ConfigProvider from '../config-provider';
|
13 | import { log } from '../util';
|
14 |
|
15 | var warning = log.warning;
|
16 |
|
17 |
|
18 | var MEDIA_COMPONENTS = ['video', 'audio', 'picture', 'iframe', 'img'];
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | var CardMedia = (_temp = _class = function (_Component) {
|
25 | _inherits(CardMedia, _Component);
|
26 |
|
27 | function CardMedia() {
|
28 | _classCallCheck(this, CardMedia);
|
29 |
|
30 | return _possibleConstructorReturn(this, _Component.apply(this, arguments));
|
31 | }
|
32 |
|
33 | CardMedia.prototype.render = function render() {
|
34 | var _props = this.props,
|
35 | prefix = _props.prefix,
|
36 | style = _props.style,
|
37 | className = _props.className,
|
38 | Component = _props.component,
|
39 | image = _props.image,
|
40 | src = _props.src,
|
41 | others = _objectWithoutProperties(_props, ['prefix', 'style', 'className', 'component', 'image', 'src']);
|
42 |
|
43 | if (!('children' in others || Boolean(image || src))) {
|
44 | warning('either `children`, `image` or `src` prop must be specified.');
|
45 | }
|
46 |
|
47 | var isMediaComponent = MEDIA_COMPONENTS.indexOf(Component) !== -1;
|
48 | var composedStyle = !isMediaComponent && image ? _extends({ backgroundImage: 'url("' + image + '")' }, style) : style;
|
49 |
|
50 | return React.createElement(Component, _extends({}, others, {
|
51 | style: composedStyle,
|
52 | className: classNames(prefix + 'card-media', className),
|
53 | src: isMediaComponent ? image || src : undefined
|
54 | }));
|
55 | };
|
56 |
|
57 | return CardMedia;
|
58 | }(Component), _class.propTypes = {
|
59 | prefix: PropTypes.string,
|
60 | |
61 |
|
62 |
|
63 | component: PropTypes.elementType,
|
64 | |
65 |
|
66 |
|
67 | image: PropTypes.string,
|
68 | |
69 |
|
70 |
|
71 | src: PropTypes.string,
|
72 | style: PropTypes.object,
|
73 | className: PropTypes.string
|
74 | }, _class.defaultProps = {
|
75 | prefix: 'next-',
|
76 | component: 'div',
|
77 | style: {}
|
78 | }, _temp);
|
79 | CardMedia.displayName = 'CardMedia';
|
80 |
|
81 |
|
82 | export default ConfigProvider.config(CardMedia); |
\ | No newline at end of file |