You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.6 KiB
42 lines
1.6 KiB
8 years ago
|
import * as React from "react";
|
||
8 years ago
|
import { Input, InputOnChangeData } from "semantic-ui-react";
|
||
8 years ago
|
|
||
8 years ago
|
import { Duration } from "@common/sprinklers";
|
||
8 years ago
|
|
||
|
export default class DurationInput extends React.Component<{
|
||
|
duration: Duration,
|
||
8 years ago
|
onDurationChange: (newDuration: Duration) => void;
|
||
|
}> {
|
||
8 years ago
|
render() {
|
||
|
const duration = this.props.duration;
|
||
|
// const editing = this.props.onDurationChange != null;
|
||
|
return <div className="field durationInput">
|
||
|
<label>Duration</label>
|
||
|
<div className="fields">
|
||
|
<Input type="number" className="field durationInput--minutes"
|
||
8 years ago
|
value={duration.minutes} onChange={this.onMinutesChange}
|
||
|
label="M" labelPosition="right" />
|
||
8 years ago
|
<Input type="number" className="field durationInput--seconds"
|
||
8 years ago
|
value={duration.seconds} onChange={this.onSecondsChange} max="60"
|
||
|
label="S" labelPosition="right" />
|
||
8 years ago
|
</div>
|
||
|
</div>;
|
||
|
}
|
||
|
|
||
8 years ago
|
private onMinutesChange = (e: React.SyntheticEvent<any>, { value }: InputOnChangeData) => {
|
||
|
if (value.length === 0 || isNaN(Number(value))) {
|
||
8 years ago
|
return;
|
||
|
}
|
||
|
const newMinutes = parseInt(value, 10);
|
||
|
this.props.onDurationChange(this.props.duration.withMinutes(newMinutes));
|
||
|
}
|
||
|
|
||
8 years ago
|
private onSecondsChange = (e: React.SyntheticEvent<any>, { value }: InputOnChangeData) => {
|
||
|
if (value.length === 0 || isNaN(Number(value))) {
|
||
8 years ago
|
return;
|
||
|
}
|
||
|
const newSeconds = parseInt(value, 10);
|
||
|
this.props.onDurationChange(this.props.duration.withSeconds(newSeconds));
|
||
|
}
|
||
|
}
|