|
|
@ -1,9 +1,11 @@
|
|
|
|
import * as moment from 'moment';
|
|
|
|
import * as moment from 'moment';
|
|
|
|
|
|
|
|
import omit from 'omit.js';
|
|
|
|
import VcTimePicker from '../vc-time-picker';
|
|
|
|
import VcTimePicker from '../vc-time-picker';
|
|
|
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
|
|
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
|
|
|
import defaultLocale from './locale/en_US';
|
|
|
|
import defaultLocale from './locale/en_US';
|
|
|
|
import BaseMixin from '../_util/BaseMixin';
|
|
|
|
import BaseMixin from '../_util/BaseMixin';
|
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
|
|
|
|
import warning from '../_util/warning';
|
|
|
|
import Icon from '../icon';
|
|
|
|
import Icon from '../icon';
|
|
|
|
import interopDefault from '../_util/interopDefault';
|
|
|
|
import interopDefault from '../_util/interopDefault';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
@ -14,6 +16,7 @@ import {
|
|
|
|
isValidElement,
|
|
|
|
isValidElement,
|
|
|
|
} from '../_util/props-util';
|
|
|
|
} from '../_util/props-util';
|
|
|
|
import { cloneElement } from '../_util/vnode';
|
|
|
|
import { cloneElement } from '../_util/vnode';
|
|
|
|
|
|
|
|
import { ConfigConsumerProps } from '../config-provider';
|
|
|
|
|
|
|
|
|
|
|
|
export function generateShowHourMinuteSecond(format) {
|
|
|
|
export function generateShowHourMinuteSecond(format) {
|
|
|
|
// Ref: http://momentjs.com/docs/#/parsing/string-format/
|
|
|
|
// Ref: http://momentjs.com/docs/#/parsing/string-format/
|
|
|
@ -53,10 +56,12 @@ export const TimePickerProps = () => ({
|
|
|
|
minuteStep: PropTypes.number,
|
|
|
|
minuteStep: PropTypes.number,
|
|
|
|
secondStep: PropTypes.number,
|
|
|
|
secondStep: PropTypes.number,
|
|
|
|
allowEmpty: PropTypes.bool,
|
|
|
|
allowEmpty: PropTypes.bool,
|
|
|
|
|
|
|
|
allowClear: PropTypes.bool,
|
|
|
|
inputReadOnly: PropTypes.bool,
|
|
|
|
inputReadOnly: PropTypes.bool,
|
|
|
|
clearText: PropTypes.string,
|
|
|
|
clearText: PropTypes.string,
|
|
|
|
defaultOpenValue: PropTypes.object,
|
|
|
|
defaultOpenValue: PropTypes.object,
|
|
|
|
popupClassName: PropTypes.string,
|
|
|
|
popupClassName: PropTypes.string,
|
|
|
|
|
|
|
|
popupStyle: PropTypes.object,
|
|
|
|
suffixIcon: PropTypes.any,
|
|
|
|
suffixIcon: PropTypes.any,
|
|
|
|
align: PropTypes.object,
|
|
|
|
align: PropTypes.object,
|
|
|
|
placement: PropTypes.any,
|
|
|
|
placement: PropTypes.any,
|
|
|
@ -69,7 +74,6 @@ const TimePicker = {
|
|
|
|
name: 'ATimePicker',
|
|
|
|
name: 'ATimePicker',
|
|
|
|
mixins: [BaseMixin],
|
|
|
|
mixins: [BaseMixin],
|
|
|
|
props: initDefaultProps(TimePickerProps(), {
|
|
|
|
props: initDefaultProps(TimePickerProps(), {
|
|
|
|
prefixCls: 'ant-time-picker',
|
|
|
|
|
|
|
|
align: {
|
|
|
|
align: {
|
|
|
|
offset: [0, -2],
|
|
|
|
offset: [0, -2],
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -94,6 +98,10 @@ const TimePicker = {
|
|
|
|
if (value && !interopDefault(moment).isMoment(value)) {
|
|
|
|
if (value && !interopDefault(moment).isMoment(value)) {
|
|
|
|
throw new Error('The value/defaultValue of TimePicker must be a moment object, ');
|
|
|
|
throw new Error('The value/defaultValue of TimePicker must be a moment object, ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
warning(
|
|
|
|
|
|
|
|
!hasProp(this, 'allowEmpty'),
|
|
|
|
|
|
|
|
'`allowEmpty` in TimePicker is deprecated. Please use `allowClear` instead.',
|
|
|
|
|
|
|
|
);
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
sValue: value,
|
|
|
|
sValue: value,
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -135,23 +143,15 @@ const TimePicker = {
|
|
|
|
return 'HH:mm:ss';
|
|
|
|
return 'HH:mm:ss';
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
renderTimePicker(locale) {
|
|
|
|
getAllowClear() {
|
|
|
|
const props = getOptionProps(this);
|
|
|
|
const { allowClear, allowEmpty } = this.$props;
|
|
|
|
delete props.defaultValue;
|
|
|
|
if ('allowClear' in this.$props) {
|
|
|
|
|
|
|
|
return allowClear;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return allowEmpty;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
const format = this.getDefaultFormat();
|
|
|
|
renderInputIcon(prefixCls) {
|
|
|
|
const className = {
|
|
|
|
|
|
|
|
[`${props.prefixCls}-${props.size}`]: !!props.size,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
const tempAddon = getComponentFromProp(this, 'addon', {}, false);
|
|
|
|
|
|
|
|
const addon = panel => {
|
|
|
|
|
|
|
|
return tempAddon ? (
|
|
|
|
|
|
|
|
<div class={`${props.prefixCls}-panel-addon`}>
|
|
|
|
|
|
|
|
{typeof tempAddon === 'function' ? tempAddon(panel) : tempAddon}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
) : null;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
const { prefixCls, getPopupContainer } = props;
|
|
|
|
|
|
|
|
let suffixIcon = getComponentFromProp(this, 'suffixIcon');
|
|
|
|
let suffixIcon = getComponentFromProp(this, 'suffixIcon');
|
|
|
|
suffixIcon = Array.isArray(suffixIcon) ? suffixIcon[0] : suffixIcon;
|
|
|
|
suffixIcon = Array.isArray(suffixIcon) ? suffixIcon[0] : suffixIcon;
|
|
|
|
const clockIcon = (suffixIcon &&
|
|
|
|
const clockIcon = (suffixIcon &&
|
|
|
@ -163,25 +163,56 @@ const TimePicker = {
|
|
|
|
<span class={`${prefixCls}-clock-icon`}>{suffixIcon}</span>
|
|
|
|
<span class={`${prefixCls}-clock-icon`}>{suffixIcon}</span>
|
|
|
|
))) || <Icon type="clock-circle" class={`${prefixCls}-clock-icon`} theme="outlined" />;
|
|
|
|
))) || <Icon type="clock-circle" class={`${prefixCls}-clock-icon`} theme="outlined" />;
|
|
|
|
|
|
|
|
|
|
|
|
const inputIcon = <span class={`${prefixCls}-icon`}>{clockIcon}</span>;
|
|
|
|
return <span class={`${prefixCls}-icon`}>{clockIcon}</span>;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
const clearIcon = (
|
|
|
|
renderClearIcon(prefixCls) {
|
|
|
|
<Icon type="close-circle" class={`${prefixCls}-panel-clear-btn-icon`} theme="filled" />
|
|
|
|
const clearIcon = <Icon type="close-circle" class={`${prefixCls}-clear`} theme="filled" />;
|
|
|
|
);
|
|
|
|
return clearIcon;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
renderTimePicker(locale) {
|
|
|
|
|
|
|
|
let props = getOptionProps(this);
|
|
|
|
|
|
|
|
props = omit(props, ['defaultValue', 'suffixIcon', 'allowEmpty', 'allowClear']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
|
|
|
|
getPopupContainer,
|
|
|
|
|
|
|
|
placeholder,
|
|
|
|
|
|
|
|
size,
|
|
|
|
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
|
|
|
|
|
|
|
|
const prefixCls = getPrefixCls('time-picker', customizePrefixCls);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const format = this.getDefaultFormat();
|
|
|
|
|
|
|
|
const pickerClassName = {
|
|
|
|
|
|
|
|
[`${prefixCls}-${size}`]: !!size,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
const tempAddon = getComponentFromProp(this, 'addon', {}, false);
|
|
|
|
|
|
|
|
const pickerAddon = panel => {
|
|
|
|
|
|
|
|
return tempAddon ? (
|
|
|
|
|
|
|
|
<div class={`${prefixCls}-panel-addon`}>
|
|
|
|
|
|
|
|
{typeof tempAddon === 'function' ? tempAddon(panel) : tempAddon}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
) : null;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
const inputIcon = this.renderInputIcon(prefixCls);
|
|
|
|
|
|
|
|
const clearIcon = this.renderClearIcon(prefixCls);
|
|
|
|
const { getPopupContainer: getContextPopupContainer } = this.configProvider;
|
|
|
|
const { getPopupContainer: getContextPopupContainer } = this.configProvider;
|
|
|
|
const timeProps = {
|
|
|
|
const timeProps = {
|
|
|
|
props: {
|
|
|
|
props: {
|
|
|
|
...generateShowHourMinuteSecond(format),
|
|
|
|
...generateShowHourMinuteSecond(format),
|
|
|
|
...props,
|
|
|
|
...props,
|
|
|
|
|
|
|
|
prefixCls,
|
|
|
|
getPopupContainer: getPopupContainer || getContextPopupContainer,
|
|
|
|
getPopupContainer: getPopupContainer || getContextPopupContainer,
|
|
|
|
format,
|
|
|
|
format,
|
|
|
|
value: this.sValue,
|
|
|
|
value: this.sValue,
|
|
|
|
placeholder: props.placeholder === undefined ? locale.placeholder : props.placeholder,
|
|
|
|
placeholder: placeholder === undefined ? locale.placeholder : placeholder,
|
|
|
|
addon,
|
|
|
|
addon: pickerAddon,
|
|
|
|
inputIcon,
|
|
|
|
inputIcon,
|
|
|
|
clearIcon,
|
|
|
|
clearIcon,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
class: className,
|
|
|
|
class: pickerClassName,
|
|
|
|
ref: 'timePicker',
|
|
|
|
ref: 'timePicker',
|
|
|
|
on: {
|
|
|
|
on: {
|
|
|
|
...this.$listeners,
|
|
|
|
...this.$listeners,
|
|
|
|