Farmbot-Web-App/frontend/controls/axis_input_box_group.tsx

68 lines
1.7 KiB
TypeScript
Raw Normal View History

2017-06-29 12:54:02 -06:00
import * as React from "react";
import { AxisInputBox } from "./axis_input_box";
import { Row, Col } from "../ui/index";
2019-02-27 19:29:38 -07:00
import { AxisInputBoxGroupProps, AxisInputBoxGroupState } from "./interfaces";
2019-02-04 07:32:26 -07:00
import { isNumber } from "lodash";
2019-02-27 19:29:38 -07:00
import { Vector3 } from "farmbot";
2019-04-02 13:59:37 -06:00
import { t } from "../i18next_wrapper";
2017-06-29 12:54:02 -06:00
2019-01-13 16:39:26 -07:00
/** Coordinate input and GO button for Move widget. */
2017-07-26 14:29:35 -06:00
export class AxisInputBoxGroup extends
React.Component<AxisInputBoxGroupProps, Partial<AxisInputBoxGroupState>> {
constructor(props: AxisInputBoxGroupProps) {
super(props);
2017-06-29 12:54:02 -06:00
this.state = {};
}
2019-02-27 19:29:38 -07:00
change = (axis: keyof Vector3, val: number) => {
2017-06-29 12:54:02 -06:00
this.setState({ [axis]: val });
}
get vector() {
2017-08-28 05:44:37 -06:00
const { x, y, z } = this.state;
const p = this.props.position;
const x2 = p.x,
2017-07-27 14:04:01 -06:00
y2 = p.y,
z2 = p.z;
2017-06-29 12:54:02 -06:00
return {
2019-02-04 07:32:26 -07:00
x: isNumber(x) ? x : (x2 || 0),
y: isNumber(y) ? y : (y2 || 0),
z: isNumber(z) ? z : (z2 || 0)
2017-06-29 12:54:02 -06:00
};
}
clicked = () => {
this.props.onCommit(this.vector);
this.setState({ x: undefined, y: undefined, z: undefined });
}
render() {
2017-08-28 05:44:37 -06:00
const { x, y, z } = this.state;
2017-08-28 05:44:37 -06:00
return <Row>
<AxisInputBox
onChange={this.change}
axis={"x"}
value={x} />
<AxisInputBox
onChange={this.change}
axis={"y"}
value={y} />
<AxisInputBox
onChange={this.change}
axis={"z"}
value={z} />
<Col xs={3}>
<button
onClick={this.clicked}
disabled={this.props.disabled || false}
2018-12-03 20:05:45 -07:00
title={t("Move to chosen location")}
2019-09-23 12:56:35 -06:00
className="full-width green go fb-button">
2017-08-28 05:44:37 -06:00
{t("GO")}
</button>
</Col>
</Row>;
2017-06-29 12:54:02 -06:00
}
}