UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

80 lines (79 loc) 4.82 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { FormattedMessage, useIntl } from 'react-intl'; import { BuilderTabs, ClearOnHide, Description, Hidden, IsSensitiveData, Key, Label, Prefill, PresentationConfig, Registration, SimpleConditional, Suffix, Tooltip, Translations, Validate, useDeriveComponentKey, } from '../../components/builder'; import { LABELS } from '../../components/builder/messages'; import { Checkbox, NumberField, TabList, TabPanel, Tabs } from '../../components/formio'; import { useErrorChecker } from '../../utils/errors'; /** * Form to configure a Formio 'number' type component. */ const EditForm = () => { const intl = useIntl(); const [isKeyManuallySetRef, generatedKey] = useDeriveComponentKey(); const { hasAnyError } = useErrorChecker(); Validate.useManageValidatorsTranslations(['required', 'min', 'max']); return (_jsxs(Tabs, { children: [_jsxs(TabList, { children: [_jsx(BuilderTabs.Basic, { hasErrors: hasAnyError('label', 'key', 'description', 'tooltip', 'showInSummary', 'showInEmail', 'showInPDF', 'hidden', 'clearOnHide', 'isSensitiveData', 'defaultValue', 'decimalLimit', 'allowNegative', 'suffix') }), _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(BuilderTabs.Translations, { hasErrors: hasAnyError('openForms.translations') })] }), _jsxs(TabPanel, { children: [_jsx(Label, {}), _jsx(Key, { isManuallySetRef: isKeyManuallySetRef, generatedValue: generatedKey }), _jsx(Description, {}), _jsx(Tooltip, {}), _jsx(Suffix, {}), _jsx(PresentationConfig, {}), _jsx(Hidden, {}), _jsx(ClearOnHide, {}), _jsx(IsSensitiveData, {}), _jsx(DefaultValue, {}), _jsx(DecimalLimit, {}), _jsx(AllowNegative, {})] }), _jsx(TabPanel, { children: _jsx(SimpleConditional, {}) }), _jsxs(TabPanel, { children: [_jsx(Validate.Required, {}), _jsx(Validate.ValidatorPluginSelect, {}), _jsx(Validate.Min, {}), _jsx(Validate.Max, {}), _jsx(Validate.ValidationErrorTranslations, {})] }), _jsx(TabPanel, { children: _jsx(Registration.RegistrationAttributeSelect, {}) }), _jsx(TabPanel, { children: _jsx(Prefill.PrefillConfiguration, {}) }), _jsx(TabPanel, { children: _jsx(Translations.ComponentTranslations, { propertyLabels: { label: intl.formatMessage(LABELS.label), description: intl.formatMessage(LABELS.description), tooltip: intl.formatMessage(LABELS.tooltip), suffix: intl.formatMessage({ id: "oWJX5K", defaultMessage: [{ type: 0, value: "Suffix (e.g. m\u00B2)" }] }), } }) })] })); }; EditForm.defaultValues = { // basic tab label: '', key: '', description: '', tooltip: '', showInSummary: true, showInEmail: false, showInPDF: true, hidden: false, clearOnHide: true, isSensitiveData: false, defaultValue: null, decimalLimit: undefined, allowNegative: false, suffix: '', // Advanced tab conditional: { show: undefined, when: '', eq: '', }, // Validation tab validate: { required: false, plugins: [], min: undefined, max: undefined, }, translatedErrors: {}, // Registration tab registration: { attribute: '', }, prefill: { plugin: '', attribute: '', identifierRole: 'main', }, }; const DefaultValue = () => { 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(NumberField, { name: "defaultValue", label: _jsx(FormattedMessage, Object.assign({}, LABELS.defaultValue)), tooltip: tooltip })); }; const DecimalLimit = () => { const intl = useIntl(); const tooltip = intl.formatMessage({ id: "m20av3", defaultMessage: [{ type: 0, value: "The maximum number of decimal places." }] }); return (_jsx(NumberField, { name: "decimalLimit", label: _jsx(FormattedMessage, { id: 'BvRBef', defaultMessage: [{ type: 0, value: "Decimal places" }] }), tooltip: tooltip })); }; const AllowNegative = () => { const intl = useIntl(); const tooltip = intl.formatMessage({ id: "3LEg1l", defaultMessage: [{ type: 0, value: "Allow negative values." }] }); return (_jsx(Checkbox, { name: "allowNegative", label: _jsx(FormattedMessage, { id: 'E8Tuiq', defaultMessage: [{ type: 0, value: "Allow negative values" }] }), tooltip: tooltip })); }; const ComparisonValueInput = NumberField; export default EditForm; export { ComparisonValueInput };