index.js
33 lines
| 1 | import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; |
| 2 | import {toUniqueId} from '../../utils'; |
| 3 | |
| 4 | import './style.scss'; |
| 5 | |
| 6 | const TextControl = ({label, value, onChange, icon, type}) => { |
| 7 | const id = toUniqueId(label); |
| 8 | |
| 9 | return ( |
| 10 | <div className="give-donor-dashboard-text-control"> |
| 11 | {label && ( |
| 12 | <label className="give-donor-dashboard-text-control__label" htmlFor={id}> |
| 13 | {label} |
| 14 | </label> |
| 15 | )} |
| 16 | <div className="give-donor-dashboard-text-control__input"> |
| 17 | {icon && <FontAwesomeIcon icon={icon} />} |
| 18 | <input id={id} type={type} value={value} onChange={(evt) => onChange(evt.target.value)} /> |
| 19 | </div> |
| 20 | </div> |
| 21 | ); |
| 22 | }; |
| 23 | |
| 24 | TextControl.defaultProps = { |
| 25 | label: null, |
| 26 | value: '', |
| 27 | onChange: null, |
| 28 | icon: null, |
| 29 | type: 'text', |
| 30 | }; |
| 31 | |
| 32 | export default TextControl; |
| 33 |