├── .babelrc ├── .eslintrc.js ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── pull_request_template.md ├── .gitignore ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── demo ├── favicon.ico ├── index.html ├── index.styled.ts └── index.tsx ├── jest.config.js ├── lib ├── index.spec.tsx └── index.tsx ├── package-lock.json ├── package.json ├── setupEnzyme.ts ├── tsconfig.json └── webpack.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | [ 4 | "@babel/preset-env", 5 | { 6 | "targets": { 7 | "browsers": ["last 2 versions", "> 10%", "ie 9"] 8 | } 9 | } 10 | ], 11 | "@babel/preset-react", 12 | "@babel/preset-typescript" 13 | ], 14 | "plugins": [ 15 | "@babel/plugin-proposal-class-properties", 16 | "@babel/plugin-proposal-object-rest-spread", 17 | "babel-plugin-styled-components" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | const off = 0; 2 | const warn = 1; 3 | const error = 2; 4 | 5 | const isProduction = process.env.NODE_ENV === 'production'; 6 | 7 | module.exports = { 8 | globals: { 9 | '$Diff': true, 10 | __PATH_PREFIX__: true, 11 | }, 12 | env: { 13 | es6: true, 14 | node: true, 15 | browser: true, 16 | }, 17 | parser: '@typescript-eslint/parser', 18 | extends: [ 19 | 'airbnb-typescript', 20 | 'plugin:import/errors', 21 | 'plugin:import/warnings', 22 | 'plugin:import/typescript', 23 | 'plugin:@typescript-eslint/recommended', 24 | 'plugin:react/recommended', 25 | 'plugin:jsx-a11y/recommended', 26 | 'eslint:recommended', 27 | ], 28 | parserOptions: { 29 | ecmaVersion: 6, 30 | sourceType: 'module', 31 | ecmaFeatures: { 32 | jsx: true, 33 | }, 34 | jsx: true, 35 | useJSXTextNode: true, 36 | }, 37 | plugins: [ 38 | '@typescript-eslint', 39 | 'react', 40 | 'jsx-a11y', 41 | 'import', 42 | ], 43 | settings: { 44 | react: { 45 | version: 'detect', 46 | }, 47 | 'import/resolver': { 48 | typescript: {}, 49 | } 50 | }, 51 | rules: { 52 | '@typescript-eslint/array-type': [error, 'array-simple'], 53 | '@typescript-eslint/camelcase': [error, { properties: 'never', ignoreDestructuring: true }], 54 | '@typescript-eslint/indent': off, 55 | '@typescript-eslint/member-ordering': [ 56 | error, 57 | { 58 | default: [ 59 | 'public-static-field', 60 | 'private-static-field', 61 | 'public-instance-field', 62 | 'private-instance-field', 63 | 'public-constructor', 64 | 'private-constructor', 65 | 'public-instance-method', 66 | 'private-instance-method', 67 | ], 68 | }, 69 | ], 70 | '@typescript-eslint/no-unused-vars': [error, { ignoreRestSiblings: true }], 71 | 'comma-dangle': [ 72 | error, 73 | { 74 | arrays: 'always-multiline', 75 | objects: 'always-multiline', 76 | imports: 'always-multiline', 77 | exports: 'always-multiline', 78 | functions: 'only-multiline', 79 | }, 80 | ], 81 | 'function-paren-newline': [error, 'consistent'], 82 | indent: off, 83 | 'jsx-a11y/anchor-is-valid': error, 84 | 'jsx-a11y/click-events-have-key-events': error, 85 | 'max-len': [error, { code: 150, ignoreRegExpLiterals: true }], 86 | 'no-console': isProduction ? error : off, 87 | 'no-multiple-empty-lines': [error, { max: error, maxEOF: error }], 88 | 'no-implicit-coercion': error, 89 | 'no-shadow': off, 90 | 'no-undef': off, 91 | 'no-underscore-dangle': off, 92 | 'no-unused-vars': [ 93 | error, { 94 | args: 'after-used', 95 | ignoreRestSiblings: false, 96 | }, 97 | ], 98 | 'no-warning-comments': [ 99 | warn, 100 | { 101 | terms: ['TODO', 'FIXME', 'XXX', 'BUG', 'NOTE'], 102 | location: 'anywhere', 103 | }, 104 | ], 105 | 'object-curly-newline': [error, { consistent: true }], 106 | 'prefer-spread': off, 107 | 'prefer-const': error, 108 | 'quotes': off, 109 | 'react/jsx-filename-extension': [error, { extensions: ['.tsx'] }], 110 | 'react/jsx-no-target-blank': error, 111 | 'react/jsx-one-expression-per-line': error, 112 | 'react/no-typos': error, 113 | 'react/no-unescaped-entities': off, 114 | 'react/react-in-jsx-scope': off, 115 | 'react/sort-comp': off, 116 | 'react/style-prop-object': off, 117 | semi: off, 118 | }, 119 | overrides: [{ 120 | files: [ 121 | '**/*.spec.ts', 122 | '**/*.spec.tsx', 123 | '**/*.test.ts', 124 | '**/*.test.tsx', 125 | ], 126 | rules: { 127 | '@typescript-eslint/explicit-function-return-type': off, 128 | 'max-len': off, 129 | } 130 | }], 131 | }; 132 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.js linguist-generated=true 2 | *.json linguist-generated=true 3 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🐞 Bug 3 | about: Bur report 4 | 5 | --- 6 | 7 | #### Version: 8 | - 9 | 10 | #### Browser: 11 | - 12 | 13 | #### How to reproduce: 14 | - 15 | 16 | #### Actual behavior: 17 | - 18 | 19 | #### Expected behavior: 20 | - 21 | 22 | #### Et cetera: 23 | - 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: ✨ Idea 3 | about: Requte Request 4 | 5 | --- 6 | 7 | #### Problem: 8 | - 9 | 10 | #### Solution: 11 | - 12 | 13 | #### Et cetera: 14 | - 15 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | #### Changes proposed 2 | - 3 | - 4 | - 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store* 3 | Icon? 4 | ._* 5 | 6 | # Windows 7 | Thumbs.db 8 | ehthumbs.db 9 | Desktop.ini 10 | 11 | # Linux 12 | # .directory 13 | *~ 14 | 15 | # npm 16 | node_modules/ 17 | bower_components/ 18 | *.log 19 | *.gz 20 | 21 | # test 22 | coverage/ 23 | 24 | # build 25 | dist/ 26 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store* 3 | Icon? 4 | ._* 5 | 6 | # Windows 7 | Thumbs.db 8 | ehthumbs.db 9 | Desktop.ini 10 | 11 | # Linux 12 | .directory 13 | *~ 14 | 15 | # npm 16 | node_modules/ 17 | bower_components/ 18 | *.log 19 | *.gz 20 | 21 | # VCS 22 | .git 23 | .svn 24 | 25 | # test 26 | coverage/ 27 | 28 | # source 29 | demo 30 | lib 31 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "7" 4 | - "8" 5 | - "9" 6 | script: npm run check 7 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## Change Log 2 | 3 | ## 2.0.2 - 2019-09-01 4 | - add test and CI 5 | 6 | ## 2.0.1 - 2019-08-24 7 | - clean dependencies 8 | 9 | ## 2.0.0 - 2019-08-24 10 | - migrate to typescript 11 | - update some dependencies 12 | - change some configurations (eslint, webpack, etc.) 13 | - change file structure 14 | 15 | ## 1.0.3 - 2019-04-02 16 | - update some dependencies 17 | 18 | ## 1.0.2 - 2018-11-22 19 | - update some dependencies 20 | 21 | ## 1.0.1 - 2018-05-08 22 | - use `this` instead of `window` in build file 23 | 24 | ## 1.0.0 - 2018-05-07 25 | - Initial release 26 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | If you are interested in contributing, Any help and contributions are welcome. 2 | 3 | # Issue report 4 | 1. Search the [issue 5 | tracker](https://github.com/wonism/react-mail-form/issues) for 6 | similar issues. 7 | 2. Fill out the form. 8 | 9 | # Contribute to `react-mail-form` 10 | 1. [Fork](https://github.com/wonism/react-mail-form/fork) the 11 | repository. 12 | 2. Clone your fork into your local. 13 | 3. Run `npm install` to get dependencies and `npm start` to serve the 14 | demo. (And access http://localhost:8888) 15 | 4. Create a branch to work in with `git checkout -b <>` 16 | 5. Make changes and commit & push them with `git add . && git commit -m 17 | '<>' && git push origin <>` 18 | 6. [Submit a pull request][pr] to master branch. 19 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 wonism 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-mail-form 2 | > React component for simple contact form with zero dependencies 3 | 4 | ## Getting Started 5 | ``` 6 | $ npm i -S react-mail-form 7 | ``` 8 | 9 | ## Development 10 | ```sh 11 | $ npm run dev 12 | ``` 13 | 14 | - access [localhost:8888](http://localhost:8888) 15 | 16 | ## Production Bundle 17 | ```sh 18 | $ npm run build 19 | ``` 20 | 21 | ## How to Use 22 | ```jsx 23 | import ReactContactForm from 'react-mail-form'; 24 | 25 | 26 | ``` 27 | 28 | ### Parameters 29 | | Parameter | Type | Remarks | 30 | |:--------------------|:----------------|:----------------| 31 | | to | string | Required | 32 | | className | string | Optional | 33 | | titleMaxLength | string / number | - | 34 | | titlePlaceholder | string | - | 35 | | contentsRows | string / number | - | 36 | | contentsMaxLength | string / number | - | 37 | | contentsPlaceholder | string | - | 38 | | buttonText | string | - | 39 | -------------------------------------------------------------------------------- /demo/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonism/react-mail-form/162276f7c69adb567a20e69524521b936c16c625/demo/favicon.ico -------------------------------------------------------------------------------- /demo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | React Contact Form 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

React Contact Form

14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /demo/index.styled.ts: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | 3 | import ReactMailForm from '../lib'; 4 | 5 | const Form = styled(ReactMailForm)` 6 | margin: auto; 7 | max-width: 720px; 8 | min-height: 100vh; 9 | font-size: 14px; 10 | text-align: center; 11 | 12 | input, 13 | textarea { 14 | display: block; 15 | margin: 12px auto; 16 | width: 100%; 17 | max-width: 480px; 18 | border: 1px solid #555; 19 | outline: 0; 20 | font-size: 16px; 21 | } 22 | 23 | input { 24 | padding: 12px 6px; 25 | } 26 | 27 | textarea{ 28 | padding: 6px; 29 | } 30 | 31 | a { 32 | display: block; 33 | margin: auto; 34 | width: 120px; 35 | height: 3em; 36 | line-height: 3em; 37 | color: #fff; 38 | background-color: #3B9CFF; 39 | font-size: 16px; 40 | font-weight: 900; 41 | text-decoration: blink; 42 | 43 | &:visited, 44 | &:hover, 45 | &:focus, 46 | &:active { 47 | color: #fff; 48 | } 49 | 50 | &:hover { 51 | opacity: .7; 52 | } 53 | } 54 | `; 55 | 56 | export default Form; 57 | -------------------------------------------------------------------------------- /demo/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from 'react-dom'; 3 | import Form from './index.styled'; 4 | 5 | const root = document.getElementById('root') as HTMLElement; 6 | 7 | render(
, root); 8 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | const { defaults: tsjPreset } = require('ts-jest/presets'); 2 | 3 | module.exports = { 4 | transform: { 5 | ...tsjPreset.transform, 6 | }, 7 | testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.([tj]sx?)$', 8 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], 9 | globals: { 10 | __PATH_PREFIX__: '', 11 | 'ts-jest': { 12 | tsConfig: 'tsconfig.json', 13 | diagnostics: false, 14 | autoMapModuleNames: true, 15 | }, 16 | }, 17 | testURL: 'http://localhost', 18 | collectCoverageFrom: [ 19 | 'lib/**/*.{ts,tsx}', 20 | '!/node_modules/', 21 | ], 22 | snapshotSerializers: ['enzyme-to-json/serializer'], 23 | setupFilesAfterEnv: ['/setupEnzyme.ts'], 24 | }; 25 | -------------------------------------------------------------------------------- /lib/index.spec.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { shallow } from 'enzyme'; 3 | import ReactMailForm from '.'; 4 | 5 | const email = 'yocee57@gmail.com'; 6 | 7 | const render = (to, props = {}) => shallow(); 8 | 9 | describe('Rendering', () => { 10 | it('Component could not be rendered without `to` prop.', () => { 11 | expect(render).toThrowError(); 12 | }); 13 | 14 | it('Component will be rendered with `to` prop.', () => { 15 | const component = render(email); 16 | 17 | expect(component.exists('div')).toBe(true); 18 | 19 | const div = component.find('div'); 20 | expect(div.hasClass('')).toBe(true); 21 | 22 | expect(div.exists('input')).toBe(true); 23 | expect(div.exists('textarea')).toBe(true); 24 | expect(div.exists('a')).toBe(true); 25 | }); 26 | 27 | it('`className` can be affected to `
` element.', () => { 28 | expect(render(email, { className: 'class-name' }).find('div').hasClass('class-name')).toBe(true); 29 | expect(render(email, { className: 'react-mail-form' }).find('div').hasClass('react-mail-form')).toBe(true); 30 | }); 31 | 32 | it('`` has a text. and it can be set by `buttonText` prop.', () => { 33 | expect(render(email).find('a').text()).toBe('Send E-mail'); 34 | expect(render(email, { buttonText: 'Contact' }).find('a').text()).toBe('Contact'); 35 | expect(render(email, { buttonText: 'Submit' }).find('a').text()).toBe('Submit'); 36 | }); 37 | 38 | it('`titleMaxLength` can be string or number. but, `maxLength` in `` will be number.', () => { 39 | expect(typeof render(email).find('input').props().maxLength).toBe('number'); 40 | expect(render(email).find('input').props().maxLength).toBe(50); 41 | expect(render(email, { titleMaxLength: '100' }).find('input').props().maxLength).toBe(100); 42 | expect(render(email, { titleMaxLength: 100 }).find('input').props().maxLength).toBe(100); 43 | expect(render(email, { titleMaxLength: '10' }).find('input').props().maxLength).toBe(10); 44 | expect(render(email, { titleMaxLength: 10 }).find('input').props().maxLength).toBe(10); 45 | }); 46 | 47 | it('`titlePlaceholder` is the placeholder of ``.', () => { 48 | expect(render(email).find('input').props().placeholder).toBe('Title...'); 49 | expect(render(email, { titlePlaceholder: 'This is placeholder' }).find('input').props().placeholder).toBe('This is placeholder'); 50 | }); 51 | 52 | it('`contentsRows` can be string or number. but, `rows` in `