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