UNPKG

@focuson/form_components

Version:

Components that can be used by @focuson/forms

37 lines (36 loc) 2.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DataDrivenFixedOptionDropDownAndDetails = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const labelAndDropdown_1 = require("./labelAndDropdown"); function DropDownFromData(props) { const { state, id, details, label, mode, allButtons, parentState, pleaseSelect, dontShowEmpty, enabledBy } = props; let s = state.main; const pathToLens = state.context.pathToLens(s, parentState.optional); const rawValues = Object.entries(details).map(([name, detail]) => [name, detail.value ? detail.value : detail.valuePath ? pathToLens(detail.valuePath).getOption(s) : '']); const values = Object.fromEntries(rawValues.filter(nv => { var _a; return !dontShowEmpty || (((_a = nv[1]) === null || _a === void 0 ? void 0 : _a.length) && nv[1].length > 0); })); return (0, jsx_runtime_1.jsx)(labelAndDropdown_1.LabelAndDropdown, { parentState: parentState, label: label, enabledBy: enabledBy, enums: values, mode: mode, allButtons: allButtons, state: state, id: id, pleaseSelect: pleaseSelect, required: true }); } function TwoColRow({ children }) { return (0, jsx_runtime_1.jsxs)("div", Object.assign({ style: { display: 'flex' } }, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ style: { flex: '50%' } }, { children: children[0] })), (0, jsx_runtime_1.jsx)("div", Object.assign({ style: { flex: '50%' } }, { children: children[1] }))] })); } function DetailsFromData(props) { var _a; const { state, id, details, label, mode, allButtons, parentState } = props; let s = state.main; const pathToLens = state.context.pathToLens(s, parentState.optional); const value = props.state.optJson(); const d = value === undefined ? undefined : details[value]; if (d && d.dataPath && d.display) { const data = d ? (_a = pathToLens(d.dataPath)) === null || _a === void 0 ? void 0 : _a.getOption(s) : undefined; return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: d.display({ id, mode, allButtons, label, state: state.copyWithLens(pathToLens(d.dataPath)), }) }); } return (0, jsx_runtime_1.jsx)("div", {}); } function DataDrivenFixedOptionDropDownAndDetails(props) { return (0, jsx_runtime_1.jsxs)(TwoColRow, { children: [(0, jsx_runtime_1.jsx)(DropDownFromData, Object.assign({}, props)), (0, jsx_runtime_1.jsx)(DetailsFromData, Object.assign({}, props))] }); } exports.DataDrivenFixedOptionDropDownAndDetails = DataDrivenFixedOptionDropDownAndDetails;