@elastic/eui
Version:
Elastic UI Component Library
143 lines (142 loc) • 8.98 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", "data-test-subj", "startDateControl", "endDateControl", "iconType", "iconSide", "inline", "shadow", "fullWidth", "compressed", "isCustom", "readOnly", "isLoading", "isInvalid", "disabled", "onFocus", "onBlur", "append", "prepend", "delimiter"];
/*
* 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(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
var EuiDatePickerRange = exports.EuiDatePickerRange = function EuiDatePickerRange(_ref) {
var children = _ref.children,
className = _ref.className,
dataTestSubj = _ref['data-test-subj'],
startDateControl = _ref.startDateControl,
endDateControl = _ref.endDateControl,
_ref$iconType = _ref.iconType,
iconType = _ref$iconType === void 0 ? true : _ref$iconType,
_ref$iconSide = _ref.iconSide,
iconSide = _ref$iconSide === void 0 ? 'left' : _ref$iconSide,
inline = _ref.inline,
_ref$shadow = _ref.shadow,
shadow = _ref$shadow === void 0 ? true : _ref$shadow,
_fullWidth = _ref.fullWidth,
_compressed = _ref.compressed,
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,
delimiter = _ref.delimiter,
rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
// `fullWidth` and `compressed` should not affect inline datepickers (matches non-range behavior)
var fullWidth = _fullWidth && !inline;
var compressed = _compressed && !inline;
var classes = (0, _classnames.default)('euiDatePickerRange', className);
var styles = (0, _services.useEuiMemoizedStyles)(_date_picker_range.euiDatePickerRangeStyles);
var inlineStyles = (0, _services.useEuiMemoizedStyles)(_date_picker_range.euiDatePickerRangeInlineStyles);
var cssStyles = !inline ? styles.euiDatePickerRange : [inlineStyles.euiDatePickerRangeInline,
// Determine the inline container query to use based on the width of the react-datepicker
startDateControl !== null && startDateControl !== void 0 && startDateControl.props.showTimeSelect || endDateControl !== null && endDateControl !== void 0 && endDateControl.props.showTimeSelect ? inlineStyles.responsiveWithTimeSelect : inlineStyles.responsive, shadow && inlineStyles.shadow];
var startControl = startDateControl;
var endControl = endDateControl;
if (!isCustom) {
startControl = startControl && /*#__PURE__*/(0, _react.cloneElement)(startDateControl, {
controlOnly: true,
showIcon: false,
inline: inline,
compressed: compressed,
fullWidth: fullWidth,
readOnly: readOnly,
disabled: disabled || (startDateControl === null || startDateControl === void 0 ? void 0 : startDateControl.props.disabled),
isInvalid: isInvalid || (startDateControl === null || startDateControl === void 0 ? void 0 : startDateControl.props.isInvalid),
className: (0, _classnames.default)('euiDatePickerRange__start', startDateControl === null || startDateControl === void 0 ? void 0 : startDateControl.props.className),
'data-test-subj': dataTestSubj ? "".concat(dataTestSubj, "-start-date") : undefined,
onBlur: function onBlur(event) {
var _startDateControl$pro, _startDateControl$pro2;
startDateControl === null || startDateControl === void 0 || (_startDateControl$pro = startDateControl.props) === null || _startDateControl$pro === void 0 || (_startDateControl$pro2 = _startDateControl$pro.onBlur) === null || _startDateControl$pro2 === void 0 || _startDateControl$pro2.call(_startDateControl$pro, event);
_onBlur === null || _onBlur === void 0 || _onBlur(event);
},
onFocus: function onFocus(event) {
var _startDateControl$pro3, _startDateControl$pro4;
startDateControl === null || startDateControl === void 0 || (_startDateControl$pro3 = startDateControl.props) === null || _startDateControl$pro3 === void 0 || (_startDateControl$pro4 = _startDateControl$pro3.onFocus) === null || _startDateControl$pro4 === void 0 || _startDateControl$pro4.call(_startDateControl$pro3, event);
_onFocus === null || _onFocus === void 0 || _onFocus(event);
}
});
endControl = endControl && /*#__PURE__*/(0, _react.cloneElement)(endDateControl, {
controlOnly: true,
showIcon: false,
inline: inline,
compressed: compressed,
fullWidth: fullWidth,
readOnly: readOnly,
disabled: disabled || (endDateControl === null || endDateControl === void 0 ? void 0 : endDateControl.props.disabled),
isInvalid: isInvalid || (endDateControl === null || endDateControl === void 0 ? void 0 : endDateControl.props.isInvalid),
popoverPlacement: 'downRight',
className: (0, _classnames.default)('euiDatePickerRange__end', endDateControl === null || endDateControl === void 0 ? void 0 : endDateControl.props.className),
'data-test-subj': dataTestSubj ? "".concat(dataTestSubj, "-end-date") : undefined,
onBlur: function onBlur(event) {
var _endDateControl$props, _endDateControl$props2;
endDateControl === null || endDateControl === void 0 || (_endDateControl$props = endDateControl.props) === null || _endDateControl$props === void 0 || (_endDateControl$props2 = _endDateControl$props.onBlur) === null || _endDateControl$props2 === void 0 || _endDateControl$props2.call(_endDateControl$props, event);
_onBlur === null || _onBlur === void 0 || _onBlur(event);
},
onFocus: function onFocus(event) {
var _endDateControl$props3, _endDateControl$props4;
endDateControl === null || endDateControl === void 0 || (_endDateControl$props3 = endDateControl.props) === null || _endDateControl$props3 === void 0 || (_endDateControl$props4 = _endDateControl$props3.onFocus) === null || _endDateControl$props4 === void 0 || _endDateControl$props4.call(_endDateControl$props3, event);
_onFocus === null || _onFocus === void 0 || _onFocus(event);
}
});
}
var icon = (0, _react.useMemo)(function () {
if (inline) return undefined;
if (iconType === false) return undefined;
if (iconType === true) return 'calendar';
if (iconType && iconSide) return {
side: iconSide,
type: iconType
};
return iconType;
}, [iconType, iconSide, inline]);
return (0, _react2.jsx)("div", (0, _extends2.default)({
className: classes,
css: cssStyles,
"data-test-subj": dataTestSubj
}, rest), (0, _react2.jsx)(_form.EuiFormControlLayoutDelimited, {
delimiter: delimiter,
icon: icon,
startControl: startControl,
endControl: endControl,
fullWidth: fullWidth,
compressed: compressed,
readOnly: readOnly,
isDisabled: disabled,
isInvalid: isInvalid,
isLoading: isLoading,
append: inline ? undefined : append,
prepend: inline ? undefined : prepend,
css: inline && !disabled && (shadow ? inlineStyles.formLayout.shadow : inlineStyles.formLayout.noShadow),
wrapperProps: {
'data-test-subj': dataTestSubj ? "".concat(dataTestSubj, "-range-wrapper") : undefined
}
}));
};