import React from "react"; import { Flex, Stack, Text, useRadioGroup } from "@chakra-ui/react"; import { useFormContext } from "react-hook-form"; import { FormControlWithError } from "./FormControlWithError"; import { RadioCard } from "./RadioCard"; export interface ITokenMintDecimalsFormProps { decimals: number; } export const TokenMintDecimalsInputs = ({ maxDecimals = 12, }: { maxDecimals?: number; }) => { const { watch, formState: { errors }, setValue, clearErrors, } = useFormContext(); const { getRootProps, getRadioProps } = useRadioGroup({ name: "decimals", onChange: (value) => { setValue("decimals", +value); clearErrors("decimals"); }, }); const decimals = watch("decimals"); const group = getRootProps(); const decimalOptions = Array.from(Array(maxDecimals + 1)).map((_, index) => ({ value: index, heading: index, })); return ( <> {decimalOptions.map(({ value, heading }) => { const radio = getRadioProps({ value }); return ( {heading} ); })} ); };