UNPKG

react-dates

Version:

A responsive and accessible date range picker component built with React

106 lines (89 loc) 2.85 kB
import React, { PropTypes } from 'react'; import { forbidExtraProps } from 'airbnb-prop-types'; import cx from 'classnames'; import { DayPickerNavigationPhrases } from '../defaultPhrases'; import getPhrasePropTypes from '../utils/getPhrasePropTypes'; import LeftArrow from '../svg/arrow-left.svg'; import RightArrow from '../svg/arrow-right.svg'; import ChevronUp from '../svg/chevron-up.svg'; import ChevronDown from '../svg/chevron-down.svg'; import ScrollableOrientationShape from '../shapes/ScrollableOrientationShape'; import { HORIZONTAL_ORIENTATION, VERTICAL_SCROLLABLE, } from '../../constants'; const propTypes = forbidExtraProps({ navPrev: PropTypes.node, navNext: PropTypes.node, orientation: ScrollableOrientationShape, onPrevMonthClick: PropTypes.func, onNextMonthClick: PropTypes.func, // internationalization phrases: PropTypes.shape(getPhrasePropTypes(DayPickerNavigationPhrases)), }); const defaultProps = { navPrev: null, navNext: null, orientation: HORIZONTAL_ORIENTATION, onPrevMonthClick() {}, onNextMonthClick() {}, // internationalization phrases: DayPickerNavigationPhrases, }; export default function DayPickerNavigation(props) { const { navPrev, navNext, onPrevMonthClick, onNextMonthClick, orientation, phrases, } = props; const isVertical = orientation !== HORIZONTAL_ORIENTATION; const isVerticalScrollable = orientation === VERTICAL_SCROLLABLE; let navPrevIcon = navPrev; let navNextIcon = navNext; let isDefaultNavPrev = false; let isDefaultNavNext = false; if (!navPrevIcon) { isDefaultNavPrev = true; navPrevIcon = isVertical ? <ChevronUp /> : <LeftArrow />; } if (!navNextIcon) { isDefaultNavNext = true; navNextIcon = isVertical ? <ChevronDown /> : <RightArrow />; } const navClassNames = cx('DayPickerNavigation', { 'DayPickerNavigation--horizontal': !isVertical, 'DayPickerNavigation--vertical': isVertical, 'DayPickerNavigation--vertical-scrollable': isVerticalScrollable, }); const prevClassNames = cx('DayPickerNavigation__prev', { 'DayPickerNavigation__prev--default': isDefaultNavPrev, }); const nextClassNames = cx('DayPickerNavigation__next', { 'DayPickerNavigation__next--default': isDefaultNavNext, }); return ( <div className={navClassNames}> {!isVerticalScrollable && ( <span aria-label={phrases.jumpToPrevMonth} className={prevClassNames} onClick={onPrevMonthClick} > {navPrevIcon} </span> )} <span aria-label={phrases.jumpToNextMonth} className={nextClassNames} onClick={onNextMonthClick} > {navNextIcon} </span> </div> ); } DayPickerNavigation.propTypes = propTypes; DayPickerNavigation.defaultProps = defaultProps;