/** @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 { onSelect, 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 ) { onSelect( { period: 'today' } ); } } render() { const { period, compare, after, before, onSelect, onClose, getUpdatePath, isValidSelection, resetCustomValues, } = 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, onSelect: PropTypes.func.isRequired, onClose: PropTypes.func.isRequired, getUpdatePath: PropTypes.func.isRequired, resetCustomValues: PropTypes.func.isRequired, }; export default DatePickerContent;