react-calendar
Advanced tools
Comparing version 2.16.0 to 2.16.1
@@ -152,4 +152,13 @@ 'use strict'; | ||
var getActiveStartDate = function getActiveStartDate(props) { | ||
var rangeType = getView(props.view, props.minDetail, props.maxDetail); | ||
var valueFrom = getValueFrom(props.value, props.minDate, props.maxDate, props.maxDetail) || props.activeStartDate || new Date(); | ||
var activeStartDate = props.activeStartDate, | ||
maxDate = props.maxDate, | ||
maxDetail = props.maxDetail, | ||
minDate = props.minDate, | ||
minDetail = props.minDetail, | ||
value = props.value, | ||
view = props.view; | ||
var rangeType = getView(view, minDetail, maxDetail); | ||
var valueFrom = getValueFrom(value, minDate, maxDate, maxDetail) || activeStartDate || new Date(); | ||
return (0, _dates.getBegin)(rangeType, valueFrom); | ||
@@ -173,6 +182,12 @@ }; | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Calendar.__proto__ || Object.getPrototypeOf(Calendar)).call.apply(_ref, [this].concat(args))), _this), _this.state = {}, _this.setActiveStartDate = function (activeStartDate) { | ||
var onActiveDateChange = _this.props.onActiveDateChange; | ||
_this.setState({ activeStartDate: activeStartDate }, function () { | ||
(0, _utils.callIfDefined)(_this.props.onActiveDateChange, { | ||
var view = _this.state.view; | ||
(0, _utils.callIfDefined)(onActiveDateChange, { | ||
activeStartDate: activeStartDate, | ||
view: _this.state.view | ||
view: view | ||
}); | ||
@@ -185,4 +200,10 @@ }); | ||
var views = getLimitedViews(_this.props.minDetail, _this.props.maxDetail); | ||
var _this$props = _this.props, | ||
maxDetail = _this$props.maxDetail, | ||
minDetail = _this$props.minDetail, | ||
onDrillDown = _this$props.onDrillDown; | ||
var views = getLimitedViews(minDetail, maxDetail); | ||
_this.setState(function (prevState) { | ||
@@ -195,5 +216,8 @@ var nextView = views[views.indexOf(prevState.view) + 1]; | ||
}, function () { | ||
(0, _utils.callIfDefined)(_this.props.onDrillDown, { | ||
var view = _this.state.view; | ||
(0, _utils.callIfDefined)(onDrillDown, { | ||
activeStartDate: activeStartDate, | ||
view: _this.state.view | ||
view: view | ||
}); | ||
@@ -206,4 +230,10 @@ }); | ||
var views = getLimitedViews(_this.props.minDetail, _this.props.maxDetail); | ||
var _this$props2 = _this.props, | ||
maxDetail = _this$props2.maxDetail, | ||
minDetail = _this$props2.minDetail, | ||
onDrillUp = _this$props2.onDrillUp; | ||
var views = getLimitedViews(minDetail, maxDetail); | ||
_this.setState(function (prevState) { | ||
@@ -218,11 +248,16 @@ var nextView = views[views.indexOf(prevState.view) - 1]; | ||
}, function () { | ||
(0, _utils.callIfDefined)(_this.props.onDrillUp, { | ||
activeStartDate: _this.state.activeStartDate, | ||
view: _this.state.view | ||
var _this$state = _this.state, | ||
activeStartDate = _this$state.activeStartDate, | ||
view = _this$state.view; | ||
(0, _utils.callIfDefined)(onDrillUp, { | ||
activeStartDate: activeStartDate, | ||
view: view | ||
}); | ||
}); | ||
}, _this.onChange = function (value) { | ||
var _this$props = _this.props, | ||
onChange = _this$props.onChange, | ||
selectRange = _this$props.selectRange; | ||
var _this$props3 = _this.props, | ||
onChange = _this$props3.onChange, | ||
selectRange = _this$props3.selectRange; | ||
@@ -298,2 +333,3 @@ | ||
renderChildren = _props2.renderChildren, | ||
selectRange = _props2.selectRange, | ||
tileClassName = _props2.tileClassName, | ||
@@ -317,3 +353,3 @@ tileContent = _props2.tileContent, | ||
minDate: minDate, | ||
onMouseOver: this.props.selectRange ? onMouseOver : null, | ||
onMouseOver: selectRange ? onMouseOver : null, | ||
tileClassName: tileClassName, | ||
@@ -330,23 +366,50 @@ tileContent: tileContent || renderChildren, // For backwards compatibility | ||
case 'century': | ||
return _react2.default.createElement(_CenturyView2.default, _extends({ | ||
onClick: (0, _utils.mergeFunctions)(clickAction, this.props.onClickDecade) | ||
}, commonProps)); | ||
{ | ||
var onClickDecade = this.props.onClickDecade; | ||
return _react2.default.createElement(_CenturyView2.default, _extends({ | ||
onClick: (0, _utils.mergeFunctions)(clickAction, onClickDecade) | ||
}, commonProps)); | ||
} | ||
case 'decade': | ||
return _react2.default.createElement(_DecadeView2.default, _extends({ | ||
onClick: (0, _utils.mergeFunctions)(clickAction, this.props.onClickYear) | ||
}, commonProps)); | ||
{ | ||
var onClickYear = this.props.onClickYear; | ||
return _react2.default.createElement(_DecadeView2.default, _extends({ | ||
onClick: (0, _utils.mergeFunctions)(clickAction, onClickYear) | ||
}, commonProps)); | ||
} | ||
case 'year': | ||
return _react2.default.createElement(_YearView2.default, _extends({ | ||
formatMonth: this.props.formatMonth, | ||
onClick: (0, _utils.mergeFunctions)(clickAction, this.props.onClickMonth) | ||
}, commonProps)); | ||
{ | ||
var _props3 = this.props, | ||
formatMonth = _props3.formatMonth, | ||
onClickMonth = _props3.onClickMonth; | ||
return _react2.default.createElement(_YearView2.default, _extends({ | ||
formatMonth: formatMonth, | ||
onClick: (0, _utils.mergeFunctions)(clickAction, onClickMonth) | ||
}, commonProps)); | ||
} | ||
case 'month': | ||
return _react2.default.createElement(_MonthView2.default, _extends({ | ||
calendarType: calendarType, | ||
formatShortWeekday: this.props.formatShortWeekday, | ||
onClick: (0, _utils.mergeFunctions)(clickAction, this.props.onClickDay), | ||
onClickWeekNumber: this.props.onClickWeekNumber, | ||
showNeighboringMonth: this.props.showNeighboringMonth, | ||
showWeekNumbers: this.props.showWeekNumbers | ||
}, commonProps)); | ||
{ | ||
var _props4 = this.props, | ||
formatShortWeekday = _props4.formatShortWeekday, | ||
onClickDay = _props4.onClickDay, | ||
onClickWeekNumber = _props4.onClickWeekNumber, | ||
showNeighboringMonth = _props4.showNeighboringMonth, | ||
showWeekNumbers = _props4.showWeekNumbers; | ||
return _react2.default.createElement(_MonthView2.default, _extends({ | ||
calendarType: calendarType, | ||
formatShortWeekday: formatShortWeekday, | ||
onClick: (0, _utils.mergeFunctions)(clickAction, onClickDay), | ||
onClickWeekNumber: onClickWeekNumber, | ||
showNeighboringMonth: showNeighboringMonth, | ||
showWeekNumbers: showWeekNumbers | ||
}, commonProps)); | ||
} | ||
default: | ||
@@ -366,18 +429,36 @@ throw new Error('Invalid view: ' + view + '.'); | ||
var _props5 = this.props, | ||
formatMonthYear = _props5.formatMonthYear, | ||
locale = _props5.locale, | ||
maxDate = _props5.maxDate, | ||
maxDetail = _props5.maxDetail, | ||
minDate = _props5.minDate, | ||
minDetail = _props5.minDetail, | ||
next2Label = _props5.next2Label, | ||
nextLabel = _props5.nextLabel, | ||
navigationLabel = _props5.navigationLabel, | ||
prev2Label = _props5.prev2Label, | ||
prevLabel = _props5.prevLabel; | ||
var _state2 = this.state, | ||
activeRange = _state2.activeRange, | ||
activeStartDate = _state2.activeStartDate, | ||
view = _state2.view; | ||
return _react2.default.createElement(_Navigation2.default, { | ||
activeRange: this.state.activeRange, | ||
activeStartDate: this.state.activeStartDate, | ||
activeRange: activeRange, | ||
activeStartDate: activeStartDate, | ||
drillUp: this.drillUp, | ||
formatMonthYear: this.props.formatMonthYear, | ||
locale: this.props.locale, | ||
maxDate: this.props.maxDate, | ||
minDate: this.props.minDate, | ||
next2Label: this.props.next2Label, | ||
nextLabel: this.props.nextLabel, | ||
navigationLabel: this.props.navigationLabel, | ||
prev2Label: this.props.prev2Label, | ||
prevLabel: this.props.prevLabel, | ||
formatMonthYear: formatMonthYear, | ||
locale: locale, | ||
maxDate: maxDate, | ||
minDate: minDate, | ||
next2Label: next2Label, | ||
nextLabel: nextLabel, | ||
navigationLabel: navigationLabel, | ||
prev2Label: prev2Label, | ||
prevLabel: prevLabel, | ||
setActiveStartDate: this.setActiveStartDate, | ||
view: this.state.view, | ||
views: getLimitedViews(this.props.minDetail, this.props.maxDetail) | ||
view: view, | ||
views: getLimitedViews(minDetail, maxDetail) | ||
}); | ||
@@ -388,5 +469,5 @@ } | ||
value: function render() { | ||
var _props3 = this.props, | ||
className = _props3.className, | ||
selectRange = _props3.selectRange; | ||
var _props6 = this.props, | ||
className = _props6.className, | ||
selectRange = _props6.selectRange; | ||
var value = this.state.value; | ||
@@ -411,5 +492,11 @@ var onMouseOut = this.onMouseOut; | ||
get: function get() { | ||
var views = getLimitedViews(this.props.minDetail, this.props.maxDetail); | ||
var _props7 = this.props, | ||
maxDetail = _props7.maxDetail, | ||
minDetail = _props7.minDetail; | ||
var view = this.state.view; | ||
return views.indexOf(this.state.view) < views.length - 1; | ||
var views = getLimitedViews(minDetail, maxDetail); | ||
return views.indexOf(view) < views.length - 1; | ||
} | ||
@@ -419,5 +506,11 @@ }, { | ||
get: function get() { | ||
var views = getLimitedViews(this.props.minDetail, this.props.maxDetail); | ||
var _props8 = this.props, | ||
maxDetail = _props8.maxDetail, | ||
minDetail = _props8.minDetail; | ||
var view = this.state.view; | ||
return views.indexOf(this.state.view) > 0; | ||
var views = getLimitedViews(minDetail, maxDetail); | ||
return views.indexOf(view) > 0; | ||
} | ||
@@ -427,3 +520,6 @@ }, { | ||
get: function get() { | ||
return getValueType(this.props.maxDetail); | ||
var maxDetail = this.props.maxDetail; | ||
return getValueType(maxDetail); | ||
} | ||
@@ -467,4 +563,4 @@ }], [{ | ||
var values = [nextProps.value, prevState.valueProps]; | ||
if (nextState.view || // Allowed view changed | ||
datesAreDifferent.apply(undefined, _toConsumableArray(values.map(function (value) { | ||
if (nextState.view // Allowed view changed | ||
|| datesAreDifferent.apply(undefined, _toConsumableArray(values.map(function (value) { | ||
return getValueFrom(value, minDate, maxDate, maxDetail); | ||
@@ -519,4 +615,4 @@ }))) || datesAreDifferent.apply(undefined, _toConsumableArray(values.map(function (value) { | ||
navigationLabel: _propTypes2.default.func, | ||
next2Label: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.node]), | ||
nextLabel: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.node]), | ||
next2Label: _propTypes2.default.node, | ||
nextLabel: _propTypes2.default.node, | ||
onActiveDateChange: _propTypes2.default.func, | ||
@@ -531,4 +627,4 @@ onChange: _propTypes2.default.func, | ||
onDrillUp: _propTypes2.default.func, | ||
prev2Label: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.node]), | ||
prevLabel: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.node]), | ||
prev2Label: _propTypes2.default.node, | ||
prevLabel: _propTypes2.default.node, | ||
renderChildren: _propTypes2.default.func, // For backwards compatibility | ||
@@ -535,0 +631,0 @@ returnValue: _propTypes2.default.oneOf(['start', 'end', 'range']), |
@@ -79,3 +79,3 @@ 'use strict'; | ||
value: function shouldComponentUpdate(nextProps) { | ||
return nextProps.activeStartDate !== this.props.activeStartDate || nextProps.view !== this.props.view; | ||
return nextProps.activeStartDate !== this.props.activeStartDate || nextProps.locale !== this.props.locale || nextProps.view !== this.props.view; | ||
} | ||
@@ -82,0 +82,0 @@ }, { |
@@ -33,2 +33,6 @@ 'use strict'; | ||
exports.default = _Calendar2.default; | ||
// File is created during build phase and placed in dist directory | ||
// eslint-disable-next-line import/no-unresolved | ||
exports.Calendar = _Calendar2.default; | ||
@@ -35,0 +39,0 @@ exports.CenturyView = _CenturyView2.default; |
@@ -24,2 +24,3 @@ 'use strict'; | ||
if (minDate) { | ||
@@ -45,2 +46,3 @@ if (!(minDate instanceof Date)) { | ||
if (maxDate) { | ||
@@ -88,5 +90,8 @@ if (!(maxDate instanceof Date)) { | ||
var view = props[propName]; | ||
if (!view) { | ||
return new Error('The prop `' + propName + '` is marked as required in `' + componentName + '`, but its value is `' + view + '`.'); | ||
} | ||
return isView(props, propName, componentName); | ||
@@ -93,0 +98,0 @@ }; |
{ | ||
"name": "react-calendar", | ||
"version": "2.16.0", | ||
"version": "2.16.1", | ||
"description": "Ultimate calendar for your React app.", | ||
@@ -9,3 +9,3 @@ "main": "dist/entry.js", | ||
"scripts": { | ||
"build": "npm run build-js && npm run copy-styles && npm run build-styles && npm run copy-types", | ||
"build": "yarn run build-js && yarn run copy-styles && yarn run build-styles && yarn run copy-types", | ||
"build-js": "babel src -d dist --ignore __tests__", | ||
@@ -15,4 +15,4 @@ "build-styles": "lessc ./dist/Calendar.less ./dist/Calendar.css", | ||
"copy-types": "node ./copy-types.js", | ||
"prepublishOnly": "npm run build", | ||
"test": "npm run test-eslint && npm run test-jest", | ||
"prepublishOnly": "yarn run build", | ||
"test": "yarn run test-eslint && yarn run test-jest", | ||
"test-eslint": "eslint ./src", | ||
@@ -74,9 +74,9 @@ "test-jest": "jest", | ||
"babel-cli": "^6.26.0", | ||
"babel-core": "^6.26.0", | ||
"babel-eslint": "^8.2.1", | ||
"babel-jest": "^22.1.0", | ||
"babel-core": "^6.26.3", | ||
"babel-eslint": "^8.2.6", | ||
"babel-jest": "^23.4.0", | ||
"babel-plugin-transform-class-properties": "^6.24.1", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2", | ||
"babel-plugin-transform-object-assign": "^6.22.0", | ||
"babel-preset-env": "^1.6.1", | ||
"babel-preset-env": "^1.7.0", | ||
"babel-preset-react": "^6.24.1", | ||
@@ -86,11 +86,10 @@ "babel-preset-stage-2": "^6.24.1", | ||
"enzyme-adapter-react-16": "^1.1.1", | ||
"eslint": "^4.16.0", | ||
"eslint-config-airbnb": "^16.1.0", | ||
"eslint-plugin-class-property": "^1.1.0", | ||
"eslint-plugin-import": "^2.8.0", | ||
"eslint-plugin-jsx-a11y": "^6.0.3", | ||
"eslint-plugin-react": "^7.6.0", | ||
"jest": "^22.1.4", | ||
"jest-cli": "^22.1.4", | ||
"less": "^2.7.3", | ||
"eslint": "^4.19.1", | ||
"eslint-config-airbnb": "^17.0.0", | ||
"eslint-plugin-import": "^2.13.0", | ||
"eslint-plugin-jsx-a11y": "^6.1.1", | ||
"eslint-plugin-react": "^7.9.1", | ||
"jest": "^23.4.1", | ||
"jest-cli": "^23.4.1", | ||
"less": "^3.7.1", | ||
"react": "^16.4.1", | ||
@@ -97,0 +96,0 @@ "react-dom": "^16.4.1" |
@@ -13,3 +13,5 @@ import React, { Component } from 'react'; | ||
import { getBegin, getEnd, getValueRange } from './shared/dates'; | ||
import { isCalendarType, isClassName, isMaxDate, isMinDate, isValue } from './shared/propTypes'; | ||
import { | ||
isCalendarType, isClassName, isMaxDate, isMinDate, isValue, | ||
} from './shared/propTypes'; | ||
import { between, callIfDefined, mergeFunctions } from './shared/utils'; | ||
@@ -21,5 +23,5 @@ | ||
const datesAreDifferent = (date1, date2) => ( | ||
(date1 && !date2) || | ||
(!date1 && date2) || | ||
(date1 && date2 && date1.getTime() !== date2.getTime()) | ||
(date1 && !date2) | ||
|| (!date1 && date2) | ||
|| (date1 && date2 && date1.getTime() !== date2.getTime()) | ||
); | ||
@@ -30,4 +32,4 @@ | ||
*/ | ||
const getLimitedViews = (minDetail, maxDetail) => | ||
allViews.slice(allViews.indexOf(minDetail), allViews.indexOf(maxDetail) + 1); | ||
const getLimitedViews = (minDetail, maxDetail) => allViews | ||
.slice(allViews.indexOf(minDetail), allViews.indexOf(maxDetail) + 1); | ||
@@ -54,4 +56,3 @@ const getView = (view, minDetail, maxDetail) => { | ||
*/ | ||
const getValueType = maxDetail => | ||
allValueTypes[allViews.indexOf(maxDetail)]; | ||
const getValueType = maxDetail => allValueTypes[allViews.indexOf(maxDetail)]; | ||
@@ -114,7 +115,17 @@ const getValueFrom = (value, minDate, maxDate, maxDetail) => { | ||
const getActiveStartDate = (props) => { | ||
const rangeType = getView(props.view, props.minDetail, props.maxDetail); | ||
const { | ||
activeStartDate, | ||
maxDate, | ||
maxDetail, | ||
minDate, | ||
minDetail, | ||
value, | ||
view, | ||
} = props; | ||
const rangeType = getView(view, minDetail, maxDetail); | ||
const valueFrom = ( | ||
getValueFrom(props.value, props.minDate, props.maxDate, props.maxDetail) || | ||
props.activeStartDate || | ||
new Date() | ||
getValueFrom(value, minDate, maxDate, maxDetail) | ||
|| activeStartDate | ||
|| new Date() | ||
); | ||
@@ -126,15 +137,23 @@ return getBegin(rangeType, valueFrom); | ||
get drillDownAvailable() { | ||
const views = getLimitedViews(this.props.minDetail, this.props.maxDetail); | ||
const { maxDetail, minDetail } = this.props; | ||
const { view } = this.state; | ||
return views.indexOf(this.state.view) < views.length - 1; | ||
const views = getLimitedViews(minDetail, maxDetail); | ||
return views.indexOf(view) < views.length - 1; | ||
} | ||
get drillUpAvailable() { | ||
const views = getLimitedViews(this.props.minDetail, this.props.maxDetail); | ||
const { maxDetail, minDetail } = this.props; | ||
const { view } = this.state; | ||
return views.indexOf(this.state.view) > 0; | ||
const views = getLimitedViews(minDetail, maxDetail); | ||
return views.indexOf(view) > 0; | ||
} | ||
get valueType() { | ||
return getValueType(this.props.maxDetail); | ||
const { maxDetail } = this.props; | ||
return getValueType(maxDetail); | ||
} | ||
@@ -196,5 +215,5 @@ | ||
if ( | ||
nextState.view || // Allowed view changed | ||
datesAreDifferent(...values.map(value => getValueFrom(value, minDate, maxDate, maxDetail))) || | ||
datesAreDifferent(...values.map(value => getValueTo(value, minDate, maxDate, maxDetail))) | ||
nextState.view // Allowed view changed | ||
|| datesAreDifferent(...values.map(value => getValueFrom(value, minDate, maxDate, maxDetail))) | ||
|| datesAreDifferent(...values.map(value => getValueTo(value, minDate, maxDate, maxDetail))) | ||
) { | ||
@@ -218,6 +237,10 @@ nextState.value = nextProps.value; | ||
setActiveStartDate = (activeStartDate) => { | ||
const { onActiveDateChange } = this.props; | ||
this.setState({ activeStartDate }, () => { | ||
callIfDefined(this.props.onActiveDateChange, { | ||
const { view } = this.state; | ||
callIfDefined(onActiveDateChange, { | ||
activeStartDate, | ||
view: this.state.view, | ||
view, | ||
}); | ||
@@ -232,4 +255,6 @@ }); | ||
const views = getLimitedViews(this.props.minDetail, this.props.maxDetail); | ||
const { maxDetail, minDetail, onDrillDown } = this.props; | ||
const views = getLimitedViews(minDetail, maxDetail); | ||
this.setState((prevState) => { | ||
@@ -242,5 +267,7 @@ const nextView = views[views.indexOf(prevState.view) + 1]; | ||
}, () => { | ||
callIfDefined(this.props.onDrillDown, { | ||
const { view } = this.state; | ||
callIfDefined(onDrillDown, { | ||
activeStartDate, | ||
view: this.state.view, | ||
view, | ||
}); | ||
@@ -255,4 +282,6 @@ }); | ||
const views = getLimitedViews(this.props.minDetail, this.props.maxDetail); | ||
const { maxDetail, minDetail, onDrillUp } = this.props; | ||
const views = getLimitedViews(minDetail, maxDetail); | ||
this.setState((prevState) => { | ||
@@ -267,5 +296,7 @@ const nextView = views[views.indexOf(prevState.view) - 1]; | ||
}, () => { | ||
callIfDefined(this.props.onDrillUp, { | ||
activeStartDate: this.state.activeStartDate, | ||
view: this.state.view, | ||
const { activeStartDate, view } = this.state; | ||
callIfDefined(onDrillUp, { | ||
activeStartDate, | ||
view, | ||
}); | ||
@@ -284,4 +315,4 @@ }); | ||
if ( | ||
!previousValue || | ||
[].concat(previousValue).length !== 1 // 0 or 2 - either way we're starting a new array | ||
!previousValue | ||
|| [].concat(previousValue).length !== 1 // 0 or 2 - either way we're starting a new array | ||
) { | ||
@@ -319,2 +350,3 @@ // First value | ||
renderChildren, | ||
selectRange, | ||
tileClassName, | ||
@@ -335,3 +367,3 @@ tileContent, | ||
minDate, | ||
onMouseOver: this.props.selectRange ? onMouseOver : null, | ||
onMouseOver: selectRange ? onMouseOver : null, | ||
tileClassName, | ||
@@ -347,36 +379,54 @@ tileContent: tileContent || renderChildren, // For backwards compatibility | ||
switch (view) { | ||
case 'century': | ||
case 'century': { | ||
const { onClickDecade } = this.props; | ||
return ( | ||
<CenturyView | ||
onClick={mergeFunctions(clickAction, this.props.onClickDecade)} | ||
onClick={mergeFunctions(clickAction, onClickDecade)} | ||
{...commonProps} | ||
/> | ||
); | ||
case 'decade': | ||
} | ||
case 'decade': { | ||
const { onClickYear } = this.props; | ||
return ( | ||
<DecadeView | ||
onClick={mergeFunctions(clickAction, this.props.onClickYear)} | ||
onClick={mergeFunctions(clickAction, onClickYear)} | ||
{...commonProps} | ||
/> | ||
); | ||
case 'year': | ||
} | ||
case 'year': { | ||
const { formatMonth, onClickMonth } = this.props; | ||
return ( | ||
<YearView | ||
formatMonth={this.props.formatMonth} | ||
onClick={mergeFunctions(clickAction, this.props.onClickMonth)} | ||
formatMonth={formatMonth} | ||
onClick={mergeFunctions(clickAction, onClickMonth)} | ||
{...commonProps} | ||
/> | ||
); | ||
case 'month': | ||
} | ||
case 'month': { | ||
const { | ||
formatShortWeekday, | ||
onClickDay, | ||
onClickWeekNumber, | ||
showNeighboringMonth, | ||
showWeekNumbers, | ||
} = this.props; | ||
return ( | ||
<MonthView | ||
calendarType={calendarType} | ||
formatShortWeekday={this.props.formatShortWeekday} | ||
onClick={mergeFunctions(clickAction, this.props.onClickDay)} | ||
onClickWeekNumber={this.props.onClickWeekNumber} | ||
showNeighboringMonth={this.props.showNeighboringMonth} | ||
showWeekNumbers={this.props.showWeekNumbers} | ||
formatShortWeekday={formatShortWeekday} | ||
onClick={mergeFunctions(clickAction, onClickDay)} | ||
onClickWeekNumber={onClickWeekNumber} | ||
showNeighboringMonth={showNeighboringMonth} | ||
showWeekNumbers={showWeekNumbers} | ||
{...commonProps} | ||
/> | ||
); | ||
} | ||
default: | ||
@@ -394,19 +444,34 @@ throw new Error(`Invalid view: ${view}.`); | ||
const { | ||
formatMonthYear, | ||
locale, | ||
maxDate, | ||
maxDetail, | ||
minDate, | ||
minDetail, | ||
next2Label, | ||
nextLabel, | ||
navigationLabel, | ||
prev2Label, | ||
prevLabel, | ||
} = this.props; | ||
const { activeRange, activeStartDate, view } = this.state; | ||
return ( | ||
<Navigation | ||
activeRange={this.state.activeRange} | ||
activeStartDate={this.state.activeStartDate} | ||
activeRange={activeRange} | ||
activeStartDate={activeStartDate} | ||
drillUp={this.drillUp} | ||
formatMonthYear={this.props.formatMonthYear} | ||
locale={this.props.locale} | ||
maxDate={this.props.maxDate} | ||
minDate={this.props.minDate} | ||
next2Label={this.props.next2Label} | ||
nextLabel={this.props.nextLabel} | ||
navigationLabel={this.props.navigationLabel} | ||
prev2Label={this.props.prev2Label} | ||
prevLabel={this.props.prevLabel} | ||
formatMonthYear={formatMonthYear} | ||
locale={locale} | ||
maxDate={maxDate} | ||
minDate={minDate} | ||
next2Label={next2Label} | ||
nextLabel={nextLabel} | ||
navigationLabel={navigationLabel} | ||
prev2Label={prev2Label} | ||
prevLabel={prevLabel} | ||
setActiveStartDate={this.setActiveStartDate} | ||
view={this.state.view} | ||
views={getLimitedViews(this.props.minDetail, this.props.maxDetail)} | ||
view={view} | ||
views={getLimitedViews(minDetail, maxDetail)} | ||
/> | ||
@@ -461,4 +526,4 @@ ); | ||
navigationLabel: PropTypes.func, | ||
next2Label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]), | ||
nextLabel: PropTypes.oneOfType([PropTypes.string, PropTypes.node]), | ||
next2Label: PropTypes.node, | ||
nextLabel: PropTypes.node, | ||
onActiveDateChange: PropTypes.func, | ||
@@ -473,4 +538,4 @@ onChange: PropTypes.func, | ||
onDrillUp: PropTypes.func, | ||
prev2Label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]), | ||
prevLabel: PropTypes.oneOfType([PropTypes.string, PropTypes.node]), | ||
prev2Label: PropTypes.node, | ||
prevLabel: PropTypes.node, | ||
renderChildren: PropTypes.func, // For backwards compatibility | ||
@@ -477,0 +542,0 @@ returnValue: PropTypes.oneOf(['start', 'end', 'range']), |
@@ -369,3 +369,3 @@ import React from 'react'; | ||
expect(button.prop('disabled')).toBe(true); | ||
expect(button.prop('disabled')).toBeTruthy(); | ||
}); | ||
@@ -390,4 +390,4 @@ | ||
expect(prev2.prop('disabled')).toBe(true); | ||
expect(prev.prop('disabled')).toBe(true); | ||
expect(prev2.prop('disabled')).toBeTruthy(); | ||
expect(prev.prop('disabled')).toBeTruthy(); | ||
}); | ||
@@ -412,4 +412,4 @@ | ||
expect(next.prop('disabled')).toBe(true); | ||
expect(next2.prop('disabled')).toBe(true); | ||
expect(next.prop('disabled')).toBeTruthy(); | ||
expect(next2.prop('disabled')).toBeTruthy(); | ||
}); | ||
@@ -433,4 +433,4 @@ | ||
expect(prev2.prop('disabled')).toBe(true); | ||
expect(prev.prop('disabled')).toBe(true); | ||
expect(prev2.prop('disabled')).toBeTruthy(); | ||
expect(prev.prop('disabled')).toBeTruthy(); | ||
}); | ||
@@ -437,0 +437,0 @@ |
@@ -22,2 +22,3 @@ import React, { Component } from 'react'; | ||
nextProps.activeStartDate !== this.props.activeStartDate || | ||
nextProps.locale !== this.props.locale || | ||
nextProps.view !== this.props.view | ||
@@ -24,0 +25,0 @@ ); |
@@ -57,3 +57,3 @@ import React from 'react'; | ||
expect(component.find('.react-calendar__tile').prop('disabled')).toBe(true); | ||
expect(component.find('.react-calendar__tile').prop('disabled')).toBeTruthy(); | ||
}); | ||
@@ -82,3 +82,3 @@ | ||
expect(component.find('.react-calendar__tile').prop('disabled')).toBe(true); | ||
expect(component.find('.react-calendar__tile').prop('disabled')).toBeTruthy(); | ||
}); | ||
@@ -85,0 +85,0 @@ |
@@ -57,3 +57,3 @@ import React from 'react'; | ||
expect(component.find('.react-calendar__tile').prop('disabled')).toBe(true); | ||
expect(component.find('.react-calendar__tile').prop('disabled')).toBeTruthy(); | ||
}); | ||
@@ -82,3 +82,3 @@ | ||
expect(component.find('.react-calendar__tile').prop('disabled')).toBe(true); | ||
expect(component.find('.react-calendar__tile').prop('disabled')).toBeTruthy(); | ||
}); | ||
@@ -85,0 +85,0 @@ |
@@ -7,2 +7,4 @@ import Calendar from './Calendar'; | ||
// File is created during build phase and placed in dist directory | ||
// eslint-disable-next-line import/no-unresolved | ||
import './Calendar.css'; | ||
@@ -9,0 +11,0 @@ |
@@ -82,3 +82,3 @@ import React from 'react'; | ||
expect(component.find('.react-calendar__tile').prop('disabled')).toBe(true); | ||
expect(component.find('.react-calendar__tile').prop('disabled')).toBeTruthy(); | ||
}); | ||
@@ -107,3 +107,3 @@ | ||
expect(component.find('.react-calendar__tile').prop('disabled')).toBe(true); | ||
expect(component.find('.react-calendar__tile').prop('disabled')).toBeTruthy(); | ||
}); | ||
@@ -110,0 +110,0 @@ |
@@ -21,2 +21,1 @@ import { | ||
}); | ||
@@ -20,2 +20,1 @@ import once from 'lodash.once'; | ||
export const getDefaultLocale = once(() => getDefaultLocales()[0]); | ||
@@ -9,3 +9,3 @@ import PropTypes from 'prop-types'; | ||
export const isMinDate = (props, propName, componentName) => { | ||
const minDate = props[propName]; | ||
const { [propName]: minDate } = props; | ||
@@ -29,3 +29,3 @@ if (minDate) { | ||
export const isMaxDate = (props, propName, componentName) => { | ||
const maxDate = props[propName]; | ||
const { [propName]: maxDate } = props; | ||
@@ -61,3 +61,3 @@ if (maxDate) { | ||
export const isView = (props, propName, componentName) => { | ||
const view = props[propName]; | ||
const { [propName]: view } = props; | ||
const { views } = props; | ||
@@ -76,6 +76,8 @@ | ||
isView.isRequired = (props, propName, componentName) => { | ||
const view = props[propName]; | ||
const { [propName]: view } = props; | ||
if (!view) { | ||
return new Error(`The prop \`${propName}\` is marked as required in \`${componentName}\`, but its value is \`${view}\`.`); | ||
} | ||
return isView(props, propName, componentName); | ||
@@ -82,0 +84,0 @@ }; |
@@ -9,4 +9,4 @@ import { getRange } from './dates'; | ||
*/ | ||
export const mergeFunctions = (...functions) => (...args) => | ||
functions.filter(Boolean).forEach(f => f(...args)); | ||
export const mergeFunctions = (...functions) => (...args) => functions | ||
.filter(Boolean).forEach(f => f(...args)); | ||
@@ -25,14 +25,14 @@ /** | ||
export const isValueWithinRange = (value, range) => ( | ||
range[0] <= value && | ||
range[1] >= value | ||
range[0] <= value | ||
&& range[1] >= value | ||
); | ||
export const isRangeWithinRange = (greaterRange, smallerRange) => ( | ||
greaterRange[0] <= smallerRange[0] && | ||
greaterRange[1] >= smallerRange[1] | ||
greaterRange[0] <= smallerRange[0] | ||
&& greaterRange[1] >= smallerRange[1] | ||
); | ||
export const doRangesOverlap = (range1, range2) => ( | ||
isValueWithinRange(range1[0], range2) || | ||
isValueWithinRange(range1[1], range2) | ||
isValueWithinRange(range1[0], range2) | ||
|| isValueWithinRange(range1[1], range2) | ||
); | ||
@@ -69,5 +69,5 @@ | ||
if ( | ||
!date || | ||
(!(value instanceof Array) && !valueType) || | ||
(!(date instanceof Array) && !dateType) | ||
!date | ||
|| (!(value instanceof Array) && !valueType) | ||
|| (!(date instanceof Array) && !dateType) | ||
) { | ||
@@ -89,9 +89,9 @@ throw new Error('getTileClasses(): Unable to get tile activity classes because one or more required arguments were not passed.'); | ||
( | ||
dateRange[1] < valueRange[0] && | ||
isRangeWithinRange([hover, valueRange[0]], dateRange) | ||
) || | ||
dateRange[1] < valueRange[0] | ||
&& isRangeWithinRange([hover, valueRange[0]], dateRange) | ||
) | ||
// Date after value | ||
( | ||
dateRange[0] > valueRange[1] && | ||
isRangeWithinRange([valueRange[1], hover], dateRange) | ||
|| ( | ||
dateRange[0] > valueRange[1] | ||
&& isRangeWithinRange([valueRange[1], hover], dateRange) | ||
) | ||
@@ -98,0 +98,0 @@ ) |
@@ -56,3 +56,3 @@ import React from 'react'; | ||
expect(component.find('.react-calendar__tile').prop('disabled')).toBe(true); | ||
expect(component.find('.react-calendar__tile').prop('disabled')).toBeTruthy(); | ||
}); | ||
@@ -81,3 +81,3 @@ | ||
expect(component.find('.react-calendar__tile').prop('disabled')).toBe(true); | ||
expect(component.find('.react-calendar__tile').prop('disabled')).toBeTruthy(); | ||
}); | ||
@@ -84,0 +84,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
325372
22
8132