UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

27 lines (26 loc) 1.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ItemsExpression = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const monaco_json_editor_1 = require("@open-formulieren/monaco-json-editor"); const formik_1 = require("formik"); const react_1 = require("react"); const react_intl_1 = require("react-intl"); const formio_1 = require("../../../components/formio"); const context_1 = require("../../../context"); const NAME = 'openForms.itemsExpression'; /** * The `ItemsExpression` component is used to specify the JsonLogic expression to * calculate the values/options for a component. * * @todo: this would really benefit from a nice, context-aware JsonLogic editor. */ const ItemsExpression = () => { const { getFieldProps, setFieldValue } = (0, formik_1.useFormikContext)(); const { value = '' } = getFieldProps(NAME); const builderContext = (0, react_1.useContext)(context_1.BuilderContext); const htmlId = `editform-${NAME}`; return ((0, jsx_runtime_1.jsxs)(formio_1.Component, Object.assign({ type: "textarea", field: NAME, required: true, htmlId: htmlId, label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: 'C48xJT', defaultMessage: [{ type: 0, value: "Items expression" }] }) }, { children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(monaco_json_editor_1.JSONEditor, { wrapperProps: { className: 'json-editor json-editor--compact' }, value: value, onChange: value => setFieldValue(NAME, value), showLines: false, theme: builderContext.theme }) }), (0, jsx_runtime_1.jsx)(formio_1.Description, { text: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: 'fe3wyn', defaultMessage: [{ type: 0, value: "A JSON logic expression returning a variable (of array type) whose items should be used as the options for this component." }] }) })] }))); }; exports.ItemsExpression = ItemsExpression; exports.default = exports.ItemsExpression;