Create select renderer
This commit is contained in:
parent
d731acd5b2
commit
5a9c663479
@ -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(
|
function generateReactComponents(
|
||||||
components: component[],
|
components: component[],
|
||||||
state: { [k: string]: string | string[] },
|
state: { [k: string]: string | string[] },
|
||||||
@ -202,8 +230,13 @@ export default function ({
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "radio":
|
||||||
|
fragmentsList.push(renderRadioElements(component, state, setState));
|
||||||
|
break;
|
||||||
|
|
||||||
case "select":
|
case "select":
|
||||||
fragmentsList.push();
|
fragmentsList.push(renderSelectElements(component, state, setState));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
fragmentsList.push(<br />, <br />, <br />);
|
fragmentsList.push(<br />, <br />, <br />);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user