choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
165 lines (145 loc) • 4.99 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import React, { Component } from 'react';
import classNames from 'classnames';
import Col from '../../../es/col';
import noop from 'lodash/noop';
import CheckBox from '../../../es/checkbox';
var ScreeningOption = /*#__PURE__*/function (_Component) {
_inherits(ScreeningOption, _Component);
var _super = _createSuper(ScreeningOption);
function ScreeningOption() {
var _this;
_classCallCheck(this, ScreeningOption);
_this = _super.apply(this, arguments);
_this.onMouseLeave = function () {
var _this$props = _this.props,
optionkey = _this$props.optionkey,
value = _this$props.value,
onMouseLeave = _this$props.onMouseLeave;
var info = {
key: optionkey,
value: value
};
if (onMouseLeave) {
onMouseLeave(info);
}
};
_this.onMouseEnter = function () {
var _this$props2 = _this.props,
optionkey = _this$props2.optionkey,
value = _this$props2.value,
onMouseEnter = _this$props2.onMouseEnter;
var info = {
key: optionkey,
value: value
};
if (onMouseEnter) {
onMouseEnter(info);
}
};
_this.onClick = function () {
var _this$props3 = _this.props,
optionkey = _this$props3.optionkey,
multiple = _this$props3.multiple,
onClick = _this$props3.onClick,
onSelect = _this$props3.onSelect,
onDeselect = _this$props3.onDeselect,
value = _this$props3.value,
isSelected = _this$props3.isSelected;
var info = {
key: optionkey,
value: value
};
if (onSelect && onClick) {
onClick(info);
if (multiple) {
if (isSelected && onDeselect) {
onDeselect(info);
} else {
onSelect(info);
}
} else {
onSelect(info);
}
}
};
return _this;
}
_createClass(ScreeningOption, [{
key: "render",
value: function render() {
var _classNames;
var _this$props4 = this.props,
prefixCls = _this$props4.prefixCls,
disabled = _this$props4.disabled,
children = _this$props4.children,
optionkey = _this$props4.optionkey,
active = _this$props4.active,
style = _this$props4.style,
multiple = _this$props4.multiple,
onMouseDown = _this$props4.onMouseDown,
isSelected = _this$props4.isSelected,
span = _this$props4.span,
order = _this$props4.order,
offset = _this$props4.offset,
push = _this$props4.push,
pull = _this$props4.pull,
xs = _this$props4.xs,
sm = _this$props4.sm,
md = _this$props4.md,
lg = _this$props4.lg,
xl = _this$props4.xl,
xxl = _this$props4.xxl,
optionRender = _this$props4.optionRender;
var ScreeningOptionPrefix = "".concat(prefixCls, "-option");
var className = classNames(ScreeningOptionPrefix, (_classNames = {}, _defineProperty(_classNames, "".concat(ScreeningOptionPrefix, "-disabled"), disabled), _defineProperty(_classNames, "".concat(ScreeningOptionPrefix, "-selected"), isSelected), _defineProperty(_classNames, "".concat(ScreeningOptionPrefix, "-active"), active), _classNames));
var attrs = {
optionkey: optionkey,
className: className,
span: span,
order: order,
offset: offset,
push: push,
pull: pull,
xs: xs,
sm: sm,
md: md,
lg: lg,
xl: xl,
xxl: xxl
};
var mouseEvent = {};
if (!disabled) {
mouseEvent = {
onClick: this.onClick,
onMouseLeave: this.onMouseLeave,
onMouseEnter: this.onMouseEnter,
onMouseDown: onMouseDown
};
}
var checkbox = multiple ? /*#__PURE__*/React.createElement(CheckBox, {
checked: isSelected
}) : null;
return /*#__PURE__*/React.createElement(Col, _extends({}, attrs, {
style: style
}), /*#__PURE__*/React.createElement("div", _extends({
className: "".concat(ScreeningOptionPrefix, "-content")
}, mouseEvent), optionRender || /*#__PURE__*/React.createElement(React.Fragment, null, checkbox, children)));
}
}]);
return ScreeningOption;
}(Component);
export { ScreeningOption as default };
ScreeningOption.defaultProps = {
onSelect: noop,
onMouseEnter: noop,
onMouseLeave: noop,
onMouseDown: noop,
isSelected: false
};
//# sourceMappingURL=ScreeningOption.js.map