All files / lib/DatePicker/DatePickerWeek index.js

100% Statements 9/9
100% Branches 0/0
100% Functions 3/3
100% Lines 9/9
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                    183x   183x 183x   183x 1281x 1281x                 183x     183x               89x            
import React from 'react';
import PropTypes from 'prop-types';
import DatePickerDay from '@collab-ui/react/DatePicker/DatePickerDay';
import { addDays, getStartOfWeek } from '@collab-ui/react/utils/dateUtils';
import moment from 'moment';
 
class DatePickerWeek extends React.PureComponent {
  static displayName = 'DatePickerWeek';
 
  render() {
    const { day, ...otherProps } = this.props;
 
    const renderDays = () => {
      const startOfWeek = getStartOfWeek(day.clone());
 
      const days = [0, 1, 2, 3, 4, 5, 6].map(offset => {
        const day = addDays(startOfWeek.clone(), offset);
        return (
          <DatePickerDay
            key={offset}
            day={day}
            {...otherProps}
          />
        );
      });
 
      return days;
    };
 
    return (
      <div className="cui-datepicker__week">
        {renderDays()}
      </div>
    );
  }
}
 
DatePickerWeek.propTypes = {
  /** Required day for the DatePickerWeek */
  day: PropTypes.instanceOf(moment).isRequired,
};
 
export default DatePickerWeek;