({ value, onChange, size = "md" }: Props)
| 33 | |
| 34 | |
| 35 | export const UnitPicker = ({ value, onChange, size = "md" }: Props) => { |
| 36 | const t = useStore(commonMsg) |
| 37 | const [units, setUnits] = useState<Units>(value) |
| 38 | if (isEmpty(units)) { |
| 39 | setUnits(getInitUnits()) |
| 40 | return |
| 41 | } |
| 42 | |
| 43 | const onAddUnit = () => { |
| 44 | units.units.push({ |
| 45 | operator: units.units[0]?.operator ?? 'x', |
| 46 | rhs: 1, |
| 47 | unit: '' |
| 48 | }) |
| 49 | setUnits(cloneDeep(units)) |
| 50 | } |
| 51 | |
| 52 | const onRemoveUnit = (i) => { |
| 53 | units.units.splice(i, 1) |
| 54 | setUnits(cloneDeep(units)) |
| 55 | } |
| 56 | |
| 57 | const onLiftUnit = (i) => { |
| 58 | [units.units[i - 1], units.units[i]] = [units.units[i], units.units[i - 1]] |
| 59 | |
| 60 | setUnits(cloneDeep(units)) |
| 61 | } |
| 62 | |
| 63 | const onChangeUnitType = t => { |
| 64 | switch (t) { |
| 65 | case "none": |
| 66 | setUnits({ |
| 67 | unitsType: t, |
| 68 | units: [] |
| 69 | }) |
| 70 | break; |
| 71 | case "short": |
| 72 | setUnits({ |
| 73 | unitsType: t, |
| 74 | units: [ |
| 75 | { |
| 76 | operator: "/", |
| 77 | rhs: 1, |
| 78 | unit: "" |
| 79 | }, |
| 80 | { |
| 81 | operator: "/", |
| 82 | rhs: 1000, |
| 83 | unit: "k" |
| 84 | }, |
| 85 | { |
| 86 | operator: "/", |
| 87 | rhs: 1000000, |
| 88 | unit: "m" |
| 89 | }, |
| 90 | ] |
| 91 | }) |
| 92 | break; |
nothing calls this directly
no test coverage detected