import { Fragment, FunctionComponent, ReactElement, useCallback } from "react"; import { styled } from "@mui/joy"; import IconButton from "@mui/joy/IconButton"; import { MinusSmIcon } from "@heroicons/react/solid"; import TextField from "./global/FormElements/TextField"; import Toggle from "./global/FormElements/Toggle"; export interface IFieldType { name: string; placeholder: string; required?: boolean; type: "text" | "toggle"; options?: { text: string; value: string; }[]; } export interface IRecordProps { fields: IFieldType[]; index: number; onRemove: (index: number) => void; } const Root = styled("div")` display: flex; flex-direction: row; justify-content: flex-start; align-items: flex-start; column-gap: ${({ theme }) => theme.spacing(2)}; @media (max-width: 768px) { column-gap: ${({ theme }) => theme.spacing(1)}; } `; const RemoveButton = styled(IconButton)``; const Record: FunctionComponent = ( props: IRecordProps ): ReactElement => { const { fields, index, onRemove } = props; const handleRemove = useCallback(() => { onRemove(index); }, [index, onRemove]); return ( {fields.map(({ type, name, placeholder, required, options }) => ( {type === "text" && ( )} {type === "toggle" && ( )} ))} ); }; export default Record;