|
1 |
| -import React, { useContext } from "react" |
2 |
| -import { Context } from "../../state" |
3 |
| -import PropTypes from "prop-types" |
4 |
| - |
5 |
| -import "./inputs.scss" |
6 |
| - |
7 |
| -const Numbers = ({ label, prop, idealLength = 4, width, twoLines, height }) => { |
8 |
| - |
9 |
| - const [state, dispatch] = useContext(Context) |
10 |
| - const id = `Numbers-${label}-${prop}`.replaceAll(" ", "_") |
11 |
| - |
12 |
| - const numberInputComponent = <> |
13 |
| - <label htmlFor={id} className={`${twoLines ? "default" : ""}`}> |
14 |
| - {label} |
15 |
| - </label> |
16 |
| - <input |
17 |
| - id={id} |
18 |
| - type="number" |
19 |
| - pattern="[0-9]*" |
20 |
| - placeholder={"0".repeat(idealLength)} |
21 |
| - autoComplete="off" |
22 |
| - className={`${width ? width : "wide"}`} |
23 |
| - onChange={(event) => { |
24 |
| - dispatch({ |
25 |
| - type: "set", |
26 |
| - prop, |
27 |
| - val: !( |
28 |
| - event.target.value === undefined || event.target.value === "" |
29 |
| - ) |
30 |
| - ? parseInt(event.target.value) |
31 |
| - : undefined, |
32 |
| - }) |
33 |
| - }} |
34 |
| - value={state[prop] ?? ""} |
35 |
| - /> |
36 |
| - </> |
37 |
| - |
38 |
| - return twoLines ? numberInputComponent : ( |
39 |
| - <div className={`Numbers ${ width ? width :"wide"} ${height}`}> |
40 |
| - {numberInputComponent} |
41 |
| - </div> |
42 |
| - ) |
43 |
| -} |
44 |
| - |
45 |
| -Numbers.propTypes = { |
46 |
| - label: PropTypes.string.isRequired, |
47 |
| - prop: PropTypes.string.isRequired, |
48 |
| - idealLength: PropTypes.number, |
49 |
| - width: PropTypes.string, |
50 |
| - twoLines: PropTypes.bool, |
51 |
| -} |
52 |
| - |
53 |
| -export default Numbers |
| 1 | +import React, { useContext } from "react" |
| 2 | +import { Context } from "../../state" |
| 3 | +import PropTypes from "prop-types" |
| 4 | + |
| 5 | +import "./inputs.scss" |
| 6 | + |
| 7 | +const Numbers = ({ label, prop, phase, idealLength = 4, width, twoLines, height }) => { |
| 8 | + |
| 9 | + const [state, dispatch] = useContext(Context) |
| 10 | + const id = `Numbers-${label}-${prop}`.replaceAll(" ", "_") |
| 11 | + |
| 12 | + const numberInputComponent = <> |
| 13 | + <label htmlFor={id} className={`${twoLines ? "default" : ""}`}> |
| 14 | + {label} |
| 15 | + </label> |
| 16 | + <input |
| 17 | + id={id} |
| 18 | + type="number" |
| 19 | + pattern="[0-9]*" |
| 20 | + placeholder={"0".repeat(idealLength)} |
| 21 | + autoComplete="off" |
| 22 | + className={`${width ? width : "wide"}`} |
| 23 | + onChange={(event) => { |
| 24 | + dispatch({ |
| 25 | + type: `set${phase ? "InPhase" : ""}`, |
| 26 | + prop, |
| 27 | + val: !( |
| 28 | + event.target.value === undefined || event.target.value === "" |
| 29 | + ) |
| 30 | + ? parseInt(event.target.value) |
| 31 | + : undefined, |
| 32 | + }) |
| 33 | + }} |
| 34 | + value={state[prop] ?? ""} |
| 35 | + /> |
| 36 | + </> |
| 37 | + |
| 38 | + return twoLines ? numberInputComponent : ( |
| 39 | + <div className={`Numbers ${ width ? width :"wide"} ${height}`}> |
| 40 | + {numberInputComponent} |
| 41 | + </div> |
| 42 | + ) |
| 43 | +} |
| 44 | + |
| 45 | +Numbers.propTypes = { |
| 46 | + label: PropTypes.string.isRequired, |
| 47 | + prop: PropTypes.string.isRequired, |
| 48 | + idealLength: PropTypes.number, |
| 49 | + width: PropTypes.string, |
| 50 | + twoLines: PropTypes.bool, |
| 51 | +} |
| 52 | + |
| 53 | +export default Numbers |
0 commit comments