@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
87 lines (85 loc) • 7.47 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_intl_1 = require("react-intl");
const builder_1 = require("../../components/builder");
const messages_1 = require("../../components/builder/messages");
const formio_1 = require("../../components/formio");
const errors_1 = require("../../utils/errors");
const GROUP_LABEL = (0, react_intl_1.defineMessage)({ id: "ehP4dQ", defaultMessage: [{ type: 0, value: "Group label" }] });
const ADD_ANOTHER_LABEL = (0, react_intl_1.defineMessage)({ id: "rkJLBr", defaultMessage: [{ type: 0, value: "'Add another' text" }] });
const SAVE_ROW_LABEL = (0, react_intl_1.defineMessage)({ id: "eUowhH", defaultMessage: [{ type: 0, value: "'Save row' text" }] });
const REMOVE_ROW_LABEL = (0, react_intl_1.defineMessage)({ id: "AyOwJl", defaultMessage: [{ type: 0, value: "'Remove row' text" }] });
/**
* Form to configure a Formio 'fieldset' type component.
*/
const EditForm = () => {
const intl = (0, react_intl_1.useIntl)();
const [isKeyManuallySetRef, generatedKey] = (0, builder_1.useDeriveComponentKey)();
const { hasAnyError } = (0, errors_1.useErrorChecker)();
return ((0, jsx_runtime_1.jsxs)(formio_1.Tabs, { children: [(0, jsx_runtime_1.jsxs)(formio_1.TabList, { children: [(0, jsx_runtime_1.jsx)(builder_1.BuilderTabs.Basic, { hasErrors: hasAnyError('label', 'key', 'groupLabel', 'description', 'tooltip', 'hidden', 'clearOnHide', 'isSensitiveData', 'hideLabel') }), (0, jsx_runtime_1.jsx)(formio_1.Tab, Object.assign({ hasErrors: hasAnyError('disableAddingRemovingRows', 'addAnother', 'saveRow', 'removeRow') }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: 'd3V6A+', defaultMessage: [{ type: 0, value: "Display" }] }) })), (0, jsx_runtime_1.jsx)(builder_1.BuilderTabs.Validation, { hasErrors: hasAnyError('validate') }), (0, jsx_runtime_1.jsx)(builder_1.BuilderTabs.Translations, { hasErrors: hasAnyError('openForms.translations') })] }), (0, jsx_runtime_1.jsxs)(formio_1.TabPanel, { children: [(0, jsx_runtime_1.jsx)(builder_1.Label, {}), (0, jsx_runtime_1.jsx)(builder_1.Key, { isManuallySetRef: isKeyManuallySetRef, generatedValue: generatedKey }), (0, jsx_runtime_1.jsx)(builder_1.Description, {}), (0, jsx_runtime_1.jsx)(builder_1.Tooltip, {}), (0, jsx_runtime_1.jsx)(GroupLabel, {}), (0, jsx_runtime_1.jsx)(builder_1.Hidden, {}), (0, jsx_runtime_1.jsx)(builder_1.ClearOnHide, {}), (0, jsx_runtime_1.jsx)(builder_1.IsSensitiveData, {}), (0, jsx_runtime_1.jsx)(HideLabel, {})] }), (0, jsx_runtime_1.jsxs)(formio_1.TabPanel, { children: [(0, jsx_runtime_1.jsx)(DisableAddingRemovingRows, {}), (0, jsx_runtime_1.jsxs)(formio_1.Panel, Object.assign({ collapsible: true, initialCollapsed: true, title: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: 'E/biiX', defaultMessage: [{ type: 0, value: "Button labels" }] }) }, { children: [(0, jsx_runtime_1.jsx)(AddAnother, {}), (0, jsx_runtime_1.jsx)(SaveRow, {}), (0, jsx_runtime_1.jsx)(RemoveRow, {})] }))] }), (0, jsx_runtime_1.jsxs)(formio_1.TabPanel, { children: [(0, jsx_runtime_1.jsx)(builder_1.Validate.Required, {}), (0, jsx_runtime_1.jsx)(builder_1.Validate.MaxLength, {})] }), (0, jsx_runtime_1.jsx)(formio_1.TabPanel, { children: (0, jsx_runtime_1.jsx)(builder_1.Translations.ComponentTranslations, { propertyLabels: {
label: intl.formatMessage(messages_1.LABELS.label),
description: intl.formatMessage(messages_1.LABELS.description),
tooltip: intl.formatMessage(messages_1.LABELS.tooltip),
groupLabel: intl.formatMessage(GROUP_LABEL),
addAnother: intl.formatMessage(ADD_ANOTHER_LABEL),
saveRow: intl.formatMessage(SAVE_ROW_LABEL),
removeRow: intl.formatMessage(REMOVE_ROW_LABEL),
} }) })] }));
};
/*
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 = {
components: [],
// basic tab
label: '',
key: '',
groupLabel: 'Item',
description: '',
tooltip: '',
hidden: false,
clearOnHide: true,
isSensitiveData: false,
hideLabel: false,
// display tab
disableAddingRemovingRows: false,
addAnother: '',
saveRow: '',
removeRow: 'Cancel',
};
const GroupLabel = () => {
const intl = (0, react_intl_1.useIntl)();
const tooltip = intl.formatMessage({ id: "VhCwEK", defaultMessage: [{ type: 0, value: "The label that will be shown above each repeating group in the summary page, the submission report and the confirmation email. The index of the item will be added next to it, i.e. if you enter 'Item' it will be displayed as 'Item 1', 'Item 2', ..." }] });
return ((0, jsx_runtime_1.jsx)(formio_1.TextField, { name: "groupLabel", label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, Object.assign({}, GROUP_LABEL)), tooltip: tooltip }));
};
const HideLabel = () => {
const intl = (0, react_intl_1.useIntl)();
const tooltip = intl.formatMessage({ id: "fagx6e", defaultMessage: [{ type: 0, value: "Hide the title/label of this component in the form." }] });
return ((0, jsx_runtime_1.jsx)(formio_1.Checkbox, { name: "hideLabel", label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: 'dWWO3N', defaultMessage: [{ type: 0, value: "Hide label" }] }), tooltip: tooltip }));
};
const DisableAddingRemovingRows = () => {
const intl = (0, react_intl_1.useIntl)();
const tooltip = intl.formatMessage({ id: "AMqUHx", defaultMessage: [{ type: 0, value: "Check if you want to hide/disable the 'Add Another' and 'Remove row' buttons." }] });
return ((0, jsx_runtime_1.jsx)(formio_1.Checkbox, { name: "disableAddingRemovingRows", label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: 'MTdKuN', defaultMessage: [{ type: 0, value: "Disable adding or removing groups" }] }), tooltip: tooltip }));
};
const AddAnother = () => {
const intl = (0, react_intl_1.useIntl)();
const tooltip = intl.formatMessage({ id: "o83CBr", defaultMessage: [{ type: 0, value: "Set the text of the 'Add Another' button." }] });
return ((0, jsx_runtime_1.jsx)(formio_1.TextField, { name: "addAnother", label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, Object.assign({}, ADD_ANOTHER_LABEL)), tooltip: tooltip }));
};
const SaveRow = () => {
const intl = (0, react_intl_1.useIntl)();
const tooltip = intl.formatMessage({ id: "/stTVr", defaultMessage: [{ type: 0, value: "Set the text of the 'Save row' button." }] });
return ((0, jsx_runtime_1.jsx)(formio_1.TextField, { name: "saveRow", label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, Object.assign({}, SAVE_ROW_LABEL)), tooltip: tooltip }));
};
const RemoveRow = () => {
const intl = (0, react_intl_1.useIntl)();
const tooltip = intl.formatMessage({ id: "gCQtSJ", defaultMessage: [{ type: 0, value: "Set the text of the 'Remove row' button." }] });
return ((0, jsx_runtime_1.jsx)(formio_1.TextField, { name: "removeRow", label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, Object.assign({}, REMOVE_ROW_LABEL)), tooltip: tooltip }));
};
exports.default = EditForm;