/** @format */ /** * External dependencies */ import { __ } from '@wordpress/i18n'; import { Component, Fragment } from '@wordpress/element'; import { Button, TabPanel } from '@wordpress/components'; import { partial } from 'lodash'; /** * Internal dependencies */ import './style.scss'; import SegmentedSelection from 'components/segmented-selection'; import PresetPeriods from './preset-periods'; class DatePicker extends Component { constructor( props ) { super( props ); /** * Getting initial data from props here, but they will come from the url * Defaults can be added here */ const { period, compare, start, end } = props; const state = { period, compare: compare, }; if ( 'custom' === period ) { Object.assign( state, { start, end } ); } this.state = state; this.update = this.update.bind( this ); this.select = this.select.bind( this ); } select( key, value ) { this.setState( { [ key ]: value } ); } update( selectedTab ) { const data = { period: 'custom' === selectedTab ? 'custom' : this.state.period, compare: this.state.compare, }; // This would be set as a result of the custom date picker, placing here as an example if ( 'custom' === selectedTab ) { Object.assign( data, { start: 'a date', end: 'another date' } ); } console.log( data ); } render() { const { period, compare } = this.state; const compareToString = __( 'compare to', 'woo-dash' ); return (

{ __( 'select a date range', 'woo-dash' ) }

{ selectedTab => ( { selectedTab === 'period' && ( ) } { selectedTab === 'custom' &&
Custom Date Picker Goes here
}

{ compareToString }

) }
); } } export default DatePicker;