import Image from "next/image"; // headless ui import { Disclosure } from "@headlessui/react"; // ui import { ToggleSwitch } from "components/ui"; import { Input } from "../input"; // icons import { CheckCircle2, ChevronDown } from "lucide-react"; // assets import NumericalRepresentation from "public/custom-attributes/number/numerical.svg"; import BarRepresentation from "public/custom-attributes/number/bar.svg"; import RingRepresentation from "public/custom-attributes/number/ring.svg"; // types import { ICustomAttribute, TCustomAttributeTypes } from "types"; // constants import { CUSTOM_ATTRIBUTES_LIST } from "constants/custom-attributes"; import { Controller, useForm } from "react-hook-form"; type Props = {}; const numberAttributeRepresentations = [ { image: NumericalRepresentation, key: "numerical", label: "Numerical", }, { image: BarRepresentation, key: "bar", label: "Bar", }, { image: RingRepresentation, key: "ring", label: "Ring", }, ]; const defaultFormValues: Partial = { default_value: "", display_name: "", extra_settings: { color: "Blue", divided_by: 100, representation: "numerical", show_number: true, }, is_required: false, }; export const NumberAttributeForm: React.FC = () => { const { control, watch } = useForm({ defaultValues: defaultFormValues }); const typeMetaData = CUSTOM_ATTRIBUTES_LIST.number; return ( {({ open }) => ( <>
{typeMetaData.label}
( )} /> ( )} />
Show as
( <> {numberAttributeRepresentations.map((representation) => (
onChange(representation.key)} >
{representation.label}
{representation.label} {value === representation.key && ( )}
))} )} />
{(watch("extra_settings.representation") === "bar" || watch("extra_settings.representation") === "ring") && (
<>
Divided by
( )} />
<>
Color
( )} />
<>
Show number
( )} />
)}
( )} /> Mandatory field
)} ); };