Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add radio generator function
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent f6a5cfe commit d731acd
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions components/FormGenerator.tsx
Expand Up @@ -14,6 +14,7 @@ import {
Radio,
RadioGroup,
Select,
Stack,
Textarea,
} from "@chakra-ui/react";
import { type Dispatch, type SetStateAction, useState } from "react";
Expand Down Expand Up @@ -106,6 +107,37 @@ export default function ({
);
}

function renderRadioElements(
c: component,
state: { [k: string]: string | string[] },
setState: Dispatch<SetStateAction<{}>>
) {
if (!c.options) throw new Error("Options for radio buttons are undefined!");
const buttons = [];

for (const option of c.options) {
buttons.push(
<Radio checked={option.default} value={option.value}>
{option.value}
</Radio>
);
}

return (
<RadioGroup
id={c.id}
onChange={(e) => {
const newState = { ...state };
newState[c.id] = e;

setState(newState);
}}
>
<Stack direction="row">{buttons}</Stack>
</RadioGroup>
);
}

function generateReactComponents(
components: component[],
state: { [k: string]: string | string[] },
Expand Down Expand Up @@ -169,6 +201,9 @@ export default function ({
</NumberInput>
);
break;

case "select":
fragmentsList.push();
}

fragmentsList.push(<br />, <br />, <br />);
Expand Down

0 comments on commit d731acd

Please sign in to comment.