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 { SingleDatePickerInputPhrases } from '../defaultPhrases';
import getPhrasePropTypes from '../utils/getPhrasePropTypes';
import noflip from '../utils/noflip';
import DateInput from './DateInput';
import IconPositionShape from '../shapes/IconPositionShape';
import CloseButton from './CloseButton';
import CalendarIcon from './CalendarIcon';
import openDirectionShape from '../shapes/OpenDirectionShape';
import { ICON_BEFORE_POSITION, ICON_AFTER_POSITION, OPEN_DOWN } from '../constants';
const propTypes = forbidExtraProps({
...withStylesPropTypes,
id: PropTypes.string.isRequired,
children: PropTypes.node,
placeholder: PropTypes.string,
ariaLabel: PropTypes.string,
displayValue: PropTypes.string,
screenReaderMessage: PropTypes.string,
focused: PropTypes.bool,
isFocused: PropTypes.bool, // describes actual DOM focus
disabled: PropTypes.bool,
required: PropTypes.bool,
readOnly: PropTypes.bool,
openDirection: openDirectionShape,
showCaret: PropTypes.bool,
showClearDate: PropTypes.bool,
customCloseIcon: PropTypes.node,
showDefaultInputIcon: PropTypes.bool,
inputIconPosition: IconPositionShape,
customInputIcon: PropTypes.node,
isRTL: PropTypes.bool,
noBorder: PropTypes.bool,
block: PropTypes.bool,
small: PropTypes.bool,
regular: PropTypes.bool,
verticalSpacing: nonNegativeInteger,
onChange: PropTypes.func,
onClearDate: PropTypes.func,
onFocus: PropTypes.func,
onKeyDownShiftTab: PropTypes.func,
onKeyDownTab: PropTypes.func,
onKeyDownArrowDown: PropTypes.func,
onKeyDownQuestionMark: PropTypes.func,
// i18n
phrases: PropTypes.shape(getPhrasePropTypes(SingleDatePickerInputPhrases)),
});
const defaultProps = {
children: null,
placeholder: 'Select Date',
ariaLabel: undefined,
displayValue: '',
screenReaderMessage: '',
focused: false,
isFocused: false,
disabled: false,
required: false,
readOnly: false,
openDirection: OPEN_DOWN,
showCaret: false,
showClearDate: false,
showDefaultInputIcon: false,
inputIconPosition: ICON_BEFORE_POSITION,
customCloseIcon: null,
customInputIcon: null,
isRTL: false,
noBorder: false,
block: false,
small: false,
regular: false,
verticalSpacing: undefined,
onChange() {},
onClearDate() {},
onFocus() {},
onKeyDownShiftTab() {},
onKeyDownTab() {},
onKeyDownArrowDown() {},
onKeyDownQuestionMark() {},
// i18n
phrases: SingleDatePickerInputPhrases,
};
function SingleDatePickerInput({
id,
children,
placeholder,
ariaLabel,
displayValue,
focused,
isFocused,
disabled,
required,
readOnly,
showCaret,
showClearDate,
showDefaultInputIcon,
inputIconPosition,
phrases,
onClearDate,
onChange,
onFocus,
onKeyDownShiftTab,
onKeyDownTab,
onKeyDownArrowDown,
onKeyDownQuestionMark,
screenReaderMessage,
customCloseIcon,
customInputIcon,
openDirection,
isRTL,
noBorder,
block,
small,
regular,
verticalSpacing,
styles,
}) {
const calendarIcon = customInputIcon || (