wix-style-react
Version:
148 lines (132 loc) • 5.85 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
import React from 'react';
import PropTypes from 'prop-types';
import Checkbox from '../Checkbox';
import Radio from '../Radio';
import Text from '../Text';
import { st, classes } from './Selector.st.css';
import ExtraText from './ExtraText';
import ProgressBar from './ProgressBar';
var Selector = /*#__PURE__*/function (_React$PureComponent) {
_inherits(Selector, _React$PureComponent);
var _super = _createSuper(Selector);
function Selector() {
var _this;
_classCallCheck(this, Selector);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_defineProperty(_assertThisInitialized(_this), "_onClick", function () {
return !_this.props.isDisabled && _this.props.onToggle(_this.props.id);
});
return _this;
}
_createClass(Selector, [{
key: "render",
value: function render() {
var _this$props = this.props,
dataHook = _this$props.dataHook,
imageSize = _this$props.imageSize,
imageShape = _this$props.imageShape,
image = _this$props.image,
title = _this$props.title,
subtitle = _this$props.subtitle,
extraNode = _this$props.extraNode,
isSelected = _this$props.isSelected,
isDisabled = _this$props.isDisabled,
toggleType = _this$props.toggleType,
showBelowNodeOnSelect = _this$props.showBelowNodeOnSelect,
subtitleNode = _this$props.subtitleNode,
belowNode = _this$props.belowNode,
className = _this$props.className;
return /*#__PURE__*/React.createElement("li", {
"data-hook": dataHook,
className: st(classes.root, className),
onClick: this._onClick,
"data-shape": imageShape,
"data-size": imageSize
}, /*#__PURE__*/React.createElement("div", {
className: classes.mainPart
}, toggleType === 'checkbox' ? /*#__PURE__*/React.createElement(Checkbox, {
dataHook: "toggle",
checked: isSelected,
disabled: isDisabled
}) : /*#__PURE__*/React.createElement(Radio, {
dataHook: "toggle",
checked: isSelected,
disabled: isDisabled
}), image && /*#__PURE__*/React.createElement("div", {
"data-hook": "selector-image",
className: st(classes.image, {
size: imageSize,
imageShape: imageShape
}),
children: image
}), /*#__PURE__*/React.createElement("div", {
className: classes.titles
}, /*#__PURE__*/React.createElement(Text, {
dataHook: "selector-title",
ellipsis: true,
children: title
}), subtitle && /*#__PURE__*/React.createElement(Text, {
size: "small",
secondary: true,
dataHook: "selector-subtitle",
ellipsis: true,
children: subtitle
}), subtitleNode && /*#__PURE__*/React.createElement("div", {
"data-hook": "subtitle-node"
}, subtitleNode)), extraNode && /*#__PURE__*/React.createElement("div", {
className: classes.extra,
"data-hook": "selector-extra-node",
children: extraNode
})), showBelowNodeOnSelect && belowNode && isSelected && /*#__PURE__*/React.createElement("div", {
"data-hook": "below-section",
className: classes.belowSection
}, belowNode));
}
}]);
return Selector;
}(React.PureComponent);
_defineProperty(Selector, "propTypes", {
/** Applied as data-hook HTML attribute that can be used in the tests */
dataHook: PropTypes.string,
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.node.isRequired,
isSelected: PropTypes.bool,
isDisabled: PropTypes.bool,
subtitle: PropTypes.string,
extraNode: PropTypes.node,
onToggle: PropTypes.func,
toggleType: PropTypes.oneOf(['checkbox', 'radio']),
showBelowNodeOnSelect: PropTypes.bool,
belowNode: PropTypes.node,
subtitleNode: PropTypes.node,
className: PropTypes.string
});
_defineProperty(Selector, "defaultProps", {
isSelected: false,
isDisabled: false,
toggleType: 'radio',
imageSize: 'large',
imageShape: 'rectangular',
onToggle: function onToggle(i) {
return i;
},
showBelowNodeOnSelect: false
});
Selector.ExtraText = ExtraText;
Selector.ProgressBar = ProgressBar;
export default Selector;