@darwino/darwino-react-bootstrap
Version:
A set of Javascript classes and utilities
101 lines (86 loc) • 2.85 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
/*
* (c) Copyright Darwino Inc. 2014-2017.
*/
import React, { Component } from "react";
import PropTypes from 'prop-types';
import { Button, FormControl, InputGroup } from 'react-bootstrap';
import FieldStatic from './FieldStatic';
import Dialog from "./Dialog";
class FieldValuePicker extends Component {
// Context to read from the parent - router
constructor(props, context) {
super(props, context);
}
getDialog() {
return this.context.documentForm.getDialog();
}
render() {
var _this$props = this.props,
{
input,
picker,
pickerTitle,
multiple,
separator,
meta,
editable,
disabled,
readOnly,
label
} = _this$props,
props = _objectWithoutProperties(_this$props, ["input", "picker", "pickerTitle", "multiple", "separator", "meta", "editable", "disabled", "readOnly", "label"]);
if (readOnly) {
var _this$props2 = this.props,
{
pickerTitle: _pickerTitle,
editable: _editable
} = _this$props2,
roprops = _objectWithoutProperties(_this$props2, ["pickerTitle", "editable"]);
return /*#__PURE__*/React.createElement(FieldStatic, roprops);
}
var inputAttr = input;
if (multiple) {
var _separator = this.props.separator || ',';
inputAttr = {
value: Array.isArray(input.value) ? input.value.join(_separator) : "",
onBlur: e => {
var a = (e.target.value || "").split(_separator);
input.onBlur(a);
},
onChange: e => {
var a = (e.target.value || "").split(_separator);
input.onChange(a);
}
};
}
var _this = this; // not sure why this is needed
return /*#__PURE__*/React.createElement(InputGroup, null, /*#__PURE__*/React.createElement(FormControl, _extends({
type: "text"
}, props, input, {
disabled: disabled,
readOnly: !editable && !disabled
})), /*#__PURE__*/React.createElement(InputGroup.Button, null, /*#__PURE__*/React.createElement(Button, {
onClick: () => _this.getDialog().picker({
multiple,
title: pickerTitle,
value: input.value,
actions: [Dialog.OkAction, Dialog.CancelAction],
picker: picker,
onClose: (action, value) => {
if (action == Dialog.OK) {
input.onChange(value);
}
}
}),
disabled: disabled
}, "...")));
}
}
_defineProperty(FieldValuePicker, "contextTypes", {
documentForm: PropTypes.object
});
export default FieldValuePicker;
//# sourceMappingURL=FieldValuePicker.js.map