shlink-web-client/src/common/DateInput.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-07-31 22:24:34 +03:00
import calendarIcon from '@fortawesome/fontawesome-free-regular/faCalendarAlt';
import FontAwesomeIcon from '@fortawesome/react-fontawesome';
import React from 'react';
import DatePicker from 'react-datepicker';
2018-08-05 09:28:16 +03:00
import './DateInput.scss';
2018-08-09 21:13:46 +03:00
import { isNil } from 'ramda';
2018-07-31 22:24:34 +03:00
export default class DateInput extends React.Component {
constructor(props) {
super(props);
this.inputRef = React.createRef();
}
render() {
2018-08-09 21:13:46 +03:00
const { isClearable, selected } = this.props;
const showCalendarIcon = !isClearable || isNil(selected);
2018-07-31 22:24:34 +03:00
return (
<div className="date-input-container">
<DatePicker
{...this.props}
className={`date-input-container__input form-control ${this.props.className || ''}`}
2018-07-31 22:24:34 +03:00
dateFormat="YYYY-MM-DD"
readOnly
ref={this.inputRef}
/>
2018-08-12 10:01:11 +03:00
{showCalendarIcon && (
<FontAwesomeIcon
icon={calendarIcon}
className="date-input-container__icon"
onClick={() => this.inputRef.current.input.focus()}
/>
)}
2018-07-31 22:24:34 +03:00
</div>
);
}
}