diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 000000000..714a80b40 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,13 @@ +module.exports = { + extends: [require.resolve('@umijs/fabric/dist/eslint')], + rules: { + 'default-case': 0, + 'react/sort-comp': 0, + 'jsx-a11y/no-noninteractive-tabindex': 0, + 'jsx-a11y/interactive-supports-focus': 0, + 'react/no-array-index-key': 0, + 'react/jsx-boolean-value': 0, + 'jsx-a11y/anchor-has-content': 0, + 'import/no-extraneous-dependencies': ['error', { devDependencies: true }], + }, +}; diff --git a/.fatherrc.js b/.fatherrc.js new file mode 100644 index 000000000..767a2abfe --- /dev/null +++ b/.fatherrc.js @@ -0,0 +1,8 @@ +export default { + cjs: 'babel', + esm: { type: 'babel', importLibToEs: true }, + preCommit: { + eslint: true, + prettier: true, + }, +}; diff --git a/.gitignore b/.gitignore index 04f78bff4..8d13dccbe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.storybook *.iml *.log .idea/ @@ -27,4 +28,6 @@ lib es coverage yarn.lock -.vscode \ No newline at end of file +.vscode +package-lock.json +.doc diff --git a/.travis.yml b/.travis.yml index cc7daab5d..7aff03e0c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ notifications: - hust2012jiangkai@gmail.com node_js: -- 6.9.1 +- 10 before_install: - | diff --git a/HISTORY.md b/HISTORY.md index 6ac5a72ae..d9ba8dc31 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,42 @@ # History ----- + +--- + +## 9.15.0 / 2019-05-26 + +- Support Malay locales + +## 9.15.0 / 2019-06-06 + +- Add numeric keyboard support + +## 9.14.0 / 2019-05-24 + +- Support Latvian locales + +## 9.13.0 / 2019-04-02 + +- Support close onBlur + +## 9.12.0 / 2019-03-16 + +- RangerPicker support null as start or end + +## 9.11.0 / 2019-03-14 + +- RangerPicker can select same month + +## 9.10.0 / 2019-01-02 + +- add `focusablePanel` prop. + +## 9.9.0 / 2018-12-23 + +- `renderFooter(mode)` support all modes. + +## 9.8.0 / 2018-11-30 + +- DateInput support multiple date format ## 9.7.0 / 2018-08-07 @@ -22,9 +59,11 @@ - React 16 support ## 9.1.0 / 2017-07-27 + - Support control panel [#284](https://github.com/react-component/calendar/pull/284) ## 9.0.0 / 2017-07-27 + - Replace react string refs with function way [#282](https://github.com/react-component/calendar/pull/282) ## 8.4.0 / 2017-05-31 @@ -202,8 +241,7 @@ upgrade to react 0.13 and es6 ## 2.0.0 / 2015-03-04 -`new` [#15](https://github.com/react-component/calendar/issues/15) support defaultValue -`improved` upgrade gregorian-calendar and gregorian-calendar-format to 3.x +`new` [#15](https://github.com/react-component/calendar/issues/15) support defaultValue `improved` upgrade gregorian-calendar and gregorian-calendar-format to 3.x ## 1.5.0 / 2015-01-22 @@ -211,18 +249,18 @@ upgrade to react 0.13 and es6 ## 1.4.0 / 2015-01-05 -`new` [#12](https://github.com/react-component/calendar/issues/12) support time select ([@yiminghe](https://github.com/yiminghe)) +`new` [#12](https://github.com/react-component/calendar/issues/12) support time select ([@yiminghe](https://github.com/yiminghe)) -`new` [#11](https://github.com/react-component/calendar/issues/11) support prefixCls ([@yiminghe](https://github.com/yiminghe)) +`new` [#11](https://github.com/react-component/calendar/issues/11) support prefixCls ([@yiminghe](https://github.com/yiminghe)) -`new` [#10](https://github.com/react-component/calendar/issues/10) support nextMonth previousMonth in calendar panel ([@yiminghe](https://github.com/yiminghe)) +`new` [#10](https://github.com/react-component/calendar/issues/10) support nextMonth previousMonth in calendar panel ([@yiminghe](https://github.com/yiminghe)) ## 1.3.0 / 2014-12-30 -`new` [#9](https://github.com/react-component/calendar/issues/9) support className prop ([@yiminghe](https://github.com/yiminghe)) +`new` [#9](https://github.com/react-component/calendar/issues/9) support className prop ([@yiminghe](https://github.com/yiminghe)) -`new` [#8](https://github.com/react-component/calendar/issues/8) support orient prop ([@yiminghe](https://github.com/yiminghe)) +`new` [#8](https://github.com/react-component/calendar/issues/8) support orient prop ([@yiminghe](https://github.com/yiminghe)) ## 1.2.4 / 2014-12-26 -`new` [#7](https://github.com/react-component/calendar/issues/7) release 1.2.4 ([@yiminghe](https://github.com/yiminghe)) +`new` [#7](https://github.com/react-component/calendar/issues/7) release 1.2.4 ([@yiminghe](https://github.com/yiminghe)) diff --git a/README.md b/README.md index 8febbe8b1..ca0975b1d 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,10 @@ # rc-calendar ---- + +[Deprecated] `rc-calendar` is deprecated. Please use `rc-picker` instead. React Calendar -[![NPM version][npm-image]][npm-url] -[![build status][travis-image]][travis-url] -[![Test coverage][codecov-image]][codecov-url] -[![gemnasium deps][gemnasium-image]][gemnasium-url] -[![npm download][download-image]][download-url] -[![Code Quality: Javascript][lgtm-badge]][lgtm-badge-url] -[![Total alerts][lgtm-alerts]][lgtm-alerts-url] +[![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![Test coverage][codecov-image]][codecov-url] [![gemnasium deps][gemnasium-image]][gemnasium-url] [![npm download][download-image]][download-url] [![Code Quality: Javascript][lgtm-badge]][lgtm-badge-url] [![Total alerts][lgtm-alerts]][lgtm-alerts-url] [npm-image]: http://img.shields.io/npm/v/rc-calendar.svg?style=flat-square [npm-url]: http://npmjs.org/package/rc-calendar @@ -40,21 +35,21 @@ React Calendar ## Feature -* support ie9,ie9+,chrome,firefox,safari -* support date, month, year, decade select panel -* support week number -* support en_US and zh_CN locale(UI), use moment.utcOffset to set timezone -* support aria and keyboard accessibility +- support ie9,ie9+,chrome,firefox,safari +- support date, month, year, decade select panel +- support week number +- support en_US and zh_CN locale(UI), use moment.utcOffset to set timezone +- support aria and keyboard accessibility ### Keyboard -* Previous month (PageUp) -* Next month (PageDown) -* tab into hour input: Last hour(Up), Next hour(Down) -* tab into hour input: Last minute(Up), Next minute(Down) -* tab into hour input: Last second(Up), Next second(Down) -* Last year (Control + left) -* Next year (Control + right) +- Previous month (PageUp) +- Next month (PageDown) +- tab into hour input: Last hour(Up), Next hour(Down) +- tab into hour input: Last minute(Up), Next minute(Down) +- tab into hour input: Last second(Up), Next second(Down) +- Last year (Control + left) +- Next year (Control + right) ## install @@ -130,7 +125,7 @@ http://react-component.github.io/calendar/examples/index.html renderFooter - () => React.Node + (mode) => React.Node extra footer @@ -154,9 +149,10 @@ http://react-component.github.io/calendar/examples/index.html format - String + String | String[] depends on whether you set timePicker and your locale - use to format/parse date(without time) value to/from input + use to format/parse date(without time) value to/from input. + When an array is provided, all values are used for parsing and first value for display. disabledDate @@ -218,6 +214,12 @@ http://react-component.github.io/calendar/examples/index.html called when a date is changed inside calendar (next year/next month/keyboard) + + onOk + Function(date: moment) + + called when ok button is pressed, only if it's visible + dateInputPlaceholder String @@ -242,10 +244,15 @@ http://react-component.github.io/calendar/examples/index.html specific the clear icon. + + inputMode + string + text + Change the keyboard in mobile device + - ### rc-calendar/lib/RangeCalendar props @@ -372,6 +379,12 @@ http://react-component.github.io/calendar/examples/index.html + + + + + + @@ -495,12 +508,6 @@ http://react-component.github.io/calendar/examples/index.html - - - - - - @@ -718,7 +725,6 @@ http://react-component.github.io/calendar/examples/index.html ``` npm test -npm run chrome-test ``` ## Coverage diff --git a/assets/index/DecadePanel.less b/assets/index/DecadePanel.less index 97ac157ce..f83c591d0 100644 --- a/assets/index/DecadePanel.less +++ b/assets/index/DecadePanel.less @@ -7,6 +7,8 @@ z-index: 10; position: absolute; outline: none; + display: flex; + flex-direction: column; } .@{prefixClass}-decade-panel-hidden { @@ -62,10 +64,13 @@ } .@{prefixClass}-decade-panel-body { + flex: 1; padding: 9px 10px 10px; - position: absolute; - bottom: 0; - top: 34px; +} + +.@{prefixClass}-decade-panel-footer { + border-top: 1px solid #ccc; + line-height: 38px; } .@{prefixClass}-decade-panel-table { diff --git a/assets/index/MonthPanel.less b/assets/index/MonthPanel.less index b65f4666a..1b35f0e6b 100644 --- a/assets/index/MonthPanel.less +++ b/assets/index/MonthPanel.less @@ -7,6 +7,12 @@ z-index: 10; position: absolute; outline: none; + + > div { + height: 100%; + display: flex; + flex-direction: column; + } } .@{prefixClass}-month-panel-hidden { @@ -71,10 +77,13 @@ } .@{prefixClass}-month-panel-body { + flex: 1; padding: 9px 10px 10px; - position: absolute; - top: 34px; - bottom: 0; +} + +.@{prefixClass}-month-panel-footer { + border-top: 1px solid #ccc; + line-height: 38px; } .@{prefixClass}-month-panel-table { diff --git a/assets/index/YearPanel.less b/assets/index/YearPanel.less index f629d2e9f..6b31dc8ec 100644 --- a/assets/index/YearPanel.less +++ b/assets/index/YearPanel.less @@ -7,6 +7,12 @@ z-index: 10; position: absolute; outline: none; + + > div { + height: 100%; + display: flex; + flex-direction: column; + } } .@{prefixClass}-year-panel-hidden { @@ -71,10 +77,13 @@ } .@{prefixClass}-year-panel-body { + flex: 1; padding: 9px 10px 10px; - position: absolute; - bottom: 0; - top: 34px; +} + +.@{prefixClass}-year-panel-footer { + border-top: 1px solid #ccc; + line-height: 38px; } .@{prefixClass}-year-panel-table { diff --git a/examples/antd-calendar.html b/examples/antd-calendar.html deleted file mode 100644 index b3a425249..000000000 --- a/examples/antd-calendar.html +++ /dev/null @@ -1 +0,0 @@ -placeholder \ No newline at end of file diff --git a/examples/antd-calendar.js b/examples/antd-calendar.js index 6e9172694..fc2f400bd 100644 --- a/examples/antd-calendar.js +++ b/examples/antd-calendar.js @@ -1,22 +1,21 @@ /* eslint react/no-multi-comp:0, no-console:0 */ -import 'rc-calendar/assets/index.less'; +import '../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'; -import enUS from 'rc-calendar/src/locale/en_US'; -import 'rc-time-picker/assets/index.css'; +import moment from 'moment'; import TimePickerPanel from 'rc-time-picker/lib/Panel'; -import moment from 'moment'; +import Calendar from '../src'; +import DatePicker from '../src/Picker'; +import zhCN from '../src/locale/zh_CN'; +import enUS from '../src/locale/en_US'; +import 'rc-time-picker/assets/index.css'; + import 'moment/locale/zh-cn'; import 'moment/locale/en-gb'; const format = 'YYYY-MM-DD HH:mm:ss'; -const cn = location.search.indexOf('cn') !== -1; +const cn = window.location.search.indexOf('cn') !== -1; const now = moment(); if (cn) { @@ -29,7 +28,6 @@ function getFormat(time) { return time ? format : 'YYYY-MM-DD'; } - const defaultCalendarValue = now.clone(); defaultCalendarValue.add(-1, 'month'); @@ -37,7 +35,7 @@ const timePickerElement = { - console.log('DatePicker change: ', (value && value.format(format))); + 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, }); - } + }; + + onOpenChange = open => { + this.setState({ + open, + }); + }; + + onFocus = () => { + if (!this.state.open && this.state.isMouseDown) { + // focus from a "click" event, let the picker trigger automatically open the calendar + this.setState({ + isMouseDown: false, + }); + } else { + // focus not caused by "click" (such as programmatic or via keyboard) + this.setState({ + open: true, + }); + } + }; + + onMouseDown = () => { + this.setState({ + isMouseDown: true, + }); + }; + + getCalendarContainer = () => this.calendarContainerRef.current; toggleDisabled = () => { + const { disabled } = this.state; this.setState({ - disabled: !this.state.disabled, + disabled: !disabled, }); - } + }; render() { - const state = this.state; - const calendar = (); - return (
-
- -      - -      - -
-
- + ); + return ( +
+
+ +      + +      + +
+
- { - ({ value }) => { - return ( - + + {({ value }) => ( + - - ); - } - } - +
+ + )} + +
+
+ ); + } +} + +const multiFormats = ['DD/MM/YYYY', 'DD/MM/YY', 'DDMMYY', 'D/M/YY']; + +class DemoMultiFormat extends React.Component { + constructor(props) { + super(props); + + this.state = { + value: now, + }; + } + + onChange = value => { + console.log('Calendar change: ', value && value.format(format)); + this.setState({ + value, + }); + }; + + render() { + const { state } = this; + return ( +
+
+ Accepts multiple input formats +
+ {multiFormats.join(', ')} +
+
+
-
); + ); } } @@ -196,38 +271,58 @@ function onStandaloneChange(value) { console.log(value && value.format(format)); } - -ReactDOM.render((
-
-
- 'extra footer'} - /> -
-
- -
-
- +export default () => ( +
+
+
+ {mode} extra footer} + /> +
+
+

disabled today select time

+ current && current <= moment()} + onSelect={onStandaloneSelect} + renderFooter={mode => {mode} extra footer} + /> +
+
+ +
+
+ +
+
+
+ +
-
-
), document.getElementById('__react-content')); +); diff --git a/examples/antd-month-calendar.html b/examples/antd-month-calendar.html deleted file mode 100644 index b3a425249..000000000 --- a/examples/antd-month-calendar.html +++ /dev/null @@ -1 +0,0 @@ -placeholder \ No newline at end of file diff --git a/examples/antd-month-calendar.js b/examples/antd-month-calendar.js index 15ed13f29..a84a0f971 100644 --- a/examples/antd-month-calendar.js +++ b/examples/antd-month-calendar.js @@ -1,21 +1,19 @@ /* eslint react/no-multi-comp:0, no-console:0 */ -import 'rc-calendar/assets/index.less'; +import '../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'; +import moment from 'moment'; +import MonthCalendar from '../src/MonthCalendar'; +import DatePicker from '../src/Picker'; -import zhCN from 'rc-calendar/src/locale/zh_CN'; -import enUS from 'rc-calendar/src/locale/en_US'; +import zhCN from '../src/locale/zh_CN'; +import enUS from '../src/locale/en_US'; -import moment from 'moment'; import 'moment/locale/zh-cn'; import 'moment/locale/en-gb'; const format = 'YYYY-MM'; -const cn = location.search.indexOf('cn') !== -1; +const cn = window.location.search.indexOf('cn') !== -1; const now = moment(); if (cn) { @@ -28,100 +26,88 @@ const defaultCalendarValue = now.clone(); defaultCalendarValue.add(-1, 'month'); class Demo extends React.Component { - static propTypes = { - defaultValue: PropTypes.object, - } - constructor(props) { super(props); this.state = { - showTime: true, disabled: false, value: props.defaultValue, }; } - onChange = (value) => { + onChange = value => { console.log(`DatePicker change: ${value && value.format(format)}`); this.setState({ value, }); - } - - onShowTimeChange = (e) => { - this.setState({ - showTime: e.target.checked, - }); - } + }; toggleDisabled = () => { + const { disabled } = this.state; this.setState({ - disabled: !this.state.disabled, + disabled: !disabled, }); - } + }; render() { - const state = this.state; - const calendar = (); - return (
-
-      - -
-
- ; + return ( +
+
+      + +
+
- { - ({ value }) => { - return ( + {({ value }) => ( + ); - } - } - - + /> + )} + +
-
); + ); } } function onStandaloneSelect(value) { - console.log('month-calendar select', (value && value.format(format))); + console.log('month-calendar select', value && value.format(format)); } function onStandaloneChange(value) { - console.log('month-calendar change', (value && value.format(format))); + console.log('month-calendar change', value && value.format(format)); } function disabledDate(value) { - return value.year() > now.year() || - value.year() === now.year() && value.month() > now.month(); + return value.year() > now.year() || (value.year() === now.year() && value.month() > now.month()); } function onMonthCellContentRender(value) { @@ -129,8 +115,8 @@ function onMonthCellContentRender(value) { return `${value.month() + 1}月`; } -ReactDOM.render( - (
( +
-
) - , document.getElementById('__react-content')); +
+); diff --git a/examples/antd-range-calendar.html b/examples/antd-range-calendar.html deleted file mode 100644 index b3a425249..000000000 --- a/examples/antd-range-calendar.html +++ /dev/null @@ -1 +0,0 @@ -placeholder \ No newline at end of file diff --git a/examples/antd-range-calendar.js b/examples/antd-range-calendar.js index 717d77a19..ec7e52486 100644 --- a/examples/antd-range-calendar.js +++ b/examples/antd-range-calendar.js @@ -1,20 +1,20 @@ /* eslint react/no-multi-comp:0, no-console:0 */ import React from 'react'; -import ReactDOM from 'react-dom'; -import Picker from 'rc-calendar/src/Picker'; -import RangeCalendar from 'rc-calendar/src/RangeCalendar'; -import zhCN from 'rc-calendar/src/locale/zh_CN'; -import enUS from 'rc-calendar/src/locale/en_US'; +import moment from 'moment'; import TimePickerPanel from 'rc-time-picker/lib/Panel'; -import 'rc-calendar/assets/index.less'; + +import Picker from '../src/Picker'; +import RangeCalendar from '../src/RangeCalendar'; +import zhCN from '../src/locale/zh_CN'; +import enUS from '../src/locale/en_US'; +import '../assets/index.less'; import 'rc-time-picker/assets/index.css'; -import moment from 'moment'; import 'moment/locale/zh-cn'; import 'moment/locale/en-gb'; -const cn = location.search.indexOf('cn') !== -1; +const cn = window.location.search.indexOf('cn') !== -1; if (cn) { moment.locale('zh-cn'); @@ -40,7 +40,7 @@ const timePickerElement = ( function newArray(start, end) { const result = []; - for (let i = start; i < end; i++) { + for (let i = start; i < end; i += 1) { result.push(i); } return result; @@ -51,7 +51,7 @@ function disabledDate(current) { date.hour(0); date.minute(0); date.second(0); - return current.isBefore(date); // can not select days before today + return current.isBefore(date); // can not select days before today } function disabledTime(time, type) { @@ -66,7 +66,8 @@ function disabledTime(time, type) { disabledMinutes(h) { if (h === 20) { return newArray(0, 31); - } else if (h === 23) { + } + if (h === 23) { return newArray(30, 60); } return []; @@ -85,7 +86,8 @@ function disabledTime(time, type) { disabledMinutes(h) { if (h === 20) { return newArray(0, 31); - } else if (h === 23) { + } + if (h === 23) { return newArray(30, 60); } return []; @@ -119,19 +121,19 @@ 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; + const { state } = this; const calendar = ( ); return ( - - { - ({ value }) => { - return ( - - ); - } - } - ); + + {({ value }) => ( + + + + )} + + ); } } -ReactDOM.render( +export default () => (

calendar

@@ -194,4 +190,5 @@ ReactDOM.render(
-
, document.getElementById('__react-content')); +
+); diff --git a/examples/baisc.js b/examples/baisc.js new file mode 100644 index 000000000..1333b4626 --- /dev/null +++ b/examples/baisc.js @@ -0,0 +1,14 @@ +import React from 'react'; +import Calendar from '../src'; +import MonthCalendar from '../src/MonthCalendar'; + +export default () => ( + <> + { + console.log(value); + }} + /> + console.log(rest, ca)} /> + +); diff --git a/examples/control-panel.html b/examples/control-panel.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/control-panel.js b/examples/control-panel.js index 0a8ac633f..32e314fac 100644 --- a/examples/control-panel.js +++ b/examples/control-panel.js @@ -1,12 +1,10 @@ /* eslint react/no-multi-comp:0, no-console:0, no-unused-vars:0 */ -import 'rc-calendar/assets/index.less'; +import '../assets/index.less'; import React from 'react'; -import ReactDOM from 'react-dom'; -import Calendar from 'rc-calendar/src'; -import RangeCalendar from 'rc-calendar/src/RangeCalendar'; +import Calendar from '../src'; +import RangeCalendar from '../src/RangeCalendar'; -import Select, { Option } from 'rc-select'; -import 'rc-select/assets/index.css'; +import 'rc-select/assets/index.less'; class Demo extends React.Component { state = { @@ -15,8 +13,8 @@ class Demo extends React.Component { rangeEndMode: 'date', }; - onModeChange = (key) => { - return function _handleChange(e) { + onModeChange = key => + function _handleChange(e) { let mode; if (e && e.target) { mode = e.target.value; @@ -28,33 +26,27 @@ class Demo extends React.Component { [key]: mode, }); }.bind(this); - } handlePanelChange = (...args) => { console.log('on panel change', ...args); - } + }; handleRangePanelChange = (...args) => { console.log('on range panel change', ...args); - } + }; render() { return (

controle Calendar panel

- {['time', 'date', 'month', 'year', 'decade'].map(item => ( - + ))} - +

controle RangeCalendar panel

, document.getElementById('__react-content')); +export default Demo; diff --git a/examples/custom-clear-icon.html b/examples/custom-clear-icon.html deleted file mode 100644 index b3a425249..000000000 --- a/examples/custom-clear-icon.html +++ /dev/null @@ -1 +0,0 @@ -placeholder \ No newline at end of file diff --git a/examples/custom-clear-icon.js b/examples/custom-clear-icon.js index 93b8d4c36..6ea94fe9a 100644 --- a/examples/custom-clear-icon.js +++ b/examples/custom-clear-icon.js @@ -1,16 +1,16 @@ /* eslint react/no-multi-comp:0, no-console:0 */ -import 'rc-calendar/assets/index.less'; +import '../assets/index.less'; import React from 'react'; -import ReactDOM from 'react-dom'; -import Calendar from 'rc-calendar'; -import RangeCalendar from 'rc-calendar/src/RangeCalendar'; +import Calendar from '../src'; +import RangeCalendar from '../src/RangeCalendar'; import 'rc-time-picker/assets/index.css'; import 'moment/locale/zh-cn'; import 'moment/locale/en-gb'; -const clearPath = 'M909.1 209.3l-56.4 44.1C775.8 155.1 656.2 92 521.9 92 ' + +const clearPath = + 'M909.1 209.3l-56.4 44.1C775.8 155.1 656.2 92 521.9 92 ' + '290 92 102.3 279.5 102 511.5 101.7 743.7 289.8 932 521.9 932c181.3 0' + ' 335.8-115 394.6-276.1 1.5-4.2-0.7-8.9-4.9-10.3l-56.7-19.5c-4.1-1.4-8.6' + ' 0.7-10.1 4.8-1.8 5-3.8 10-5.9 14.9-17.3 41-42.1 77.8-73.7 109.4-31.6' + @@ -23,23 +23,24 @@ const clearPath = 'M909.1 209.3l-56.4 44.1C775.8 155.1 656.2 92 521.9 92 ' + '-7.7l0.8-180.9c-0.1-6.6-7.8-10.3-13-6.2z'; const svg = ( - ); -const calendars = ['time', 'date', 'month', 'year', 'decade'].map((mode) => { - return ( -
-
{mode}
- -
- ); -}); +const calendars = ['time', 'date', 'month', 'year', 'decade'].map(mode => ( +
+
{mode}
+ +
+)); -ReactDOM.render((
-
-
- +export default () => ( +
+
+
+ +
+ {calendars} +
+
- {calendars} -
-
-
), document.getElementById('__react-content')); +); diff --git a/examples/full-calendar.html b/examples/full-calendar.html deleted file mode 100644 index b3a425249..000000000 --- a/examples/full-calendar.html +++ /dev/null @@ -1 +0,0 @@ -placeholder \ No newline at end of file diff --git a/examples/full-calendar.js b/examples/full-calendar.js index 2cf7ed64b..0bdf985b1 100644 --- a/examples/full-calendar.js +++ b/examples/full-calendar.js @@ -1,22 +1,22 @@ /* eslint react/no-multi-comp:0, no-console:0 */ -import 'rc-calendar/assets/index.less'; +import '../assets/index.less'; import React from 'react'; -import ReactDOM from 'react-dom'; -import FullCalendar from 'rc-calendar/src/FullCalendar'; - -import 'rc-select/assets/index.css'; import Select from 'rc-select'; +import moment from 'moment'; -import zhCN from 'rc-calendar/src/locale/zh_CN'; -import enUS from 'rc-calendar/src/locale/en_US'; +import FullCalendar from '../src/FullCalendar'; + +import 'rc-select/assets/index.less'; + +import zhCN from '../src/locale/zh_CN'; +import enUS from '../src/locale/en_US'; -import moment from 'moment'; import 'moment/locale/zh-cn'; import 'moment/locale/en-gb'; const format = 'YYYY-MM-DD'; -const cn = location.search.indexOf('cn') !== -1; +const cn = window.location.search.indexOf('cn') !== -1; const now = moment(); if (cn) { @@ -37,11 +37,11 @@ class Demo extends React.Component { type: 'month', }; - onTypeChange = (type) => { + onTypeChange = type => { this.setState({ type, }); - } + }; render() { return ( @@ -69,4 +69,4 @@ class Demo extends React.Component { } } -ReactDOM.render(, document.getElementById('__react-content')); +export default Demo; diff --git a/examples/getCalendarContainer.html b/examples/getCalendarContainer.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/getCalendarContainer.js b/examples/getCalendarContainer.js index fe3c4fd1a..088f35e6b 100644 --- a/examples/getCalendarContainer.js +++ b/examples/getCalendarContainer.js @@ -1,20 +1,20 @@ -import 'rc-calendar/assets/index.less'; +import '../assets/index.less'; import React from 'react'; -import ReactDOM from 'react-dom'; -import Calendar from 'rc-calendar'; -import DatePicker from 'rc-calendar/src/Picker'; import Dialog from 'rc-dialog'; +import moment from 'moment'; + +import Calendar from '../src'; +import DatePicker from '../src/Picker'; import 'rc-dialog/assets/index.css'; -import zhCN from 'rc-calendar/src/locale/zh_CN'; -import enUS from 'rc-calendar/src/locale/en_US'; +import zhCN from '../src/locale/zh_CN'; +import enUS from '../src/locale/en_US'; -import moment from 'moment'; import 'moment/locale/zh-cn'; import 'moment/locale/en-gb'; const format = 'YYYY-MM-DD'; -const cn = location.search.indexOf('cn') !== -1; +const cn = window.location.search.indexOf('cn') !== -1; const now = moment(); if (cn) { @@ -44,51 +44,58 @@ class Demo extends React.Component { open = () => { this.setVisible(true); - } + }; close = () => { this.setVisible(false); - } + }; destroy = () => { this.setState({ destroy: true, }); - } + }; render() { if (this.state.destroy) { return null; } - return (
- -   - - -
(this.d = n)} /> -
- } - > - { - ({ value }) => { - return ( - - + return ( +
+ +   + + +
{ + this.d = n; + }} + /> +
+ } + > + {({ value }) => ( + + - ); - } - } - -
-
-
); + )} +
+
+
+
+ ); } } -ReactDOM.render(, document.getElementById('__react-content')); +export default Demo; diff --git a/examples/start-end-range.html b/examples/start-end-range.html deleted file mode 100644 index b3a425249..000000000 --- a/examples/start-end-range.html +++ /dev/null @@ -1 +0,0 @@ -placeholder \ No newline at end of file diff --git a/examples/start-end-range.js b/examples/start-end-range.js index 013dfd1de..c5bb963ea 100644 --- a/examples/start-end-range.js +++ b/examples/start-end-range.js @@ -1,22 +1,21 @@ /* eslint react/no-multi-comp:0, no-console:0, react/prop-types:0 */ -import 'rc-calendar/assets/index.less'; +import '../assets/index.less'; import React from 'react'; -import ReactDOM from 'react-dom'; -import RangeCalendar from 'rc-calendar/src/RangeCalendar'; -import DatePicker from 'rc-calendar/src/Picker'; +import moment from 'moment'; +import RangeCalendar from '../src/RangeCalendar'; +import DatePicker from '../src/Picker'; -import zhCN from 'rc-calendar/src/locale/zh_CN'; -import enUS from 'rc-calendar/src/locale/en_US'; +import zhCN from '../src/locale/zh_CN'; +import enUS from '../src/locale/en_US'; -import moment from 'moment'; import 'moment/locale/zh-cn'; import 'moment/locale/en-gb'; const format = 'YYYY-MM-DD'; const fullFormat = 'YYYY-MM-DD dddd'; -const cn = location.search.indexOf('cn') !== -1; +const cn = window.location.search.indexOf('cn') !== -1; const now = moment(); if (cn) { @@ -30,13 +29,13 @@ class Picker extends React.Component { hoverValue: [], }; - onHoverChange = (hoverValue) => { + onHoverChange = hoverValue => { console.log(hoverValue); this.setState({ hoverValue }); - } + }; render() { - const props = this.props; + const { props } = this; const { showValue } = props; const calendar = ( ); + /> + ); return ( - { - () => { - return ( - - - - ); - } - } - ); + {() => ( + + + + )} + + ); } } @@ -82,45 +79,45 @@ class Demo extends React.Component { endOpen: false, }; - onStartOpenChange = (startOpen) => { + onStartOpenChange = startOpen => { this.setState({ startOpen, }); - } + }; - onEndOpenChange = (endOpen) => { + onEndOpenChange = endOpen => { this.setState({ endOpen, }); - } + }; - onStartChange = (value) => { + onStartChange = value => { this.setState({ startValue: value[0], startOpen: false, endOpen: true, }); - } + }; - onEndChange = (value) => { + onEndChange = value => { this.setState({ endValue: value[1], }); - } + }; - disabledStartDate = (endValue) => { + disabledStartDate = endValue => { if (!endValue) { return false; } - const startValue = this.state.startValue; + const { startValue } = this.state; if (!startValue) { return false; } return endValue.diff(startValue, 'days') < 0; - } + }; render() { - const state = this.state; + const { state } = this; return (

@@ -147,9 +144,9 @@ class Demo extends React.Component { onChange={this.onEndChange} />

-
); +
+ ); } } - -ReactDOM.render(, document.getElementById('__react-content')); +export default Demo; diff --git a/examples/start-end.html b/examples/start-end.html deleted file mode 100644 index b3a425249..000000000 --- a/examples/start-end.html +++ /dev/null @@ -1 +0,0 @@ -placeholder \ No newline at end of file diff --git a/examples/start-end.js b/examples/start-end.js index 8014be62b..fedf50657 100644 --- a/examples/start-end.js +++ b/examples/start-end.js @@ -1,22 +1,22 @@ /* eslint react/no-multi-comp:0, no-console:0 */ -import 'rc-calendar/assets/index.less'; +import '../assets/index.less'; import React from 'react'; -import ReactDOM from 'react-dom'; -import Calendar from 'rc-calendar'; -import DatePicker from 'rc-calendar/src/Picker'; +import moment from 'moment'; +import TimePickerPanel from 'rc-time-picker/lib/Panel'; + +import Calendar from '../src'; +import DatePicker from '../src/Picker'; -import zhCN from 'rc-calendar/src/locale/zh_CN'; -import enUS from 'rc-calendar/src/locale/en_US'; +import zhCN from '../src/locale/zh_CN'; +import enUS from '../src/locale/en_US'; import 'rc-time-picker/assets/index.css'; -import TimePickerPanel from 'rc-time-picker/lib/Panel'; -import moment from 'moment'; import 'moment/locale/zh-cn'; import 'moment/locale/en-gb'; const format = 'YYYY-MM-DD HH:mm:ss'; -const cn = location.search.indexOf('cn') !== -1; +const cn = window.location.search.indexOf('cn') !== -1; const now = moment(); if (cn) { @@ -29,54 +29,44 @@ function getFormat(time) { return time ? format : 'YYYY-MM-DD'; } - const defaultCalendarValue = now.clone(); defaultCalendarValue.add(-1, 'month'); const timePickerElement = ; - const SHOW_TIME = true; -class Picker extends React.Component { - state = { - showTime: SHOW_TIME, - disabled: false, - }; - - render() { - const props = this.props; - const calendar = ( { + const calendar = ( + ); - return ( + ); + return ( + - { - ({ value }) => { - return ( - - - - ); - } - } - ); - } -} + {({ value }) => ( + + + + )} + + ); +}; class Demo extends React.Component { state = { @@ -89,55 +79,54 @@ class Demo extends React.Component { this.setState({ [field]: value, }); - } + }; - disabledEndDate = (endValue) => { + disabledEndDate = endValue => { if (!endValue) { return false; } - const startValue = this.state.startValue; + const { startValue } = this.state; if (!startValue) { return false; } - return SHOW_TIME ? endValue.isBefore(startValue) : - endValue.diff(startValue, 'days') <= 0; - } + return SHOW_TIME ? endValue.isBefore(startValue) : endValue.diff(startValue, 'days') <= 0; + }; - disabledStartDate = (startValue) => { + disabledStartDate = startValue => { if (!startValue) { return false; } - const endValue = this.state.endValue; + const { endValue } = this.state; if (!endValue) { return false; } - return SHOW_TIME ? endValue.isBefore(startValue) : - endValue.diff(startValue, 'days') <= 0; - } + return SHOW_TIME ? endValue.isBefore(startValue) : endValue.diff(startValue, 'days') <= 0; + }; render() { - const state = this.state; - return (
-

- 开始时间: - -

- -

- 结束时间: - -

-
); + const { state } = this; + return ( +
+

+ 开始时间: + this.onChange('startValue', value)} + /> +

+ +

+ 结束时间: + this.onChange('endValue', value)} + /> +

+
+ ); } } - -ReactDOM.render(, document.getElementById('__react-content')); +export default Demo; diff --git a/examples/week.html b/examples/week.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/week.js b/examples/week.js index 245b98e02..27384dc3f 100644 --- a/examples/week.js +++ b/examples/week.js @@ -1,20 +1,18 @@ /* eslint react/no-multi-comp:0, no-console:0 */ -import 'rc-calendar/assets/index.less'; +import '../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'; -import enUS from 'rc-calendar/src/locale/en_US'; - import moment from 'moment'; +import Calendar from '../src'; +import DatePicker from '../src/Picker'; +import zhCN from '../src/locale/zh_CN'; +import enUS from '../src/locale/en_US'; + import 'moment/locale/zh-cn'; import 'moment/locale/en-gb'; const format = 'YYYY-Wo'; -const cn = location.search.indexOf('cn') !== -1; +const cn = window.location.search.indexOf('cn') !== -1; const now = moment(); if (cn) { @@ -51,63 +49,60 @@ const style = ` `; class Demo extends React.Component { - static propTypes = { - defaultValue: PropTypes.object, - defaultCalendarValue: PropTypes.object, - } - state = { value: undefined, open: false, }; - onChange = (value) => { - console.log('DatePicker change: ', (value && value.format(format))); + 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()) { - return (
-
- {current.date()} + if ( + selectedValue && + current.year() === selectedValue.year() && + current.week() === selectedValue.week() + ) { + return ( +
+
{current.date()}
-
); + ); } - return ( -
- {current.date()} -
); - } + return
{current.date()}
; + }; lastWeek = () => { - const value = this.state.value || now; + const { state } = this; + const value = state.value || now; value.add(-1, 'weeks'); this.setState({ value, open: false, }); - } + }; - renderSidebar() { - return ( -
- -
); - } + renderSidebar = () => ( +
+ +
+ ); render() { - const state = this.state; + const { state } = this; const calendar = ( ); - return (
-
- + ); + return ( +
+
- { - ({ value }) => { - return ( - + + {({ value }) => ( + - - ); - } - } - + + )} + +
-
); + ); } } -ReactDOM.render((
-
called when a date range is changed inside calendar (next year/next month/keyboard)
onOkFunction(date: moment)called when ok button is pressed, only if it's visible
dateInputPlaceholder String[] Custom month cell render method
dateCellRenderfunctionCustom date cell render method
monthCellContentRender function