UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

185 lines (184 loc) 8.04 kB
"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"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } const maximumChildren = 9; function ChildrenWithAge({ mode, enableAdditionalQuestions, toWizardStep, ...props }) { const spacingProps = (0, _utils.pickSpacingProps)(props); const restProps = (0, _utils.omitSpacingProps)(props); return _react.default.createElement(_index.Form.Section, _extends({ translations: _ChildrenWithAgeTranslations.translations, required: true }, restProps), mode === 'summary' ? _react.default.createElement(SummaryContainer, { toWizardStep: toWizardStep, spacingProps: spacingProps, enableAdditionalQuestions: enableAdditionalQuestions }) : _react.default.createElement(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 _react.default.createElement(_index.Form.Card, spacingProps, _react.default.createElement(_index2.Lead, null, tr.ChildrenWithAge.hasChildren.title), _react.default.createElement(_index.Field.Boolean, { path: "/hasChildren", label: tr.ChildrenWithAge.hasChildren.fieldLabel, variant: "buttons", errorMessages: { 'Field.errorRequired': tr.ChildrenWithAge.hasChildren.required } }), _react.default.createElement(_index.Form.Visibility, { pathTrue: "/hasChildren", animate: true }, _react.default.createElement(_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 }), _react.default.createElement(_index.Iterate.Array, { path: "/children", countPath: "/countChildren", countPathLimit: maximumChildren, animate: true }, _react.default.createElement(_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')) && _react.default.createElement(_index.Form.Visibility, { pathTrue: "/hasChildren", animate: true }, _react.default.createElement(_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 && _react.default.createElement(_index.Form.Visibility, { pathTrue: "/usesDaycare", animate: true }, _react.default.createElement(_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')) && _react.default.createElement(_index.Form.Visibility, { pathTrue: "/hasChildren", animate: true }, _react.default.createElement(_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 && _react.default.createElement(_index.Form.Visibility, { pathTrue: "/hasJointResponsibility", animate: true }, _react.default.createElement(_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 _react.default.createElement(_index.Form.Card, spacingProps, _react.default.createElement(_index2.Lead, null, tr.ChildrenWithAge.hasChildren.title), _react.default.createElement(_index.Value.SummaryList, null, _react.default.createElement(_index.Value.Boolean, { path: "/hasChildren", label: tr.ChildrenWithAge.hasChildren.fieldLabel }), _react.default.createElement(_index.Form.Visibility, { pathTrue: "/hasChildren" }, _react.default.createElement(_index.Value.Number, { path: "/countChildren", label: tr.ChildrenWithAge.countChildren.fieldLabel, suffix: tr.ChildrenWithAge.countChildren.suffix, maximum: maximumChildren }), _react.default.createElement(_index.Iterate.Array, { path: "/children" }, _react.default.createElement(_index.Value.Number, { itemPath: "/age", label: tr.ChildrenWithAge.childrenAge.fieldLabel, suffix: tr.ChildrenWithAge.childrenAge.suffix, defaultValue: "\u2013" })), _react.default.createElement(_index.Form.Visibility, { pathDefined: "/usesDaycare" }, _react.default.createElement(_index.Value.Boolean, { label: tr.ChildrenWithAge.usesDaycare.fieldLabel, path: "/usesDaycare" }), _react.default.createElement(_index.Form.Visibility, { pathTrue: "/usesDaycare" }, _react.default.createElement(_index.Value.Currency, { label: tr.ChildrenWithAge.dayCareExpenses.fieldLabel, path: "/daycareExpenses", decimals: 0 }))), _react.default.createElement(_index.Form.Visibility, { pathDefined: "/hasJointResponsibility" }, _react.default.createElement(_index.Value.Boolean, { path: "/hasJointResponsibility", label: tr.ChildrenWithAge.hasJointResponsibility.fieldLabel }), _react.default.createElement(_index.Form.Visibility, { pathTrue: "/hasJointResponsibility" }, _react.default.createElement(_index.Value.Currency, { label: tr.ChildrenWithAge.jointResponsibilityExpenses.fieldLabel, path: "/jointResponsibilityExpenses", decimals: 0 }))))), typeof toWizardStep === 'number' ? _react.default.createElement(_index.Wizard.EditButton, { toStep: toWizardStep }) : null); } ChildrenWithAge._supportsSpacingProps = true; //# sourceMappingURL=ChildrenWithAge.js.map