@react-awesome-query-builder/antd
Version:
User-friendly query builder for React. AntDesign widgets
132 lines (131 loc) • 5.06 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
import React, { PureComponent } from "react";
import map from "lodash/map";
import { Button, Radio } from "antd";
var ButtonGroup = Button.Group;
var ConjsButton = /*#__PURE__*/function (_PureComponent) {
function ConjsButton() {
var _this;
_classCallCheck(this, ConjsButton);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, ConjsButton, [].concat(args));
_this.onClick = function (_e) {
var _this$props = _this.props,
setConjunction = _this$props.setConjunction,
item = _this$props.item;
var conj = item.key;
setConjunction(conj);
};
return _this;
}
_inherits(ConjsButton, _PureComponent);
return _createClass(ConjsButton, [{
key: "render",
value: function render() {
var _this$props2 = this.props,
disabled = _this$props2.disabled,
item = _this$props2.item;
return /*#__PURE__*/React.createElement(Button, {
disabled: disabled,
type: item.checked ? "primary" : null,
onClick: this.onClick
}, item.label);
}
}]);
}(PureComponent);
var ConjsButtons = /*#__PURE__*/function (_PureComponent2) {
function ConjsButtons() {
var _this2;
_classCallCheck(this, ConjsButtons);
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
_this2 = _callSuper(this, ConjsButtons, [].concat(args));
_this2.setNot = function (e) {
var _this2$props = _this2.props,
setNot = _this2$props.setNot,
not = _this2$props.not;
if (setNot) setNot(!not);
};
return _this2;
}
_inherits(ConjsButtons, _PureComponent2);
return _createClass(ConjsButtons, [{
key: "render",
value: function render() {
var _this$props3 = this.props,
readonly = _this$props3.readonly,
disabled = _this$props3.disabled,
not = _this$props3.not,
conjunctionOptions = _this$props3.conjunctionOptions,
config = _this$props3.config,
setConjunction = _this$props3.setConjunction,
notLabel = _this$props3.notLabel,
showNot = _this$props3.showNot;
var conjsCount = Object.keys(conjunctionOptions).length;
var lessThenTwo = disabled;
var _config$settings = config.settings,
forceShowConj = _config$settings.forceShowConj,
renderSize = _config$settings.renderSize;
var showConj = forceShowConj || conjsCount > 1 && !lessThenTwo;
return /*#__PURE__*/React.createElement(ButtonGroup, {
key: "group-conjs-buttons",
size: renderSize,
disabled: disabled || readonly
}, showNot && (readonly ? not : true) && /*#__PURE__*/React.createElement(Button, {
key: "group-not",
onClick: this.setNot,
type: not ? "primary" : "text",
disabled: readonly,
danger: true
}, notLabel), showConj && map(conjunctionOptions, function (item, _index) {
return (readonly || disabled) && !item.checked ? null : /*#__PURE__*/React.createElement(ConjsButton, {
key: item.id,
item: item,
disabled: disabled || readonly,
setConjunction: setConjunction
});
}));
}
}]);
}(PureComponent); // obsolete
/*
const RadioButton = Radio.Button;
const RadioGroup = Radio.Group;
class ConjsRadios extends PureComponent {
setConjunction = (e) => {
const {setConjunction} = this.props;
const conj = e.target.value;
setConjunction(conj);
}
render() {
const {readonly, disabled, selectedConjunction, conjunctionOptions, config} = this.props;
return (
<RadioGroup
key="group-conjs-radios"
disabled={disabled}
value={selectedConjunction}
size={config.settings.renderSize}
onChange={this.setConjunction}
>
{map(conjunctionOptions, (item, _index) => readonly && !item.checked ? null : (
<RadioButton
key={item.id}
value={item.key}
//checked={item.checked}
>{item.label}</RadioButton>
))}
</RadioGroup>
);
}
}
*/
export { ConjsButtons as default };