From 6ab243ffaae9ddad1e6bc5a59337f897ff17258c Mon Sep 17 00:00:00 2001
From: tanjinzhou <415800467@qq.com>
Date: Tue, 21 Jul 2020 16:46:39 +0800
Subject: [PATCH] feat: update time-picker
---
antdv-demo | 2 +-
components/time-picker/index.jsx | 88 +++++++++++++-----------
components/vc-time-picker/Combobox.jsx | 1 +
components/vc-time-picker/Header.jsx | 17 ++---
components/vc-time-picker/Panel.jsx | 13 ++--
components/vc-time-picker/Select.jsx | 8 ++-
components/vc-time-picker/TimePicker.jsx | 29 ++++----
examples/App.vue | 2 +-
examples/index.js | 2 +
9 files changed, 90 insertions(+), 72 deletions(-)
diff --git a/antdv-demo b/antdv-demo
index c2521df74..aae9db4ae 160000
--- a/antdv-demo
+++ b/antdv-demo
@@ -1 +1 @@
-Subproject commit c2521df74700792b5cd6c353cf9fce91fbd40e19
+Subproject commit aae9db4ae607a00f4c8482c159bfaf71fe982595
diff --git a/components/time-picker/index.jsx b/components/time-picker/index.jsx
index b5b091175..85905ae85 100644
--- a/components/time-picker/index.jsx
+++ b/components/time-picker/index.jsx
@@ -1,4 +1,5 @@
import omit from 'omit.js';
+import { inject, provide } from 'vue';
import VcTimePicker from '../vc-time-picker';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import BaseMixin from '../_util/BaseMixin';
@@ -13,11 +14,9 @@ import {
getOptionProps,
getComponent,
isValidElement,
- getListeners,
} from '../_util/props-util';
import { cloneElement } from '../_util/vnode';
import { ConfigConsumerProps } from '../config-provider';
-import Base from '../base';
import {
checkValidate,
stringToMoment,
@@ -69,10 +68,21 @@ export const TimePickerProps = () => ({
clearIcon: PropTypes.any,
locale: PropTypes.object,
valueFormat: PropTypes.string,
+ onChange: PropTypes.func,
+ onAmPmChange: PropTypes.func,
+ onOpen: PropTypes.func,
+ onClose: PropTypes.func,
+ onFocus: PropTypes.func,
+ onBlur: PropTypes.func,
+ onKeydown: PropTypes.func,
+ onOpenChange: PropTypes.func,
+ 'onUpdate:value': PropTypes.func,
+ 'onUpdate:open': PropTypes.func,
});
const TimePicker = {
name: 'ATimePicker',
+ inheritAttrs: false,
mixins: [BaseMixin],
props: initDefaultProps(TimePickerProps(), {
align: {
@@ -88,18 +98,15 @@ const TimePicker = {
focusOnOpen: true,
allowClear: true,
}),
- model: {
- prop: 'value',
- event: 'change',
+ created() {
+ provide('savePopupRef', this.savePopupRef);
},
- provide() {
+ setup() {
return {
- savePopupRef: this.savePopupRef,
+ configProvider: inject('configProvider', ConfigConsumerProps),
};
},
- inject: {
- configProvider: { default: () => ConfigConsumerProps },
- },
+
data() {
const { value, defaultValue, valueFormat } = this;
@@ -148,16 +155,17 @@ const TimePicker = {
savePopupRef(ref) {
this.popupRef = ref;
},
+ saveTimePicker(timePickerRef) {
+ this.timePickerRef = timePickerRef;
+ },
handleChange(value) {
if (!hasProp(this, 'value')) {
this.setState({ sValue: value });
}
const { format = 'HH:mm:ss' } = this;
- this.$emit(
- 'change',
- this.valueFormat ? momentToString(value, this.valueFormat) : value,
- (value && value.format(format)) || '',
- );
+ const val = this.valueFormat ? momentToString(value, this.valueFormat) : value;
+ this.$emit('update:value', val);
+ this.$emit('change', val, (value && value.format(format)) || '');
},
handleOpenClose({ open }) {
@@ -166,11 +174,11 @@ const TimePicker = {
},
focus() {
- this.$refs.timePicker.focus();
+ this.timePickerRef.focus();
},
blur() {
- this.$refs.timePicker.blur();
+ this.timePickerRef.blur();
},
renderInputIcon(prefixCls) {
@@ -201,13 +209,14 @@ const TimePicker = {
renderTimePicker(locale) {
let props = getOptionProps(this);
props = omit(props, ['defaultValue', 'suffixIcon', 'allowEmpty', 'allowClear']);
-
+ const { class: className } = this.$attrs;
const { prefixCls: customizePrefixCls, getPopupContainer, placeholder, size } = props;
const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('time-picker', customizePrefixCls);
const format = this.getDefaultFormat();
const pickerClassName = {
+ [className]: className,
[`${prefixCls}-${size}`]: !!size,
};
const tempAddon = getComponent(this, 'addon', {}, false);
@@ -222,27 +231,23 @@ const TimePicker = {
const clearIcon = this.renderClearIcon(prefixCls);
const { getPopupContainer: getContextPopupContainer } = this.configProvider;
const timeProps = {
- props: {
- ...generateShowHourMinuteSecond(format),
- ...props,
- allowEmpty: this.getAllowClear(),
- prefixCls,
- getPopupContainer: getPopupContainer || getContextPopupContainer,
- format,
- value: this.sValue,
- placeholder: placeholder === undefined ? locale.placeholder : placeholder,
- addon: pickerAddon,
- inputIcon,
- clearIcon,
- },
+ ...generateShowHourMinuteSecond(format),
+ ...props,
+ ...this.$attrs,
+ allowEmpty: this.getAllowClear(),
+ prefixCls,
+ getPopupContainer: getPopupContainer || getContextPopupContainer,
+ format,
+ value: this.sValue,
+ placeholder: placeholder === undefined ? locale.placeholder : placeholder,
+ addon: pickerAddon,
+ inputIcon,
+ clearIcon,
class: pickerClassName,
- ref: 'timePicker',
- on: {
- ...getListeners(this),
- change: this.handleChange,
- open: this.handleOpenClose,
- close: this.handleOpenClose,
- },
+ ref: this.saveTimePicker,
+ onChange: this.handleChange,
+ onOpen: this.handleOpenClose,
+ onClose: this.handleOpenClose,
};
return