UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

100 lines (98 loc) 6.9 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useFormikContext } from 'formik'; import { FormattedMessage, useIntl } from 'react-intl'; import { AutoComplete, BuilderTabs, ClearOnHide, ComponentSelect, Description, Hidden, IsSensitiveData, Key, Label, Multiple, Placeholder, Prefill, PresentationConfig, ReadOnly, Registration, ShowCharCount, SimpleConditional, Tooltip, Translations, Validate, useDeriveComponentKey, } from '../../components/builder'; import { LABELS } from '../../components/builder/messages'; import { Checkbox, Panel, Tab, TabList, TabPanel, Tabs, TextField } from '../../components/formio'; import { useErrorChecker } from '../../utils/errors'; /** * Form to configure a Formio 'textfield' type component. */ const EditForm = () => { const intl = useIntl(); const [isKeyManuallySetRef, generatedKey] = useDeriveComponentKey(); const { values } = useFormikContext(); const { hasAnyError } = useErrorChecker(); Validate.useManageValidatorsTranslations([ 'required', 'maxLength', 'pattern', ]); return (_jsxs(Tabs, { children: [_jsxs(TabList, { children: [_jsx(BuilderTabs.Basic, { hasErrors: hasAnyError('label', 'key', 'description', 'tooltip', 'showInSummary', 'showInEmail', 'showInPDF', 'multiple', 'hidden', 'clearOnHide', 'isSensitiveData', 'defaultValue', 'autocomplete', 'disabled', 'placeholder', 'showCharCount') }), _jsx(BuilderTabs.Advanced, { hasErrors: hasAnyError('conditional') }), _jsx(BuilderTabs.Validation, { hasErrors: hasAnyError('validate') }), _jsx(BuilderTabs.Registration, { hasErrors: hasAnyError('registration') }), _jsx(BuilderTabs.Prefill, { hasErrors: hasAnyError('prefill') }), _jsx(Tab, Object.assign({ hasErrors: hasAnyError('deriveStreetName', 'deriveCity', 'derivePostcode', 'deriveHouseNumber') }, { children: _jsx(FormattedMessage, { id: '4/cCvG', defaultMessage: [{ type: 0, value: "Location" }] }) })), _jsx(BuilderTabs.Translations, { hasErrors: hasAnyError('openForms.translations') })] }), _jsxs(TabPanel, { children: [_jsx(Label, {}), _jsx(Key, { isManuallySetRef: isKeyManuallySetRef, generatedValue: generatedKey }), _jsx(Description, {}), _jsx(Tooltip, {}), _jsx(PresentationConfig, {}), _jsx(Multiple, {}), _jsx(Hidden, {}), _jsx(ClearOnHide, {}), _jsx(IsSensitiveData, {}), _jsx(DefaultValue, { multiple: !!values.multiple }), _jsx(AutoComplete, {}), _jsx(ReadOnly, {}), _jsx(Placeholder, {}), _jsx(ShowCharCount, {})] }), _jsx(TabPanel, { children: _jsx(SimpleConditional, {}) }), _jsxs(TabPanel, { children: [_jsx(Validate.Required, {}), _jsx(Validate.ValidatorPluginSelect, {}), _jsx(Validate.MaxLength, {}), _jsx(Validate.RegexValidation, {}), _jsx(Validate.ValidationErrorTranslations, {})] }), _jsx(TabPanel, { children: _jsx(Registration.RegistrationAttributeSelect, {}) }), _jsx(TabPanel, { children: _jsx(Prefill.PrefillConfiguration, {}) }), _jsxs(TabPanel, { children: [_jsxs("p", { children: [_jsx("i", { className: "fa fa-circle-info" }), "\u00A0", _jsx(FormattedMessage, { id: 'fGTdJz', defaultMessage: [{ type: 0, value: "Deriving the location via text fields is deprecated. Use the AddressNL component instead." }] })] }), _jsxs(Panel, Object.assign({ title: _jsx(FormattedMessage, { id: 'V2/ceD', defaultMessage: [{ type: 0, value: "Configuration (deprecated)" }] }), collapsible: true, initialCollapsed: true }, { children: [_jsx(DeriveStreetName, {}), _jsx(DeriveCity, {}), _jsx(DerivePostcode, {}), _jsx(DeriveHouseNumber, {})] }))] }), _jsx(TabPanel, { children: _jsx(Translations.ComponentTranslations, { propertyLabels: { label: intl.formatMessage(LABELS.label), description: intl.formatMessage(LABELS.description), tooltip: intl.formatMessage(LABELS.tooltip), placeholder: intl.formatMessage(LABELS.placeholder), } }) })] })); }; /* Making this introspected or declarative doesn't seem advisable, as React is calling React.Children and related API's legacy API - this may get removed in future versions. Explicitly specifying the schema and default values is therefore probbaly best, at the cost of some repetition. */ EditForm.defaultValues = { // basic tab label: '', key: '', description: '', tooltip: '', showInSummary: true, showInEmail: false, showInPDF: true, multiple: false, hidden: false, clearOnHide: true, isSensitiveData: false, defaultValue: '', autocomplete: '', disabled: false, placeholder: '', showCharCount: false, // location tab deriveStreetName: false, deriveCity: false, derivePostcode: '', deriveHouseNumber: '', // Advanced tab conditional: { show: undefined, when: '', eq: '', }, // Validation tab validate: { required: false, plugins: [], maxLength: 1000, pattern: '', }, translatedErrors: {}, registration: { attribute: '', }, prefill: { plugin: '', attribute: '', identifierRole: 'main', }, }; const DefaultValue = ({ multiple }) => { const intl = useIntl(); const tooltip = intl.formatMessage({ id: "FffJxu", defaultMessage: [{ type: 0, value: "This will be the initial value for this field before user interaction." }] }); return (_jsx(TextField, { name: "defaultValue", label: _jsx(FormattedMessage, Object.assign({}, LABELS.defaultValue)), tooltip: tooltip, multiple: multiple })); }; const DeriveStreetName = () => { const intl = useIntl(); const tooltip = intl.formatMessage({ id: "W4PizY", defaultMessage: [{ type: 0, value: "If the postcode and house number are entered this field will autofill with the street name" }] }); return (_jsx(Checkbox, { name: "deriveStreetName", label: _jsx(FormattedMessage, { id: 'asZV7t', defaultMessage: [{ type: 0, value: "Derive street name" }] }), tooltip: tooltip })); }; const DeriveCity = () => { const intl = useIntl(); const tooltip = intl.formatMessage({ id: "V6ClU9", defaultMessage: [{ type: 0, value: "If the postcode and house number are entered this field will autofill with the city" }] }); return (_jsx(Checkbox, { name: "deriveCity", label: _jsx(FormattedMessage, { id: 'H4sILo', defaultMessage: [{ type: 0, value: "Derive city" }] }), tooltip: tooltip })); }; const DerivePostcode = () => (_jsx(ComponentSelect, { name: "derivePostcode", label: _jsx(FormattedMessage, { id: 'Uv58uI', defaultMessage: [{ type: 0, value: "Postcode component" }] }), isSearchable: true, isClearable: true })); const DeriveHouseNumber = () => (_jsx(ComponentSelect, { name: "deriveHouseNumber", label: _jsx(FormattedMessage, { id: 'jLg5l6', defaultMessage: [{ type: 0, value: "House number component" }] }), isSearchable: true, isClearable: true })); export default EditForm;