UNPKG

@react-awesome-query-builder/antd

Version:
89 lines 3.54 kB
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 { TimePicker } from "../moment"; import { Utils } from "@react-awesome-query-builder/ui"; var moment = Utils.moment; var TimeWidget = /*#__PURE__*/function (_PureComponent) { function TimeWidget(props) { var _this; _classCallCheck(this, TimeWidget); _this = _callSuper(this, TimeWidget, [props]); _this.handleChange = function (aValue) { var _this$props = _this.props, setValue = _this$props.setValue, valueFormat = _this$props.valueFormat, timeFormat = _this$props.timeFormat; if (aValue && aValue.isValid() && timeFormat == "HH:mm") { aValue.set({ second: 0, millisecond: 0 }); } var value = aValue && aValue.isValid() ? aValue.format(valueFormat) : undefined; if (value || aValue === null) setValue(value); }; var _valueFormat = props.valueFormat, _value = props.value, _setValue = props.setValue; var mValue = _value ? moment(_value, _valueFormat) : null; if (mValue && !mValue.isValid()) { _setValue(null); } return _this; } _inherits(TimeWidget, _PureComponent); return _createClass(TimeWidget, [{ key: "render", value: function render() { var _this$props2 = this.props, placeholder = _this$props2.placeholder, customProps = _this$props2.customProps, value = _this$props2.value, valueFormat = _this$props2.valueFormat, timeFormat = _this$props2.timeFormat, use12Hours = _this$props2.use12Hours, config = _this$props2.config, readonly = _this$props2.readonly; var renderSize = config.settings.renderSize; var timeValue = value ? moment(value, valueFormat) : null; return /*#__PURE__*/React.createElement(TimePicker, _extends({ disabled: readonly, use12Hours: use12Hours, key: "widget-time", size: renderSize, placeholder: placeholder, format: timeFormat, value: timeValue, onChange: this.handleChange }, customProps)); } }]); }(PureComponent); TimeWidget.propTypes = { setValue: PropTypes.func.isRequired, value: PropTypes.string, //in valueFormat config: PropTypes.object.isRequired, field: PropTypes.any, placeholder: PropTypes.string, customProps: PropTypes.object, readonly: PropTypes.bool, // from fieldSettings: timeFormat: PropTypes.string, valueFormat: PropTypes.string, use12Hours: PropTypes.bool }; TimeWidget.defaultProps = { timeFormat: "HH:mm", valueFormat: "HH:mm:ss", use12Hours: false }; export { TimeWidget as default };