UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

61 lines (60 loc) 2.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _index = _interopRequireDefault(require("../String/index.js")); var _formatBankAccountNumber = require("../../../../components/number-format/utils/formatBankAccountNumber.js"); var _useTranslation = _interopRequireDefault(require("../../hooks/useTranslation.js")); var _index2 = require("../../ValueBlock/index.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 }; } function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } function BankAccountNumber(props) { const { bankAccountType = 'norwegianBban', ...restProps } = props; const translations = (0, _useTranslation.default)().BankAccountNumber; const toInput = (0, _react.useCallback)(external => { if ((0, _index2.isValueEmpty)(external)) { return undefined; } return (0, _formatBankAccountNumber.formatBankAccountNumberByType)(String(external), bankAccountType).number; }, [bankAccountType]); const label = (0, _react.useMemo)(() => { if (restProps.label !== undefined) { return restProps.label; } if (restProps.inline) { return undefined; } switch (bankAccountType) { case 'swedishBban': return translations.labelSwedishBban; case 'swedishBankgiro': return translations.labelSwedishBankgiro; case 'swedishPlusgiro': return translations.labelSwedishPlusgiro; case 'iban': return translations.labelIban; default: return translations.label; } }, [restProps.label, restProps.inline, bankAccountType, translations]); const stringValueProps = { ...restProps, label, toInput }; return (0, _jsxRuntime.jsx)(_index.default, { ...stringValueProps }); } (0, _withComponentMarkers.default)(BankAccountNumber, { _supportsSpacingProps: true }); var _default = exports.default = BankAccountNumber; //# sourceMappingURL=BankAccountNumber.js.map