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';
const propTypes = forbidExtraProps({
...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,
});
const defaultProps = {
children: null,
startDateId: START_DATE,
endDateId: END_DATE,
startDatePlaceholderText: 'Start Date',
endDatePlaceholderText: 'End Date',
startDateAriaLabel: undefined,
endDateAriaLabel: undefined,
screenReaderMessage: '',
onStartDateFocus() {},
onEndDateFocus() {},
onStartDateChange() {},
onEndDateChange() {},
onStartDateShiftTab() {},
onEndDateTab() {},
onClearDates() {},
onKeyDownArrowDown() {},
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({
children,
startDate,
startDateId,
startDatePlaceholderText,
screenReaderMessage,
isStartDateFocused,
onStartDateChange,
onStartDateFocus,
onStartDateShiftTab,
startDateAriaLabel,
endDate,
endDateId,
endDatePlaceholderText,
isEndDateFocused,
onEndDateChange,
onEndDateFocus,
onEndDateTab,
endDateAriaLabel,
onKeyDownArrowDown,
onKeyDownQuestionMark,
onClearDates,
showClearDates,
disabled,
required,
readOnly,
showCaret,
openDirection,
showDefaultInputIcon,
inputIconPosition,
customInputIcon,
customArrowIcon,
customCloseIcon,
isFocused,
phrases,
isRTL,
noBorder,
block,
verticalSpacing,
small,
regular,
styles,
}) {
const calendarIcon = customInputIcon || (