Skip to content

Instantly share code, notes, and snippets.

@FrenchMajesty
Last active July 3, 2019 02:40
Show Gist options
  • Save FrenchMajesty/6758013397e065a831211879423818fd to your computer and use it in GitHub Desktop.
Save FrenchMajesty/6758013397e065a831211879423818fd to your computer and use it in GitHub Desktop.
Ant Design Input and React-Text-Mask
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import MaskedInput from 'react-text-mask';
import { Icon, Input } from 'antd';
class PhoneNumberInput extends Component {
render() {
return (
<MaskedInput
mask={['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]}
guide={false}
showMask
render={(ref, props) => <Input ref={(input) => ref(input && input.input)} prefix={<Icon type="phone" />} {...props} />}
{...this.props}
/>
);
}
}
PhoneNumberInput.propTypes = {
onChange: PropTypes.func,
'data-__field': PropTypes.object,
value: PropTypes.string,
};
export default PhoneNumberInput;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment