import * as React from "react";
import { Input, InputProps } from "semantic-ui-react";
import { Duration } from "@common/sprinklers";
export default class DurationInput extends React.Component<{
duration: Duration,
onDurationChange: (newDuration: Duration) => void;
}> {
render() {
const duration = this.props.duration;
// const editing = this.props.onDurationChange != null;
return (
);
}
private onMinutesChange: InputProps["onChange"] = (e, { value }) => {
if (value.length === 0 || isNaN(Number(value))) {
return;
}
const newMinutes = parseInt(value, 10);
this.props.onDurationChange(this.props.duration.withMinutes(newMinutes));
}
private onSecondsChange: InputProps["onChange"] = (e, { value }) => {
if (value.length === 0 || isNaN(Number(value))) {
return;
}
const newSeconds = parseInt(value, 10);
this.props.onDurationChange(this.props.duration.withSeconds(newSeconds));
}
}