-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
301 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,61 @@ | ||
import { ComponentType } from "react"; | ||
import { Equation, InteractiveCalculatorProps } from "@/types/calculators"; | ||
import PeakAbsoluteMagnitude from "./peakAbsoluteMagnitude"; | ||
import SupernovaDistance from "./supernovaDistance"; | ||
|
||
const InteractiveCalculators: Record< | ||
Equation, | ||
ComponentType<InteractiveCalculatorProps> | ||
> = { | ||
peakAbsoluteMagnitude: PeakAbsoluteMagnitude, | ||
supernovaDistance: SupernovaDistance, | ||
/* eslint-disable jsx-a11y/label-has-associated-control */ | ||
import { FormEvent, FunctionComponent } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { InteractiveCalculatorProps } from "@/types/calculators"; | ||
import MathInput from "@/components/form/Input/patterns/MathInput"; | ||
import Equation from "@/components/atomic/Equation"; | ||
import Calculator from "@/components/calculators/lib"; | ||
import * as Styled from "./styles"; | ||
|
||
const InteractiveCalculator: FunctionComponent<InteractiveCalculatorProps> = ({ | ||
equation, | ||
id, | ||
value = {}, | ||
onChangeCallback, | ||
}) => { | ||
const { | ||
t, | ||
i18n: { language }, | ||
} = useTranslation(); | ||
|
||
const { fields = {}, result, latex } = Calculator(equation, value, language); | ||
|
||
const handleChange = (event: FormEvent<HTMLInputElement>, key: string) => { | ||
onChangeCallback && | ||
onChangeCallback({ | ||
...value, | ||
[key]: parseFloat((event.target as HTMLInputElement).value), | ||
}); | ||
}; | ||
|
||
return ( | ||
<Styled.MathContainer> | ||
<Styled.Inputs id={id}> | ||
{Object.keys(fields).map((key: string) => { | ||
const { label, precision } = fields[key]; | ||
return ( | ||
<Styled.InputRow key={key}> | ||
<label htmlFor={key}> | ||
<Equation latex={label} /> | ||
</label> | ||
<MathInput | ||
value={value[key] ?? ""} | ||
onChange={(e) => handleChange(e, key)} | ||
id={key} | ||
step={10 ** -precision} | ||
/> | ||
</Styled.InputRow> | ||
); | ||
})} | ||
</Styled.Inputs> | ||
<Equation latex={latex} /> | ||
<Styled.LiveRegion htmlFor={id}> | ||
{t(`calculators.output.${equation}`, { result })} | ||
</Styled.LiveRegion> | ||
</Styled.MathContainer> | ||
); | ||
}; | ||
|
||
export default InteractiveCalculators; | ||
InteractiveCalculator.displayName = "Calculator.Interactive"; | ||
|
||
export default InteractiveCalculator; |
94 changes: 0 additions & 94 deletions
94
components/calculators/interactive/peakAbsoluteMagnitude.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 0 additions & 110 deletions
110
components/calculators/interactive/supernovaDistance.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.