@focuson/form_components
Version:
Components that can be used by @focuson/forms
22 lines (21 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SelectedItem = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const lens_1 = require("@focuson/lens");
function SelectedItem({ index, state, display, mode, id, allButtons, header, showNofM, headerIfEmpty }) {
// console.log ( "SelectedItem", index, newState.optional.description, newState.optJson () )
const realIndex = index ? index : 0;
const newProps = { state: state.chainLens(lens_1.Lenses.nth(realIndex)), mode, id, allButtons };
if (header || showNofM || headerIfEmpty) {
const array = state.optJsonOr([]);
const nm = showNofM && (headerIfEmpty === undefined || array.length > 0) ?
(0, jsx_runtime_1.jsxs)("span", Object.assign({ id: `${id}.nOfM` }, { children: [" ", realIndex + 1, " / ", array.length] })) :
(0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
const emptyHeader = headerIfEmpty && array.length === 0 ? (0, jsx_runtime_1.jsx)("span", Object.assign({ id: `${id}.emptyHeader` }, { children: headerIfEmpty })) : (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
return (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsxs)("h2", { children: [header, nm, emptyHeader] }), display(newProps)] });
}
else
return display(newProps);
}
exports.SelectedItem = SelectedItem;