feat: update vc-calendar
parent
6ab243ffaa
commit
f6e2e54f65
|
@ -1,11 +1,13 @@
|
||||||
import PropTypes from '../../../_util/vue-types';
|
import PropTypes from '../../../_util/vue-types';
|
||||||
import BaseMixin from '../../../_util/BaseMixin';
|
import BaseMixin from '../../../_util/BaseMixin';
|
||||||
import { getOptionProps, getListeners } from '../../../_util/props-util';
|
import { getOptionProps } from '../../../_util/props-util';
|
||||||
import TodayButton from './TodayButton';
|
import TodayButton from './TodayButton';
|
||||||
import OkButton from './OkButton';
|
import OkButton from './OkButton';
|
||||||
import TimePickerButton from './TimePickerButton';
|
import TimePickerButton from './TimePickerButton';
|
||||||
|
|
||||||
const CalendarFooter = {
|
const CalendarFooter = {
|
||||||
|
name: 'CalendarFooter',
|
||||||
|
inheritAttrs: false,
|
||||||
mixins: [BaseMixin],
|
mixins: [BaseMixin],
|
||||||
props: {
|
props: {
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
|
@ -42,11 +44,9 @@ const CalendarFooter = {
|
||||||
const extraFooter = renderFooter && renderFooter(mode);
|
const extraFooter = renderFooter && renderFooter(mode);
|
||||||
if (showToday || timePicker || extraFooter) {
|
if (showToday || timePicker || extraFooter) {
|
||||||
const btnProps = {
|
const btnProps = {
|
||||||
props: {
|
|
||||||
...props,
|
...props,
|
||||||
|
...this.$attrs,
|
||||||
value,
|
value,
|
||||||
},
|
|
||||||
on: getListeners(this),
|
|
||||||
};
|
};
|
||||||
let nowEl = null;
|
let nowEl = null;
|
||||||
if (showToday) {
|
if (showToday) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ function showIf(condition, el) {
|
||||||
|
|
||||||
const CalendarHeader = {
|
const CalendarHeader = {
|
||||||
name: 'CalendarHeader',
|
name: 'CalendarHeader',
|
||||||
|
inheritAttrs: false,
|
||||||
mixins: [BaseMixin],
|
mixins: [BaseMixin],
|
||||||
props: {
|
props: {
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
function noop() {}
|
function noop() {}
|
||||||
export default {
|
const OkButton = (_, { attrs }) => {
|
||||||
functional: true,
|
const { prefixCls, locale, okDisabled, onOk } = attrs;
|
||||||
render(createElement, context) {
|
|
||||||
const { props, listeners = {} } = context;
|
|
||||||
const { prefixCls, locale, okDisabled } = props;
|
|
||||||
const { ok = noop } = listeners;
|
|
||||||
let className = `${prefixCls}-ok-btn`;
|
let className = `${prefixCls}-ok-btn`;
|
||||||
if (okDisabled) {
|
if (okDisabled) {
|
||||||
className += ` ${prefixCls}-ok-btn-disabled`;
|
className += ` ${prefixCls}-ok-btn-disabled`;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<a class={className} role="button" onClick={okDisabled ? noop : ok}>
|
<a class={className} role="button" onClick={okDisabled ? noop : onOk}>
|
||||||
{locale.ok}
|
{locale.ok}
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
OkButton.inheritAttrs = false;
|
||||||
|
export default OkButton;
|
||||||
|
|
|
@ -1,22 +1,27 @@
|
||||||
function noop() {}
|
function noop() {}
|
||||||
export default {
|
const TimePickerButton = (_, { attrs }) => {
|
||||||
functional: true,
|
const {
|
||||||
render(h, context) {
|
prefixCls,
|
||||||
const { props, listeners = {} } = context;
|
locale,
|
||||||
const { prefixCls, locale, showTimePicker, timePickerDisabled } = props;
|
showTimePicker,
|
||||||
const { closeTimePicker = noop, openTimePicker = noop } = listeners;
|
timePickerDisabled,
|
||||||
|
onCloseTimePicker = noop,
|
||||||
|
onOpenTimePicker = noop,
|
||||||
|
} = attrs;
|
||||||
const className = {
|
const className = {
|
||||||
[`${prefixCls}-time-picker-btn`]: true,
|
[`${prefixCls}-time-picker-btn`]: true,
|
||||||
[`${prefixCls}-time-picker-btn-disabled`]: timePickerDisabled,
|
[`${prefixCls}-time-picker-btn-disabled`]: timePickerDisabled,
|
||||||
};
|
};
|
||||||
let onClick = noop;
|
let onClick = noop;
|
||||||
if (!timePickerDisabled) {
|
if (!timePickerDisabled) {
|
||||||
onClick = showTimePicker ? closeTimePicker : openTimePicker;
|
onClick = showTimePicker ? onCloseTimePicker : onOpenTimePicker;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<a class={className} role="button" onClick={onClick}>
|
<a class={className} role="button" onClick={onClick}>
|
||||||
{showTimePicker ? locale.dateSelect : locale.timeSelect}
|
{showTimePicker ? locale.dateSelect : locale.timeSelect}
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TimePickerButton.inheritAttrs = false;
|
||||||
|
export default TimePickerButton;
|
||||||
|
|
|
@ -1,20 +1,7 @@
|
||||||
import { getTodayTimeStr, getTodayTime, isAllowedDate } from '../util/';
|
import { getTodayTimeStr, getTodayTime, isAllowedDate } from '../util/';
|
||||||
function noop() {}
|
function noop() {}
|
||||||
export default {
|
const TodayButton = (_, { attrs }) => {
|
||||||
functional: true,
|
const { prefixCls, locale, value, timePicker, disabled, disabledDate, onToday, text } = attrs;
|
||||||
render(createElement, context) {
|
|
||||||
const { props, listeners = {} } = context;
|
|
||||||
const {
|
|
||||||
prefixCls,
|
|
||||||
locale,
|
|
||||||
value,
|
|
||||||
timePicker,
|
|
||||||
disabled,
|
|
||||||
disabledDate,
|
|
||||||
// onToday,
|
|
||||||
text,
|
|
||||||
} = props;
|
|
||||||
const { today = noop } = listeners;
|
|
||||||
const localeNow = (!text && timePicker ? locale.now : text) || locale.today;
|
const localeNow = (!text && timePicker ? locale.now : text) || locale.today;
|
||||||
const disabledToday = disabledDate && !isAllowedDate(getTodayTime(value), disabledDate);
|
const disabledToday = disabledDate && !isAllowedDate(getTodayTime(value), disabledDate);
|
||||||
const isDisabled = disabledToday || disabled;
|
const isDisabled = disabledToday || disabled;
|
||||||
|
@ -23,11 +10,14 @@ export default {
|
||||||
<a
|
<a
|
||||||
class={`${prefixCls}-today-btn ${disabledTodayClass}`}
|
class={`${prefixCls}-today-btn ${disabledTodayClass}`}
|
||||||
role="button"
|
role="button"
|
||||||
onClick={isDisabled ? noop : today}
|
onClick={isDisabled ? noop : onToday}
|
||||||
title={getTodayTimeStr(value)}
|
title={getTodayTimeStr(value)}
|
||||||
>
|
>
|
||||||
{localeNow}
|
{localeNow}
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TodayButton.inheritAttrs = false;
|
||||||
|
|
||||||
|
export default TodayButton;
|
||||||
|
|
|
@ -10,6 +10,8 @@ let cachedSelectionEnd;
|
||||||
let dateInputInstance;
|
let dateInputInstance;
|
||||||
|
|
||||||
const DateInput = {
|
const DateInput = {
|
||||||
|
name: 'DateInput',
|
||||||
|
inheritAttrs: false,
|
||||||
mixins: [BaseMixin],
|
mixins: [BaseMixin],
|
||||||
props: {
|
props: {
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
|
@ -190,17 +192,7 @@ const DateInput = {
|
||||||
<div class={`${prefixCls}-input-wrap`}>
|
<div class={`${prefixCls}-input-wrap`}>
|
||||||
<div class={`${prefixCls}-date-input-wrap`}>
|
<div class={`${prefixCls}-date-input-wrap`}>
|
||||||
<input
|
<input
|
||||||
{...{
|
ref={this.saveDateInput}
|
||||||
directives: [
|
|
||||||
{
|
|
||||||
name: 'ant-ref',
|
|
||||||
value: this.saveDateInput,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'ant-input',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}}
|
|
||||||
class={`${prefixCls}-input ${invalidClass}`}
|
class={`${prefixCls}-input ${invalidClass}`}
|
||||||
value={str}
|
value={str}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import PropTypes from '../../../_util/vue-types';
|
import PropTypes from '../../../_util/vue-types';
|
||||||
import { getOptionProps, getListeners } from '../../../_util/props-util';
|
import { getOptionProps } from '../../../_util/props-util';
|
||||||
import cx from 'classnames';
|
import cx from 'classnames';
|
||||||
import DateConstants from './DateConstants';
|
import DateConstants from './DateConstants';
|
||||||
import { getTitleString, getTodayTime } from '../util/';
|
import { getTitleString, getTodayTime } from '../util/';
|
||||||
|
@ -27,6 +27,8 @@ function getIdFromDate(date) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const DateTBody = {
|
const DateTBody = {
|
||||||
|
name: 'DateTBody',
|
||||||
|
inheritAttrs: false,
|
||||||
props: {
|
props: {
|
||||||
contentRender: PropTypes.func,
|
contentRender: PropTypes.func,
|
||||||
dateRender: PropTypes.func,
|
dateRender: PropTypes.func,
|
||||||
|
@ -50,7 +52,7 @@ const DateTBody = {
|
||||||
disabledDate,
|
disabledDate,
|
||||||
hoverValue,
|
hoverValue,
|
||||||
} = props;
|
} = props;
|
||||||
const { select = noop, dayHover = noop } = getListeners(this);
|
const { onSelect = noop, onDayHover = noop } = this.$attrs;
|
||||||
let iIndex;
|
let iIndex;
|
||||||
let jIndex;
|
let jIndex;
|
||||||
let current;
|
let current;
|
||||||
|
@ -227,8 +229,8 @@ const DateTBody = {
|
||||||
dateCells.push(
|
dateCells.push(
|
||||||
<td
|
<td
|
||||||
key={passed}
|
key={passed}
|
||||||
onClick={disabled ? noop : select.bind(null, current)}
|
onClick={disabled ? noop : onSelect.bind(null, current)}
|
||||||
onMouseenter={disabled ? noop : dayHover.bind(null, current)}
|
onMouseenter={disabled ? noop : onDayHover.bind(null, current)}
|
||||||
role="gridcell"
|
role="gridcell"
|
||||||
title={getTitleString(current)}
|
title={getTitleString(current)}
|
||||||
class={cls}
|
class={cls}
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
import DateConstants from './DateConstants';
|
import DateConstants from './DateConstants';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
export default {
|
const DateTHead = (_, { attrs }) => {
|
||||||
functional: true,
|
const value = attrs.value;
|
||||||
render(createElement, context) {
|
|
||||||
const { props } = context;
|
|
||||||
const value = props.value;
|
|
||||||
const localeData = value.localeData();
|
const localeData = value.localeData();
|
||||||
const prefixCls = props.prefixCls;
|
const prefixCls = attrs.prefixCls;
|
||||||
const veryShortWeekdays = [];
|
const veryShortWeekdays = [];
|
||||||
const weekDays = [];
|
const weekDays = [];
|
||||||
const firstDayOfWeek = localeData.firstDayOfWeek();
|
const firstDayOfWeek = localeData.firstDayOfWeek();
|
||||||
|
@ -20,12 +17,9 @@ export default {
|
||||||
weekDays[dateColIndex] = localeData.weekdaysShort(now);
|
weekDays[dateColIndex] = localeData.weekdaysShort(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props.showWeekNumber) {
|
if (attrs.showWeekNumber) {
|
||||||
showWeekNumberEl = (
|
showWeekNumberEl = (
|
||||||
<th
|
<th role="columnheader" class={`${prefixCls}-column-header ${prefixCls}-week-number-header`}>
|
||||||
role="columnheader"
|
|
||||||
class={`${prefixCls}-column-header ${prefixCls}-week-number-header`}
|
|
||||||
>
|
|
||||||
<span class={`${prefixCls}-column-header-inner`}>x</span>
|
<span class={`${prefixCls}-column-header-inner`}>x</span>
|
||||||
</th>
|
</th>
|
||||||
);
|
);
|
||||||
|
@ -45,5 +39,8 @@ export default {
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
);
|
);
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DateTHead.inheritAttrs = false;
|
||||||
|
|
||||||
|
export default DateTHead;
|
||||||
|
|
|
@ -1,20 +1,16 @@
|
||||||
import DateTHead from './DateTHead';
|
import DateTHead from './DateTHead';
|
||||||
import DateTBody from './DateTBody';
|
import DateTBody from './DateTBody';
|
||||||
|
|
||||||
export default {
|
const DateTable = (_, { attrs }) => {
|
||||||
functional: true,
|
const prefixCls = attrs.prefixCls;
|
||||||
render(createElement, context) {
|
|
||||||
const { props, listeners = {} } = context;
|
|
||||||
const prefixCls = props.prefixCls;
|
|
||||||
const bodyProps = {
|
|
||||||
props,
|
|
||||||
on: listeners,
|
|
||||||
};
|
|
||||||
return (
|
return (
|
||||||
<table class={`${prefixCls}-table`} cellSpacing="0" role="grid">
|
<table class={`${prefixCls}-table`} cellSpacing="0" role="grid">
|
||||||
<DateTHead {...bodyProps} />
|
<DateTHead {...attrs} />
|
||||||
<DateTBody {...bodyProps} />
|
<DateTBody {...attrs} />
|
||||||
</table>
|
</table>
|
||||||
);
|
);
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DateTable.inheritAttrs = false;
|
||||||
|
|
||||||
|
export default DateTable;
|
||||||
|
|
|
@ -20,7 +20,9 @@ function chooseDecade(year, event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
name: 'DecadePanel',
|
||||||
mixins: [BaseMixin],
|
mixins: [BaseMixin],
|
||||||
|
inheritAttrs: false,
|
||||||
props: {
|
props: {
|
||||||
locale: PropTypes.object,
|
locale: PropTypes.object,
|
||||||
value: PropTypes.object,
|
value: PropTypes.object,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { getMonthName } from '../util';
|
||||||
|
|
||||||
const CalendarHeader = {
|
const CalendarHeader = {
|
||||||
name: 'CalendarHeader',
|
name: 'CalendarHeader',
|
||||||
|
inheritAttrs: false,
|
||||||
mixins: [BaseMixin],
|
mixins: [BaseMixin],
|
||||||
props: {
|
props: {
|
||||||
value: PropTypes.object,
|
value: PropTypes.object,
|
||||||
|
|
|
@ -26,6 +26,7 @@ function isMoment(value) {
|
||||||
const MomentType = PropTypes.custom(isMoment);
|
const MomentType = PropTypes.custom(isMoment);
|
||||||
const CalendarMixin = {
|
const CalendarMixin = {
|
||||||
mixins: [BaseMixin],
|
mixins: [BaseMixin],
|
||||||
|
inheritAttrs: false,
|
||||||
name: 'CalendarMixinWrapper',
|
name: 'CalendarMixinWrapper',
|
||||||
props: {
|
props: {
|
||||||
value: MomentType,
|
value: MomentType,
|
||||||
|
@ -62,18 +63,18 @@ const CalendarMixin = {
|
||||||
},
|
},
|
||||||
|
|
||||||
renderRoot(newProps) {
|
renderRoot(newProps) {
|
||||||
const props = this.$props;
|
const props = { ...this.$props, ...this.$attrs };
|
||||||
const prefixCls = props.prefixCls;
|
const prefixCls = props.prefixCls;
|
||||||
|
|
||||||
const className = {
|
const className = {
|
||||||
[prefixCls]: 1,
|
[prefixCls]: 1,
|
||||||
[`${prefixCls}-hidden`]: !props.visible,
|
[`${prefixCls}-hidden`]: !props.visible,
|
||||||
// [props.className]: !!props.className,
|
[props.class]: !!props.class,
|
||||||
[newProps.class]: !!newProps.class,
|
[newProps.class]: !!newProps.class,
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref="rootInstance"
|
ref={this.saveRoot}
|
||||||
class={className}
|
class={className}
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
onKeydown={this.onKeyDown || noop}
|
onKeydown={this.onKeyDown || noop}
|
||||||
|
|
|
@ -15,12 +15,15 @@ export default {
|
||||||
focus() {
|
focus() {
|
||||||
if (this.focusElement) {
|
if (this.focusElement) {
|
||||||
this.focusElement.focus();
|
this.focusElement.focus();
|
||||||
} else if (this.$refs.rootInstance) {
|
} else if (this.rootInstance) {
|
||||||
this.$refs.rootInstance.focus();
|
this.rootInstance.focus();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
saveFocusElement(focusElement) {
|
saveFocusElement(focusElement) {
|
||||||
this.focusElement = focusElement;
|
this.focusElement = focusElement;
|
||||||
},
|
},
|
||||||
|
saveRoot(root) {
|
||||||
|
this.rootInstance = root;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue