@arun-s-aot/formio-react
Version:
React renderer for formsflow form.io forms.
61 lines (58 loc) • 1.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getComponentDefaultColumn = void 0;
exports.setColumnsWidth = setColumnsWidth;
exports.stopPropagationWrapper = void 0;
var _lib = require("@arun-s-aot/formiojs/lib");
var _get2 = _interopRequireDefault(require("lodash/get"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const getComponentDefaultColumn = component => ({
component: _lib.Components.create(component, null, null, true),
key: `data.${component.key}`,
sort: true,
title: component.label || component.title || component.key,
value(submission) {
const cellValue = (0, _get2.default)(submission, this.key, null);
if (cellValue === null) {
return '';
}
const rendered = this.component.asString(cellValue);
if (cellValue !== rendered) {
return {
content: rendered,
isHtml: true
};
}
return cellValue;
}
});
/**
* @param {import('./types').Column[]} columns
*/
exports.getComponentDefaultColumn = getComponentDefaultColumn;
function setColumnsWidth(columns) {
if (columns.length > 6) {
columns.forEach(column => {
column.width = 2;
});
} else {
const columnsAmount = columns.length;
const rowWidth = 12;
const basewidth = Math.floor(rowWidth / columnsAmount);
const remainingWidth = rowWidth - basewidth * columnsAmount;
columns.forEach((column, index) => {
column.width = index < remainingWidth ? basewidth + 1 : basewidth;
});
}
}
/**
* @param {Function} fn
* @returns {(function(*): void)|*}
*/
const stopPropagationWrapper = fn => event => {
event.stopPropagation();
fn();
};
exports.stopPropagationWrapper = stopPropagationWrapper;