Lengths and angles should be set with |abs| values (#93)

* Lengths and angles should be set with |abs| values

* clean up
This commit is contained in:
Kurt Hutten
2023-04-02 17:20:11 +10:00
committed by GitHub
parent b279daa8e0
commit 01bf3c1049
13 changed files with 159 additions and 55 deletions

View File

@ -25,6 +25,7 @@ export const GetInfoModal = ({
valueNode: Value
variableName?: string
newVariableInsertIndex: number
sign: number
}) => void
onReject: (a: any) => void
segName: string
@ -32,8 +33,9 @@ export const GetInfoModal = ({
value: number
initialVariableName: string
}) => {
const [sign, setSign] = useState(Math.sign(Number(initialValue)))
const [segName, setSegName] = useState(initialSegName)
const [value, setValue] = useState(String(initialValue))
const [value, setValue] = useState(String(Math.abs(initialValue)))
const [shouldCreateVariable, setShouldCreateVariable] = useState(false)
const {
@ -45,7 +47,7 @@ export const GetInfoModal = ({
newVariableName,
isNewVariableNameUnique,
newVariableInsertIndex,
} = useCalc({ value, initialVariableName })
} = useCalc({ value: value, initialVariableName })
return (
<Transition appear show={isOpen} as={Fragment}>
@ -93,7 +95,13 @@ export const GetInfoModal = ({
>
Distance
</label>
<div className="mt-1">
<div className="mt-1 flex">
<button
className="border border-gray-300 px-2 mr-1"
onClick={() => setSign(-sign)}
>
{sign > 0 ? '+' : '-'}
</button>
<input
type="text"
name="val"
@ -145,6 +153,7 @@ export const GetInfoModal = ({
value,
valueNode,
newVariableInsertIndex,
sign,
variableName: shouldCreateVariable
? newVariableName
: undefined,