Skip to content

Commit 67e6a7e

Browse files
committed
New properties 'minDate' & 'maxDate'
1 parent e7850c4 commit 67e6a7e

File tree

7 files changed

+41
-8
lines changed

7 files changed

+41
-8
lines changed

components/date_picker/calendar/_config.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ $calendar-arrows-font-size: 2 * $unit;
88
$calendar-arrows-ripple-duration: 450ms;
99
$calendar-year-font-size: 2.4;
1010
$calendar-day-font-size: 1.3 * $unit;
11+
$calendar-day-disable-opacity: 0.25;
1112
$calendar-row-height: 3 * $unit;
1213
$calendar-day-padding: .2 * $unit;
1314
$calendar-total-height: $calendar-row-height * 8 + $calendar-day-padding * 12;

components/date_picker/calendar/day.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import style from './style';
55
class Day extends React.Component {
66
static propTypes = {
77
day: React.PropTypes.number,
8+
disabled: React.PropTypes.bool,
89
onClick: React.PropTypes.func,
910
selectedDate: React.PropTypes.object,
1011
viewDate: React.PropTypes.object
@@ -26,7 +27,9 @@ class Day extends React.Component {
2627
}
2728

2829
render () {
29-
const className = this.isSelected() ? `${style.day} ${style.active}` : style.day;
30+
let className = this.isSelected() ? `${style.day} ${style.active}` : style.day;
31+
if (this.props.disabled) className += ` ${style.disabled}`;
32+
3033
return (
3134
<div className={className} style={this.dayStyle()}>
3235
<span onClick={this.props.onClick}>

components/date_picker/calendar/index.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import style from './style';
1010
class Calendar extends React.Component {
1111
static propTypes = {
1212
display: React.PropTypes.oneOf(['months', 'years']),
13+
maxDate: React.PropTypes.object,
14+
minDate: React.PropTypes.object,
1315
onChange: React.PropTypes.func,
1416
selectedDate: React.PropTypes.object,
1517
viewDate: React.PropTypes.object
@@ -98,6 +100,8 @@ class Calendar extends React.Component {
98100
<CSSTransitionGroup transitionName={animation} transitionEnterTimeout={350} transitionLeaveTimeout={350}>
99101
<Month
100102
key={this.state.viewDate.getMonth()}
103+
maxDate={this.props.maxDate}
104+
minDate={this.props.minDate}
101105
viewDate={this.state.viewDate}
102106
selectedDate={this.props.selectedDate}
103107
onDayClick={this.handleDayClick} />

components/date_picker/calendar/month.jsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import style from './style';
55

66
class Month extends React.Component {
77
static propTypes = {
8+
maxDate: React.PropTypes.object,
9+
minDate: React.PropTypes.object,
810
onDayClick: React.PropTypes.func,
911
selectedDate: React.PropTypes.object,
1012
viewDate: React.PropTypes.object
@@ -22,11 +24,21 @@ class Month extends React.Component {
2224

2325
renderDays () {
2426
return utils.range(1, utils.time.getDaysInMonth(this.props.viewDate) + 1).map(i => {
27+
let active = true;
28+
29+
if (this.props.minDate || this.props.maxDate) {
30+
const date = new Date(this.props.viewDate.getFullYear(), this.props.viewDate.getMonth(), i);
31+
if (this.props.minDate && !(date >= this.props.minDate)) active = false;
32+
if (this.props.maxDate && !(date <= this.props.maxDate)) active = false;
33+
console.log('day', i, date, this.props.minDate, active);
34+
}
35+
2536
return (
2637
<Day
2738
key={i}
2839
day={i}
29-
onClick={this.handleDayClick.bind(this, i)}
40+
disabled={!active}
41+
onClick={active ? this.handleDayClick.bind(this, i) : null}
3042
selectedDate={this.props.selectedDate}
3143
viewDate={this.props.viewDate}
3244
/>
@@ -35,6 +47,7 @@ class Month extends React.Component {
3547
}
3648

3749
render () {
50+
console.info('max/min', this.props.maxDate, this.props.minDate);
3851
return (
3952
<div className={style.month}>
4053
<span className={style.title}>

components/date_picker/calendar/style.scss

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,19 @@
5050
.week {
5151
display: flex;
5252
height: $calendar-row-height;
53+
flex-wrap: wrap;
5354
font-size: $calendar-day-font-size;
5455
line-height: $calendar-row-height;
5556
opacity: .5;
56-
57-
flex-wrap: wrap;
5857
> span {
5958
flex: 0 0 (100% / 7);
6059
}
6160
}
6261

6362
.days {
6463
display: flex;
65-
font-size: $calendar-day-font-size;
66-
6764
flex-wrap: wrap;
65+
font-size: $calendar-day-font-size;
6866
}
6967

7068
.day {
@@ -75,17 +73,22 @@
7573
width: $calendar-row-height;
7674
height: $calendar-row-height;
7775
line-height: $calendar-row-height;
78-
cursor: pointer;
7976
border-radius: 50%;
8077
}
81-
&:hover:not(.active) > span {
78+
&:hover:not(.active):not(.disabled) > span {
8279
color: $calendar-primary-contrast-color;
8380
background: $calendar-primary-hover-color;
8481
}
8582
&.active > span {
8683
color: $calendar-primary-contrast-color;
8784
background: $calendar-primary-color;
8885
}
86+
&:hover:not(.disabled) > span {
87+
cursor: pointer;
88+
}
89+
&.disabled {
90+
opacity: $calendar-day-disable-opacity;
91+
}
8992
}
9093

9194
.month {

components/date_picker/dialog.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import Dialog from '../dialog';
77
class CalendarDialog extends React.Component {
88
static propTypes = {
99
active: React.PropTypes.bool,
10+
maxDate: React.PropTypes.object,
11+
minDate: React.PropTypes.object,
1012
onDismiss: React.PropTypes.func,
1113
onSelect: React.PropTypes.func,
1214
value: React.PropTypes.object
@@ -61,6 +63,8 @@ class CalendarDialog extends React.Component {
6163
<div className={style.wrapper}>
6264
<Calendar
6365
display={this.state.display}
66+
maxDate={this.props.maxDate}
67+
minDate={this.props.minDate}
6468
onChange={this.handleCalendarChange}
6569
selectedDate={this.state.date} />
6670
</div>

components/date_picker/index.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import style from './style';
77

88
class DatePicker extends React.Component {
99
static propTypes = {
10+
maxDate: React.PropTypes.object,
11+
minDate: React.PropTypes.object,
1012
onChange: React.PropTypes.func,
1113
value: React.PropTypes.object
1214
};
@@ -32,6 +34,7 @@ class DatePicker extends React.Component {
3234
render () {
3335
const { value } = this.props;
3436
const date = value ? `${value.getDate()} ${time.getFullMonth(value)} ${value.getFullYear()}` : null;
37+
3538
return (
3639
<div data-toolbox='date-picker'>
3740
<Input
@@ -44,6 +47,8 @@ class DatePicker extends React.Component {
4447
/>
4548
<CalendarDialog
4649
active={this.state.active}
50+
maxDate={this.props.maxDate}
51+
minDate={this.props.minDate}
4752
onDismiss={this.handleDismiss}
4853
onSelect={this.handleSelect}
4954
value={this.props.value}

0 commit comments

Comments
 (0)