@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
214 lines (213 loc) • 8.69 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = ChildrenWithAge;
var _react = _interopRequireDefault(require("react"));
var _index = require("../../index.js");
var _index2 = require("../../../../elements/index.js");
var _ChildrenWithAgeTranslations = require("./ChildrenWithAgeTranslations.js");
var _utils = require("../../../../components/flex/utils.js");
var _withComponentMarkers = _interopRequireDefault(require("../../../../shared/helpers/withComponentMarkers.js"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const maximumChildren = 9;
function ChildrenWithAge({
mode,
enableAdditionalQuestions,
toWizardStep,
...props
}) {
const spacingProps = (0, _utils.pickSpacingProps)(props);
const restProps = (0, _utils.omitSpacingProps)(props);
return (0, _jsxRuntime.jsx)(_index.Form.Section, {
translations: _ChildrenWithAgeTranslations.translations,
required: true,
...restProps,
children: mode === 'summary' ? (0, _jsxRuntime.jsx)(SummaryContainer, {
toWizardStep: toWizardStep,
spacingProps: spacingProps,
enableAdditionalQuestions: enableAdditionalQuestions
}) : (0, _jsxRuntime.jsx)(EditContainer, {
enableAdditionalQuestions: enableAdditionalQuestions,
spacingProps: spacingProps
})
});
}
function EditContainer({
spacingProps,
enableAdditionalQuestions
}) {
const tr = _index.Form.useTranslation();
const {
getValue
} = _index.Form.useData();
const hasChildren = getValue('/hasChildren') === true;
return (0, _jsxRuntime.jsxs)(_index.Form.Card, {
...spacingProps,
children: [(0, _jsxRuntime.jsx)(_index2.Lead, {
children: tr.ChildrenWithAge.hasChildren.title
}), (0, _jsxRuntime.jsx)(_index.Field.Boolean, {
path: "/hasChildren",
label: tr.ChildrenWithAge.hasChildren.fieldLabel,
variant: "buttons",
errorMessages: {
'Field.errorRequired': tr.ChildrenWithAge.hasChildren.required
}
}), (0, _jsxRuntime.jsxs)(_index.Form.Visibility, {
pathTrue: "/hasChildren",
animate: true,
children: [(0, _jsxRuntime.jsx)(_index.Field.Number, {
path: "/countChildren",
label: tr.ChildrenWithAge.countChildren.fieldLabel,
errorMessages: {
'NumberField.errorMinimum': tr.ChildrenWithAge.countChildren.required,
'Field.errorRequired': tr.ChildrenWithAge.countChildren.required
},
defaultValue: 1,
width: "small",
showStepControls: true,
minimum: 1,
maximum: maximumChildren,
decimalLimit: 0,
allowNegative: false
}), (0, _jsxRuntime.jsx)(_index.Iterate.Array, {
path: "/children",
countPath: "/countChildren",
countPathLimit: maximumChildren,
animate: true,
children: (0, _jsxRuntime.jsx)(_index.Field.Number, {
itemPath: "/age",
label: tr.ChildrenWithAge.childrenAge.fieldLabel,
errorMessages: {
'Field.errorRequired': tr.ChildrenWithAge.childrenAge.required
},
width: "small",
minimum: 0,
maximum: 17,
decimalLimit: 0,
allowNegative: false
})
})]
}), (enableAdditionalQuestions === null || enableAdditionalQuestions === void 0 ? void 0 : enableAdditionalQuestions.includes('daycare')) && (0, _jsxRuntime.jsx)(_index.Form.Visibility, {
pathTrue: "/hasChildren",
animate: true,
children: (0, _jsxRuntime.jsx)(_index.Field.Boolean, {
path: "/usesDaycare",
label: tr.ChildrenWithAge.usesDaycare.fieldLabel,
variant: "buttons",
errorMessages: {
'Field.errorRequired': tr.ChildrenWithAge.usesDaycare.required
},
help: {
title: tr.ChildrenWithAge.usesDaycare.fieldLabel,
content: tr.renderMessage(tr.ChildrenWithAge.usesDaycare.helpText)
}
})
}), (enableAdditionalQuestions === null || enableAdditionalQuestions === void 0 ? void 0 : enableAdditionalQuestions.includes('daycare')) && hasChildren && (0, _jsxRuntime.jsx)(_index.Form.Visibility, {
pathTrue: "/usesDaycare",
animate: true,
children: (0, _jsxRuntime.jsx)(_index.Field.Currency, {
path: "/daycareExpenses",
label: tr.ChildrenWithAge.dayCareExpenses.fieldLabel,
errorMessages: {
'Field.errorRequired': tr.ChildrenWithAge.dayCareExpenses.required
},
minimum: 1,
maximum: 1000000,
decimalLimit: 0,
allowNegative: false
})
}), (enableAdditionalQuestions === null || enableAdditionalQuestions === void 0 ? void 0 : enableAdditionalQuestions.includes('joint-responsibility')) && (0, _jsxRuntime.jsx)(_index.Form.Visibility, {
pathTrue: "/hasChildren",
animate: true,
children: (0, _jsxRuntime.jsx)(_index.Field.Boolean, {
path: "/hasJointResponsibility",
label: tr.ChildrenWithAge.hasJointResponsibility.fieldLabel,
variant: "buttons",
errorMessages: {
'Field.errorRequired': tr.ChildrenWithAge.hasJointResponsibility.required
}
})
}), (enableAdditionalQuestions === null || enableAdditionalQuestions === void 0 ? void 0 : enableAdditionalQuestions.includes('joint-responsibility')) && hasChildren && (0, _jsxRuntime.jsx)(_index.Form.Visibility, {
pathTrue: "/hasJointResponsibility",
animate: true,
children: (0, _jsxRuntime.jsx)(_index.Field.Currency, {
path: "/jointResponsibilityExpenses",
label: tr.ChildrenWithAge.jointResponsibilityExpenses.fieldLabel,
errorMessages: {
'Field.errorRequired': tr.ChildrenWithAge.jointResponsibilityExpenses.required
},
minimum: 1,
maximum: 1000000,
decimalLimit: 0,
allowNegative: false
})
})]
});
}
function SummaryContainer({
spacingProps,
toWizardStep
}) {
const tr = _index.Form.useTranslation();
return (0, _jsxRuntime.jsxs)(_index.Form.Card, {
...spacingProps,
children: [(0, _jsxRuntime.jsx)(_index2.Lead, {
children: tr.ChildrenWithAge.hasChildren.title
}), (0, _jsxRuntime.jsxs)(_index.Value.SummaryList, {
children: [(0, _jsxRuntime.jsx)(_index.Value.Boolean, {
path: "/hasChildren",
label: tr.ChildrenWithAge.hasChildren.fieldLabel
}), (0, _jsxRuntime.jsxs)(_index.Form.Visibility, {
pathTrue: "/hasChildren",
children: [(0, _jsxRuntime.jsx)(_index.Value.Number, {
path: "/countChildren",
label: tr.ChildrenWithAge.countChildren.fieldLabel,
suffix: tr.ChildrenWithAge.countChildren.suffix,
maximum: maximumChildren
}), (0, _jsxRuntime.jsx)(_index.Iterate.Array, {
path: "/children",
children: (0, _jsxRuntime.jsx)(_index.Value.Number, {
itemPath: "/age",
label: tr.ChildrenWithAge.childrenAge.fieldLabel,
suffix: tr.ChildrenWithAge.childrenAge.suffix,
defaultValue: "\u2013"
})
}), (0, _jsxRuntime.jsxs)(_index.Form.Visibility, {
pathDefined: "/usesDaycare",
children: [(0, _jsxRuntime.jsx)(_index.Value.Boolean, {
label: tr.ChildrenWithAge.usesDaycare.fieldLabel,
path: "/usesDaycare"
}), (0, _jsxRuntime.jsx)(_index.Form.Visibility, {
pathTrue: "/usesDaycare",
children: (0, _jsxRuntime.jsx)(_index.Value.Currency, {
label: tr.ChildrenWithAge.dayCareExpenses.fieldLabel,
path: "/daycareExpenses",
decimals: 0
})
})]
}), (0, _jsxRuntime.jsxs)(_index.Form.Visibility, {
pathDefined: "/hasJointResponsibility",
children: [(0, _jsxRuntime.jsx)(_index.Value.Boolean, {
path: "/hasJointResponsibility",
label: tr.ChildrenWithAge.hasJointResponsibility.fieldLabel
}), (0, _jsxRuntime.jsx)(_index.Form.Visibility, {
pathTrue: "/hasJointResponsibility",
children: (0, _jsxRuntime.jsx)(_index.Value.Currency, {
label: tr.ChildrenWithAge.jointResponsibilityExpenses.fieldLabel,
path: "/jointResponsibilityExpenses",
decimals: 0
})
})]
})]
})]
}), typeof toWizardStep === 'number' ? (0, _jsxRuntime.jsx)(_index.Wizard.EditButton, {
toStep: toWizardStep
}) : null]
});
}
(0, _withComponentMarkers.default)(ChildrenWithAge, {
_supportsSpacingProps: true
});
//# sourceMappingURL=ChildrenWithAge.js.map