wix-style-react
Version:
wix-style-react
122 lines (104 loc) • 5.16 kB
JavaScript
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 classNames from 'classnames';
import WixComponent from '../BaseComponents/WixComponent';
import Checkbox from '../Checkbox';
import RadioButton from '../RadioGroup/RadioButton/RadioButton';
import Text from '../Text';
import styles from './Selector.scss';
import ExtraText from './ExtraText';
import ProgressBar from './ProgressBar';
var Selector = (_temp2 = _class = function (_WixComponent) {
_inherits(Selector, _WixComponent);
function Selector() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, Selector);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Selector.__proto__ || Object.getPrototypeOf(Selector)).call.apply(_ref, [this].concat(args))), _this), _this.radioButtonAndImageMargins = '57px', _this._onClick = function () {
return !_this.props.isDisabled && _this.props.onToggle(_this.props.id);
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(Selector, [{
key: 'render',
value: function render() {
var _props = this.props,
imageSize = _props.imageSize,
imageShape = _props.imageShape,
image = _props.image,
title = _props.title,
subtitle = _props.subtitle,
extraNode = _props.extraNode,
isSelected = _props.isSelected,
isDisabled = _props.isDisabled,
toggleType = _props.toggleType;
return React.createElement(
'li',
{ className: styles.root, onClick: this._onClick },
toggleType === 'checkbox' ? React.createElement(Checkbox, {
dataHook: 'toggle',
checked: isSelected,
disabled: isDisabled
}) : React.createElement(RadioButton, {
dataHook: 'toggle',
checked: isSelected,
disabled: isDisabled
}),
image && React.createElement('div', {
'data-hook': 'selector-image',
className: classNames(styles.image, styles[imageSize], styles[imageShape]),
children: image
}),
React.createElement(
'div',
{ className: styles.titles },
React.createElement(Text, { dataHook: 'selector-title', ellipsis: true, children: title }),
subtitle && React.createElement(Text, {
size: 'small',
secondary: true,
dataHook: 'selector-subtitle',
ellipsis: true,
children: subtitle
})
),
extraNode && React.createElement('div', {
className: styles.extra,
'data-hook': 'selector-extra-node',
children: extraNode
})
);
}
}]);
return Selector;
}(WixComponent), _class.propTypes = {
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
image: PropTypes.node,
imageSize: PropTypes.oneOf(['tiny', 'small', 'portrait', 'large', 'cinema']),
imageShape: PropTypes.oneOf(['rectangular', 'circle']),
title: PropTypes.string.isRequired,
isSelected: PropTypes.bool,
isDisabled: PropTypes.bool,
subtitle: PropTypes.string,
extraNode: PropTypes.node,
onToggle: PropTypes.func,
toggleType: PropTypes.oneOf(['checkbox', 'radio'])
}, _class.defaultProps = {
isSelected: false,
isDisabled: false,
toggleType: 'radio',
imageSize: 'large',
imageShape: 'rectangular',
onToggle: function onToggle(i) {
return i;
}
}, _temp2);
Selector.ExtraText = ExtraText;
Selector.ProgressBar = ProgressBar;
export default Selector;