import _extends from "@babel/runtime/helpers/esm/extends"; import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } import React from 'react'; import PropTypes from 'prop-types'; import { forbidExtraProps, nonNegativeInteger } from 'airbnb-prop-types'; import { css, withStyles, withStylesPropTypes } from 'react-with-styles'; import { DateRangePickerInputPhrases } from '../defaultPhrases'; import getPhrasePropTypes from '../utils/getPhrasePropTypes'; import noflip from '../utils/noflip'; import openDirectionShape from '../shapes/OpenDirectionShape'; import DateInput from './DateInput'; import IconPositionShape from '../shapes/IconPositionShape'; import DisabledShape from '../shapes/DisabledShape'; import RightArrow from './RightArrow'; import LeftArrow from './LeftArrow'; import CloseButton from './CloseButton'; import CalendarIcon from './CalendarIcon'; import { START_DATE, END_DATE, ICON_BEFORE_POSITION, ICON_AFTER_POSITION, OPEN_DOWN } from '../constants'; var propTypes = process.env.NODE_ENV !== "production" ? forbidExtraProps(_objectSpread({}, withStylesPropTypes, { children: PropTypes.node, startDateId: PropTypes.string, startDatePlaceholderText: PropTypes.string, startDateAriaLabel: PropTypes.string, screenReaderMessage: PropTypes.string, endDateId: PropTypes.string, endDatePlaceholderText: PropTypes.string, endDateAriaLabel: PropTypes.string, onStartDateFocus: PropTypes.func, onEndDateFocus: PropTypes.func, onStartDateChange: PropTypes.func, onEndDateChange: PropTypes.func, onStartDateShiftTab: PropTypes.func, onEndDateTab: PropTypes.func, onClearDates: PropTypes.func, onKeyDownArrowDown: PropTypes.func, onKeyDownQuestionMark: PropTypes.func, startDate: PropTypes.string, endDate: PropTypes.string, isStartDateFocused: PropTypes.bool, isEndDateFocused: PropTypes.bool, showClearDates: PropTypes.bool, disabled: DisabledShape, required: PropTypes.bool, readOnly: PropTypes.bool, openDirection: openDirectionShape, showCaret: PropTypes.bool, showDefaultInputIcon: PropTypes.bool, inputIconPosition: IconPositionShape, customInputIcon: PropTypes.node, customArrowIcon: PropTypes.node, customCloseIcon: PropTypes.node, noBorder: PropTypes.bool, block: PropTypes.bool, small: PropTypes.bool, regular: PropTypes.bool, verticalSpacing: nonNegativeInteger, // accessibility isFocused: PropTypes.bool, // describes actual DOM focus // i18n phrases: PropTypes.shape(getPhrasePropTypes(DateRangePickerInputPhrases)), isRTL: PropTypes.bool })) : {}; var defaultProps = { children: null, startDateId: START_DATE, endDateId: END_DATE, startDatePlaceholderText: 'Start Date', endDatePlaceholderText: 'End Date', startDateAriaLabel: undefined, endDateAriaLabel: undefined, screenReaderMessage: '', onStartDateFocus: function onStartDateFocus() {}, onEndDateFocus: function onEndDateFocus() {}, onStartDateChange: function onStartDateChange() {}, onEndDateChange: function onEndDateChange() {}, onStartDateShiftTab: function onStartDateShiftTab() {}, onEndDateTab: function onEndDateTab() {}, onClearDates: function onClearDates() {}, onKeyDownArrowDown: function onKeyDownArrowDown() {}, onKeyDownQuestionMark: function onKeyDownQuestionMark() {}, startDate: '', endDate: '', isStartDateFocused: false, isEndDateFocused: false, showClearDates: false, disabled: false, required: false, readOnly: false, openDirection: OPEN_DOWN, showCaret: false, showDefaultInputIcon: false, inputIconPosition: ICON_BEFORE_POSITION, customInputIcon: null, customArrowIcon: null, customCloseIcon: null, noBorder: false, block: false, small: false, regular: false, verticalSpacing: undefined, // accessibility isFocused: false, // i18n phrases: DateRangePickerInputPhrases, isRTL: false }; function DateRangePickerInput(_ref) { var children = _ref.children, startDate = _ref.startDate, startDateId = _ref.startDateId, startDatePlaceholderText = _ref.startDatePlaceholderText, screenReaderMessage = _ref.screenReaderMessage, isStartDateFocused = _ref.isStartDateFocused, onStartDateChange = _ref.onStartDateChange, onStartDateFocus = _ref.onStartDateFocus, onStartDateShiftTab = _ref.onStartDateShiftTab, startDateAriaLabel = _ref.startDateAriaLabel, endDate = _ref.endDate, endDateId = _ref.endDateId, endDatePlaceholderText = _ref.endDatePlaceholderText, isEndDateFocused = _ref.isEndDateFocused, onEndDateChange = _ref.onEndDateChange, onEndDateFocus = _ref.onEndDateFocus, onEndDateTab = _ref.onEndDateTab, endDateAriaLabel = _ref.endDateAriaLabel, onKeyDownArrowDown = _ref.onKeyDownArrowDown, onKeyDownQuestionMark = _ref.onKeyDownQuestionMark, onClearDates = _ref.onClearDates, showClearDates = _ref.showClearDates, disabled = _ref.disabled, required = _ref.required, readOnly = _ref.readOnly, showCaret = _ref.showCaret, openDirection = _ref.openDirection, showDefaultInputIcon = _ref.showDefaultInputIcon, inputIconPosition = _ref.inputIconPosition, customInputIcon = _ref.customInputIcon, customArrowIcon = _ref.customArrowIcon, customCloseIcon = _ref.customCloseIcon, isFocused = _ref.isFocused, phrases = _ref.phrases, isRTL = _ref.isRTL, noBorder = _ref.noBorder, block = _ref.block, verticalSpacing = _ref.verticalSpacing, small = _ref.small, regular = _ref.regular, styles = _ref.styles; var calendarIcon = customInputIcon || React.createElement(CalendarIcon, css(styles.DateRangePickerInput_calendarIcon_svg)); var arrowIcon = customArrowIcon || React.createElement(RightArrow, css(styles.DateRangePickerInput_arrow_svg)); if (isRTL) arrowIcon = React.createElement(LeftArrow, css(styles.DateRangePickerInput_arrow_svg)); if (small) arrowIcon = '-'; var closeIcon = customCloseIcon || React.createElement(CloseButton, css(styles.DateRangePickerInput_clearDates_svg, small && styles.DateRangePickerInput_clearDates_svg__small)); var screenReaderStartDateText = screenReaderMessage || phrases.keyboardForwardNavigationInstructions; var screenReaderEndDateText = screenReaderMessage || phrases.keyboardBackwardNavigationInstructions; var inputIcon = (showDefaultInputIcon || customInputIcon !== null) && React.createElement("button", _extends({}, css(styles.DateRangePickerInput_calendarIcon), { type: "button", disabled: disabled, "aria-label": phrases.focusStartDate, onClick: onKeyDownArrowDown }), calendarIcon); var startDateDisabled = disabled === START_DATE || disabled === true; var endDateDisabled = disabled === END_DATE || disabled === true; return React.createElement("div", css(styles.DateRangePickerInput, disabled && styles.DateRangePickerInput__disabled, isRTL && styles.DateRangePickerInput__rtl, !noBorder && styles.DateRangePickerInput__withBorder, block && styles.DateRangePickerInput__block, showClearDates && styles.DateRangePickerInput__showClearDates), inputIconPosition === ICON_BEFORE_POSITION && inputIcon, React.createElement(DateInput, { id: startDateId, placeholder: startDatePlaceholderText, ariaLabel: startDateAriaLabel, displayValue: startDate, screenReaderMessage: screenReaderStartDateText, focused: isStartDateFocused, isFocused: isFocused, disabled: startDateDisabled, required: required, readOnly: readOnly, showCaret: showCaret, openDirection: openDirection, onChange: onStartDateChange, onFocus: onStartDateFocus, onKeyDownShiftTab: onStartDateShiftTab, onKeyDownArrowDown: onKeyDownArrowDown, onKeyDownQuestionMark: onKeyDownQuestionMark, verticalSpacing: verticalSpacing, small: small, regular: regular }), children, React.createElement("div", _extends({}, css(styles.DateRangePickerInput_arrow), { "aria-hidden": "true", role: "presentation" }), arrowIcon), React.createElement(DateInput, { id: endDateId, placeholder: endDatePlaceholderText, ariaLabel: endDateAriaLabel, displayValue: endDate, screenReaderMessage: screenReaderEndDateText, focused: isEndDateFocused, isFocused: isFocused, disabled: endDateDisabled, required: required, readOnly: readOnly, showCaret: showCaret, openDirection: openDirection, onChange: onEndDateChange, onFocus: onEndDateFocus, onKeyDownArrowDown: onKeyDownArrowDown, onKeyDownQuestionMark: onKeyDownQuestionMark, onKeyDownTab: onEndDateTab, verticalSpacing: verticalSpacing, small: small, regular: regular }), showClearDates && React.createElement("button", _extends({ type: "button", "aria-label": phrases.clearDates }, css(styles.DateRangePickerInput_clearDates, small && styles.DateRangePickerInput_clearDates__small, !customCloseIcon && styles.DateRangePickerInput_clearDates_default, !(startDate || endDate) && styles.DateRangePickerInput_clearDates__hide), { onClick: onClearDates, disabled: disabled }), closeIcon), inputIconPosition === ICON_AFTER_POSITION && inputIcon); } DateRangePickerInput.propTypes = process.env.NODE_ENV !== "production" ? propTypes : {}; DateRangePickerInput.defaultProps = defaultProps; export default withStyles(function (_ref2) { var _ref2$reactDates = _ref2.reactDates, border = _ref2$reactDates.border, color = _ref2$reactDates.color, sizing = _ref2$reactDates.sizing; return { DateRangePickerInput: { backgroundColor: color.background, display: 'inline-block' }, DateRangePickerInput__disabled: { background: color.disabled }, DateRangePickerInput__withBorder: { borderColor: color.border, borderWidth: border.pickerInput.borderWidth, borderStyle: border.pickerInput.borderStyle, borderRadius: border.pickerInput.borderRadius }, DateRangePickerInput__rtl: { direction: noflip('rtl') }, DateRangePickerInput__block: { display: 'block' }, DateRangePickerInput__showClearDates: { paddingRight: 30 // TODO: should be noflip wrapped and handled by an isRTL prop }, DateRangePickerInput_arrow: { display: 'inline-block', verticalAlign: 'middle', color: color.text }, DateRangePickerInput_arrow_svg: { verticalAlign: 'middle', fill: color.text, height: sizing.arrowWidth, width: sizing.arrowWidth }, DateRangePickerInput_clearDates: { background: 'none', border: 0, color: 'inherit', font: 'inherit', lineHeight: 'normal', overflow: 'visible', cursor: 'pointer', padding: 10, margin: '0 10px 0 5px', // TODO: should be noflip wrapped and handled by an isRTL prop position: 'absolute', right: 0, // TODO: should be noflip wrapped and handled by an isRTL prop top: '50%', transform: 'translateY(-50%)' }, DateRangePickerInput_clearDates__small: { padding: 6 }, DateRangePickerInput_clearDates_default: { ':focus': { background: color.core.border, borderRadius: '50%' }, ':hover': { background: color.core.border, borderRadius: '50%' } }, DateRangePickerInput_clearDates__hide: { visibility: 'hidden' }, DateRangePickerInput_clearDates_svg: { fill: color.core.grayLight, height: 12, width: 15, verticalAlign: 'middle' }, DateRangePickerInput_clearDates_svg__small: { height: 9 }, DateRangePickerInput_calendarIcon: { background: 'none', border: 0, color: 'inherit', font: 'inherit', lineHeight: 'normal', overflow: 'visible', cursor: 'pointer', display: 'inline-block', verticalAlign: 'middle', padding: 10, margin: '0 5px 0 10px' // TODO: should be noflip wrapped and handled by an isRTL prop }, DateRangePickerInput_calendarIcon_svg: { fill: color.core.grayLight, height: 15, width: 14, verticalAlign: 'middle' } }; }, { pureComponent: typeof React.PureComponent !== 'undefined' })(DateRangePickerInput);