dopry/netlify-cms

View on GitHub
src/components/Widgets/DateTimeControl.js

Summary

Maintainability
A
0 mins
Test Coverage
import PropTypes from 'prop-types';
import React from 'react';
import DateTime from 'react-datetime';

export default class DateTimeControl extends React.Component {
  componentDidMount() {
    if (!this.props.value) {
      this.props.onChange(new Date());
    }
  }

  handleChange = (datetime) => {
    this.props.onChange(datetime);
  };

  render() {
    return <DateTime value={this.props.value} onChange={this.handleChange} />;
  }
}

DateTimeControl.propTypes = {
  onChange: PropTypes.func.isRequired,
  value: PropTypes.oneOfType([
    PropTypes.object,
    PropTypes.string,
  ]),
};