From c0d84fe60367283b782f043f3dcb83ee6009b28c Mon Sep 17 00:00:00 2001
From: Wei Zhu
Date: Mon, 6 Nov 2017 11:49:30 +0800
Subject: [PATCH] Update examples
---
examples/antd-calendar.js | 45 +++++++++++-----------
examples/antd-month-calendar.js | 38 ++++++++++---------
examples/antd-range-calendar.js | 26 ++++++-------
examples/control-panel.js | 36 +++++++++---------
examples/full-calendar.js | 22 +++++------
examples/getCalendarContainer.js | 44 ++++++++++++----------
examples/start-end-range.js | 64 ++++++++++++++++----------------
examples/start-end.js | 51 ++++++++++++-------------
examples/week.js | 45 +++++++++++-----------
9 files changed, 188 insertions(+), 183 deletions(-)
diff --git a/examples/antd-calendar.js b/examples/antd-calendar.js
index f90c8ca4..950e5c32 100644
--- a/examples/antd-calendar.js
+++ b/examples/antd-calendar.js
@@ -3,6 +3,7 @@
import 'rc-calendar/assets/index.less';
import React from 'react';
import ReactDOM from 'react-dom';
+import PropTypes from 'prop-types';
import Calendar from 'rc-calendar';
import DatePicker from 'rc-calendar/src/Picker';
import zhCN from 'rc-calendar/src/locale/zh_CN';
@@ -63,45 +64,47 @@ function disabledDate(current) {
return current.valueOf() < date.valueOf(); // can not select days before today
}
-const Test = React.createClass({
- propTypes: {
- defaultValue: React.PropTypes.object,
- defaultCalendarValue: React.PropTypes.object,
- },
+class Demo extends React.Component {
+ static propTypes = {
+ defaultValue: PropTypes.object,
+ defaultCalendarValue: PropTypes.object,
+ }
- getInitialState() {
- return {
+ constructor(props) {
+ super(props);
+
+ this.state = {
showTime: true,
showDateInput: true,
disabled: false,
- value: this.props.defaultValue,
+ value: props.defaultValue,
};
- },
+ }
- onChange(value) {
+ onChange = (value) => {
console.log('DatePicker change: ', (value && value.format(format)));
this.setState({
value,
});
- },
+ }
- onShowTimeChange(e) {
+ onShowTimeChange = (e) => {
this.setState({
showTime: e.target.checked,
});
- },
+ }
- onShowDateInputChange(e) {
+ onShowDateInputChange = (e) => {
this.setState({
showDateInput: e.target.checked,
});
- },
+ }
- toggleDisabled() {
+ toggleDisabled = () => {
this.setState({
disabled: !this.state.disabled,
});
- },
+ }
render() {
const state = this.state;
@@ -180,8 +183,8 @@ const Test = React.createClass({
);
- },
-});
+ }
+}
function onStandaloneSelect(value) {
console.log('onStandaloneSelect');
@@ -219,10 +222,10 @@ ReactDOM.render((
-
+
-
+
diff --git a/examples/antd-month-calendar.js b/examples/antd-month-calendar.js
index 5b6b52c3..b2467f90 100644
--- a/examples/antd-month-calendar.js
+++ b/examples/antd-month-calendar.js
@@ -3,6 +3,7 @@
import 'rc-calendar/assets/index.less';
import React from 'react';
import ReactDOM from 'react-dom';
+import PropTypes from 'prop-types';
import MonthCalendar from 'rc-calendar/src/MonthCalendar';
import DatePicker from 'rc-calendar/src/Picker';
@@ -26,36 +27,39 @@ if (cn) {
const defaultCalendarValue = now.clone();
defaultCalendarValue.add(-1, 'month');
-const Test = React.createClass({
- propTypes: {
- defaultValue: React.PropTypes.object,
- },
- getInitialState() {
- return {
+class Demo extends React.Component {
+ static propTypes = {
+ defaultValue: PropTypes.object,
+ }
+
+ constructor(props) {
+ super(props);
+
+ this.state = {
showTime: true,
disabled: false,
- value: this.props.defaultValue,
+ value: props.defaultValue,
};
- },
+ }
- onChange(value) {
+ onChange = (value) => {
console.log(`DatePicker change: ${value && value.format(format)}`);
this.setState({
value,
});
- },
+ }
- onShowTimeChange(e) {
+ onShowTimeChange = (e) => {
this.setState({
showTime: e.target.checked,
});
- },
+ }
- toggleDisabled() {
+ toggleDisabled = () => {
this.setState({
disabled: !this.state.disabled,
});
- },
+ }
render() {
const state = this.state;
@@ -104,8 +108,8 @@ const Test = React.createClass({
);
- },
-});
+ }
+}
function onStandaloneSelect(value) {
console.log('month-calendar select', (value && value.format(format)));
@@ -145,7 +149,7 @@ ReactDOM.render(
/>
-
+
)
, document.getElementById('__react-content'));
diff --git a/examples/antd-range-calendar.js b/examples/antd-range-calendar.js
index bd132d8e..6cf77a3b 100644
--- a/examples/antd-range-calendar.js
+++ b/examples/antd-range-calendar.js
@@ -115,22 +115,20 @@ function onStandaloneSelect(value) {
console.log(format(value[0]), format(value[1]));
}
-const Test = React.createClass({
- getInitialState() {
- return {
- value: [],
- hoverValue: [],
- };
- },
+class Demo extends React.Component {
+ state = {
+ value: [],
+ hoverValue: [],
+ }
- onChange(value) {
+ onChange = (value) => {
console.log('onChange', value);
this.setState({ value });
- },
+ }
- onHoverChange(hoverValue) {
+ onHoverChange = (hoverValue) => {
this.setState({ hoverValue });
- },
+ }
render() {
const state = this.state;
@@ -168,8 +166,8 @@ const Test = React.createClass({
}
}
);
- },
-});
+ }
+}
ReactDOM.render(
@@ -193,6 +191,6 @@ ReactDOM.render(
-
+
, document.getElementById('__react-content'));
diff --git a/examples/control-panel.js b/examples/control-panel.js
index 6de7eb0c..0a8ac633 100644
--- a/examples/control-panel.js
+++ b/examples/control-panel.js
@@ -8,15 +8,14 @@ import RangeCalendar from 'rc-calendar/src/RangeCalendar';
import Select, { Option } from 'rc-select';
import 'rc-select/assets/index.css';
-const App = React.createClass({
- getInitialState() {
- return {
- mode: 'month',
- rangeStartMode: 'date',
- rangeEndMode: 'date',
- };
- },
- onModeChange(key) {
+class Demo extends React.Component {
+ state = {
+ mode: 'month',
+ rangeStartMode: 'date',
+ rangeEndMode: 'date',
+ };
+
+ onModeChange = (key) => {
return function _handleChange(e) {
let mode;
if (e && e.target) {
@@ -29,13 +28,16 @@ const App = React.createClass({
[key]: mode,
});
}.bind(this);
- },
- handlePanelChange(...args) {
+ }
+
+ handlePanelChange = (...args) => {
console.log('on panel change', ...args);
- },
- handleRangePanelChange(...args) {
+ }
+
+ handleRangePanelChange = (...args) => {
console.log('on range panel change', ...args);
- },
+ }
+
render() {
return (
@@ -78,7 +80,7 @@ const App = React.createClass({
/>
);
- },
-});
+ }
+}
-ReactDOM.render(, document.getElementById('__react-content'));
+ReactDOM.render(, document.getElementById('__react-content'));
diff --git a/examples/full-calendar.js b/examples/full-calendar.js
index 0e8b9658..2cf7ed64 100644
--- a/examples/full-calendar.js
+++ b/examples/full-calendar.js
@@ -32,17 +32,17 @@ function onSelect(value) {
console.log('select', value.format(format));
}
-const App = React.createClass({
- getInitialState() {
- return {
- type: 'month',
- };
- },
- onTypeChange(type) {
+class Demo extends React.Component {
+ state = {
+ type: 'month',
+ };
+
+ onTypeChange = (type) => {
this.setState({
type,
});
- },
+ }
+
render() {
return (
@@ -66,7 +66,7 @@ const App = React.createClass({
/>
);
- },
-});
+ }
+}
-ReactDOM.render(, document.getElementById('__react-content'));
+ReactDOM.render(, document.getElementById('__react-content'));
diff --git a/examples/getCalendarContainer.js b/examples/getCalendarContainer.js
index a70ccc45..fe3c4fd1 100644
--- a/examples/getCalendarContainer.js
+++ b/examples/getCalendarContainer.js
@@ -26,32 +26,36 @@ if (cn) {
const defaultCalendarValue = now.clone();
defaultCalendarValue.add(-1, 'month');
-const Test = React.createClass({
- getInitialState() {
- return {
- open: false,
- destroy: false,
- };
- },
+class Demo extends React.Component {
+ state = {
+ open: false,
+ destroy: false,
+ };
+
getCalendarContainer() {
- return this.refs.d || document.getElementById('d');
- },
+ return this.d || document.getElementById('d');
+ }
+
setVisible(open) {
this.setState({
open,
});
- },
- open() {
+ }
+
+ open = () => {
this.setVisible(true);
- },
- close() {
+ }
+
+ close = () => {
this.setVisible(false);
- },
- destroy() {
+ }
+
+ destroy = () => {
this.setState({
destroy: true,
});
- },
+ }
+
render() {
if (this.state.destroy) {
return null;
@@ -61,7 +65,7 @@ const Test = React.createClass({
);
- },
-});
+ }
+}
-ReactDOM.render(, document.getElementById('__react-content'));
+ReactDOM.render(, document.getElementById('__react-content'));
diff --git a/examples/week.js b/examples/week.js
index 025d4c66..245b98e0 100644
--- a/examples/week.js
+++ b/examples/week.js
@@ -3,6 +3,7 @@
import 'rc-calendar/assets/index.less';
import React from 'react';
import ReactDOM from 'react-dom';
+import PropTypes from 'prop-types';
import Calendar from 'rc-calendar';
import DatePicker from 'rc-calendar/src/Picker';
import zhCN from 'rc-calendar/src/locale/zh_CN';
@@ -49,33 +50,31 @@ const style = `
}
`;
-const Test = React.createClass({
- propTypes: {
- defaultValue: React.PropTypes.object,
- defaultCalendarValue: React.PropTypes.object,
- },
+class Demo extends React.Component {
+ static propTypes = {
+ defaultValue: PropTypes.object,
+ defaultCalendarValue: PropTypes.object,
+ }
- getInitialState() {
- return {
- value: undefined,
- open: false,
- };
- },
+ state = {
+ value: undefined,
+ open: false,
+ };
- onChange(value) {
+ onChange = (value) => {
console.log('DatePicker change: ', (value && value.format(format)));
this.setState({
value,
});
- },
+ }
- onOpenChange(open) {
+ onOpenChange = (open) => {
this.setState({
open,
});
- },
+ }
- dateRender(current) {
+ dateRender = (current) => {
const selectedValue = this.state.value;
if (selectedValue && current.year() === selectedValue.year() &&
current.week() === selectedValue.week()) {
@@ -89,23 +88,23 @@ const Test = React.createClass({
{current.date()}
);
- },
+ }
- lastWeek() {
+ lastWeek = () => {
const value = this.state.value || now;
value.add(-1, 'weeks');
this.setState({
value,
open: false,
});
- },
+ }
renderSidebar() {
return (
);
- },
+ }
render() {
const state = this.state;
@@ -159,8 +158,8 @@ const Test = React.createClass({
);
- },
-});
+ }
+}
ReactDOM.render((), document.getElementById('__react-content'));