UNPKG

@emcsistemas/native-ui

Version:
48 lines 2.12 kB
import React, { forwardRef } from "react"; import { TextInput } from "react-native"; import { makeBaseMaskedInputStyle } from "../../styles/styles.factory"; import EMCBox from "../EMCBox/EMCBox"; import { inputMaskCEP, inputMaskCNPJ, inputMaskCPF, inputMaskCPFCNPJ, inputMaskCurrency, inputMaskNumbers, inputMaskPhone, inputMaskTime, } from "../../util/util.masks"; import { Colors } from "../../theme"; const EMCMaskedInput = (props, ref) => { const baseStyle = props.style ?? makeBaseMaskedInputStyle(props); function handleChangeText(value) { if (props.maskType) { switch (props.maskType) { case "cep": value = inputMaskCEP(value); break; case "cnpj": value = inputMaskCNPJ(value); break; case "cpf": value = inputMaskCPF(value); break; case "cpfcnpj": value = inputMaskCPFCNPJ(value); break; case "currency": value = inputMaskCurrency(value, false); break; case "numbers": value = inputMaskNumbers(value); break; case "telephone": value = inputMaskPhone(value); break; case "time": value = inputMaskTime(value); break; } props.onChangeValue(value); } else { props.onChangeValue(value); } } return (<EMCBox w="full"> <TextInput ref={ref || undefined} {...props} style={baseStyle} numberOfLines={1} autoCorrect={false} clearButtonMode={props.noClear ? "never" : "always"} autoComplete={props.autoComplete} cursorColor={Colors.cursor} editable={!props.readOnly} autoCapitalize="none" keyboardType="number-pad" onChangeText={(value) => handleChangeText(value)}/> </EMCBox>); }; export default forwardRef(EMCMaskedInput); //# sourceMappingURL=EMCMaskedInput.js.map