@elastic/eui
Version:
Elastic UI Component Library
129 lines (128 loc) • 7.76 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.EuiDatePickerRange = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _form = require("../form");
var _services = require("../../services");
var _date_picker_range = require("./date_picker_range.styles");
var _react2 = require("@emotion/react");
var _excluded = ["children", "className", "startDateControl", "endDateControl", "iconType", "inline", "shadow", "fullWidth", "isCustom", "readOnly", "isLoading", "isInvalid", "disabled", "onFocus", "onBlur", "append", "prepend"];
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var EuiDatePickerRange = function EuiDatePickerRange(_ref) {
var children = _ref.children,
className = _ref.className,
startDateControl = _ref.startDateControl,
endDateControl = _ref.endDateControl,
_ref$iconType = _ref.iconType,
iconType = _ref$iconType === void 0 ? true : _ref$iconType,
inline = _ref.inline,
_ref$shadow = _ref.shadow,
shadow = _ref$shadow === void 0 ? true : _ref$shadow,
_fullWidth = _ref.fullWidth,
isCustom = _ref.isCustom,
readOnly = _ref.readOnly,
isLoading = _ref.isLoading,
isInvalid = _ref.isInvalid,
disabled = _ref.disabled,
_onFocus = _ref.onFocus,
_onBlur = _ref.onBlur,
append = _ref.append,
prepend = _ref.prepend,
rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
// `fullWidth` should not affect inline datepickers (matches non-range behavior)
var fullWidth = _fullWidth && !inline;
var classes = (0, _classnames.default)('euiDatePickerRange', className);
var euiTheme = (0, _services.useEuiTheme)();
var styles = (0, _date_picker_range.euiDatePickerRangeStyles)(euiTheme);
var cssStyles = [styles.euiDatePickerRange];
if (inline) {
// Determine the inline container query to use based on the width of the react-datepicker
var hasTimeSelect = startDateControl.props.showTimeSelect || endDateControl.props.showTimeSelect;
var inlineStyles = (0, _date_picker_range.euiDatePickerRangeInlineStyles)(euiTheme);
cssStyles.push(inlineStyles.inline);
cssStyles.push(hasTimeSelect ? inlineStyles.responsiveWithTimeSelect : inlineStyles.responsive);
if (shadow) cssStyles.push(inlineStyles.shadow);
}
var startControl = startDateControl;
var endControl = endDateControl;
if (!isCustom) {
startControl = /*#__PURE__*/(0, _react.cloneElement)(startDateControl, {
controlOnly: true,
showIcon: false,
inline: inline,
fullWidth: fullWidth,
readOnly: readOnly,
disabled: disabled || startDateControl.props.disabled,
isInvalid: isInvalid || startDateControl.props.isInvalid,
className: (0, _classnames.default)('euiDatePickerRange__start', startDateControl.props.className),
onBlur: function onBlur(event) {
var _startDateControl$pro, _startDateControl$pro2;
(_startDateControl$pro = startDateControl.props) === null || _startDateControl$pro === void 0 ? void 0 : (_startDateControl$pro2 = _startDateControl$pro.onBlur) === null || _startDateControl$pro2 === void 0 ? void 0 : _startDateControl$pro2.call(_startDateControl$pro, event);
_onBlur === null || _onBlur === void 0 ? void 0 : _onBlur(event);
},
onFocus: function onFocus(event) {
var _startDateControl$pro3, _startDateControl$pro4;
(_startDateControl$pro3 = startDateControl.props) === null || _startDateControl$pro3 === void 0 ? void 0 : (_startDateControl$pro4 = _startDateControl$pro3.onFocus) === null || _startDateControl$pro4 === void 0 ? void 0 : _startDateControl$pro4.call(_startDateControl$pro3, event);
_onFocus === null || _onFocus === void 0 ? void 0 : _onFocus(event);
}
});
endControl = /*#__PURE__*/(0, _react.cloneElement)(endDateControl, {
controlOnly: true,
showIcon: false,
inline: inline,
fullWidth: fullWidth,
readOnly: readOnly,
disabled: disabled || endDateControl.props.disabled,
isInvalid: isInvalid || endDateControl.props.isInvalid,
popoverPlacement: 'downRight',
className: (0, _classnames.default)('euiDatePickerRange__end', endDateControl.props.className),
onBlur: function onBlur(event) {
var _endDateControl$props, _endDateControl$props2;
(_endDateControl$props = endDateControl.props) === null || _endDateControl$props === void 0 ? void 0 : (_endDateControl$props2 = _endDateControl$props.onBlur) === null || _endDateControl$props2 === void 0 ? void 0 : _endDateControl$props2.call(_endDateControl$props, event);
_onBlur === null || _onBlur === void 0 ? void 0 : _onBlur(event);
},
onFocus: function onFocus(event) {
var _endDateControl$props3, _endDateControl$props4;
(_endDateControl$props3 = endDateControl.props) === null || _endDateControl$props3 === void 0 ? void 0 : (_endDateControl$props4 = _endDateControl$props3.onFocus) === null || _endDateControl$props4 === void 0 ? void 0 : _endDateControl$props4.call(_endDateControl$props3, event);
_onFocus === null || _onFocus === void 0 ? void 0 : _onFocus(event);
}
});
}
var icon = (0, _react.useMemo)(function () {
if (inline) return undefined;
if (iconType === false) return undefined;
if (iconType === true) return 'calendar';
return iconType;
}, [iconType, inline]);
return (0, _react2.jsx)("span", (0, _extends2.default)({
className: classes,
css: cssStyles
}, rest), (0, _react2.jsx)(_form.EuiFormControlLayoutDelimited, {
icon: icon,
startControl: startControl,
endControl: endControl,
fullWidth: fullWidth,
readOnly: readOnly,
isDisabled: disabled,
isInvalid: isInvalid,
isLoading: isLoading,
append: inline ? undefined : append,
prepend: inline ? undefined : prepend
}));
};
exports.EuiDatePickerRange = EuiDatePickerRange;