@sparklink-pro/apant
Version:
Apollo & Antd tools
26 lines • 889 B
JavaScript
import IMask from 'imask';
import 'imask/esm/masked/number';
import { useRef } from 'react';
export const useInputMask = (opts) => {
const inputRef = useRef();
const attach = (input) => {
inputRef.current = { input, mask: IMask(input, opts) };
// inputRef.current.input.onkeydown = (e) => inputRef.current.mask.updateValue();
};
const detach = () => {
var _a;
if ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.mask) {
inputRef.current.mask.destroy();
inputRef.current = null;
}
};
const refresh = () => {
var _a;
if ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.mask) {
inputRef.current.mask.updateValue();
}
};
return { attach, detach, refresh };
};
export default useInputMask;
//# sourceMappingURL=useInputMask.js.map