UNPKG

2.56 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
3import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
4import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
5import _inherits from 'babel-runtime/helpers/inherits';
6
7var _class, _temp;
8
9import React, { Component } from 'react';
10import PropTypes from 'prop-types';
11import classNames from 'classnames';
12import ConfigProvider from '../config-provider';
13import { log } from '../util';
14
15var warning = log.warning;
16
17
18var MEDIA_COMPONENTS = ['video', 'audio', 'picture', 'iframe', 'img'];
19
20/**
21 * Card.Media
22 * @order 1
23 */
24var 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);
79CardMedia.displayName = 'CardMedia';
80
81
82export default ConfigProvider.config(CardMedia);
\No newline at end of file