wix-style-react
Version:
wix-style-react
172 lines (138 loc) • 6.67 kB
JavaScript
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _class, _temp2;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
import React from 'react';
import PropTypes from 'prop-types';
import styles from './Thumbnail.st.css';
import Check from 'wix-ui-icons-common/Check';
import Text from '../Text';
var noop = function noop() {};
var isString = function isString(a) {
return typeof a === 'string';
};
/**
* # Thumbnail
* Component for showing thumbnails
*
* It takes full space of parent component, works well together with `<Proportion/>`
* */
var Thumbnail = (_temp2 = _class = function (_React$PureComponent) {
_inherits(Thumbnail, _React$PureComponent);
function Thumbnail() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, Thumbnail);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Thumbnail.__proto__ || Object.getPrototypeOf(Thumbnail)).call.apply(_ref, [this].concat(args))), _this), _this._renderBackgroundLayout = function () {
return isString(_this.props.backgroundImage) ? React.createElement('div', {
className: styles.backgroundImage,
'data-hook': 'thumbnail-background-image',
style: { backgroundImage: 'url(' + _this.props.backgroundImage + ')' }
}) : _this.props.backgroundImage;
}, _this._renderNoBackgroundLayout = function () {
var _this$props = _this.props,
title = _this$props.title,
description = _this$props.description,
image = _this$props.image,
size = _this$props.size;
return React.createElement(
'div',
null,
image && React.createElement('div', {
className: styles.image,
'data-hook': 'thumbnail-image',
children: isString(image) ? React.createElement('img', { src: image }) : image
}),
title && React.createElement(Text, {
className: styles.title,
'data-hook': 'thumbnail-title',
size: size,
tagName: 'div',
weight: 'normal',
children: title
}),
description && React.createElement(Text, {
className: styles.description,
'data-hook': 'thumbnail-description',
size: size,
weight: 'thin',
tagName: 'div',
secondary: true,
children: description
})
);
}, _this._renderSelectedIcon = function () {
return React.createElement(
'div',
{ className: styles.selectedIcon, 'data-hook': 'thumbnail-selected-icon' },
React.createElement(Check, { size: '24' })
);
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(Thumbnail, [{
key: 'render',
value: function render() {
var _props = this.props,
dataHook = _props.dataHook,
size = _props.size,
selected = _props.selected,
disabled = _props.disabled,
backgroundImage = _props.backgroundImage,
onClick = _props.onClick,
hideSelectedIcon = _props.hideSelectedIcon,
width = _props.width,
height = _props.height;
var hasBackground = !!backgroundImage;
return React.createElement(
'div',
_extends({
style: { width: width, height: height }
}, styles('root', { selected: selected, disabled: disabled, size: size, hasBackground: hasBackground }, this.props), {
'data-hook': dataHook,
onClick: disabled ? noop : onClick
}),
!hideSelectedIcon && selected && this._renderSelectedIcon(),
hasBackground && this._renderBackgroundLayout(),
!hasBackground && this._renderNoBackgroundLayout()
);
}
}]);
return Thumbnail;
}(React.PureComponent), _class.displayName = 'Thumbnail', _class.propTypes = {
dataHook: PropTypes.string,
/** Title node */
title: PropTypes.node,
/** Description node */
description: PropTypes.node,
/** Image to display in thumbnail.
* If given as string, it will be used within `<img/>`.
* Otherwise can be given as React.Node
*/
image: PropTypes.node,
/** Thumbnail size */
size: PropTypes.oneOf(['tiny', 'small', 'medium']),
/** Set selected state of thumbnail */
selected: PropTypes.bool,
/** Set disabled state of thumbnail */
disabled: PropTypes.bool,
/** Hide icon when thumbnail is selected */
hideSelectedIcon: PropTypes.bool,
/** Overrides title, description and image properties */
backgroundImage: PropTypes.node,
/** Callback function for onClick event */
onClick: PropTypes.func,
/** Width of Thumbnail */
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/** Height of Thumbnail */
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
}, _class.defaultProps = {
size: 'medium',
selected: false,
disabled: false
}, _temp2);
export default Thumbnail;