import React from "react"; import DatePicker from "react-widgets/DatePicker"; import "react-widgets/styles.css"; import moment from "moment"; const messages = { moveToday: "Сегодня", moveBack: "Назад", moveForward: "Вперед", dateButton: "Выбрать дату", }; export default class CalendarDatePicker extends React.Component { constructor(props) { super(props); this.state = { readonly: true, input_value: undefined, }; } _handle_onChange = (date, raw) => { // console.log("CalendarDatePicker", "_handle_onChange", { date, raw }); const { readonly } = this.state; if(this.props.onChange !== undefined) { if(!readonly) { if(moment(date).isValid()) { this.props.onChange(date, raw); } else { this.props.onChange(null, null); } } } } _handle_onFocus = () => { this.setState({ readonly: false }); } _handle_onBlur = () => { this.setState({ readonly: true }); } _parse = (str) => { const { min, max } = this.props; const date = moment(str, 'DD.MM.YYYY'); if(date.isValid()) { if(min !== undefined) { const min_to_compare = moment(moment(min).format("YYYY-MM-DD 00:00:00")); if(date < min_to_compare) { return null; } } if(max !== undefined) { const max_to_compare = moment(moment(max).format("YYYY-MM-DD 00:00:00")); if(date > max_to_compare) { return null; } } return date.toDate(); } return null; } render() { const { id, placeholder, value, min, max, disabled, plain, style, required, className } = this.props; const { readonly, input_value } = this.state; if(disabled) { return (