Made stocks color responsive to input

This commit is contained in:
keannu125 2023-03-02 22:29:30 +08:00
parent fec3d9a47d
commit 3bd532c02c

View file

@ -22,36 +22,36 @@ export default function Inventory() {
} }
} }
function StockRender(in_stock: number) { function StockRender(in_stock: number) {
const [stock, setStock] = useState("" + in_stock); const [stock, setStock] = useState(in_stock);
if (in_stock > 0 && in_stock < 3) { if (stock >= 0 && stock <= 3) {
return ( return (
<TableCell style={styles.text_red}> <TableCell>
<input <input
style={{ style={{
...styles.text, ...styles.text_red,
...{ border: "none", background: "none" }, ...{ border: "none", background: "none" },
}} }}
value={stock} value={stock}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => { onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
if (is_number(e.target.value) === true) { if (is_number(e.target.value) === true) {
setStock(e.target.value); setStock(parseInt(e.target.value));
} }
}} }}
/> />
</TableCell> </TableCell>
); );
} else if (in_stock > 3 && in_stock < 9) { } else if (stock >= 4 && stock < 9) {
return ( return (
<TableCell style={styles.text_orange}> <TableCell>
<input <input
style={{ style={{
...styles.text, ...styles.text_orange,
...{ border: "none", background: "none" }, ...{ border: "none", background: "none" },
}} }}
value={stock} value={stock}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => { onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
if (is_number(e.target.value) === true) { if (is_number(e.target.value) === true) {
setStock(e.target.value); setStock(parseInt(e.target.value));
} }
}} }}
/> />
@ -59,16 +59,16 @@ export default function Inventory() {
); );
} else { } else {
return ( return (
<TableCell style={styles.text_green}> <TableCell>
<input <input
style={{ style={{
...styles.text, ...styles.text_green,
...{ border: "none", background: "none" }, ...{ border: "none", background: "none" },
}} }}
value={stock} value={stock}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => { onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
if (is_number(e.target.value) === true) { if (is_number(e.target.value) === true) {
setStock(e.target.value); setStock(parseInt(e.target.value));
} }
}} }}
/> />