ant-design-vue/components/date-picker/RangePicker.jsx

430 lines
11 KiB
Vue
Raw Normal View History

2019-01-12 11:33:27 +08:00
import * as moment from 'moment';
import RangeCalendar from '../vc-calendar/src/RangeCalendar';
import VcDatePicker from '../vc-calendar/src/Picker';
import classNames from 'classnames';
import shallowequal from 'shallowequal';
import Icon from '../icon';
import Tag from '../tag';
import interopDefault from '../_util/interopDefault';
import { RangePickerProps } from './interface';
import {
hasProp,
getOptionProps,
initDefaultProps,
mergeProps,
getComponentFromProp,
isValidElement,
} from '../_util/props-util';
import BaseMixin from '../_util/BaseMixin';
import { cloneElement } from '../_util/vnode';
function noop() {}
function getShowDateFromValue(value) {
const [start, end] = value;
2018-03-17 21:38:29 +08:00
// value could be an empty array, then we should not reset showDate
if (!start && !end) {
2019-01-12 11:33:27 +08:00
return;
2018-03-17 21:38:29 +08:00
}
2019-01-12 11:33:27 +08:00
const newEnd = end && end.isSame(start, 'month') ? end.clone().add(1, 'month') : end;
return [start, newEnd];
2018-03-17 21:38:29 +08:00
}
2019-01-12 11:33:27 +08:00
function formatValue(value, format) {
return (value && value.format(format)) || '';
2018-03-17 21:38:29 +08:00
}
2019-01-12 11:33:27 +08:00
function pickerValueAdapter(value) {
2018-03-17 21:38:29 +08:00
if (!value) {
2019-01-12 11:33:27 +08:00
return;
2018-03-17 21:38:29 +08:00
}
if (Array.isArray(value)) {
2019-01-12 11:33:27 +08:00
return value;
2018-03-17 21:38:29 +08:00
}
2019-01-12 11:33:27 +08:00
return [value, value.clone().add(1, 'month')];
2018-03-17 21:38:29 +08:00
}
2019-01-12 11:33:27 +08:00
function isEmptyArray(arr) {
2018-03-17 21:38:29 +08:00
if (Array.isArray(arr)) {
2019-01-12 11:33:27 +08:00
return arr.length === 0 || arr.every(i => !i);
2018-03-17 21:38:29 +08:00
}
2019-01-12 11:33:27 +08:00
return false;
2018-03-17 21:38:29 +08:00
}
2019-01-12 11:33:27 +08:00
function fixLocale(value, localeCode) {
2018-03-17 21:38:29 +08:00
if (!localeCode) {
2019-01-12 11:33:27 +08:00
return;
2018-03-17 21:38:29 +08:00
}
if (!value || value.length === 0) {
2019-01-12 11:33:27 +08:00
return;
2018-03-17 21:38:29 +08:00
}
2019-01-12 11:33:27 +08:00
const [start, end] = value;
if (start) {
2019-01-12 11:33:27 +08:00
start.locale(localeCode);
2018-03-17 21:38:29 +08:00
}
if (end) {
2019-01-12 11:33:27 +08:00
end.locale(localeCode);
2018-03-17 21:38:29 +08:00
}
}
export default {
2018-04-08 21:17:20 +08:00
name: 'ARangePicker',
2019-02-01 17:23:00 +08:00
mixins: [BaseMixin],
model: {
prop: 'value',
event: 'change',
},
2018-03-17 21:38:29 +08:00
props: initDefaultProps(RangePickerProps(), {
prefixCls: 'ant-calendar',
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 21:28:54 +08:00
tagPrefixCls: 'ant-tag',
2018-03-17 21:38:29 +08:00
allowClear: true,
showToday: false,
}),
2019-01-12 11:33:27 +08:00
data() {
const value = this.value || this.defaultValue || [];
const [start, end] = value;
2018-03-17 21:38:29 +08:00
if (
2019-01-12 11:33:27 +08:00
(start && !interopDefault(moment).isMoment(start)) ||
(end && !interopDefault(moment).isMoment(end))
2018-03-17 21:38:29 +08:00
) {
throw new Error(
'The value/defaultValue of RangePicker must be a moment object array after `antd@2.0`, ' +
2019-01-12 11:33:27 +08:00
'see: https://u.ant.design/date-picker-value',
);
2018-03-17 21:38:29 +08:00
}
2019-01-12 11:33:27 +08:00
const pickerValue = !value || isEmptyArray(value) ? this.defaultPickerValue : value;
2018-03-17 21:38:29 +08:00
return {
sValue: value,
2018-04-07 14:29:59 +08:00
sShowDate: pickerValueAdapter(pickerValue || interopDefault(moment)()),
2018-03-17 21:38:29 +08:00
sOpen: this.open,
sHoverValue: [],
2019-01-12 11:33:27 +08:00
};
2018-03-17 21:38:29 +08:00
},
watch: {
2019-01-12 11:33:27 +08:00
value(val) {
const value = val || [];
let state = { sValue: value };
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 21:28:54 +08:00
if (!shallowequal(val, this.sValue)) {
state = {
...state,
sShowDate: getShowDateFromValue(value) || this.sShowDate,
2019-01-12 11:33:27 +08:00
};
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 21:28:54 +08:00
}
2019-01-12 11:33:27 +08:00
this.setState(state);
2018-03-17 21:38:29 +08:00
},
2019-01-12 11:33:27 +08:00
open(val) {
2018-03-17 21:38:29 +08:00
this.setState({
sOpen: val,
2019-01-12 11:33:27 +08:00
});
2018-03-17 21:38:29 +08:00
},
},
methods: {
2019-01-12 11:33:27 +08:00
clearSelection(e) {
e.preventDefault();
e.stopPropagation();
this.setState({ sValue: [] });
this.handleChange([]);
2018-03-17 21:38:29 +08:00
},
2019-01-12 11:33:27 +08:00
clearHoverValue() {
this.setState({ sHoverValue: [] });
2018-03-17 21:38:29 +08:00
},
2019-01-12 11:33:27 +08:00
handleChange(value) {
2018-03-17 21:38:29 +08:00
if (!hasProp(this, 'value')) {
this.setState(({ sShowDate }) => ({
sValue: value,
sShowDate: getShowDateFromValue(value) || sShowDate,
2019-01-12 11:33:27 +08:00
}));
2018-03-17 21:38:29 +08:00
}
2019-01-12 11:33:27 +08:00
const [start, end] = value;
this.$emit('change', value, [formatValue(start, this.format), formatValue(end, this.format)]);
2018-03-17 21:38:29 +08:00
},
2019-01-12 11:33:27 +08:00
handleOpenChange(open) {
2018-03-17 21:38:29 +08:00
if (!hasProp(this, 'open')) {
2019-01-12 11:33:27 +08:00
this.setState({ sOpen: open });
2018-03-17 21:38:29 +08:00
}
if (open === false) {
2019-01-12 11:33:27 +08:00
this.clearHoverValue();
2018-03-17 21:38:29 +08:00
}
2019-01-12 11:33:27 +08:00
this.$emit('openChange', open);
if (!open) {
2019-01-12 11:33:27 +08:00
this.focus();
}
2018-03-17 21:38:29 +08:00
},
2019-01-12 11:33:27 +08:00
handleShowDateChange(showDate) {
this.setState({ sShowDate: showDate });
2018-03-17 21:38:29 +08:00
},
2019-01-12 11:33:27 +08:00
handleHoverChange(hoverValue) {
this.setState({ sHoverValue: hoverValue });
2018-03-17 21:38:29 +08:00
},
2019-01-12 11:33:27 +08:00
handleRangeMouseLeave() {
2018-03-17 21:38:29 +08:00
if (this.sOpen) {
2019-01-12 11:33:27 +08:00
this.clearHoverValue();
2018-03-17 21:38:29 +08:00
}
},
2019-01-12 11:33:27 +08:00
handleCalendarInputSelect(value) {
const [start] = value;
if (!start) {
2019-01-12 11:33:27 +08:00
return;
2018-03-17 21:38:29 +08:00
}
this.setState(({ sShowDate }) => ({
sValue: value,
sShowDate: getShowDateFromValue(value) || sShowDate,
2019-01-12 11:33:27 +08:00
}));
2018-03-17 21:38:29 +08:00
},
2019-01-12 11:33:27 +08:00
handleRangeClick(value) {
2018-03-17 21:38:29 +08:00
if (typeof value === 'function') {
2019-01-12 11:33:27 +08:00
value = value();
2018-03-17 21:38:29 +08:00
}
2019-01-12 11:33:27 +08:00
this.setValue(value, true);
this.$emit('ok', value);
this.$emit('openChange', false);
2018-03-17 21:38:29 +08:00
},
2019-01-12 11:33:27 +08:00
setValue(value, hidePanel) {
this.handleChange(value);
2018-03-17 21:38:29 +08:00
if ((hidePanel || !this.showTime) && !hasProp(this, 'open')) {
2019-01-12 11:33:27 +08:00
this.setState({ sOpen: false });
2018-03-17 21:38:29 +08:00
}
},
2019-01-12 11:33:27 +08:00
onMouseEnter(e) {
this.$emit('mouseenter', e);
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 21:28:54 +08:00
},
2019-01-12 11:33:27 +08:00
onMouseLeave(e) {
this.$emit('mouseleave', e);
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 21:28:54 +08:00
},
2019-01-12 11:33:27 +08:00
focus() {
this.$refs.picker.focus();
2018-03-17 21:38:29 +08:00
},
2019-01-12 11:33:27 +08:00
blur() {
this.$refs.picker.blur();
2018-03-17 21:38:29 +08:00
},
2019-01-12 11:33:27 +08:00
renderFooter(...args) {
const { prefixCls, ranges, $scopedSlots, $slots, tagPrefixCls } = this;
const renderExtraFooter =
this.renderExtraFooter || $scopedSlots.renderExtraFooter || $slots.renderExtraFooter;
2018-03-17 21:38:29 +08:00
if (!ranges && !renderExtraFooter) {
2019-01-12 11:33:27 +08:00
return null;
2018-03-17 21:38:29 +08:00
}
const customFooter = renderExtraFooter ? (
2019-01-12 11:33:27 +08:00
<div class={`${prefixCls}-footer-extra`} key="extra">
2018-03-18 22:05:55 +08:00
{typeof renderExtraFooter === 'function' ? renderExtraFooter(...args) : renderExtraFooter}
2018-03-17 21:38:29 +08:00
</div>
2019-01-12 11:33:27 +08:00
) : null;
const operations = Object.keys(ranges || {}).map(range => {
const value = ranges[range];
2018-03-17 21:38:29 +08:00
return (
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 21:28:54 +08:00
<Tag
2018-03-17 21:38:29 +08:00
key={range}
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 21:28:54 +08:00
prefixCls={tagPrefixCls}
2019-01-12 11:33:27 +08:00
color="blue"
2018-03-17 21:38:29 +08:00
onClick={() => this.handleRangeClick(value)}
onMouseenter={() => this.setState({ sHoverValue: value })}
onMouseleave={this.handleRangeMouseLeave}
>
{range}
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 21:28:54 +08:00
</Tag>
2019-01-12 11:33:27 +08:00
);
});
const rangeNode =
operations && operations.length > 0 ? (
<div class={`${prefixCls}-footer-extra ${prefixCls}-range-quick-selector`} key="range">
{operations}
</div>
) : null;
return [rangeNode, customFooter];
2018-03-17 21:38:29 +08:00
},
},
2019-01-12 11:33:27 +08:00
render() {
const props = getOptionProps(this);
let suffixIcon = getComponentFromProp(this, 'suffixIcon');
suffixIcon = Array.isArray(suffixIcon) ? suffixIcon[0] : suffixIcon;
const {
sValue: value,
sShowDate: showDate,
sHoverValue: hoverValue,
sOpen: open,
$listeners,
$scopedSlots,
} = this;
2018-03-17 21:38:29 +08:00
const {
2019-01-12 11:33:27 +08:00
calendarChange = noop,
ok = noop,
focus = noop,
blur = noop,
panelChange = noop,
} = $listeners;
const {
prefixCls,
popupStyle,
disabledDate,
disabledTime,
showTime,
showToday,
ranges,
locale,
localeCode,
format,
} = props;
const dateRender = props.dateRender || $scopedSlots.dateRender;
fixLocale(value, localeCode);
fixLocale(showDate, localeCode);
2018-03-17 21:38:29 +08:00
const calendarClassName = classNames({
[`${prefixCls}-time`]: showTime,
[`${prefixCls}-range-with-ranges`]: ranges,
2019-01-12 11:33:27 +08:00
});
2018-03-17 21:38:29 +08:00
// 需要选择时间时,点击 ok 时才触发 onChange
const pickerChangeHandler = {
on: {
change: this.handleChange,
},
2019-01-12 11:33:27 +08:00
};
2018-03-17 21:38:29 +08:00
let calendarProps = {
on: {
ok: this.handleChange,
2019-01-12 11:33:27 +08:00
},
props: {},
};
2018-03-17 21:38:29 +08:00
if (props.timePicker) {
2019-01-12 11:33:27 +08:00
pickerChangeHandler.on.change = changedValue => this.handleChange(changedValue);
2018-03-17 21:38:29 +08:00
} else {
2019-01-12 11:33:27 +08:00
calendarProps = { on: {}, props: {} };
2018-03-17 21:38:29 +08:00
}
if ('mode' in props) {
2019-01-12 11:33:27 +08:00
calendarProps.props.mode = props.mode;
2018-03-17 21:38:29 +08:00
}
2019-01-12 11:33:27 +08:00
const startPlaceholder =
'placeholder' in props ? props.placeholder[0] : locale.lang.rangePlaceholder[0];
const endPlaceholder =
'placeholder' in props ? props.placeholder[1] : locale.lang.rangePlaceholder[1];
2018-03-17 21:38:29 +08:00
const rangeCalendarProps = mergeProps(calendarProps, {
props: {
format: format,
prefixCls: prefixCls,
renderFooter: this.renderFooter,
timePicker: props.timePicker,
disabledDate: disabledDate,
disabledTime: disabledTime,
dateInputPlaceholder: [startPlaceholder, endPlaceholder],
locale: locale.lang,
dateRender: dateRender,
value: showDate,
hoverValue: hoverValue,
showToday: showToday,
},
on: {
change: calendarChange,
ok: ok,
valueChange: this.handleShowDateChange,
hoverChange: this.handleHoverChange,
2018-12-08 16:47:05 +08:00
panelChange,
2018-03-17 21:38:29 +08:00
inputSelect: this.handleCalendarInputSelect,
},
class: calendarClassName,
scopedSlots: $scopedSlots,
2019-01-12 11:33:27 +08:00
});
const calendar = <RangeCalendar {...rangeCalendarProps} />;
2018-03-17 21:38:29 +08:00
// default width for showTime
2019-01-12 11:33:27 +08:00
const pickerStyle = {};
2018-03-17 21:38:29 +08:00
if (props.showTime) {
2019-01-12 11:33:27 +08:00
pickerStyle.width = '350px';
2018-03-17 21:38:29 +08:00
}
2019-01-12 11:33:27 +08:00
const [startValue, endValue] = value;
const clearIcon =
!props.disabled && props.allowClear && value && (startValue || endValue) ? (
<Icon
type="close-circle"
class={`${prefixCls}-picker-clear`}
onClick={this.clearSelection}
theme="filled"
/>
) : null;
2018-03-17 21:38:29 +08:00
2019-01-12 11:33:27 +08:00
const inputIcon = (suffixIcon &&
(isValidElement(suffixIcon) ? (
cloneElement(suffixIcon, {
class: `${prefixCls}-picker-icon`,
})
) : (
<span class={`${prefixCls}-picker-icon`}>{suffixIcon}</span>
))) || <Icon type="calendar" class={`${prefixCls}-picker-icon`} />;
2018-12-08 16:47:05 +08:00
2018-03-17 21:38:29 +08:00
const input = ({ value: inputValue }) => {
2019-01-12 11:33:27 +08:00
const [start, end] = inputValue;
2018-03-17 21:38:29 +08:00
return (
<span class={props.pickerInputClass}>
<input
disabled={props.disabled}
readOnly
value={(start && start.format(props.format)) || ''}
placeholder={startPlaceholder}
class={`${prefixCls}-range-picker-input`}
tabIndex={-1}
/>
<span class={`${prefixCls}-range-picker-separator`}> ~ </span>
<input
disabled={props.disabled}
readOnly
value={(end && end.format(props.format)) || ''}
placeholder={endPlaceholder}
class={`${prefixCls}-range-picker-input`}
tabIndex={-1}
/>
{clearIcon}
2018-12-08 16:47:05 +08:00
{inputIcon}
2018-03-17 21:38:29 +08:00
</span>
2019-01-12 11:33:27 +08:00
);
};
const vcDatePickerProps = mergeProps(
{
props,
on: $listeners,
2018-03-17 21:38:29 +08:00
},
2019-01-12 11:33:27 +08:00
pickerChangeHandler,
{
props: {
calendar: calendar,
value: value,
open: open,
prefixCls: `${prefixCls}-picker-container`,
},
on: {
openChange: this.handleOpenChange,
},
style: popupStyle,
2018-03-17 21:38:29 +08:00
},
2019-01-12 11:33:27 +08:00
);
2018-03-17 21:38:29 +08:00
return (
<span
2019-01-12 11:33:27 +08:00
ref="picker"
2018-03-17 21:38:29 +08:00
class={props.pickerClass}
style={pickerStyle}
tabIndex={props.disabled ? -1 : 0}
onFocus={focus}
onBlur={blur}
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 21:28:54 +08:00
onMouseenter={this.onMouseEnter}
onMouseleave={this.onMouseLeave}
2018-03-17 21:38:29 +08:00
>
2019-01-12 11:33:27 +08:00
<VcDatePicker {...vcDatePickerProps}>{input}</VcDatePicker>
2018-03-17 21:38:29 +08:00
</span>
2019-01-12 11:33:27 +08:00
);
2018-03-17 21:38:29 +08:00
},
2019-01-12 11:33:27 +08:00
};