Add radio generator function
This commit is contained in:
@ -14,6 +14,7 @@ import {
|
||||
Radio,
|
||||
RadioGroup,
|
||||
Select,
|
||||
Stack,
|
||||
Textarea,
|
||||
} from "@chakra-ui/react";
|
||||
import { type Dispatch, type SetStateAction, useState } from "react";
|
||||
@ -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[] },
|
||||
@ -169,6 +201,9 @@ export default function ({
|
||||
</NumberInput>
|
||||
);
|
||||
break;
|
||||
|
||||
case "select":
|
||||
fragmentsList.push();
|
||||
}
|
||||
|
||||
fragmentsList.push(<br />, <br />, <br />);
|
||||
|
Reference in New Issue
Block a user