@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
53 lines • 1.77 kB
JavaScript
import React, { useCallback, useMemo } from 'react';
import StringValue from "../String/index.js";
import { formatBankAccountNumberByType } from "../../../../components/number-format/utils/formatBankAccountNumber.js";
import useTranslation from "../../hooks/useTranslation.js";
import { isValueEmpty } from "../../ValueBlock/index.js";
import withComponentMarkers from "../../../../shared/helpers/withComponentMarkers.js";
import { jsx as _jsx } from "react/jsx-runtime";
function BankAccountNumber(props) {
const {
bankAccountType = 'norwegianBban',
...restProps
} = props;
const translations = useTranslation().BankAccountNumber;
const toInput = useCallback(external => {
if (isValueEmpty(external)) {
return undefined;
}
return formatBankAccountNumberByType(String(external), bankAccountType).number;
}, [bankAccountType]);
const label = 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 _jsx(StringValue, {
...stringValueProps
});
}
withComponentMarkers(BankAccountNumber, {
_supportsSpacingProps: true
});
export default BankAccountNumber;
//# sourceMappingURL=BankAccountNumber.js.map