initial setup, formik, fields, layout
This commit is contained in:
parent
765cc0c7cf
commit
b23d706180
16 changed files with 578 additions and 53 deletions
38
components/Form/ToggleField.tsx
Normal file
38
components/Form/ToggleField.tsx
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { useField } from "formik";
|
||||
import React, { useState } from "react";
|
||||
import ErrorMessage from "./ErrorMessage";
|
||||
import RequiredAsterisk from "./RequiredAsterisk";
|
||||
import * as SwitchPrimitive from "@radix-ui/react-switch";
|
||||
|
||||
const ToggleField = ({
|
||||
children,
|
||||
...props
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
} & React.InputHTMLAttributes<HTMLInputElement>) => {
|
||||
const { required, ...restProps } = props;
|
||||
const [field, meta] = useField({ ...(restProps as { name: string }), type: "checkbox" });
|
||||
const [checked, setChecked] = useState(false);
|
||||
|
||||
return (
|
||||
<div className="">
|
||||
<label className="flex items-center gap-2">
|
||||
{children}
|
||||
<RequiredAsterisk required={required} />
|
||||
</label>
|
||||
<SwitchPrimitive.Root
|
||||
className="relative h-[25px] w-[42px] cursor-default rounded-full bg-black shadow-[0_2px_10px] outline-none focus:shadow-[0_0_0_2px] focus:shadow-black"
|
||||
checked={checked}
|
||||
onCheckedChange={(isChecked) => {
|
||||
setChecked(isChecked);
|
||||
field.onChange({ target: { name: field.name, value: isChecked } });
|
||||
}}
|
||||
>
|
||||
<SwitchPrimitive.Thumb className="block h-[21px] w-[21px] translate-x-0.5 rounded-full bg-white shadow-[0_2px_2px] shadow-black transition-transform duration-100 will-change-transform data-[state=checked]:translate-x-[19px]" />
|
||||
</SwitchPrimitive.Root>
|
||||
<ErrorMessage touched={meta.touched} error={meta.error} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ToggleField;
|
||||
Loading…
Add table
Add a link
Reference in a new issue