bitburner-src/src/DevMenu/ui/Adjuster.tsx

74 lines
2.2 KiB
TypeScript
Raw Normal View History

2021-09-14 02:37:35 +02:00
import React, { useState } from "react";
2021-09-17 01:23:03 +02:00
import AddIcon from "@mui/icons-material/Add";
import RemoveIcon from "@mui/icons-material/Remove";
import IconButton from "@mui/material/IconButton";
import ClearIcon from "@mui/icons-material/Clear";
import DoubleArrowIcon from "@mui/icons-material/DoubleArrow";
import TextField from "@mui/material/TextField";
import Tooltip from "@mui/material/Tooltip";
2021-09-14 02:37:35 +02:00
interface IProps {
label: string;
placeholder: string;
add: (x: number) => void;
subtract: (x: number) => void;
tons: () => void;
reset: () => void;
}
export function Adjuster(props: IProps): React.ReactElement {
const [value, setValue] = useState<number | string>("");
function onChange(event: React.ChangeEvent<HTMLInputElement>): void {
if (event.target.value === "") setValue("");
else setValue(parseFloat(event.target.value));
}
const { label, placeholder, add, subtract, reset, tons } = props;
return (
<>
<TextField
label={label}
value={value}
onChange={onChange}
placeholder={placeholder}
type="number"
InputProps={{
startAdornment: (
<>
2021-09-14 04:27:43 +02:00
<Tooltip title="Add a lot">
2021-09-17 01:23:03 +02:00
<IconButton color="primary" onClick={tons} size="large">
2021-09-14 04:27:43 +02:00
<DoubleArrowIcon style={{ transform: "rotate(-90deg)" }} />
</IconButton>
</Tooltip>
<Tooltip title="Add">
2021-09-17 01:23:03 +02:00
<IconButton color="primary" onClick={() => add(typeof value !== "string" ? value : 0)} size="large">
2021-09-14 04:27:43 +02:00
<AddIcon />
</IconButton>
</Tooltip>
2021-09-14 02:37:35 +02:00
</>
),
endAdornment: (
<>
2021-09-14 04:27:43 +02:00
<Tooltip title="Remove">
2021-09-17 01:23:03 +02:00
<IconButton
color="primary"
onClick={() => subtract(typeof value !== "string" ? value : 0)}
size="large"
>
2021-09-14 04:27:43 +02:00
<RemoveIcon />
</IconButton>
</Tooltip>
<Tooltip title="Reset">
2021-09-17 01:23:03 +02:00
<IconButton color="primary" onClick={reset} size="large">
<ClearIcon />
2021-09-14 04:27:43 +02:00
</IconButton>
</Tooltip>
2021-09-14 02:37:35 +02:00
</>
),
}}
/>
</>
);
}