Farmbot-Web-App/frontend/devices/components/hardware_settings/zero_row.tsx

40 lines
1.3 KiB
TypeScript
Raw Normal View History

2017-06-29 12:54:02 -06:00
import * as React from "react";
import { getDevice } from "../../../device";
import { Axis } from "../../interfaces";
import { ToolTips } from "../../../constants";
2019-09-19 07:41:37 -06:00
import { Row, Col, Help } from "../../../ui/index";
2018-03-09 02:34:24 -07:00
import { ZeroRowProps } from "../interfaces";
import { commandErr } from "../../actions";
2019-04-02 13:59:37 -06:00
import { t } from "../../../i18next_wrapper";
2019-09-19 07:41:37 -06:00
import { Position } from "@blueprintjs/core";
2017-06-29 12:54:02 -06:00
const zero =
(axis: Axis) => getDevice().setZero(axis).catch(commandErr("Zeroing"));
2017-06-29 12:54:02 -06:00
const AXES: Axis[] = ["x", "y", "z"];
2018-03-09 02:34:24 -07:00
export function ZeroButton(props: { axis: Axis; disabled: boolean; }) {
const { axis, disabled } = props;
2017-06-29 12:54:02 -06:00
return <button
className="fb-button yellow"
2018-03-09 02:34:24 -07:00
disabled={disabled}
2019-09-23 12:56:35 -06:00
onClick={() => zero(axis)}>
2017-06-29 12:54:02 -06:00
{t("zero {{axis}}", { axis })}
</button>;
}
2018-03-09 02:34:24 -07:00
export function ZeroRow({ botDisconnected }: ZeroRowProps) {
2017-06-29 12:54:02 -06:00
return <Row>
2019-09-19 07:41:37 -06:00
<Col xs={6} className={"widget-body-tooltips"}>
2017-06-29 12:54:02 -06:00
<label>
{t("SET ZERO POSITION")}
</label>
2019-09-19 07:41:37 -06:00
<Help text={ToolTips.SET_ZERO_POSITION} requireClick={true} position={Position.RIGHT} />
2017-06-29 12:54:02 -06:00
</Col>
{AXES.map((axis) => {
2018-01-29 11:32:32 -07:00
return <Col xs={2} key={axis} className={"centered-button-div"}>
2018-03-09 02:34:24 -07:00
<ZeroButton axis={axis} disabled={botDisconnected} />
2017-07-28 19:58:24 -06:00
</Col>;
2017-06-29 12:54:02 -06:00
})}
</Row>;
}