@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
31 lines (30 loc) • 2.11 kB
JavaScript
"use client";
import _extends from "@babel/runtime/helpers/esm/extends";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import React, { useContext } from 'react';
import classnames from 'classnames';
import SharedContext from '../../../../shared/Context';
import { getCurrencySymbol } from '../../../../components/number-format/NumberUtils';
import { CURRENCY } from '../../../../shared/defaults';
import useDataValue from '../../hooks/useDataValue';
import NumberField from '../Number';
function Currency(props) {
var _props$placeholder;
const sharedContext = useContext(SharedContext);
const {
getSourceValue
} = useDataValue();
const currencyValue = getSourceValue(props.currency);
const preparedProps = _objectSpread(_objectSpread({}, props), {}, {
currency: currencyValue !== null && currencyValue !== void 0 ? currencyValue : CURRENCY,
placeholder: (_props$placeholder = props.placeholder) !== null && _props$placeholder !== void 0 ? _props$placeholder : getCurrencySymbol(sharedContext === null || sharedContext === void 0 ? void 0 : sharedContext.locale, currencyValue, props.currencyDisplay)
});
return React.createElement(NumberField, _extends({}, preparedProps, {
className: classnames('dnb-forms-field-currency', props.className)
}));
}
Currency._supportsSpacingProps = true;
export default Currency;
//# sourceMappingURL=Currency.js.map