/** @format */ /** * External dependencies */ import { __ } from '@wordpress/i18n'; import { Component, Fragment } from '@wordpress/element'; import { TabPanel, Button } from '@wordpress/components'; import PropTypes from 'prop-types'; import classnames from 'classnames'; /** * Internal dependencies */ import ComparePeriods from './compare-periods'; import { H, Section } from 'layout/section'; import PresetPeriods from './preset-periods'; import Link from 'components/link'; import { DateRange } from 'components/calendar'; const isMobileViewport = () => window.innerWidth < 782; class DatePickerContent extends Component { constructor() { super(); this.onTabSelect = this.onTabSelect.bind( this ); } onTabSelect( tab ) { const { onUpdate, period } = this.props; /** * If the period is `custom` and the user switches tabs to view the presets, * then a preset should be selected. This logic selects the default, otherwise * `custom` value for period will result in no selection. */ if ( 'period' === tab && 'custom' === period ) { onUpdate( { period: 'today' } ); } } render() { const { period, compare, after, before, onUpdate, onClose, getUpdatePath, isValidSelection, resetCustomValues, focusedInput, afterText, beforeText, afterError, beforeError, shortDateFormat, } = this.props; return (
{ __( 'Select date range and comparison', 'wc-admin' ) }
{ __( 'select a date range', 'wc-admin' ) } { selectedTab => ( { selectedTab === 'period' && ( ) } { selectedTab === 'custom' && ( ) }
{ __( 'compare to', 'wc-admin' ) }
{ selectedTab === 'custom' && ( ) } { isValidSelection( selectedTab ) ? ( { __( 'Update', 'wc-admin' ) } ) : ( ) }
) }
); } } DatePickerContent.propTypes = { period: PropTypes.string.isRequired, compare: PropTypes.string.isRequired, onUpdate: PropTypes.func.isRequired, onClose: PropTypes.func.isRequired, getUpdatePath: PropTypes.func.isRequired, resetCustomValues: PropTypes.func.isRequired, focusedInput: PropTypes.string, afterText: PropTypes.string, beforeText: PropTypes.string, afterError: PropTypes.string, beforeError: PropTypes.string, shortDateFormat: PropTypes.string.isRequired, }; export default DatePickerContent;