1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var _react = _interopRequireDefault(require("react"));
|
9 |
|
10 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
11 |
|
12 | var _Shimmer = _interopRequireDefault(require("./Shimmer"));
|
13 |
|
14 | var _withStyles = require("../helpers/withStyles");
|
15 |
|
16 | var _reactWithStyles = require("react-with-styles");
|
17 |
|
18 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19 |
|
20 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
21 |
|
22 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
23 |
|
24 | var propTypes = _objectSpread({}, _reactWithStyles.withStylesPropTypes, {
|
25 | inline: _propTypes.default.bool,
|
26 | loading: _propTypes.default.bool,
|
27 | aspectRatio: _propTypes.default.number,
|
28 | rectangular: _propTypes.default.bool,
|
29 | source: _propTypes.default.string,
|
30 | width: _propTypes.default.string
|
31 | });
|
32 |
|
33 | var defaultProps = {
|
34 | aspectRatio: 1,
|
35 | width: '100%'
|
36 | };
|
37 |
|
38 | var Image = function Image(_ref) {
|
39 | var css = _ref.css,
|
40 | inline = _ref.inline,
|
41 | loading = _ref.loading,
|
42 | aspectRatio = _ref.aspectRatio,
|
43 | rectangular = _ref.rectangular,
|
44 | source = _ref.source,
|
45 | styles = _ref.styles,
|
46 | width = _ref.width;
|
47 | return _react.default.createElement("div", css(styles.container, inline && styles.inline, {
|
48 | width: width
|
49 | }), _react.default.createElement("div", css(styles.image, rectangular && styles.image_rectangular, {
|
50 | paddingTop: "".concat(aspectRatio * 100, "%"),
|
51 | width: width,
|
52 | backgroundImage: source && "url(".concat(source, ")")
|
53 | })), loading && _react.default.createElement("div", css(styles.loading), _react.default.createElement(_Shimmer.default, {
|
54 | width: "100%",
|
55 | height: "100%"
|
56 | })));
|
57 | };
|
58 |
|
59 | Image.propTypes = propTypes;
|
60 | Image.defaultProps = defaultProps;
|
61 | var ImageWithStyles = (0, _withStyles.withStyles)(function (_ref2) {
|
62 | var color = _ref2.color,
|
63 | radius = _ref2.radius;
|
64 | return {
|
65 | container: {
|
66 | position: 'relative',
|
67 | overflow: 'hidden',
|
68 | boxSizing: 'border-box',
|
69 | borderRadius: radius
|
70 | },
|
71 | image: {
|
72 | backgroundColor: color.gray,
|
73 | backgroundSize: 'cover',
|
74 | backgroundPosition: 'center'
|
75 | },
|
76 | inline: {
|
77 | display: 'inline-block'
|
78 | },
|
79 | image_rectangular: {
|
80 | borderRadius: 0
|
81 | },
|
82 | loading: {
|
83 | position: 'absolute',
|
84 | top: 0,
|
85 | right: 0,
|
86 | bottom: 0,
|
87 | left: 0
|
88 | }
|
89 | };
|
90 | })(Image);
|
91 | var _default = ImageWithStyles;
|
92 | exports.default = _default; |
\ | No newline at end of file |