import React, { Component, SyntheticEvent } from 'react'; import { TimeRange, TimeOptions, TimeOption } from '../../types/time'; import { Moment } from 'moment'; import { TimePickerCalendar } from './TimePickerCalendar'; import { TimePickerInput } from './TimePickerInput'; import { mapTimeOptionToTimeRange } from './time'; import { Timezone } from '../../utils/datemath'; export interface Props { value: TimeRange; options: TimeOptions; isTimezoneUtc: boolean; timezone?: Timezone; onChange?: (timeRange: TimeRange) => void; } export interface State { value: TimeRange; isFromInputValid: boolean; isToInputValid: boolean; } export class TimePickerPopover extends Component { static popoverClassName = 'time-picker-popover'; constructor(props: Props) { super(props); this.state = { value: props.value, isFromInputValid: true, isToInputValid: true }; } onFromInputChanged = (value: string, valid: boolean) => { this.setState({ value: { ...this.state.value, raw: { ...this.state.value.raw, from: value } }, isFromInputValid: valid, }); }; onToInputChanged = (value: string, valid: boolean) => { this.setState({ value: { ...this.state.value, raw: { ...this.state.value.raw, to: value } }, isToInputValid: valid, }); }; onFromCalendarChanged = (value: Moment) => { this.setState({ value: { ...this.state.value, raw: { ...this.state.value.raw, from: value } }, }); }; onToCalendarChanged = (value: Moment) => { this.setState({ value: { ...this.state.value, raw: { ...this.state.value.raw, to: value } }, }); }; onTimeOptionClick = (timeOption: TimeOption) => { const { isTimezoneUtc, timezone, onChange } = this.props; if (onChange) { onChange(mapTimeOptionToTimeRange(timeOption, isTimezoneUtc, timezone)); } }; onApplyClick = () => { const { onChange } = this.props; if (onChange) { onChange(this.state.value); } }; render() { const { options, isTimezoneUtc, timezone } = this.props; const { isFromInputValid, isToInputValid, value } = this.state; const isValid = isFromInputValid && isToInputValid; return (
Quick ranges
{Object.keys(options).map(key => { return ( ); })}
Custom range
From:
To:
); } }