UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

27 lines (26 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const zod_1 = require("zod"); const validation_1 = require("../../registry/validation"); const buildColumnsSchema = (intl) => zod_1.z .array(zod_1.z.object({ size: zod_1.z.number().int().gte(1).lte(12), sizeMobile: zod_1.z.number().int().gte(1).lte(4), })) // Check that the total columns does not exceed 12, as that would cause column wrapping. // While the CSS itself can handle the wrapping, it's best to avoid it and instead // explicitly design your rows in your form by using multiple column components. // Note that this restricting does not apply to mobile viewports, since there we // deliberate use less columns and leverage wrapping onto the next row for a friendlier // layout. .refine(cols => { const totalSize = cols.reduce((acc, curVal) => acc + curVal.size, 0); return totalSize <= 12; }, { message: intl.formatMessage({ id: "mpzdoT", defaultMessage: [{ type: 0, value: "The sum of column sizes may not exceed 12." }] }), }); const schema = ({ intl }) => zod_1.z.object({ key: (0, validation_1.buildKeySchema)(intl), columns: buildColumnsSchema(intl), }); exports.default = schema;