-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
379 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
84 changes: 84 additions & 0 deletions
84
src/components/UI/molecules/InputTextField/InputTextField.jsx
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,84 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import InputField from '<atoms>/InputField/InputField'; | ||
import Text from '<atoms>/Text/Text'; | ||
import FlexContainer from '<atoms>/layouts/FlexContainer/FlexContainer'; | ||
import Label from '<molecules>/label/Label'; | ||
import themeBorderRadius from '<variables>/border'; | ||
import width from '<variables>/width'; | ||
import { textColors } from '<variables>/colorPalette'; | ||
|
||
/** | ||
* @description - InputFormField component combined with an error field | ||
* | ||
* @prop {string} - placeholder | ||
* @prop {string | number} - value | ||
* @prop {string} - errorMessage | ||
* @prop {func} - onChange | ||
* @prop {string} - inputWidth | ||
* | ||
* @returns {JSX} - Input, Text, FlexContainer Component | ||
* | ||
* InputForm field Component | ||
*/ | ||
const InputTextField = ({ | ||
value, | ||
placeholder, | ||
onChange, | ||
errorMessage, | ||
inputWidth, | ||
borderRadius, | ||
type, | ||
name, | ||
label, | ||
color, | ||
}) => { | ||
const id = btoa(`${name}-${value}`); | ||
|
||
return ( | ||
|
||
<FlexContainer> | ||
{label && <Label | ||
id={id} | ||
htmlFor={id} | ||
color = {color} | ||
> | ||
{label} | ||
</Label>} | ||
<InputField | ||
id={id} | ||
name={name} | ||
type={type} | ||
placeholder={placeholder} | ||
value={value} | ||
inputWidth={inputWidth} | ||
borderRadius={borderRadius} | ||
error={errorMessage} | ||
onChange={onChange} /> | ||
{errorMessage | ||
&& <span><Text color='red' fontSize='small' display='block'> | ||
{errorMessage} | ||
</Text></span>} | ||
</FlexContainer> | ||
|
||
); | ||
}; | ||
|
||
InputTextField.propTypes = { | ||
type: PropTypes.oneOf(['number', 'email', 'password', 'text']).isRequired, | ||
label: PropTypes.string, | ||
inputWidth: PropTypes.oneOf(Object.keys(width)), | ||
placeholder: PropTypes.string, | ||
value: PropTypes.string, | ||
name: PropTypes.string.isRequired, | ||
errorMessage: PropTypes.string, | ||
borderRadius: PropTypes.oneOf(Object.keys(themeBorderRadius)), | ||
onChange: PropTypes.func.isRequired, | ||
color: PropTypes.oneOf(Object.keys(textColors)), | ||
}; | ||
|
||
InputTextField.defaultProps = { | ||
type: 'text', | ||
}; | ||
|
||
export default InputTextField; |
65 changes: 65 additions & 0 deletions
65
src/components/UI/molecules/InputTextField/InputTextField.md
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,65 @@ | ||
InputFormField Default: | ||
```jsx | ||
<InputTextField | ||
label='First Name' | ||
name='firstname' | ||
type='text' | ||
placeholder='Enter first name' | ||
onChange={e => setText(e.target.value)} | ||
inputWidth='fullWidth' | ||
value='asd1' | ||
/> | ||
``` | ||
|
||
example | ||
```jsx | ||
<InputTextField | ||
label='First Name' | ||
name='firstname' | ||
type='text' | ||
placeholder='enter first name' | ||
onChange={e => setText(e.target.value)} | ||
inputWidth='fullWidth' | ||
value='asd2' | ||
/> | ||
``` | ||
Form field with password | ||
```jsx | ||
<InputTextField | ||
label='Password ' | ||
name='password' | ||
type='password' | ||
placeholder='enter password' | ||
onChange={e => setText(e.target.value)} | ||
inputWidth='fullWidth' | ||
value='asd3' | ||
/> | ||
``` | ||
|
||
Form field with error message | ||
```jsx | ||
<InputTextField | ||
label='First Name' | ||
name='firstname' | ||
type='password' | ||
placeholder='enter first name' | ||
onChange={e => setText(e.target.value)} | ||
inputWidth='fullWidth' | ||
errorMessage='first name is required' | ||
value='asd4' | ||
/> | ||
``` | ||
|
||
Form field with half width | ||
```jsx | ||
<InputTextField | ||
label='First Name' | ||
name='firstname' | ||
type='text' | ||
placeholder='enter first name' | ||
onChange={e => setText(e.target.value)} | ||
inputWidth='searchBarWidth' | ||
errorMessage='first name is required' | ||
value='asd5' | ||
/> | ||
``` |
57 changes: 57 additions & 0 deletions
57
src/components/UI/molecules/InputTextField/InputTextField.spec.js
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,57 @@ | ||
import React from 'react'; | ||
import { render, cleanup } from '<src>/helpers/testUtils'; | ||
import InputTextField from './InputTextField'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
afterEach(cleanup); | ||
|
||
const defaultProps = { | ||
label: 'First Name', | ||
name: 'firstname', | ||
type: 'text', | ||
errorMessage: 'this field required', | ||
onChange: () => {}, | ||
}; | ||
|
||
// const id = getStringId(5); | ||
|
||
const setUp = (props) => { | ||
const utils = render(<InputTextField {...defaultProps} {...props} />); | ||
return utils; | ||
}; | ||
|
||
describe('Input Text Fields', () => { | ||
it('should render a input field component', () => { | ||
const { container } = setUp(); | ||
expect(container).toBeTruthy(); | ||
}); | ||
|
||
it('should render and return the first name', () => { | ||
const { getByLabelText } = setUp({ type: 'password' }); | ||
const input = getByLabelText(defaultProps.label); | ||
|
||
expect(input.getAttribute('name')).toBe('firstname'); | ||
}); | ||
|
||
|
||
it('should render a input password field component', () => { | ||
const { getByLabelText } = setUp({ type: 'password' }); | ||
const input = getByLabelText(defaultProps.label); | ||
|
||
expect(input.getAttribute('type')).toBe('password'); | ||
}); | ||
|
||
it('should render a input password field component and return the id', () => { | ||
const { getByLabelText } = setUp({ type: 'password' }); | ||
const input = getByLabelText(defaultProps.label); | ||
const value = input.getAttribute('id'); | ||
|
||
expect(input.getAttribute(input.attributes[1].name)).toBe(value); | ||
}); | ||
|
||
it('should render password field component and return error message', () => { | ||
const { container } = setUp({ type: 'password' }); | ||
|
||
expect(container.lastChild).toHaveTextContent(defaultProps.errorMessage); | ||
}); | ||
}); |
Oops, something went wrong.