@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
76 lines (75 loc) • 2.29 kB
JavaScript
"use client";
var _InputMaskedElement;
import withComponentMarkers from "../../shared/helpers/withComponentMarkers.js";
import React from 'react';
import { extendPropsWithContext } from "../../shared/component-helper.js";
import InputMaskedContext from "./InputMaskedContext.js";
import InputMaskedElement from "./InputMaskedElement.js";
import { inputDefaultProps } from "../input/Input.js";
import Context from "../../shared/Context.js";
import { jsx as _jsx } from "react/jsx-runtime";
function InputMasked({
ref,
...restProps
}) {
const context = React.useContext(Context);
const contextInputMasked = React.useMemo(() => {
if (!(restProps !== null && restProps !== void 0 && restProps.mask) || !(context !== null && context !== void 0 && context.InputMasked)) {
return context === null || context === void 0 ? void 0 : context.InputMasked;
}
const clone = {
...context.InputMasked
};
for (const key in clone) {
if (/^as[_A-Z]|numberMask|currencyMask/.test(key)) {
delete clone[key];
}
}
return clone;
}, [context === null || context === void 0 ? void 0 : context.InputMasked, restProps === null || restProps === void 0 ? void 0 : restProps.mask]);
const contextAndProps = React.useMemo(() => {
const propsWithRef = {
...restProps,
ref
};
return extendPropsWithContext(propsWithRef, defaultProps, contextInputMasked);
}, [contextInputMasked, restProps, ref]);
return _jsx(InputMaskedContext, {
value: {
props: contextAndProps,
context
},
children: _InputMaskedElement || (_InputMaskedElement = _jsx(InputMaskedElement, {}))
});
}
const {
onKeyDown: _,
...inputBaseDefaults
} = inputDefaultProps;
const defaultProps = {
...inputBaseDefaults,
mask: null,
numberMask: null,
currencyMask: null,
maskOptions: null,
numberFormat: null,
asCurrency: null,
asNumber: null,
asPercent: null,
locale: null,
showMask: false,
allowOverflow: false,
overwriteMode: null,
onChange: null,
onSubmit: null,
onFocus: null,
onBlur: null,
onSubmitFocus: null,
onSubmitBlur: null
};
withComponentMarkers(InputMasked, {
_formElement: true,
_supportsSpacingProps: true
});
export default InputMasked;
//# sourceMappingURL=InputMasked.js.map