@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
26 lines (25 loc) • 1.1 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { useFormikContext } from 'formik';
import { Utils as FormioUtils } from 'formiojs';
import { useContext } from 'react';
import { BuilderContext } from '../../context';
import { Select } from '../formio';
function ComponentSelect(props) {
const { getFormComponents } = useContext(BuilderContext);
const { values } = useFormikContext();
// Get all the components in the form from Formio
const options = props.options || [];
if (!props.options) {
FormioUtils.eachComponent(getFormComponents(), (component, path) => {
// FIXME: calculate path of the component properly instead of just using the key
if (('id' in values && component.id === values.id) || path === values.key)
return;
options.push({
value: path,
label: `${component.label || component.key} (${path})`,
});
});
}
return _jsx(Select, Object.assign({}, props, { valueProperty: "value", options: options }));
}
export default ComponentSelect;