@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
83 lines (82 loc) • 3.96 kB
JavaScript
"use client";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
var _InputMaskedElement;
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 from 'react';
import PropTypes from 'prop-types';
import { extendPropsWithContext } from '../../shared/component-helper';
import InputMaskedContext from './InputMaskedContext';
import InputMaskedElement from './InputMaskedElement';
import Input, { inputPropTypes } from '../input/Input';
import Context from '../../shared/Context';
const InputMasked = props => {
const context = React.useContext(Context);
if (props !== null && props !== void 0 && props.mask) {
const alias = context === null || context === void 0 ? void 0 : context.InputMasked;
for (const key in alias) {
if (/^as[_A-Z]|number_mask|currency_mask/.test(key)) {
delete alias[key];
}
}
}
const contextAndProps = React.useMemo(() => {
return extendPropsWithContext(props, defaultProps, context === null || context === void 0 ? void 0 : context.InputMasked);
}, [context === null || context === void 0 ? void 0 : context.InputMasked, props]);
return React.createElement(InputMaskedContext.Provider, {
value: {
props: contextAndProps,
context
}
}, _InputMaskedElement || (_InputMaskedElement = React.createElement(InputMaskedElement, null)));
};
process.env.NODE_ENV !== "production" ? InputMasked.propTypes = _objectSpread({
mask: PropTypes.oneOfType([PropTypes.object, PropTypes.array, PropTypes.func]),
number_mask: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.object]),
currency_mask: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.object]),
mask_options: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
number_format: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
locale: PropTypes.string,
as_currency: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
as_number: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
as_percent: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
show_mask: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
show_guide: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
pipe: PropTypes.func,
keep_char_positions: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
placeholder_char: PropTypes.string,
inner_ref: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
on_change: PropTypes.func,
on_submit: PropTypes.func,
on_focus: PropTypes.func,
on_blur: PropTypes.func,
on_submit_focus: PropTypes.func,
on_submit_blur: PropTypes.func
}, inputPropTypes) : void 0;
const defaultProps = _objectSpread(_objectSpread({}, Input.defaultProps), {}, {
mask: null,
number_mask: null,
currency_mask: null,
mask_options: null,
number_format: null,
as_currency: null,
as_number: null,
as_percent: null,
locale: null,
show_mask: false,
show_guide: true,
pipe: null,
keep_char_positions: false,
placeholder_char: null,
inner_ref: null,
on_change: null,
on_submit: null,
on_focus: null,
on_blur: null,
on_submit_focus: null,
on_submit_blur: null
});
InputMasked._formElement = true;
InputMasked._supportsSpacingProps = true;
export default InputMasked;
//# sourceMappingURL=InputMasked.js.map