All files / lib/DatePicker/DatePickerMonth index.js

100% Statements 11/11
100% Branches 0/0
100% Functions 2/2
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59                                37x   37x 37x       37x 37x   37x 185x               185x       37x         37x               89x            
import React from 'react';
import PropTypes from 'prop-types';
import DatePickerWeek from '@collab-ui/react/DatePicker/DatePickerWeek';
import {
  addWeeks,
  getMonth,
  getStartOfMonth,
  getStartOfWeek,
  isSameMonth,
} from '@collab-ui/react/utils/dateUtils';
import moment from 'moment';
 
class DatePickerMonth extends React.Component {
  static displayName = 'DatePickerMonth';
 
  renderWeeks = () => {
    const { day, ...otherProps } = this.props;
 
    let i = 0;
    let currentWeekStart = getStartOfWeek(
      getStartOfMonth(day.clone())
    );
 
    const weeks = [];
    const month = getMonth(day);
 
    do {
      weeks.push(
        <DatePickerWeek
          key={i++}
          day={currentWeekStart}
          month={month}
          {...otherProps}
        />
      );
      currentWeekStart = addWeeks(currentWeekStart.clone(), 1);
 
    } while(isSameMonth(currentWeekStart, day));
 
    return weeks;
  };
 
 
  render() {
    return (
      <div className='cui-datepicker__month'>
        {this.renderWeeks()}
      </div>
    );
  }
}
 
DatePickerMonth.propTypes = {
  /** @prop Required day for the DatePickerMonth */
  day: PropTypes.instanceOf(moment).isRequired,
};
 
export default DatePickerMonth;