All files / datepicker week.js

100% Statements 8/8
0% Branches 0/1
42.86% Functions 3/7
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78                                                                  47x 47x   47x   329x 329x                                                                 47x 47x 47x      
/*
Copyright (c) 2018-2019 Uber Technologies, Inc.
 
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
// @flow
import * as React from 'react';
import Day from './day.js';
import {StyledWeek} from './styled-components.js';
import {
  getStartOfWeek,
  addDays,
  isDayDisabled,
  isSameDay,
} from './utils/index.js';
import {WEEKDAYS} from './constants.js';
import {getOverrides} from '../helpers/overrides.js';
import type {WeekPropsT} from './types.js';
 
export default class Week extends React.Component<WeekPropsT> {
  static defaultProps = {
    date: new Date(),
    highlightedDate: null,
    onDayClick: () => {},
    onDayMouseOver: () => {},
    onDayMouseLeave: () => {},
    onChange: () => {},
    overrides: {},
    peekNextMonth: false,
  };
 
  renderDays = () => {
    const startOfWeek = getStartOfWeek(this.props.date, this.props.locale);
    const days = [];
    // $FlowFixMe
    return days.concat(
      WEEKDAYS.map((offset: number) => {
        const day = addDays(startOfWeek, offset);
        return (
          // eslint-disable-next-line jsx-a11y/mouse-events-have-key-events
          <Day
            date={day}
            disabled={isDayDisabled(day, this.props)}
            excludeDates={this.props.excludeDates}
            filterDate={this.props.filterDate}
            highlightedDate={this.props.highlightedDate}
            highlighted={isSameDay(day, this.props.highlightedDate)}
            includeDates={this.props.includeDates}
            focusedCalendar={this.props.focusedCalendar}
            range={this.props.range}
            key={offset}
            locale={this.props.locale}
            minDate={this.props.minDate}
            maxDate={this.props.maxDate}
            month={this.props.month}
            onSelect={this.props.onChange}
            onBlur={this.props.onDayBlur}
            onFocus={this.props.onDayFocus}
            onClick={this.props.onDayClick}
            onMouseOver={this.props.onDayMouseOver}
            onMouseLeave={this.props.onDayMouseLeave}
            overrides={this.props.overrides}
            peekNextMonth={this.props.peekNextMonth}
            value={this.props.value}
          />
        );
      }),
    );
  };
 
  render() {
    const {overrides = {}} = this.props;
    const [Week, weekProps] = getOverrides(overrides.Week, StyledWeek);
    return <Week {...weekProps}>{this.renderDays()}</Week>;
  }
}