UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

191 lines (190 loc) 8.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = ChildrenWithAge; var _react = _interopRequireDefault(require("react")); var _ = require("../.."); var _elements = require("../../../../elements"); var _ChildrenWithAgeTranslations = require("./ChildrenWithAgeTranslations"); var _utils = require("../../../../components/flex/utils"); const _excluded = ["mode", "enableAdditionalQuestions", "toWizardStep"]; 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); } function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; } function ChildrenWithAge(_ref) { let { mode, enableAdditionalQuestions, toWizardStep } = _ref, props = _objectWithoutProperties(_ref, _excluded); const spacingProps = (0, _utils.pickSpacingProps)(props); const restProps = (0, _utils.omitSpacingProps)(props); return _react.default.createElement(_.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(_ref2) { let { spacingProps, enableAdditionalQuestions } = _ref2; const tr = _.Form.useTranslation(); const { getValue } = _.Form.useData(); const hasChildren = getValue('/hasChildren') === true; return _react.default.createElement(_.Form.Card, spacingProps, _react.default.createElement(_elements.Lead, null, tr.ChildrenWithAge.hasChildren.title), _react.default.createElement(_.Field.Boolean, { path: "/hasChildren", label: tr.ChildrenWithAge.hasChildren.fieldLabel, variant: "buttons", errorMessages: { 'Field.errorRequired': tr.ChildrenWithAge.hasChildren.required } }), _react.default.createElement(_.Form.Visibility, { pathTrue: "/hasChildren", animate: true }, _react.default.createElement(_.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: 20, decimalLimit: 0, allowNegative: false }), _react.default.createElement(_.Iterate.Array, { path: "/children", countPath: "/countChildren", countPathLimit: 20, animate: true }, _react.default.createElement(_.Field.Number, { itemPath: "/age", label: tr.ChildrenWithAge.childrenAge.fieldLabel, errorMessages: { 'Field.errorRequired': tr.ChildrenWithAge.childrenAge.required }, placeholder: "0", width: "small", minimum: 0, maximum: 17, decimalLimit: 0, allowNegative: false }))), (enableAdditionalQuestions === null || enableAdditionalQuestions === void 0 ? void 0 : enableAdditionalQuestions.includes('daycare')) && _react.default.createElement(_.Form.Visibility, { pathTrue: "/hasChildren", animate: true }, _react.default.createElement(_.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(_.Form.Visibility, { pathTrue: "/usesDaycare", animate: true }, _react.default.createElement(_.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(_.Form.Visibility, { pathTrue: "/hasChildren", animate: true }, _react.default.createElement(_.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(_.Form.Visibility, { pathTrue: "/hasJointResponsibility", animate: true }, _react.default.createElement(_.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(_ref3) { let { spacingProps, toWizardStep } = _ref3; const tr = _.Form.useTranslation(); return _react.default.createElement(_.Form.Card, spacingProps, _react.default.createElement(_elements.Lead, null, tr.ChildrenWithAge.hasChildren.title), _react.default.createElement(_.Value.SummaryList, null, _react.default.createElement(_.Value.Boolean, { path: "/hasChildren", label: tr.ChildrenWithAge.hasChildren.fieldLabel }), _react.default.createElement(_.Form.Visibility, { pathTrue: "/hasChildren" }, _react.default.createElement(_.Value.Number, { path: "/countChildren", label: tr.ChildrenWithAge.countChildren.fieldLabel, suffix: tr.ChildrenWithAge.countChildren.suffix, maximum: 20 }), _react.default.createElement(_.Iterate.Array, { path: "/children" }, _react.default.createElement(_.Value.Number, { itemPath: "/age", label: tr.ChildrenWithAge.childrenAge.fieldLabel, suffix: tr.ChildrenWithAge.childrenAge.suffix, defaultValue: "\u2013" })), _react.default.createElement(_.Form.Visibility, { pathDefined: "/usesDaycare" }, _react.default.createElement(_.Value.Boolean, { label: tr.ChildrenWithAge.usesDaycare.fieldLabel, path: "/usesDaycare" }), _react.default.createElement(_.Form.Visibility, { pathTrue: "/usesDaycare" }, _react.default.createElement(_.Value.Currency, { label: tr.ChildrenWithAge.dayCareExpenses.fieldLabel, path: "/daycareExpenses", decimals: "0" }))), _react.default.createElement(_.Form.Visibility, { pathDefined: "/hasJointResponsibility" }, _react.default.createElement(_.Value.Boolean, { path: "/hasJointResponsibility", label: tr.ChildrenWithAge.hasJointResponsibility.fieldLabel }), _react.default.createElement(_.Form.Visibility, { pathTrue: "/hasJointResponsibility" }, _react.default.createElement(_.Value.Currency, { label: tr.ChildrenWithAge.jointResponsibilityExpenses.fieldLabel, path: "/jointResponsibilityExpenses", decimals: "0" }))))), typeof toWizardStep === 'number' ? _react.default.createElement(_.Wizard.EditButton, { toStep: toWizardStep }) : null); } ChildrenWithAge._supportsSpacingProps = true; //# sourceMappingURL=ChildrenWithAge.js.map