Skip to content

Commit

Permalink
Exposing onDayMouseEnter and onMonthMouseLeave callback
Browse files Browse the repository at this point in the history
  • Loading branch information
aviklai committed Mar 10, 2019
1 parent ad499a2 commit 010c807
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 31 deletions.
67 changes: 47 additions & 20 deletions docs-site/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,7 @@
});

for (
var es6Symbols = // 19.4.2.2, 19.4.2.3, 19.4.2.4, 19.4.2.6, 19.4.2.8, 19.4.2.9, 19.4.2.10, 19.4.2.11, 19.4.2.12, 19.4.2.13, 19.4.2.14
"hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables".split(
var es6Symbols = "hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables".split( // 19.4.2.2, 19.4.2.3, 19.4.2.4, 19.4.2.6, 19.4.2.8, 19.4.2.9, 19.4.2.10, 19.4.2.11, 19.4.2.12, 19.4.2.13, 19.4.2.14
","
),
j = 0;
Expand Down Expand Up @@ -24266,8 +24265,7 @@
},
/* 382 */
/***/ function(module, exports) {
module.exports
/**
module.exports = /**
* Known issues:
*
* - invalid hex string literals will be recognized as a double quoted strings
Expand All @@ -24281,7 +24279,7 @@
*
* - special token sequence rule is not strictly following D grammar (anything following #line
* up to the end of line is matched as special token sequence)
*/ = function(hljs) {
*/ function(hljs) {
/**
* Language keywords
*
Expand Down Expand Up @@ -28051,7 +28049,8 @@
},
/* 416 */
/***/ function(module, exports) {
module.exports = function(hljs) { // TODO support filter tags like :javascript, support inline HTML
module.exports = function(hljs) {
// TODO support filter tags like :javascript, support inline HTML
return {
case_insensitive: true,
contains: [
Expand Down Expand Up @@ -37805,7 +37804,8 @@
},
/* 479 */
/***/ function(module, exports) {
module.exports = function(hljs) { // Base deafult colors in PB IDE: background: #FFFFDF; foreground: #000000;
module.exports = function(hljs) {
// Base deafult colors in PB IDE: background: #FFFFDF; foreground: #000000;
var STRINGS = {
// PB IDE color: #0080FF (Azure Radiance)
className: "string",
Expand Down Expand Up @@ -43746,7 +43746,9 @@
_this.props.disabledKeyboardNavigation,
renderCustomHeader: _this.props.renderCustomHeader,
popperProps: _this.props.popperProps,
renderDayContents: _this.props.renderDayContents
renderDayContents: _this.props.renderDayContents,
onDayMouseEnter: _this.props.onDayMouseEnter,
onMonthMouseLeave: _this.props.onMonthMouseLeave
},
_this.props.children
);
Expand Down Expand Up @@ -44427,11 +44429,13 @@
};

_this.handleDayMouseEnter = function(day) {
return _this.setState({ selectingDate: day });
_this.setState({ selectingDate: day });
_this.props.onDayMouseEnter && _this.props.onDayMouseEnter(day);
};

_this.handleMonthMouseLeave = function() {
return _this.setState({ selectingDate: null });
_this.setState({ selectingDate: null });
_this.props.onMonthMouseLeave && _this.props.onMonthMouseLeave();
};

_this.handleYearChange = function(date) {
Expand Down Expand Up @@ -45062,7 +45066,9 @@
previousMonthButtonLabel: _propTypes2.default.string,
nextMonthButtonLabel: _propTypes2.default.string,
renderCustomHeader: _propTypes2.default.func,
renderDayContents: _propTypes2.default.func
renderDayContents: _propTypes2.default.func,
onDayMouseEnter: _propTypes2.default.func,
onMonthMouseLeave: _propTypes2.default.func
};
exports.default = Calendar;

Expand Down Expand Up @@ -46124,10 +46130,16 @@
}

function isDayInRange(day, startDate, endDate) {
return (0, _isWithinInterval2.default)(day, {
start: startDate,
end: endDate
});
var valid = void 0;
try {
valid = (0, _isWithinInterval2.default)(day, {
start: startDate,
end: endDate
});
} catch (err) {
valid = false;
}
return valid;
}

// *** Diffing ***
Expand Down Expand Up @@ -46158,7 +46170,7 @@
}

function getFormattedWeekdayInLocale(date, formatFunc, locale) {
return formatFunc(formatDate(date, "dddd", locale));
return formatFunc(formatDate(date, "EEEE", locale));
}

function getWeekdayMinInLocale(date, locale) {
Expand Down Expand Up @@ -46264,10 +46276,17 @@
(0, _setMinutes2.default)(base, (0, _getMinutes2.default)(maxTime)),
(0, _getHours2.default)(maxTime)
);
return !(0, _isWithinInterval2.default)(baseTime, {
start: min,
end: max
});

var valid = void 0;
try {
valid = !(0, _isWithinInterval2.default)(baseTime, {
start: min,
end: max
});
} catch (err) {
valid = false;
}
return valid;
}

function monthDisabledBefore(day) {
Expand Down Expand Up @@ -62934,6 +62953,14 @@
_react2.default.createElement(
"code",
{ className: "jsx" },
"// Note: Make sure to npm install the right version of date-fns as",
_react2.default.createElement("br", null),
"// specified in packaged.json. The default one may not be compatiable",
_react2.default.createElement("br", null),
"// npm install --save date-fns@version",
_react2.default.createElement("br", null),
"import DatePicker, { registerLocale } from 'react-datepicker';",
_react2.default.createElement("br", null),
"import enGB from 'date-fns/locale/en-GB';",
_react2.default.createElement("br", null),
"registerLocale('en-GB', enGB);",
Expand Down
14 changes: 11 additions & 3 deletions src/calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ export default class Calendar extends React.Component {
previousMonthButtonLabel: PropTypes.string,
nextMonthButtonLabel: PropTypes.string,
renderCustomHeader: PropTypes.func,
renderDayContents: PropTypes.func
renderDayContents: PropTypes.func,
onDayMouseEnter: PropTypes.func,
onMonthMouseLeave: PropTypes.func
};

static get defaultProps() {
Expand Down Expand Up @@ -216,9 +218,15 @@ export default class Calendar extends React.Component {
handleDayClick = (day, event, monthSelectedIn) =>
this.props.onSelect(day, event, monthSelectedIn);

handleDayMouseEnter = day => this.setState({ selectingDate: day });
handleDayMouseEnter = day => {
this.setState({ selectingDate: day });
this.props.onDayMouseEnter && this.props.onDayMouseEnter(day);
};

handleMonthMouseLeave = () => this.setState({ selectingDate: null });
handleMonthMouseLeave = () => {
this.setState({ selectingDate: null });
this.props.onMonthMouseLeave && this.props.onMonthMouseLeave();
};

handleYearChange = date => {
if (this.props.onYearChange) {
Expand Down
18 changes: 10 additions & 8 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ export default class DatePicker extends React.Component {
this.props.openToDate
? this.props.openToDate
: this.props.selectsEnd && this.props.startDate
? this.props.startDate
: this.props.selectsStart && this.props.endDate
? this.props.endDate
: newDate();
? this.props.startDate
: this.props.selectsStart && this.props.endDate
? this.props.endDate
: newDate();

calcInitialState = () => {
const defaultPreSelection = this.getPreSelection();
Expand All @@ -256,8 +256,8 @@ export default class DatePicker extends React.Component {
minDate && isBefore(defaultPreSelection, minDate)
? minDate
: maxDate && isAfter(defaultPreSelection, maxDate)
? maxDate
: defaultPreSelection;
? maxDate
: defaultPreSelection;
return {
open: this.props.startOpen || false,
preventFocus: false,
Expand Down Expand Up @@ -669,6 +669,8 @@ export default class DatePicker extends React.Component {
renderCustomHeader={this.props.renderCustomHeader}
popperProps={this.props.popperProps}
renderDayContents={this.props.renderDayContents}
onDayMouseEnter={this.props.onDayMouseEnter}
onMonthMouseLeave={this.props.onMonthMouseLeave}
>
{this.props.children}
</WrappedCalendar>
Expand All @@ -686,8 +688,8 @@ export default class DatePicker extends React.Component {
typeof this.props.value === "string"
? this.props.value
: typeof this.state.inputValue === "string"
? this.state.inputValue
: safeDateFormat(this.props.selected, this.props);
? this.state.inputValue
: safeDateFormat(this.props.selected, this.props);

return React.cloneElement(customInput, {
[customInputRef]: input => {
Expand Down

0 comments on commit 010c807

Please sign in to comment.