Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create select renderer
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent d731acd commit 5a9c663
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion components/FormGenerator.tsx
Expand Up @@ -138,6 +138,34 @@ export default function ({
);
}

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

const selectOptions = [];

for (const option of c.options) {
selectOptions.push(<option value={option.value}>{option.value}</option>);
}

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

setState(newState);
}}
placeholder="Select option"
>
{selectOptions}
</Select>
);
}

function generateReactComponents(
components: component[],
state: { [k: string]: string | string[] },
Expand Down Expand Up @@ -202,8 +230,13 @@ export default function ({
);
break;

case "radio":
fragmentsList.push(renderRadioElements(component, state, setState));
break;

case "select":
fragmentsList.push();
fragmentsList.push(renderSelectElements(component, state, setState));
break;
}

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

0 comments on commit 5a9c663

Please sign in to comment.