Skip to content

Commit 738d2f4

Browse files
committed
feat: calendar update locale
1 parent 9077e18 commit 738d2f4

File tree

21 files changed

+333
-78
lines changed

21 files changed

+333
-78
lines changed

build/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
22
dev: {
3-
componentName: 'table', // dev components
3+
componentName: 'calendar', // dev components
44
},
55
};

components/calendar/index.jsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import PropTypes from '../_util/vue-types';
22
import BaseMixin from '../_util/BaseMixin';
3-
import {
4-
getOptionProps,
5-
hasProp,
6-
initDefaultProps,
7-
getListeners,
8-
getComponentFromProp,
9-
} from '../_util/props-util';
3+
import { getOptionProps, hasProp, initDefaultProps, getListeners } from '../_util/props-util';
104
import * as moment from 'moment';
115
import FullCalendar from '../vc-calendar/src/FullCalendar';
12-
import Header, { HeaderRender } from './Header';
6+
import Header from './Header';
137
import LocaleReceiver from '../locale-provider/LocaleReceiver';
148
import interopDefault from '../_util/interopDefault';
159
import { ConfigConsumerProps } from '../config-provider';

components/vc-calendar/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// based on rc-calendar 9.10.10
1+
// based on rc-calendar 9.15.8
22
import Vue from 'vue';
33
import ref from 'vue-ref';
44
import Calendar from './src/';

components/vc-calendar/src/Calendar.jsx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ import enUs from './locale/en_US';
1414
import { getTimeConfig, getTodayTime, syncTime } from './util';
1515
import { goStartMonth, goEndMonth, goTime } from './util/toTime';
1616

17+
const getMomentObjectIfValid = date => {
18+
if (moment.isMoment(date) && date.isValid()) {
19+
return date;
20+
}
21+
return false;
22+
};
23+
1724
const Calendar = {
1825
props: {
1926
locale: PropTypes.object.def(enUs),
@@ -46,6 +53,7 @@ const Calendar = {
4653
renderSidebar: PropTypes.func.def(() => null),
4754
clearIcon: PropTypes.any,
4855
focusablePanel: PropTypes.bool.def(true),
56+
inputMode: PropTypes.string,
4957
},
5058

5159
mixins: [BaseMixin, CommonMixin, CalendarMixin],
@@ -54,7 +62,10 @@ const Calendar = {
5462
const props = this.$props;
5563
return {
5664
sMode: this.mode || 'date',
57-
sValue: props.value || props.defaultValue || moment(),
65+
sValue:
66+
getMomentObjectIfValid(props.value) ||
67+
getMomentObjectIfValid(props.defaultValue) ||
68+
moment(),
5869
sSelectedValue: props.selectedValue || props.defaultSelectedValue,
5970
};
6071
},
@@ -63,9 +74,11 @@ const Calendar = {
6374
this.setState({ sMode: val });
6475
},
6576
value(val) {
66-
const sValue = val || this.defaultValue || getNowByCurrentStateValue(this.sValue);
6777
this.setState({
68-
sValue,
78+
sValue:
79+
getMomentObjectIfValid(val) ||
80+
getMomentObjectIfValid(this.defaultValue) ||
81+
getNowByCurrentStateValue(this.sValue),
6982
});
7083
},
7184
selectedValue(val) {
@@ -190,6 +203,25 @@ const Calendar = {
190203
source: 'todayButton',
191204
});
192205
},
206+
207+
onBlur(event) {
208+
setTimeout(() => {
209+
const dateInput = DateInput.getInstance();
210+
const rootInstance = this.rootInstance;
211+
212+
if (
213+
!rootInstance ||
214+
rootInstance.contains(document.activeElement) ||
215+
(dateInput && dateInput.contains(document.activeElement))
216+
) {
217+
// focused element is still part of Calendar
218+
return;
219+
}
220+
221+
this.$emit('blur', event);
222+
}, 0);
223+
},
224+
193225
getRootDOMNode() {
194226
return this.$el;
195227
},
@@ -217,6 +249,9 @@ const Calendar = {
217249
sSelectedValue,
218250
sMode,
219251
renderFooter,
252+
inputMode,
253+
monthCellRender,
254+
monthCellContentRender,
220255
$props: props,
221256
} = this;
222257
const clearIcon = getComponentFromProp(this, 'clearIcon');
@@ -267,6 +302,7 @@ const Calendar = {
267302
onChange={this.onDateInputChange}
268303
clearIcon={clearIcon}
269304
onSelect={this.onDateInputSelect}
305+
inputMode={inputMode}
270306
/>
271307
) : null;
272308
const children = [];
@@ -286,6 +322,8 @@ const Calendar = {
286322
renderFooter={renderFooter}
287323
showTimePicker={showTimePicker}
288324
prefixCls={prefixCls}
325+
monthCellRender={monthCellRender}
326+
monthCellContentRender={monthCellContentRender}
289327
/>
290328
{timePicker && showTimePicker ? (
291329
<div class={`${prefixCls}-time-picker`}>

components/vc-calendar/src/MonthCalendar.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const MonthCalendar = {
1414
visible: PropTypes.bool.def(true),
1515
prefixCls: PropTypes.string.def('rc-calendar'),
1616
monthCellRender: PropTypes.func,
17-
dateCellRender: PropTypes.func,
1817
value: PropTypes.object,
1918
defaultValue: PropTypes.object,
2019
selectedValue: PropTypes.object,

components/vc-calendar/src/Picker.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const Picker = {
3838
defaultValue: PropTypes.oneOfType([MomentType, PropTypes.arrayOf(MomentType)]),
3939
align: PropTypes.object.def({}),
4040
dropdownClassName: PropTypes.string,
41+
dateRender: PropTypes.func,
4142
},
4243
mixins: [BaseMixin],
4344

@@ -123,6 +124,10 @@ const Picker = {
123124
this.closeCalendar(this.focus);
124125
},
125126

127+
onCalendarBlur() {
128+
this.setOpen(false);
129+
},
130+
126131
onVisibleChange(open) {
127132
this.setOpen(open);
128133
},
@@ -144,6 +149,7 @@ const Picker = {
144149
ok: createChainedFunction(calendarEvents.ok, this.onCalendarOk),
145150
select: createChainedFunction(calendarEvents.select, this.onCalendarSelect),
146151
clear: createChainedFunction(calendarEvents.clear, this.onCalendarClear),
152+
blur: createChainedFunction(calendarEvents.blur, this.onCalendarBlur),
147153
},
148154
};
149155

0 commit comments

Comments
 (0)