@react-awesome-query-builder-dev/ui
Version:
User-friendly query builder for React. Core React UI
99 lines • 4.21 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
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 PropTypes from "prop-types";
import range from "lodash/range";
var Proximity = /*#__PURE__*/function (_PureComponent) {
function Proximity() {
var _this;
_classCallCheck(this, Proximity);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, Proximity, [].concat(args));
_this.handleChange = function (value) {
_this.props.setOption("proximity", parseInt(value));
};
return _this;
}
_inherits(Proximity, _PureComponent);
return _createClass(Proximity, [{
key: "render",
value: function render() {
var _this$props = this.props,
defaults = _this$props.defaults,
options = _this$props.options,
config = _this$props.config,
optionLabel = _this$props.optionLabel,
optionPlaceholder = _this$props.optionPlaceholder,
customProps = _this$props.customProps,
minProximity = _this$props.minProximity,
maxProximity = _this$props.maxProximity,
optionTextBefore = _this$props.optionTextBefore,
readonly = _this$props.readonly;
var settings = config.settings,
widgets = config.widgets,
ctx = config.ctx;
var defaultProximity = defaults ? defaults.proximity : undefined;
var showLabels = settings.showLabels;
var selectedProximity = options.get("proximity", defaultProximity);
var proxValues = range(minProximity, maxProximity + 1).map(function (item) {
return {
title: item,
value: item
};
});
var factory = widgets.select.factory;
var Select = function Select(props) {
return factory(props, ctx);
};
return /*#__PURE__*/React.createElement("div", {
className: "operator--PROXIMITY"
}, /*#__PURE__*/React.createElement("div", {
className: "operator--options"
}, showLabels && /*#__PURE__*/React.createElement("label", {
className: "rule--label"
}, optionLabel), !showLabels && optionTextBefore && /*#__PURE__*/React.createElement("div", {
className: "operator--options--sep"
}, /*#__PURE__*/React.createElement("span", null, optionTextBefore)), /*#__PURE__*/React.createElement(Select, _extends({
config: config,
value: selectedProximity,
listValues: proxValues,
setValue: this.handleChange,
readonly: readonly,
placeholder: optionPlaceholder
}, customProps))), /*#__PURE__*/React.createElement("div", {
className: "operator--widgets"
}, this.props.children));
}
}]);
}(PureComponent);
Proximity.propTypes = {
config: PropTypes.object.isRequired,
setOption: PropTypes.func.isRequired,
options: PropTypes.any.isRequired,
//instanceOf(Immutable.Map)
minProximity: PropTypes.number,
maxProximity: PropTypes.number,
optionPlaceholder: PropTypes.string,
optionTextBefore: PropTypes.string,
optionLabel: PropTypes.string,
customProps: PropTypes.object,
readonly: PropTypes.bool
//children
};
Proximity.defaultProps = {
customProps: {},
minProximity: 2,
maxProximity: 10,
optionPlaceholder: "Select words between",
optionLabel: "Words between",
optionTextBefore: null
};
export { Proximity as default };