Skip to content

Commit

Permalink
optimize disabledDate
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe committed Jan 8, 2015
1 parent a1027db commit a0d7d4e
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
root = true

# Unix-style newlines with a newline ending every file
[*.{js,css}]
[*.{js,css,md}]
end_of_line = lf
insert_final_newline = true
indent_style = space
Expand Down
7 changes: 6 additions & 1 deletion assets/bootstrap/picker.less
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,15 @@
}

.rc-calendar-last-month-cell .rc-calendar-date,
.rc-calendar-next-month-btn-day .rc-calendar-date {
.rc-calendar-next-month-btn-day .rc-calendar-date,
.rc-calendar-disabled-cell .rc-calendar-date {
color: #bfbfbf;
}

.rc-calendar-disabled-cell:hover {
background: #ffffff;
}

.rc-calendar-disabled-cell .rc-calendar-date {
cursor: default;
}
Expand Down
6 changes: 6 additions & 0 deletions assets/classic/Picker.less
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
}

.classic-calendar-last-month-cell .classic-calendar-date,
.classic-calendar-disabled-cell .classic-calendar-date,
.classic-calendar-next-month-btn-day .classic-calendar-date {
color: #bfbfbf;
}
Expand All @@ -182,6 +183,11 @@
border-color: #88b1ea;
}

.classic-calendar-disabled-cell .classic-calendar-date:hover {
background-color: #ffffff;
border-color: transparent;
}

.classic-calendar-disabled-cell .classic-calendar-date {
cursor: default;
}
Expand Down
41 changes: 39 additions & 2 deletions examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,47 @@ React.render(
<h2>calendar (en-us, U.S.A. California San Francisco)</h2>
<Calendar showWeekNumber={true}
showTime={true}
onSelect={onSelect} prefixCls='classic-calendar'/>
onSelect={onSelect} prefixCls="classic-calendar"/>
</div>, document.getElementById('react-content-standalone2'));
````

## disable date

<link rel="stylesheet" href="../assets/bootstrap.css">

````html
<div id='react-content-standalone3'></div>
````

````js
/** @jsx React.DOM */
var Calendar = require('../');
var GregorianCalendarFormat = require('gregorian-calendar-format');
var React = require('react');
var formatter = new GregorianCalendarFormat('yyyy-MM-dd HH:mm:ss');

function onSelect(value) {
console.log('onSelect');
console.log(formatter.format(value))
}

function disabledDate(current,value){
var date = new Date();
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
return current.getTime() < date.getTime(); //can not select days before today
}

React.render(
<div>
<h2>calendar (en-us, U.S.A. California San Francisco)</h2>
<Calendar showWeekNumber={true}
disabledDate={disabledDate}
onSelect={onSelect}/>
</div>, document.getElementById('react-content-standalone3'));
````


## render with input

Expand All @@ -78,4 +115,4 @@ React.render(
<h2>input (zh-cn, Beijing)</h2>
<CalendarInput />
</div>, document.getElementById('react-content-input'));
````
````
7 changes: 2 additions & 5 deletions lib/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ var Calendar = React.createClass({

chooseDay: function (current) {
var props = this.props;
var disabledDate = props.disabledDate;
if (disabledDate && disabledDate(current, this.state.value)) {
return;
}
this.setState({
value: current
});
Expand Down Expand Up @@ -334,8 +330,9 @@ var Calendar = React.createClass({
{current.getDayOfMonth()}
</span>);
}

dateCells.push(
<td key={passed} onClick={this.chooseDay.bind(this, current)} role="gridcell" title={dateFormatter.format(current)} className = {cls}>
<td key={passed} onClick={disabled ? noop : this.chooseDay.bind(this, current)} role="gridcell" title={dateFormatter.format(current)} className = {cls}>
{dateHtml}
</td>);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-calendar",
"version": "1.4.0",
"version": "1.4.1",
"description": "calendar ui component for react",
"keywords": [
"react",
Expand Down

0 comments on commit a0d7d4e

Please sign in to comment.