├── .npmignore ├── .gitignore ├── .babelrc ├── package.json ├── LICENSE ├── README.md └── src └── index.js /.npmignore: -------------------------------------------------------------------------------- 1 | .idea 2 | src 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules 3 | dist 4 | npm-debug.log 5 | .npmignore -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "es2015", 4 | "react", 5 | "stage-1" 6 | ] 7 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-mailcheck", 3 | "version": "1.2.0", 4 | "description": "React component for suggesting emails", 5 | "main": "dist/index.js", 6 | "scripts": { 7 | "build": "babel src/index.js -o dist/index.js", 8 | "prebuild": "mkdir -p dist" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/eligolding/react-mailcheck" 13 | }, 14 | "bugs": "https://github.com/eligolding/react-mailcheck/issues", 15 | "keywords": [ 16 | "react", 17 | "mailcheck" 18 | ], 19 | "author": "Eli Golding ", 20 | "license": "MIT", 21 | "dependencies": { 22 | "mailcheck": "^1.1.1" 23 | }, 24 | "devDependencies": { 25 | "react": "^15.5.4", 26 | "prop-types": "^15.5.8", 27 | "babel-cli": "^6.9.0", 28 | "babel-core": "^6.9.0", 29 | "babel-preset-es2015": "^6.9.0", 30 | "babel-preset-react": "^6.5.0", 31 | "babel-preset-stage-1": "^6.5.0" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Eli Golding 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React-Mailcheck 2 | React component for the [mailcheck](https://github.com/mailcheck/mailcheck) library. Reduce user-misspelled email addresses in your forms by suggesting a right domain when your users misspell it in an email address. 3 | 4 | ### Installation 5 | ``` 6 | npm install --save react-mailcheck 7 | ``` 8 | 9 | ### Usage 10 | ```jsx 11 | import MailCheck from 'react-mailcheck' 12 | 13 | 14 | {suggestion => ( 15 |
16 | { this.setState({ inputText: e.target.value }); }} 20 | /> 21 | {suggestion && 22 |
23 | Did you mean {suggestion.full}? 24 |
25 | } 26 |
27 | )} 28 |
29 | ``` 30 | 31 | #### Props 32 | 33 | ##### - email: String 34 | Required 35 | The input email that you want to check. 36 | 37 | ##### - children: (suggestion: Object | null) => ReactElement 38 | Required **function**. 39 | - `suggestion`: The suggestion object passed back to you, or null if mailcheck has nothing to suggest. The suggestion object has the following members: 40 | ```js 41 | { 42 | address: 'test', // the address; part before the @ sign 43 | domain: 'gmail.com', // the suggested domain 44 | full: 'test@gmail.com' // the full suggested email 45 | } 46 | ``` 47 | - Return: must return a React element to render. 48 | 49 | ## Thanks 50 | - https://github.com/mailcheck/mailcheck 51 | 52 | ## License 53 | MIT 54 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import mailcheck from 'mailcheck'; 4 | 5 | const { string, number, array, func } = PropTypes; 6 | 7 | class MailCheck extends React.Component { 8 | 9 | static propTypes = { 10 | email: string.isRequired, 11 | children: func.isRequired, 12 | domainThreshold: number, 13 | secondLevelThreshold: number, 14 | topLevelThreshold: number, 15 | domains: array, 16 | topLevelDomains: array, 17 | secondLevelDomains: array, 18 | distanceFunction: func, 19 | }; 20 | 21 | state = { 22 | suggestion: null, 23 | }; 24 | 25 | componentWillMount() { 26 | this.checkEmail(this.props.email); 27 | } 28 | 29 | componentWillReceiveProps(nextProps) { 30 | this.checkEmail(nextProps.email); 31 | } 32 | 33 | checkEmail = (email) => { 34 | const { 35 | domainThreshold, 36 | secondLevelThreshold, 37 | topLevelThreshold, 38 | domains, 39 | topLevelDomains, 40 | secondLevelDomains, 41 | distanceFunction 42 | } = this.props; 43 | 44 | mailcheck.domainThreshold = domainThreshold || mailcheck.domainThreshold; 45 | mailcheck.secondLevelThreshold = secondLevelThreshold || mailcheck.secondLevelThreshold; 46 | mailcheck.topLevelThreshold = topLevelThreshold || mailcheck.topLevelThreshold; 47 | 48 | mailcheck.run({ 49 | email, 50 | domains, 51 | topLevelDomains, 52 | secondLevelDomains, 53 | distanceFunction, 54 | suggested: (suggestion) => { 55 | this.setState({ 56 | suggestion, 57 | }); 58 | }, 59 | empty: () => { 60 | if (this.state.suggestion) { 61 | this.setState({ suggestion: null }); 62 | } 63 | }, 64 | }); 65 | } 66 | 67 | render() { 68 | return this.props.children(this.state.suggestion); 69 | } 70 | } 71 | 72 | export default MailCheck; 73 | --------------------------------------------------------------------------------