diff --git a/package.json b/package.json index b236adb15..7a6d65764 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "react-date-range", - "version": "1.3.0", + "name": "605-react-date-range", + "version": "1.3.2", "description": "A React component for choosing dates and date ranges.", "main": "dist/index.js", "scripts": { diff --git a/src/components/Calendar/index.js b/src/components/Calendar/index.js index 22541d56b..8b6c995ad 100644 --- a/src/components/Calendar/index.js +++ b/src/components/Calendar/index.js @@ -1,12 +1,4 @@ -import React, { PureComponent } from 'react'; -import PropTypes from 'prop-types'; -import { rangeShape } from '../DayCell'; -import Month from '../Month'; -import DateInput from '../DateInput'; -import { calcFocusDate, generateStyles, getMonthDisplayRange } from '../../utils'; import classnames from 'classnames'; -import ReactList from 'react-list'; -import { shallowEqualObjects } from 'shallow-equal'; import { addMonths, format, @@ -27,14 +19,26 @@ import { max, } from 'date-fns'; import defaultLocale from 'date-fns/locale/en-US'; -import coreStyles from '../../styles'; +import PropTypes from 'prop-types'; +import React, { PureComponent } from 'react'; +import ReactList from 'react-list'; +import { shallowEqualObjects } from 'shallow-equal'; import { ariaLabelsShape } from '../../accessibility'; +import coreStyles from '../../styles'; +import { calcFocusDate, generateStyles, getMonthDisplayRange } from '../../utils'; +import DateInput from '../DateInput'; +import { rangeShape } from '../DayCell'; +import Month from '../Month'; class Calendar extends PureComponent { constructor(props, context) { super(props, context); this.dateOptions = { locale: props.locale }; - if (props.weekStartsOn !== undefined) this.dateOptions.weekStartsOn = props.weekStartsOn; + if (props.broadcastCalendar) { + this.dateOptions.weekStartsOn = 1; + } else if (props.weekStartsOn !== undefined) { + this.dateOptions.weekStartsOn = props.weekStartsOn; + }; this.styles = generateStyles([coreStyles, props.classNames]); this.listSizeCache = {}; this.isFirstRender = true; @@ -122,7 +126,10 @@ class Calendar extends PureComponent { date: 'date', }; const targetProp = propMapper[this.props.displayMode]; - if (this.props[targetProp] !== prevProps[targetProp]) { + if ( + this.props[targetProp] !== prevProps[targetProp] || + this.props.focusedRange != prevProps.focusedRange + ) { this.updateShownDate(this.props); } @@ -526,6 +533,7 @@ Calendar.defaultProps = { dateDisplayFormat: 'MMM d, yyyy', monthDisplayFormat: 'MMM yyyy', weekdayDisplayFormat: 'E', + broadcastCalendar: false, dayDisplayFormat: 'd', showDateDisplay: true, showPreview: true, @@ -545,6 +553,7 @@ Calendar.defaultProps = { dragSelectionEnabled: true, fixedHeight: false, ariaLabels: {}, + weekNumberColor: '#B86EF3', }; Calendar.propTypes = { @@ -572,6 +581,8 @@ Calendar.propTypes = { monthDisplayFormat: PropTypes.string, weekdayDisplayFormat: PropTypes.string, weekStartsOn: PropTypes.number, + broadcastCalendar: PropTypes.bool, + weekNumberColor: PropTypes.string, dayDisplayFormat: PropTypes.string, focusedRange: PropTypes.arrayOf(PropTypes.number), initialFocusedRange: PropTypes.arrayOf(PropTypes.number), diff --git a/src/components/DayCell/index.js b/src/components/DayCell/index.js index 26f12539e..860360bc2 100644 --- a/src/components/DayCell/index.js +++ b/src/components/DayCell/index.js @@ -1,8 +1,8 @@ /* eslint-disable no-fallthrough */ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; import classnames from 'classnames'; import { startOfDay, format, isSameDay, isAfter, isBefore, endOfDay } from 'date-fns'; +import PropTypes from 'prop-types'; +import React, { Component } from 'react'; class DayCell extends Component { constructor(props, context) { @@ -58,6 +58,7 @@ class DayCell extends Component { }; getClassNames = () => { const { + broadcastCalendar, isPassive, isToday, isWeekend, @@ -76,7 +77,7 @@ class DayCell extends Component { [styles.dayWeekend]: isWeekend, [styles.dayStartOfWeek]: isStartOfWeek, [styles.dayEndOfWeek]: isEndOfWeek, - [styles.dayStartOfMonth]: isStartOfMonth, + [styles.dayStartOfMonth]: isStartOfMonth && !broadcastCalendar, [styles.dayEndOfMonth]: isEndOfMonth, [styles.dayHovered]: this.state.hover, [styles.dayActive]: this.state.active, @@ -128,7 +129,7 @@ class DayCell extends Component { ...result, { isStartEdge, - isEndEdge: isEndEdge, + isEndEdge, isInRange, ...range, }, @@ -166,21 +167,32 @@ class DayCell extends Component { onKeyUp={this.handleKeyEvent} className={this.getClassNames(this.props.styles)} {...(this.props.disabled || this.props.isPassive ? { tabIndex: -1 } : {})} - style={{ color: this.props.color }}> + style={{ + color: this.props.color, + backgroundColor: this.props.weekNumber ? '#fff' : '', + width: this.props.broadcastCalendar ? 'calc(100% / 8)' : 'calc(100% / 7)', + }}> {this.renderSelectionPlaceholders()} {this.renderPreviewPlaceholder()} - - { - dayContentRenderer?.(this.props.day) || - {format(this.props.day, this.props.dayDisplayFormat)} - } - + {this.props.weekNumber + ? ( + {this.props.weekNumber} + ) + : ( + { + dayContentRenderer?.(this.props.day) || + {format(this.props.day, this.props.dayDisplayFormat)} + } + ) + } ); } } -DayCell.defaultProps = {}; +DayCell.defaultProps = { + weekNumberColor: '#B86EF3', +}; export const rangeShape = PropTypes.shape({ startDate: PropTypes.object, @@ -219,6 +231,8 @@ DayCell.propTypes = { onMouseUp: PropTypes.func, onMouseEnter: PropTypes.func, dayContentRenderer: PropTypes.func, + weekNumber: PropTypes.number, + weekNumberColor: PropTypes.string, }; export default DayCell; diff --git a/src/components/Month/index.js b/src/components/Month/index.js index 6f7802636..ba8b7e650 100644 --- a/src/components/Month/index.js +++ b/src/components/Month/index.js @@ -1,7 +1,4 @@ /* eslint-disable no-fallthrough */ -import React, { PureComponent } from 'react'; -import PropTypes from 'prop-types'; -import DayCell, { rangeShape } from '../DayCell'; import { format, startOfDay, @@ -15,20 +12,41 @@ import { isWithinInterval, eachDayOfInterval, } from 'date-fns'; -import { getMonthDisplayRange } from '../../utils'; +import PropTypes from 'prop-types'; +import React, { PureComponent } from 'react'; +import { + getMonthDisplayRange, + calculateBroadcastWeekNumber, + shouldRenderBroadcastDay +} from '../../utils'; +import DayCell, { rangeShape } from '../DayCell'; -function renderWeekdays(styles, dateOptions, weekdayDisplayFormat) { +function renderWeekdays(styles, dateOptions, weekdayDisplayFormat, broadcastCalendar) { const now = new Date(); return (