This repository has been archived by the owner on Sep 5, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from jhonmike/input
Init Input Component
- Loading branch information
Showing
7 changed files
with
194 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { configure } from 'enzyme' | ||
import Adapter from 'enzyme-adapter-react-16' | ||
|
||
configure({ adapter: new Adapter() }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react' | ||
import classnames from 'classnames' | ||
import PropTypes from 'prop-types' | ||
|
||
import styles from './input.css' | ||
|
||
const Input = props => { | ||
const { className, type, ...otherProps } = props | ||
|
||
const classes = classnames( | ||
isSimpleInput(type) ? styles['simple-input'] : null, | ||
className | ||
) | ||
|
||
return <input {...otherProps} type={type} className={classes} /> | ||
} | ||
|
||
Input.propTypes = { | ||
type: PropTypes.string.isRequired, | ||
className: PropTypes.string, | ||
value: PropTypes.string, | ||
checked: PropTypes.bool, | ||
} | ||
|
||
export default Input | ||
|
||
function isSimpleInput(type) { | ||
return ['text', 'email', 'password'].includes(type) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Input Component renders checkbox component 1`] = ` | ||
<input | ||
checkbox={false} | ||
className="" | ||
type="checkbox" | ||
/> | ||
`; | ||
|
||
exports[`Input Component renders email component 1`] = ` | ||
<input | ||
className="simple-input" | ||
type="email" | ||
value="" | ||
/> | ||
`; | ||
|
||
exports[`Input Component renders radio component 1`] = ` | ||
<input | ||
checked={true} | ||
className="" | ||
name="gender" | ||
type="radio" | ||
value="male" | ||
/> | ||
`; | ||
|
||
exports[`Input Component renders text component 1`] = ` | ||
<input | ||
className="simple-input" | ||
type="text" | ||
value="" | ||
/> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react' | ||
import renderer from 'react-test-renderer' | ||
import Input from '../Input' | ||
|
||
describe('Input Component', () => { | ||
it('renders text component', () => { | ||
const tree = renderer.create(<Input type="text" value={''} />).toJSON() | ||
|
||
expect(tree).toMatchSnapshot() | ||
}) | ||
|
||
it('renders email component', () => { | ||
const tree = renderer.create(<Input type="email" value={''} />).toJSON() | ||
|
||
expect(tree).toMatchSnapshot() | ||
}) | ||
|
||
it('renders checkbox component', () => { | ||
const tree = renderer.create(<Input type="checkbox" checkbox={false} />).toJSON() | ||
|
||
expect(tree).toMatchSnapshot() | ||
}) | ||
|
||
it('renders radio component', () => { | ||
const tree = renderer.create(<Input type="radio" name="gender" value="male" checked={true} />).toJSON() | ||
|
||
expect(tree).toMatchSnapshot() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.simple-input { | ||
display: flex; | ||
overflow-y: scroll; | ||
padding: 1px; | ||
} | ||
.simple-input input { | ||
margin: 0 .25rem; | ||
min-width: 125px; | ||
border: 1px solid #eee; | ||
border-left: 3px solid; | ||
border-radius: 5px; | ||
transition: border-color .5s ease-out; | ||
} | ||
.simple-input input:optional { | ||
border-left-color: #999; | ||
} | ||
.simple-input input:required { | ||
border-left-color: palegreen; | ||
} | ||
.simple-input input:invalid { | ||
border-left-color: salmon; | ||
} |