@focuson/form_components
Version:
Components that can be used by @focuson/forms
43 lines (42 loc) • 2.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LabelAndYNBooleanInput = exports.LabelAndBooleanInput = exports.LabelAndNumberInput = exports.LabelAndStringInput = exports.LabelAndTInput = exports.makeInputChangeTxs = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const input_1 = require("./input");
const label_1 = require("./label");
const transformers_1 = require("./transformers");
const utils_1 = require("@focuson/utils");
const rest_1 = require("@focuson/rest");
const makeButtons_1 = require("./makeButtons");
const CustomError_1 = require("./CustomError");
function makeInputChangeTxs(id, parentState, change) {
if (parentState === undefined)
return [];
const { simpleMessagesL, pathToLens, dateFn, pageSelectionL } = parentState.context;
const config = {
dateFn,
toPathTolens: pathToLens(parentState.main, parentState.optional),
stringToMsg: (0, utils_1.stringToSimpleMsg)(utils_1.defaultDateFn, 'info'),
messageL: simpleMessagesL,
pageSelectionL,
context: parentState.context,
s: parentState.main
};
return (0, rest_1.processChangeCommandProcessor)(`Modal button.${id}`, (0, rest_1.inputCommandProcessors)(config)(parentState.main), (0, utils_1.toArray)(change));
}
exports.makeInputChangeTxs = makeInputChangeTxs;
const LabelAndTInput = (tProps) => (props) => {
const label = (0, jsx_runtime_1.jsx)(label_1.Label, { state: props.state, htmlFor: props.id, label: props.label });
const input = (0, input_1.Input)(tProps)(props);
const buttonClasses = props.buttons && props.buttons.length > 0 ? ['inputAndButtons'] : [];
const checkboxClasses = (0, transformers_1.isCheckboxProps)(tProps) ? ['checkbox-container'] : [];
const classNameFromProps = props.className ? [props.className] : [];
const allClasses = [...buttonClasses, ...checkboxClasses, ...classNameFromProps];
const classes = allClasses.length > 0 ? allClasses.join(' ') : '';
return (0, jsx_runtime_1.jsxs)("div", Object.assign({ className: `labelValueButton ${props.labelPosition == 'Horizontal' ? 'd-flex-inline' : ''}` }, { children: [" ", props.noLabel ? '' : label, (0, jsx_runtime_1.jsxs)("div", Object.assign({ className: `${classes}` }, { children: [input, (0, makeButtons_1.makeButtons)(props)] })), (0, jsx_runtime_1.jsx)(CustomError_1.CustomError, { id: props.id, validationMessage: props.errorMessage })] }));
};
exports.LabelAndTInput = LabelAndTInput;
exports.LabelAndStringInput = (0, exports.LabelAndTInput)(transformers_1.StringTransformer);
exports.LabelAndNumberInput = (0, exports.LabelAndTInput)(transformers_1.NumberTransformer);
exports.LabelAndBooleanInput = (0, exports.LabelAndTInput)(transformers_1.BooleanTransformer);
exports.LabelAndYNBooleanInput = (0, exports.LabelAndTInput)(transformers_1.BooleanYNTransformer);