UNPKG

@elastic/eui

Version:

Elastic UI Component Library

970 lines (966 loc) 44.4 kB
var _excluded = ["isDisabled"]; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /* * 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. */ import React, { Component } from 'react'; import PropTypes from "prop-types"; import classNames from 'classnames'; import moment from 'moment'; // eslint-disable-line import/named import dateMath from '@elastic/datemath'; import { useEuiMemoizedStyles, RenderWithEuiTheme } from '../../../services'; import { isObject } from '../../../services/predicate'; import { euiTextTruncateCSS } from '../../../global_styling'; import { EuiI18nConsumer } from '../../context'; import { EuiDatePickerRange } from '../date_picker_range'; import { EuiFormControlButton, EuiFormControlLayout } from '../../form'; import { EuiToolTip } from '../../tool_tip'; import { RenderI18nTimeOptions } from './time_options'; import { PrettyDuration, showPrettyDuration } from './pretty_duration'; import { EuiTimeWindowButtons } from './time_window_buttons'; import { AsyncInterval } from './async_interval'; import { EuiSuperUpdateButton } from './super_update_button'; import { EuiQuickSelectPopover } from './quick_select_popover/quick_select_popover'; import { EuiDatePopoverButton } from './date_popover/date_popover_button'; import { EuiAutoRefresh, EuiAutoRefreshButton } from '../auto_refresh/auto_refresh'; import { euiSuperDatePickerStyles } from './super_date_picker.styles'; import { jsx as ___EmotionJSX } from "@emotion/react"; function isRangeInvalid(start, end, minDate, maxDate) { if (start === 'now' && end === 'now') { return true; } var startMoment = dateMath.parse(start); var endMoment = dateMath.parse(end, { roundUp: true }); var isInvalid = !startMoment || !endMoment || !startMoment.isValid() || !endMoment.isValid() || !moment(startMoment).isValid() || !moment(endMoment).isValid() || startMoment.isAfter(endMoment) || endMoment.isBefore(startMoment) || minDate != null && startMoment.isBefore(minDate) || maxDate != null && endMoment.isAfter(maxDate); return isInvalid; } export var EuiSuperDatePickerInternal = /*#__PURE__*/function (_Component) { function EuiSuperDatePickerInternal() { var _this; _classCallCheck(this, EuiSuperDatePickerInternal); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _callSuper(this, EuiSuperDatePickerInternal, [].concat(args)); _defineProperty(_this, "asyncInterval", void 0); _defineProperty(_this, "state", { prevProps: { start: _this.props.start, end: _this.props.end }, start: _this.props.start, end: _this.props.end, isInvalid: isRangeInvalid(_this.props.start, _this.props.end, _this.props.minDate, _this.props.maxDate), hasChanged: false, showPrettyDuration: showPrettyDuration(_this.props.start, _this.props.end, _this.props.commonlyUsedRanges), isStartDatePopoverOpen: false, isEndDatePopoverOpen: false }); _defineProperty(_this, "setTime", function (_ref) { var end = _ref.end, start = _ref.start; var isInvalid = isRangeInvalid(start, end, _this.props.minDate, _this.props.maxDate); _this.setState({ start: start, end: end, isInvalid: isInvalid, hasChanged: !(_this.state.prevProps.start === start && _this.state.prevProps.end === end) }); if (!_this.props.showUpdateButton) { _this.props.onTimeChange({ start: start, end: end, isQuickSelection: false, isInvalid: isInvalid }); } }); _defineProperty(_this, "componentDidMount", function () { if (!_this.props.isPaused) { _this.startInterval(_this.props.refreshInterval); } }); _defineProperty(_this, "componentDidUpdate", function () { _this.stopInterval(); if (!_this.props.isPaused) { _this.startInterval(_this.props.refreshInterval); } }); _defineProperty(_this, "componentWillUnmount", function () { _this.stopInterval(); }); _defineProperty(_this, "setStart", function (start) { _this.setTime({ start: start, end: _this.state.end }); }); _defineProperty(_this, "setEnd", function (end) { _this.setTime({ start: _this.state.start, end: end }); }); _defineProperty(_this, "applyTime", function () { _this.props.onTimeChange({ start: _this.state.start, end: _this.state.end, isQuickSelection: false, isInvalid: false }); }); _defineProperty(_this, "applyQuickTime", function (_ref2) { var start = _ref2.start, end = _ref2.end; _this.setState({ showPrettyDuration: showPrettyDuration(start, end, _this.props.commonlyUsedRanges) }); _this.props.onTimeChange({ start: start, end: end, isQuickSelection: true, isInvalid: false }); }); _defineProperty(_this, "hidePrettyDuration", function () { _this.setState({ showPrettyDuration: false, isStartDatePopoverOpen: true }); }); _defineProperty(_this, "onStartDatePopoverToggle", function () { _this.setState(function (prevState) { return { isStartDatePopoverOpen: !prevState.isStartDatePopoverOpen }; }); }); _defineProperty(_this, "onStartDatePopoverClose", function () { _this.setState({ isStartDatePopoverOpen: false }); }); _defineProperty(_this, "onEndDatePopoverToggle", function () { _this.setState(function (prevState) { return { isEndDatePopoverOpen: !prevState.isEndDatePopoverOpen }; }); }); _defineProperty(_this, "onEndDatePopoverClose", function () { _this.setState({ isEndDatePopoverOpen: false }); }); _defineProperty(_this, "onRefreshChange", function (_ref3) { var refreshInterval = _ref3.refreshInterval, intervalUnits = _ref3.intervalUnits, isPaused = _ref3.isPaused; _this.stopInterval(); if (!isPaused) { _this.startInterval(refreshInterval); } if (_this.props.onRefreshChange) { _this.props.onRefreshChange({ refreshInterval: refreshInterval, isPaused: isPaused, intervalUnits: intervalUnits }); } }); _defineProperty(_this, "stopInterval", function () { if (_this.asyncInterval) { _this.asyncInterval.stop(); } }); _defineProperty(_this, "startInterval", function (refreshInterval) { var onRefresh = _this.props.onRefresh; if (onRefresh) { var handler = function handler() { var _this$props = _this.props, start = _this$props.start, end = _this$props.end; onRefresh({ start: start, end: end, refreshInterval: refreshInterval }); }; _this.asyncInterval = new AsyncInterval(handler, refreshInterval); } }); _defineProperty(_this, "renderQuickSelect", function () { var _this$props2 = _this.props, start = _this$props2.start, end = _this$props2.end, customQuickSelectPanels = _this$props2.customQuickSelectPanels, customQuickSelectRender = _this$props2.customQuickSelectRender, commonlyUsedRanges = _this$props2.commonlyUsedRanges, timeOptions = _this$props2.timeOptions, dateFormat = _this$props2.dateFormat, onRefreshChange = _this$props2.onRefreshChange, recentlyUsedRanges = _this$props2.recentlyUsedRanges, refreshInterval = _this$props2.refreshInterval, refreshMinInterval = _this$props2.refreshMinInterval, refreshIntervalUnits = _this$props2.refreshIntervalUnits, isPaused = _this$props2.isPaused, isDisabled = _this$props2.isDisabled, quickSelectButtonProps = _this$props2.quickSelectButtonProps; return ___EmotionJSX(EuiQuickSelectPopover, { applyRefreshInterval: onRefreshChange ? _this.onRefreshChange : undefined, applyTime: _this.applyQuickTime, commonlyUsedRanges: commonlyUsedRanges, customQuickSelectPanels: customQuickSelectPanels, customQuickSelectRender: customQuickSelectRender, dateFormat: dateFormat, end: end, isDisabled: !!isDisabled, isPaused: isPaused, recentlyUsedRanges: recentlyUsedRanges, refreshInterval: refreshInterval, refreshMinInterval: refreshMinInterval, intervalUnits: refreshIntervalUnits, start: start, timeOptions: timeOptions, buttonProps: quickSelectButtonProps }); }); _defineProperty(_this, "renderDatePickerRange", function () { var _this$state = _this.state, end = _this$state.end, hasChanged = _this$state.hasChanged, isEndDatePopoverOpen = _this$state.isEndDatePopoverOpen, isInvalid = _this$state.isInvalid, isStartDatePopoverOpen = _this$state.isStartDatePopoverOpen, showPrettyDuration = _this$state.showPrettyDuration, start = _this$state.start; var _this$props3 = _this.props, isQuickSelectOnly = _this$props3.isQuickSelectOnly, showUpdateButton = _this$props3.showUpdateButton, commonlyUsedRanges = _this$props3.commonlyUsedRanges, canRoundRelativeUnits = _this$props3.canRoundRelativeUnits, timeOptions = _this$props3.timeOptions, dateFormat = _this$props3.dateFormat, refreshInterval = _this$props3.refreshInterval, refreshMinInterval = _this$props3.refreshMinInterval, refreshIntervalUnits = _this$props3.refreshIntervalUnits, isPaused = _this$props3.isPaused, isDisabled = _this$props3.isDisabled, isLoading = _this$props3.isLoading, locale = _this$props3.locale, timeFormat = _this$props3.timeFormat, utcOffset = _this$props3.utcOffset, minDate = _this$props3.minDate, maxDate = _this$props3.maxDate, compressed = _this$props3.compressed, onFocus = _this$props3.onFocus, styles = _this$props3.memoizedStyles, _this$props3$timeZone = _this$props3.timeZoneDisplayProps, timeZoneDisplayProps = _this$props3$timeZone === void 0 ? {} : _this$props3$timeZone; var autoRefreshAppend = !isPaused ? ___EmotionJSX(EuiAutoRefreshButton, { refreshInterval: refreshInterval, minInterval: refreshMinInterval, intervalUnits: refreshIntervalUnits, isDisabled: !!isDisabled, isPaused: isPaused, onRefreshChange: _this.onRefreshChange, shortHand: true }) : undefined; var formControlLayoutProps = { compressed: compressed, isInvalid: isInvalid, isLoading: isLoading && !showUpdateButton, isDisabled: !!isDisabled, prepend: _this.renderQuickSelect(), append: autoRefreshAppend, fullWidth: true, css: [styles.states.euiSuperDatePicker__formControlLayout, isDisabled ? styles.states.disabled : isInvalid ? styles.states.invalid : hasChanged ? styles.states.needsUpdating : styles.states.default] }; var isDisabledDisplay = isObject(isDisabled) && (isDisabled === null || isDisabled === void 0 ? void 0 : isDisabled.display); if (isDisabledDisplay || showPrettyDuration && !isStartDatePopoverOpen && !isEndDatePopoverOpen) { // Tooltip content with full range var startMoment = dateMath.parse(start); var endMoment = dateMath.parse(end, { roundUp: true }); var separator = ' – '; var formattedFullRange = isInvalid ? '' : (startMoment === null || startMoment === void 0 ? void 0 : startMoment.format(dateFormat)) + separator + (endMoment === null || endMoment === void 0 ? void 0 : endMoment.format(dateFormat)); return ___EmotionJSX(RenderWithEuiTheme, null, function (euiTheme) { return ___EmotionJSX(EuiFormControlLayout, formControlLayoutProps, !isQuickSelectOnly && ___EmotionJSX(EuiToolTip, { css: styles.euiSuperDatePicker__prettyDurationTooltip, content: formattedFullRange, display: "block", offset: euiTheme.euiTheme.base * 0.5 }, ___EmotionJSX(EuiFormControlButton, { type: "button", className: classNames('euiSuperDatePicker__prettyFormat', { 'euiSuperDatePicker__prettyFormat--disabled': isDisabled }), compressed: compressed, "data-test-subj": "superDatePickerShowDatesButton", disabled: !!isDisabled, onClick: _this.hidePrettyDuration, onFocus: onFocus }, isDisabledDisplay ? isDisabled.display : ___EmotionJSX("span", { css: euiTextTruncateCSS() }, ___EmotionJSX(PrettyDuration, { timeFrom: start, timeTo: end, quickRanges: commonlyUsedRanges, dateFormat: dateFormat }))))); }); } var rangeCssStyles = [styles.euiSuperDatePicker__range, formControlLayoutProps.css]; // EuiFormControlLayout wants `isDisabled`, EuiDatePickerRange wants `disabled` :T var _ = formControlLayoutProps.isDisabled, _rangeProps = _objectWithoutProperties(formControlLayoutProps, _excluded); var rangeProps = _objectSpread(_objectSpread({}, _rangeProps), {}, { disabled: formControlLayoutProps.isDisabled }); var hasChangedIcon = hasChanged && !isInvalid; return ___EmotionJSX(EuiI18nConsumer, null, function (_ref4) { var contextLocale = _ref4.locale; return ___EmotionJSX(EuiDatePickerRange, _extends({}, rangeProps, { css: rangeCssStyles, isCustom: true, iconType: hasChangedIcon ? 'checkCircle' : false, iconSide: hasChangedIcon ? 'right' : undefined, delimiter: isQuickSelectOnly ? '' : undefined, startDateControl: isQuickSelectOnly ? undefined : ___EmotionJSX(EuiDatePopoverButton, { css: styles.euiSuperDatePicker__rangeInput, className: "euiSuperDatePicker__startPopoverButton", compressed: compressed, position: "start", needsUpdating: hasChanged, isInvalid: isInvalid, isDisabled: !!isDisabled, onChange: _this.setStart, value: start, dateFormat: dateFormat, utcOffset: utcOffset, timeFormat: timeFormat, locale: locale || contextLocale, minDate: minDate, maxDate: maxDate, canRoundRelativeUnits: canRoundRelativeUnits, isOpen: _this.state.isStartDatePopoverOpen, onPopoverToggle: _this.onStartDatePopoverToggle, onPopoverClose: _this.onStartDatePopoverClose, timeOptions: timeOptions, buttonProps: { onFocus: onFocus }, timeZoneDisplayProps: timeZoneDisplayProps }), endDateControl: isQuickSelectOnly ? undefined : ___EmotionJSX(EuiDatePopoverButton, { css: styles.euiSuperDatePicker__rangeInput, position: "end", compressed: compressed, needsUpdating: hasChanged, isInvalid: isInvalid, isDisabled: !!isDisabled, onChange: _this.setEnd, value: end, dateFormat: dateFormat, utcOffset: utcOffset, timeFormat: timeFormat, locale: locale || contextLocale, minDate: minDate, maxDate: maxDate, canRoundRelativeUnits: canRoundRelativeUnits, roundUp: true, isOpen: _this.state.isEndDatePopoverOpen, onPopoverToggle: _this.onEndDatePopoverToggle, onPopoverClose: _this.onEndDatePopoverClose, timeOptions: timeOptions, buttonProps: { onFocus: onFocus }, timeZoneDisplayProps: timeZoneDisplayProps }) })); }); }); _defineProperty(_this, "handleClickUpdateButton", function () { if (!_this.state.hasChanged && _this.props.onRefresh) { var _this$props4 = _this.props, start = _this$props4.start, end = _this$props4.end, refreshInterval = _this$props4.refreshInterval; _this.props.onRefresh({ start: start, end: end, refreshInterval: refreshInterval }); } else { _this.applyTime(); } }); _defineProperty(_this, "renderTimeWindowButtons", function () { if (!_this.props.showTimeWindowButtons || _this.props.isAutoRefreshOnly) { return null; } var _this$props5 = _this.props, start = _this$props5.start, end = _this$props5.end, showTimeWindowButtons = _this$props5.showTimeWindowButtons, compressed = _this$props5.compressed, isDisabled = _this$props5.isDisabled; var config = typeof showTimeWindowButtons === 'boolean' ? {} : showTimeWindowButtons; return ___EmotionJSX(EuiTimeWindowButtons, _extends({ applyTime: _this.applyQuickTime, start: start, end: end, compressed: compressed, isDisabled: !!isDisabled || _this.state.isInvalid }, config)); }); _defineProperty(_this, "renderUpdateButton", function () { var _this$props6 = _this.props, isLoading = _this$props6.isLoading, isDisabled = _this$props6.isDisabled, updateButtonProps = _this$props6.updateButtonProps, showUpdateButton = _this$props6.showUpdateButton, compressed = _this$props6.compressed; if (!showUpdateButton) return null; return ___EmotionJSX(EuiSuperUpdateButton, _extends({ needsUpdate: _this.state.hasChanged, showTooltip: !_this.state.isStartDatePopoverOpen && !_this.state.isEndDatePopoverOpen, isLoading: isLoading, isDisabled: !!isDisabled || _this.state.isInvalid, onClick: _this.handleClickUpdateButton, "data-test-subj": "superDatePickerApplyTimeButton", size: compressed ? 's' : 'm', iconOnly: showUpdateButton === 'iconOnly' }, updateButtonProps)); }); return _this; } _inherits(EuiSuperDatePickerInternal, _Component); return _createClass(EuiSuperDatePickerInternal, [{ key: "render", value: function render() { var _this$props7 = this.props, isAutoRefreshOnly = _this$props7.isAutoRefreshOnly, isDisabled = _this$props7.isDisabled, isPaused = _this$props7.isPaused, onRefreshChange = _this$props7.onRefreshChange, refreshInterval = _this$props7.refreshInterval, refreshMinInterval = _this$props7.refreshMinInterval, refreshIntervalUnits = _this$props7.refreshIntervalUnits, showUpdateButton = _this$props7.showUpdateButton, dataTestSubj = _this$props7['data-test-subj'], _width = _this$props7.width, isQuickSelectOnly = _this$props7.isQuickSelectOnly, compressed = _this$props7.compressed, className = _this$props7.className, styles = _this$props7.memoizedStyles; var _this$state2 = this.state, hasChanged = _this$state2.hasChanged, isInvalid = _this$state2.isInvalid; var classes = classNames('euiSuperDatePicker', className, { 'euiSuperDatePicker--needsUpdating': hasChanged && !isDisabled && !isInvalid }); // Force reduction in width if showing quick select only var width = isQuickSelectOnly ? 'auto' : _width !== null && _width !== void 0 ? _width : 'restricted'; var cssStyles = [styles.euiSuperDatePicker, styles.widths[width], !showUpdateButton && styles.noUpdateButton[width], isAutoRefreshOnly && styles.isAutoRefreshOnly[width], isQuickSelectOnly && styles.isQuickSelectOnly]; return ___EmotionJSX("div", { css: cssStyles, className: classes, "data-test-subj": dataTestSubj }, isAutoRefreshOnly && onRefreshChange ? ___EmotionJSX(EuiAutoRefresh, { isPaused: isPaused, refreshInterval: refreshInterval, minInterval: refreshMinInterval, intervalUnits: refreshIntervalUnits, onRefreshChange: this.onRefreshChange, fullWidth: width === 'full', compressed: compressed, isDisabled: !!isDisabled, className: className }) : ___EmotionJSX(React.Fragment, null, this.renderDatePickerRange(), this.renderTimeWindowButtons(), this.renderUpdateButton())); } }], [{ key: "getDerivedStateFromProps", value: function getDerivedStateFromProps(nextProps, prevState) { if (nextProps.start !== prevState.prevProps.start || nextProps.end !== prevState.prevProps.end) { return { prevProps: { start: nextProps.start, end: nextProps.end }, start: nextProps.start, end: nextProps.end, isInvalid: isRangeInvalid(nextProps.start, nextProps.end, nextProps.minDate, nextProps.maxDate), hasChanged: false, showPrettyDuration: showPrettyDuration(nextProps.start, nextProps.end, nextProps.commonlyUsedRanges) }; } return null; } }]); }(Component); // Because EuiSuperDatePicker is a class component and not a functional component, // we have to use a render prop here in order for us to pass i18n'd strings/objects/etc // to all underlying usages of our timeOptions constants. If someday we convert // EuiSuperDatePicker to an FC, we can likely get rid of this wrapper. _defineProperty(EuiSuperDatePickerInternal, "defaultProps", { dateFormat: 'MMM D, YYYY @ HH:mm:ss.SSS', end: 'now', isAutoRefreshOnly: false, isDisabled: false, isPaused: true, recentlyUsedRanges: [], refreshInterval: 1000, showUpdateButton: true, canRoundRelativeUnits: true, start: 'now-15m', timeFormat: 'HH:mm', width: 'restricted' }); EuiSuperDatePickerInternal.propTypes = { className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any, // The below options are marked as required because they have default fallbacks commonlyUsedRanges: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.shape({ end: PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]).isRequired, label: PropTypes.string, start: PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]).isRequired }).isRequired), PropTypes.arrayOf(PropTypes.shape({ end: PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]).isRequired, label: PropTypes.string, start: PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]).isRequired }).isRequired).isRequired]), customQuickSelectPanels: PropTypes.arrayOf(PropTypes.shape({ title: PropTypes.string.isRequired, content: PropTypes.element.isRequired }).isRequired), /** * An optional render prop function that allows customizing the display of the Quick Select menu. * This function passes all default quick select panels within an object, allowing you to * re-order panels, omit certain panels entirely, or pass in your own fully custom content. */ customQuickSelectRender: PropTypes.func, /** * Specifies the formatted used when displaying dates and/or datetimes * @default 'MMM D, YYYY @ HH:mm:ss.SSS' */ dateFormat: PropTypes.oneOfType([PropTypes.string, PropTypes.string.isRequired]), /** * Set isAutoRefreshOnly to true to limit the component to only display auto refresh content. */ isAutoRefreshOnly: PropTypes.bool, /** * Accepts either a true/false boolean or an object configuration. * * The configuration will render the component as disabled, and allow you to * customize the displayed disabled text. */ isDisabled: PropTypes.oneOfType([PropTypes.bool.isRequired, PropTypes.shape({ display: PropTypes.node.isRequired }).isRequired]), isLoading: PropTypes.bool, /** * @default true */ isPaused: PropTypes.oneOfType([PropTypes.bool, PropTypes.bool.isRequired]), /** * Sets the overall width by adding sensible min and max widths. * - `auto`: fits width to internal content / time string. * - `restricted`: static width that fits the longest possible time string. * - `full`: expands to 100% of the container. * @default 'restricted' */ width: PropTypes.oneOf(["restricted", "full", "auto"]), /** * Reduces overall height to compressed form size */ compressed: PropTypes.bool, /** * Used to localize e.g. month names, passed to `moment` */ locale: PropTypes.any, /** * Triggered whenever the EuiSuperDatePicker's dates are focused */ onFocus: PropTypes.any, /** * Callback for when the refresh interval is fired. * EuiSuperDatePicker will only manage a refresh interval timer when onRefresh callback is supplied * If a promise is returned, the next refresh interval will not start until the promise has resolved. * If the promise rejects the refresh interval will stop and the error thrown */ onRefresh: PropTypes.func, /** * Callback for when the refresh interval changes. * Supply onRefreshChange to show refresh interval inputs in quick select popover */ onRefreshChange: PropTypes.func, /** * Callback for when the time changes. */ onTimeChange: PropTypes.func.isRequired, recentlyUsedRanges: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.shape({ end: PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]).isRequired, label: PropTypes.string, start: PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]).isRequired }).isRequired), PropTypes.arrayOf(PropTypes.shape({ end: PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]).isRequired, label: PropTypes.string, start: PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]).isRequired }).isRequired).isRequired]), refreshInterval: PropTypes.oneOfType([PropTypes.number, PropTypes.number.isRequired]), refreshMinInterval: PropTypes.number, /** * By default, refresh interval units will be rounded up to next largest unit of time * (for example, 90 seconds will become 2m). * * If you do not want this behavior, you will need to store the user-set `intervalUnits` * (passed by `onRefreshChange`) and manually control it via this prop. */ refreshIntervalUnits: PropTypes.any, start: PropTypes.oneOfType([PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]), PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]).isRequired]), end: PropTypes.oneOfType([PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]), PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]).isRequired]), /** * Defines min. date accepted as a selection (in moment format) */ minDate: PropTypes.any, /** * Defines max. date accepted as a selection (in moment format) */ maxDate: PropTypes.any, /** * Specifies the formatted used when displaying times * @default 'HH:mm' */ timeFormat: PropTypes.oneOfType([PropTypes.string, PropTypes.string.isRequired]), utcOffset: PropTypes.number, /** * Set showUpdateButton to false to immediately invoke onTimeChange for all start and end changes. * @default true */ showUpdateButton: PropTypes.oneOfType([PropTypes.bool.isRequired, PropTypes.oneOf(["iconOnly"])]), /** * Set to true to display buttons for time shifting and zooming out, * next to the top-level control. */ showTimeWindowButtons: PropTypes.oneOfType([PropTypes.bool.isRequired, PropTypes.shape({ /** * Show button for zooming out * @default true */ showZoomOut: PropTypes.bool, /** * Show button for zooming in. * Defaults to false because it's a less common use case * @default false */ showZoomIn: PropTypes.bool, /** * Show buttons for shifting the time window forward and backward * @default true */ showShiftArrows: PropTypes.bool, /** * How much the time window is increased when zooming. * A number between 0 and 1 e.g. 0.25, or a string representing a percentage e.g. 25% * @default 0.5 * */ zoomFactor: PropTypes.oneOfType([PropTypes.number.isRequired, PropTypes.string.isRequired]) }).isRequired]), /** * Hides the actual input reducing to just the quick select button. */ isQuickSelectOnly: PropTypes.bool, /** * Props passed to the update button {@link EuiSuperUpdateButtonProps} */ updateButtonProps: PropTypes.shape({ /** * Overrides the default button label with a custom React node. * * When defined, you're responsible for updating the custom label * when the data needs updating (the `needsUpdate` prop) * or is loading (the `isLoading` prop). */ children: PropTypes.node, /** * Show the "Click to apply" tooltip */ showTooltip: PropTypes.bool, /** * Passes props to `EuiToolTip` */ toolTipProps: PropTypes.any, /** * Returns an IconButton instead */ iconOnly: PropTypes.bool, /** * Forces state to be `iconOnly` when within provided breakpoints. * Remove completely with `false` or provide your own list of breakpoints. */ responsive: PropTypes.oneOfType([PropTypes.oneOf([false]), PropTypes.arrayOf(PropTypes.any.isRequired).isRequired]) }), /** * Props passed to the quick select button {@link EuiQuickSelectButtonProps} */ quickSelectButtonProps: PropTypes.any, /** * By default, relative units will be rounded up to next largest unit of time * (for example, 90 minutes will become ~ 2 hours). * * If you do not want this behavior and instead wish to keep the exact units * input by the user, set this flag to `false`. */ canRoundRelativeUnits: PropTypes.bool, /** * Props passed to the time zone display in the popovers {@link EuiTimeZoneDisplayProps} * * Setting `timeZoneDisplayProps.timeZone` with a valid time zone name will make * the time zone information be visible below the start and end input fields. * This is informational only, it will not affect how date/times are handled. */ timeZoneDisplayProps: PropTypes.shape({ /** * A valid time zone name, from the IANA database, e.g. "America/Los_Angeles". * * @link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones */ timeZone: PropTypes.string, /** * Render prop function to add additional content to the time zone display. * Useful for e.g. adding links to documentation or setting pages. */ customRender: PropTypes.func, /** * Reference date to be used while resolving the UTC offset. * Only useful for edge cases involving daylight saving time. */ date: PropTypes.any }), memoizedStyles: PropTypes.any.isRequired, timeOptions: PropTypes.shape({ timeTenseOptions: PropTypes.arrayOf(PropTypes.any.isRequired).isRequired, timeUnitsOptions: PropTypes.arrayOf(PropTypes.any.isRequired).isRequired, relativeOptions: PropTypes.arrayOf(PropTypes.shape({ text: PropTypes.string.isRequired, value: PropTypes.oneOfType([PropTypes.oneOf(["s", "m", "h", "d", "w", "M", "y"]).isRequired, PropTypes.oneOf(["s+", "m+", "h+", "d+", "w+", "M+", "y+"]).isRequired]).isRequired }).isRequired).isRequired, relativeRoundingLabels: PropTypes.any.isRequired, refreshUnitsOptions: PropTypes.arrayOf(PropTypes.any.isRequired).isRequired, commonDurationRanges: PropTypes.arrayOf(PropTypes.shape({ end: PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]).isRequired, label: PropTypes.string, start: PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]).isRequired }).isRequired).isRequired }).isRequired }; export var EuiSuperDatePicker = function EuiSuperDatePicker(props) { var styles = useEuiMemoizedStyles(euiSuperDatePickerStyles); return ___EmotionJSX(RenderI18nTimeOptions, null, function (timeOptions) { return ___EmotionJSX(EuiSuperDatePickerInternal, _extends({}, props, { timeOptions: timeOptions, commonlyUsedRanges: props.commonlyUsedRanges || timeOptions.commonDurationRanges, memoizedStyles: styles })); }); }; EuiSuperDatePicker.propTypes = { className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any, commonlyUsedRanges: PropTypes.arrayOf(PropTypes.shape({ end: PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]).isRequired, label: PropTypes.string, start: PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]).isRequired }).isRequired), customQuickSelectPanels: PropTypes.arrayOf(PropTypes.shape({ title: PropTypes.string.isRequired, content: PropTypes.element.isRequired }).isRequired), /** * An optional render prop function that allows customizing the display of the Quick Select menu. * This function passes all default quick select panels within an object, allowing you to * re-order panels, omit certain panels entirely, or pass in your own fully custom content. */ customQuickSelectRender: PropTypes.func, /** * Specifies the formatted used when displaying dates and/or datetimes * @default 'MMM D, YYYY @ HH:mm:ss.SSS' */ dateFormat: PropTypes.string, /** * Set isAutoRefreshOnly to true to limit the component to only display auto refresh content. */ isAutoRefreshOnly: PropTypes.bool, /** * Accepts either a true/false boolean or an object configuration. * * The configuration will render the component as disabled, and allow you to * customize the displayed disabled text. */ isDisabled: PropTypes.oneOfType([PropTypes.bool.isRequired, PropTypes.shape({ display: PropTypes.node.isRequired }).isRequired]), isLoading: PropTypes.bool, /** * @default true */ isPaused: PropTypes.bool, /** * Sets the overall width by adding sensible min and max widths. * - `auto`: fits width to internal content / time string. * - `restricted`: static width that fits the longest possible time string. * - `full`: expands to 100% of the container. * @default 'restricted' */ width: PropTypes.oneOf(["restricted", "full", "auto"]), /** * Reduces overall height to compressed form size */ compressed: PropTypes.bool, /** * Used to localize e.g. month names, passed to `moment` */ locale: PropTypes.any, /** * Triggered whenever the EuiSuperDatePicker's dates are focused */ onFocus: PropTypes.any, /** * Callback for when the refresh interval is fired. * EuiSuperDatePicker will only manage a refresh interval timer when onRefresh callback is supplied * If a promise is returned, the next refresh interval will not start until the promise has resolved. * If the promise rejects the refresh interval will stop and the error thrown */ onRefresh: PropTypes.func, /** * Callback for when the refresh interval changes. * Supply onRefreshChange to show refresh interval inputs in quick select popover */ onRefreshChange: PropTypes.func, /** * Callback for when the time changes. */ onTimeChange: PropTypes.func.isRequired, recentlyUsedRanges: PropTypes.arrayOf(PropTypes.shape({ end: PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]).isRequired, label: PropTypes.string, start: PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]).isRequired }).isRequired), /** * Minimum refresh interval in milliseconds * @default 0 */ refreshInterval: PropTypes.number, refreshMinInterval: PropTypes.number, /** * By default, refresh interval units will be rounded up to next largest unit of time * (for example, 90 seconds will become 2m). * * If you do not want this behavior, you will need to store the user-set `intervalUnits` * (passed by `onRefreshChange`) and manually control it via this prop. */ refreshIntervalUnits: PropTypes.any, /** * @default 'now' */ start: PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]), end: PropTypes.oneOfType([PropTypes.oneOf(["now"]), PropTypes.string.isRequired]), /** * Defines min. date accepted as a selection (in moment format) */ minDate: PropTypes.any, /** * Defines max. date accepted as a selection (in moment format) */ maxDate: PropTypes.any, /** * Specifies the formatted used when displaying times * @default 'HH:mm' */ timeFormat: PropTypes.string, utcOffset: PropTypes.number, /** * Set showUpdateButton to false to immediately invoke onTimeChange for all start and end changes. * @default true */ showUpdateButton: PropTypes.oneOfType([PropTypes.bool.isRequired, PropTypes.oneOf(["iconOnly"])]), /** * Set to true to display buttons for time shifting and zooming out, * next to the top-level control. */ showTimeWindowButtons: PropTypes.oneOfType([PropTypes.bool.isRequired, PropTypes.shape({ showZoomOut: PropTypes.bool, showZoomIn: PropTypes.bool, showShiftArrows: PropTypes.bool, zoomFactor: PropTypes.oneOfType([PropTypes.number.isRequired, PropTypes.string.isRequired]) }).isRequired]), /** * Hides the actual input reducing to just the quick select button. */ isQuickSelectOnly: PropTypes.bool, /** * Props passed to the update button {@link EuiSuperUpdateButtonProps} */ updateButtonProps: PropTypes.shape({ children: PropTypes.node, showTooltip: PropTypes.bool, toolTipProps: PropTypes.any, iconOnly: PropTypes.bool, responsive: PropTypes.oneOfType([PropTypes.oneOf([false]), PropTypes.arrayOf(PropTypes.any.isRequired).isRequired]) }), /** * Props passed to the quick select button {@link EuiQuickSelectButtonProps} */ quickSelectButtonProps: PropTypes.any, /** * By default, relative units will be rounded up to next largest unit of time * (for example, 90 minutes will become ~ 2 hours). * * If you do not want this behavior and instead wish to keep the exact units * input by the user, set this flag to `false`. */ canRoundRelativeUnits: PropTypes.bool, /** * Props passed to the time zone display in the popovers {@link EuiTimeZoneDisplayProps} * * Setting `timeZoneDisplayProps.timeZone` with a valid time zone name will make * the time zone information be visible below the start and end input fields. * This is informational only, it will not affect how date/times are handled. */ timeZoneDisplayProps: PropTypes.shape({ timeZone: PropTypes.string, customRender: PropTypes.func, date: PropTypes.any }) };