Forked from Lukeghenco/Enzyme-React-Testing-Libary-step-1.jsx
Created
October 25, 2019 15:16
-
-
Save dumpofmemory/18153ebe2cccccbb1014ff4b134f2d0b to your computer and use it in GitHub Desktop.
Enzyme/React-Testing-Libary step: 1
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
// TextAreaInput.jsx | |
import React, { Fragment } from 'react' | |
import PropTypes from 'prop-types' | |
import InputError from './InputError' | |
const TextAreaInput = ({ | |
labelText, | |
id, | |
className, | |
labelClassName, | |
errorMessage, | |
disabled, | |
handleOnChange, | |
name, | |
…props | |
}) => { | |
let inputClassName = `input${className ? ` ${className}` : ''}` | |
const forId = id || name | |
if (errorMessage) { | |
inputClassName = `${inputClassName} red-border` | |
} | |
if (disabled) { | |
inputClassName = `${inputClassName} disabled-input` | |
} | |
return ( | |
<Fragment> | |
<label className={labelClassName} htmlFor={forId} > | |
{labelText} | |
</label> | |
<textarea | |
{…props} | |
className={inputClassName} | |
id={forId} | |
disabled={disabled} | |
onChange={handleOnChange} | |
/> | |
<InputError errorMessage={errorMessage} /> | |
</Fragment> | |
) | |
} | |
TextAreaInput.propTypes = { | |
labelText: PropTypes.string, | |
errorMessage: PropTypes.string, | |
value: PropTypes.string, | |
id: PropTypes.string, | |
placeholder: PropTypes.string, | |
className: PropTypes.string, | |
labelClassName: PropTypes.string, | |
disabled: PropTypes.bool, | |
name: PropTypes.string.isRequired, | |
handleOnChange: PropTypes.func.isRequired | |
} | |
TextAreaInput.defaultProps = { | |
labelText: '', | |
errorMessage: '', | |
placeholder: '', | |
className: '', | |
labelClassName: 'large-heading', | |
disabled: false | |
} | |
export default TextAreaInput | |
// InputError.jsx | |
import React from 'react' | |
import PropTypes from 'prop-types' | |
const InputError = ({ className, typographyClass, errorMessage }) => { | |
const cssClasses = `${typographyClass} ${className}` | |
if (!errorMessage) { return null } | |
return ( | |
<div className={cssClasses}> | |
{errorMessage} | |
</div> | |
) | |
} | |
InputError.propTypes = { | |
className: PropTypes.string, | |
errorMessage: PropTypes.string, | |
typographyClass: PropTypes.string | |
} | |
InputError.defaultProps = { | |
className: '', | |
errorMessage: '', | |
typographyClass: 'large-heading red-heading smaller-font-size unselectable' | |
} | |
export default InputError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment