2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 import React from 'react';
17 import PropTypes from 'prop-types';
18 import DatePicker from 'react-datepicker';
19 import moment from 'moment';
20 import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
22 class CustomInput extends React.Component {
24 placeHolderText: PropTypes.string,
25 onChange: PropTypes.func,
26 onClick: PropTypes.func,
27 value: PropTypes.string
38 const text = date ? date : placeholderText;
39 const textStyle = date ? '' : 'placeholder';
44 className="datepicker-custom-input">
45 <div className={`datepicker-text ${textStyle}`}>{text}</div>
53 className="clear-input"
56 <SVGIcon name="calendar" />
62 const parseDate = (date, format) => {
63 return typeof date === 'number' ? moment.unix(date) : moment(date, format);
66 class Datepicker extends React.Component {
68 date: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
69 format: PropTypes.string,
70 onChange: PropTypes.func,
71 selectsStart: PropTypes.bool,
72 selectsEnd: PropTypes.bool,
73 startDate: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
74 endDate: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
75 disabled: PropTypes.bool,
76 label: PropTypes.string,
77 isRequired: PropTypes.bool
91 const placeholderText = 'Enter a date';
96 selected: date ? parseDate(date, format) : date,
100 startDate: startDate ? parseDate(startDate, format) : startDate,
101 endDate: endDate ? parseDate(endDate, format) : endDate
105 <div className="customized-date-picker">
107 calendarClassName="customized-date-picker-calendar"
111 onClear={() => onChange(undefined)}
112 placeholderText={placeholderText}
116 selectsEnd && props.startDate
121 selectsStart && props.endDate
127 boundariesElement: 'scrollParent'
137 export default Datepicker;