Farmbot-Web-App/frontend/controls/move/step_size_selector.tsx

34 lines
964 B
TypeScript
Raw Normal View History

2017-06-29 12:54:02 -06:00
import * as React from "react";
import { StepSizeSelectorProps } from "./interfaces";
2019-02-04 07:32:26 -07:00
import { first, last } from "lodash";
2020-02-28 09:34:28 -07:00
import { t } from "../../i18next_wrapper";
2017-06-29 12:54:02 -06:00
2019-02-06 18:36:11 -07:00
export class StepSizeSelector extends React.Component<StepSizeSelectorProps, {}> {
2017-06-29 12:54:02 -06:00
cssForIndex(num: number) {
2017-08-28 05:49:13 -06:00
const choices = this.props.choices;
2017-06-29 12:54:02 -06:00
let css = "move-amount no-radius fb-button ";
2019-02-04 07:32:26 -07:00
if (num === first(choices)) {
2017-06-29 12:54:02 -06:00
css += "leftmost ";
}
2019-02-04 07:32:26 -07:00
if (num === last(choices)) {
2017-06-29 12:54:02 -06:00
css += "rightmost ";
}
if (num === this.props.selected) {
css += "move-amount-selected ";
}
return css;
}
render() {
return <div className="move-amount-wrapper">
2020-02-28 09:35:32 -07:00
{this.props.choices.map((item: number, inx: number) =>
<button key={inx}
title={t("{{ amount }}mm", { amount: item })}
className={this.cssForIndex(item)}
onClick={() => this.props.selector(item)}>
{item}
</button>)}
2017-06-29 12:54:02 -06:00
</div>;
}
}