Completed
Push — master ( e26cdc...da6d7a )
by Alejandro
17s queued 11s
created

src/utils/DateInput.js

Complexity

Total Complexity 0
Complexity/F 0

Size

Lines of Code 45
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 0
eloc 38
mnd 0
bc 0
fnc 0
dl 0
loc 45
ccs 6
cts 7
cp 0.8571
bpm 0
cpm 0
noi 0
c 0
b 0
f 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