UNPKG

@sparklink-pro/apant

Version:

Apollo & Antd tools

26 lines 893 B
import { useRef } from 'react'; import IMask from 'imask'; import 'imask/esm/masked/number'; export const useInputMask = (opts) => { const inputRef = useRef(null); 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