// @ts-ignore import TimeView from 'react-datetime/src/TimeView'; import moment from 'moment'; import React from 'react'; import {LocaleProps, localeable} from '../../locale'; import {Icon} from '../icons'; import {ClassNamesFn} from '../../theme'; export class CustomTimeView extends TimeView { props: { viewDate: moment.Moment; subtractTime: ( amount: number, type: string, toSelected?: moment.Moment ) => () => void; addTime: ( amount: number, type: string, toSelected?: moment.Moment ) => () => void; showView: (view: string) => () => void; timeFormat: string; classnames: ClassNamesFn; setTime: (type: string, value: any) => void; } & LocaleProps; onStartClicking: any; disableContextMenu: any; updateMilli: any; renderHeader: any; pad: any; state: {daypart: any; counters: Array; [propName: string]: any}; timeConstraints: any; padValues = { hours: 2, minutes: 2, seconds: 2, milliseconds: 3 }; renderDayPart = () => { const {translate: __, classnames: cx} = this.props; return (
{__(this.state.daypart)}
); }; renderCounter = (type: string) => { const cx = this.props.classnames; if (type !== 'daypart') { var value = this.state[type]; if ( type === 'hours' && this.props.timeFormat.toLowerCase().indexOf(' a') !== -1 ) { value = ((value - 1) % 12) + 1; if (value === 0) { value = 12; } } const {min, max, step} = this.timeConstraints[type]; return (
this.props.setTime( type, Math.max( min, Math.min( parseInt(e.currentTarget.value.replace(/\D/g, ''), 10) || 0, max ) ) ) } />
); } return null; }; render() { const counters: Array = []; const cx = this.props.classnames; this.state.counters.forEach(c => { if (counters.length) { counters.push(
:
); } counters.push(this.renderCounter(c)); }); if (this.state.daypart !== false) { counters.push(this.renderDayPart()); } if ( this.state.counters.length === 3 && this.props.timeFormat.indexOf('S') !== -1 ) { counters.push(
:
); counters.push(
); } return
{counters}
; } } export default localeable(CustomTimeView as any);