|
|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
import lodash from "lodash";
|
|
|
|
|
import { useFormikContext } from "formik";
|
|
|
|
|
import { FunctionComponent, ReactElement, useCallback } from "react";
|
|
|
|
|
import { Fragment, FunctionComponent, ReactElement, useCallback } from "react";
|
|
|
|
|
import { Button, styled } from "@mui/joy";
|
|
|
|
|
|
|
|
|
|
export interface IToggleProps {
|
|
|
|
|
@ -33,6 +33,10 @@ const ToggleButton = styled(Button)<IToggleButtonProps>(({ index, total }) => ({
|
|
|
|
|
fontSize: 11
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const ButtonBorder = styled("div")`
|
|
|
|
|
border-right: 1px solid white;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const Toggle: FunctionComponent<IToggleProps> = (
|
|
|
|
|
props: IToggleProps
|
|
|
|
|
): ReactElement => {
|
|
|
|
|
@ -42,13 +46,14 @@ const Toggle: FunctionComponent<IToggleProps> = (
|
|
|
|
|
lodash.get(formik.touched, name) && lodash.get(formik.errors, name);
|
|
|
|
|
const value = lodash.get(formik.values, name);
|
|
|
|
|
|
|
|
|
|
const handleChange = (value: string) => () => {
|
|
|
|
|
formik.setFieldValue(name, value);
|
|
|
|
|
const handleChange = (newValue: string) => () => {
|
|
|
|
|
formik.setFieldValue(name, newValue === value ? "" : newValue);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Root>
|
|
|
|
|
{options.map((option, index) => (
|
|
|
|
|
<Fragment key={option.value}>
|
|
|
|
|
<ToggleButton
|
|
|
|
|
variant={value === option.value ? "solid" : "soft"}
|
|
|
|
|
size="sm"
|
|
|
|
|
@ -59,6 +64,8 @@ const Toggle: FunctionComponent<IToggleProps> = (
|
|
|
|
|
>
|
|
|
|
|
{option.text}
|
|
|
|
|
</ToggleButton>
|
|
|
|
|
{index + 1 < options.length && <ButtonBorder />}
|
|
|
|
|
</Fragment>
|
|
|
|
|
))}
|
|
|
|
|
|
|
|
|
|
<div className="mt-1 text-xs text-red-600">
|
|
|
|
|
|