Skip to content

Commit

Permalink
fix utils.getMonthsForYear() to account for months shorter than that …
Browse files Browse the repository at this point in the history
…of the selected date; resolves clauderic#140
  • Loading branch information
meta-meta committed Oct 31, 2017
1 parent c776d13 commit 9e8bf2f
Show file tree
Hide file tree
Showing 4 changed files with 2,017 additions and 1,234 deletions.
1 change: 1 addition & 0 deletions demo/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ import './demo.css';
render(
<InfiniteCalendar
width={Math.min(window.innerWidth, 400)}
display="years"
/>
, document.querySelector('#demo'));
5 changes: 4 additions & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ export function getDateString(year, month, date) {
}

export function getMonthsForYear(year, day = 1) {
return Array.apply(null, Array(12)).map((val, index) => new Date(year, index, day));
return Array.apply(null, Array(12)).map((val, index) => {
const constrainedDay = Math.min(getDaysInMonth(new Date(year, index, 1)), day);
return new Date(year, index, constrainedDay);
});
}

export const withImmutableProps = (props) => withPropsOnChange(() => false, props);
Expand Down
40 changes: 32 additions & 8 deletions styles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
imported from Day.scss
*/

.Cal__Day__root {
display: inline-block;
box-sizing: border-box;
Expand Down Expand Up @@ -149,6 +153,8 @@
box-sizing: border-box; }
.Cal__Day__range.Cal__Day__selected.Cal__Day__end .Cal__Day__selection .Cal__Day__day {
top: 4px; }
/* imported from Container.scss */

.Cal__Container__root {
position: relative;
display: table;
Expand All @@ -175,6 +181,8 @@
position: relative;
overflow: hidden;
background-color: #FFF; }
/* imported from Header.scss */

.Cal__Header__root {
position: relative;
display: flex;
Expand Down Expand Up @@ -258,6 +266,18 @@
.Cal__Header__range .Cal__Header__wrapper .Cal__Header__date {
white-space: nowrap;
z-index: 1; }
/* imported from MonthList.scss */

.Cal__MonthList__root {
width: 100% !important;
background-color: #FFF;
-webkit-overflow-scrolling: touch; }
.Cal__MonthList__root.Cal__MonthList__scrolling > div {
pointer-events: none; }
.Cal__MonthList__root.Cal__MonthList__scrolling label {
opacity: 1; }
/* imported from Today.scss */

.Cal__Today__root {
position: absolute;
top: 0;
Expand Down Expand Up @@ -292,14 +312,8 @@
transform: rotate(180deg); }
.Cal__Today__root.Cal__Today__chevronDown .Cal__Today__chevron {
transform: rotate(360deg); }
.Cal__MonthList__root {
width: 100% !important;
background-color: #FFF;
-webkit-overflow-scrolling: touch; }
.Cal__MonthList__root.Cal__MonthList__scrolling > div {
pointer-events: none; }
.Cal__MonthList__root.Cal__MonthList__scrolling label {
opacity: 1; }
/* imported from Weekdays.scss */

.Cal__Weekdays__root {
position: relative;
z-index: 5;
Expand All @@ -315,6 +329,8 @@
flex-grow: 1;
font-weight: 500;
text-align: center; }
/* imported from Years.scss */

.Cal__Years__root {
position: absolute;
left: 0;
Expand Down Expand Up @@ -423,6 +439,8 @@
padding-top: 40px; }
.Cal__Years__year.Cal__Years__last {
padding-bottom: 40px; }
/* imported from Animation.scss */

.Cal__Animation__enter {
opacity: 0;
transform: translate3d(0, -100%, 0);
Expand All @@ -439,6 +457,8 @@
.Cal__Animation__leave.Cal__Animation__leaveActive {
opacity: 0;
transform: translate3d(0, 100%, 0); }
/* imported from Slider.scss */

.Cal__Slider__root, .Cal__Slider__slide {
position: absolute;
top: 0;
Expand Down Expand Up @@ -481,6 +501,8 @@
.Cal__Slider__arrowLeft {
left: 0;
transform: scaleX(-1); }
/* imported from transition.scss */

.Cal__transition__enter {
opacity: 0; }

Expand All @@ -494,6 +516,8 @@
.Cal__transition__leaveActive {
opacity: 0;
transition: opacity 0.3s ease; }
/* imported from Month.scss */

.Cal__Month__rows {
position: relative;
background: linear-gradient(to bottom, rgba(255, 255, 255, 0) 50%, rgba(0, 0, 0, 0.05) 100%); }
Expand Down
Loading

0 comments on commit 9e8bf2f

Please sign in to comment.