| Total Complexity | 0 |
| Complexity/F | 0 |
| Lines of Code | 45 |
| Function Count | 0 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Coverage | 85.71% |
| Changes | 0 | ||
| 1 | import React from 'react'; |
||
| 2 | import { isNil } from 'ramda'; |
||
| 3 | import DatePicker from 'react-datepicker'; |
||
| 4 | import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; |
||
| 5 | import { faCalendarAlt as calendarIcon } from '@fortawesome/free-regular-svg-icons'; |
||
| 6 | import * as PropTypes from 'prop-types'; |
||
| 7 | import classNames from 'classnames'; |
||
| 8 | import './DateInput.scss'; |
||
| 9 | |||
| 10 | 6 | const propTypes = { |
|
| 11 | className: PropTypes.string, |
||
| 12 | isClearable: PropTypes.bool, |
||
| 13 | selected: PropTypes.oneOfType([ PropTypes.string, PropTypes.object ]), |
||
| 14 | ref: PropTypes.object, |
||
| 15 | disabled: PropTypes.bool, |
||
| 16 | }; |
||
| 17 | |||
| 18 | 6 | const DateInput = (props) => { |
|
| 19 | 4 | const { className, isClearable, selected, ref = React.createRef() } = props; |
|
| 20 | 4 | const showCalendarIcon = !isClearable || isNil(selected); |
|
| 21 | |||
| 22 | 4 | return ( |
|
| 23 | <div className="date-input-container"> |
||
| 24 | <DatePicker |
||
| 25 | {...props} |
||
| 26 | className={classNames('date-input-container__input form-control', className)} |
||
| 27 | dateFormat="YYYY-MM-DD" |
||
| 28 | readOnly |
||
| 29 | ref={ref} |
||
| 30 | /> |
||
| 31 | {showCalendarIcon && ( |
||
| 32 | <FontAwesomeIcon |
||
| 33 | icon={calendarIcon} |
||
| 34 | className="date-input-container__icon" |
||
| 35 | onClick={() => ref.current.input.focus()} |
||
| 36 | /> |
||
| 37 | )} |
||
| 38 | </div> |
||
| 39 | ); |
||
| 40 | }; |
||
| 41 | |||
| 42 | 6 | DateInput.propTypes = propTypes; |
|
| 43 | |||
| 44 | export default DateInput; |
||
| 45 |