feat: update vc-calendar

pull/2682/head
tanjinzhou 2020-07-21 18:36:27 +08:00
parent 6ab243ffaa
commit f6e2e54f65
13 changed files with 139 additions and 151 deletions

View File

@ -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) {

View File

@ -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,

View File

@ -1,18 +1,16 @@
function noop() {} function noop() {}
export default { const OkButton = (_, { attrs }) => {
functional: true, const { prefixCls, locale, okDisabled, onOk } = attrs;
render(createElement, context) { let className = `${prefixCls}-ok-btn`;
const { props, listeners = {} } = context; if (okDisabled) {
const { prefixCls, locale, okDisabled } = props; className += ` ${prefixCls}-ok-btn-disabled`;
const { ok = noop } = listeners; }
let className = `${prefixCls}-ok-btn`; return (
if (okDisabled) { <a class={className} role="button" onClick={okDisabled ? noop : onOk}>
className += ` ${prefixCls}-ok-btn-disabled`; {locale.ok}
} </a>
return ( );
<a class={className} role="button" onClick={okDisabled ? noop : ok}>
{locale.ok}
</a>
);
},
}; };
OkButton.inheritAttrs = false;
export default OkButton;

View File

@ -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,
const className = { onCloseTimePicker = noop,
[`${prefixCls}-time-picker-btn`]: true, onOpenTimePicker = noop,
[`${prefixCls}-time-picker-btn-disabled`]: timePickerDisabled, } = attrs;
}; const className = {
let onClick = noop; [`${prefixCls}-time-picker-btn`]: true,
if (!timePickerDisabled) { [`${prefixCls}-time-picker-btn-disabled`]: timePickerDisabled,
onClick = showTimePicker ? closeTimePicker : openTimePicker; };
} let onClick = noop;
return ( if (!timePickerDisabled) {
<a class={className} role="button" onClick={onClick}> onClick = showTimePicker ? onCloseTimePicker : onOpenTimePicker;
{showTimePicker ? locale.dateSelect : locale.timeSelect} }
</a> return (
); <a class={className} role="button" onClick={onClick}>
}, {showTimePicker ? locale.dateSelect : locale.timeSelect}
</a>
);
}; };
TimePickerButton.inheritAttrs = false;
export default TimePickerButton;

View File

@ -1,33 +1,23 @@
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 localeNow = (!text && timePicker ? locale.now : text) || locale.today;
const { props, listeners = {} } = context; const disabledToday = disabledDate && !isAllowedDate(getTodayTime(value), disabledDate);
const { const isDisabled = disabledToday || disabled;
prefixCls, const disabledTodayClass = isDisabled ? `${prefixCls}-today-btn-disabled` : '';
locale, return (
value, <a
timePicker, class={`${prefixCls}-today-btn ${disabledTodayClass}`}
disabled, role="button"
disabledDate, onClick={isDisabled ? noop : onToday}
// onToday, title={getTodayTimeStr(value)}
text, >
} = props; {localeNow}
const { today = noop } = listeners; </a>
const localeNow = (!text && timePicker ? locale.now : text) || locale.today; );
const disabledToday = disabledDate && !isAllowedDate(getTodayTime(value), disabledDate);
const isDisabled = disabledToday || disabled;
const disabledTodayClass = isDisabled ? `${prefixCls}-today-btn-disabled` : '';
return (
<a
class={`${prefixCls}-today-btn ${disabledTodayClass}`}
role="button"
onClick={isDisabled ? noop : today}
title={getTodayTimeStr(value)}
>
{localeNow}
</a>
);
},
}; };
TodayButton.inheritAttrs = false;
export default TodayButton;

View File

@ -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}

View File

@ -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}

View File

@ -1,49 +1,46 @@
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 localeData = value.localeData();
const { props } = context; const prefixCls = attrs.prefixCls;
const value = props.value; const veryShortWeekdays = [];
const localeData = value.localeData(); const weekDays = [];
const prefixCls = props.prefixCls; const firstDayOfWeek = localeData.firstDayOfWeek();
const veryShortWeekdays = []; let showWeekNumberEl;
const weekDays = []; const now = moment();
const firstDayOfWeek = localeData.firstDayOfWeek(); for (let dateColIndex = 0; dateColIndex < DateConstants.DATE_COL_COUNT; dateColIndex++) {
let showWeekNumberEl; const index = (firstDayOfWeek + dateColIndex) % DateConstants.DATE_COL_COUNT;
const now = moment(); now.day(index);
for (let dateColIndex = 0; dateColIndex < DateConstants.DATE_COL_COUNT; dateColIndex++) { veryShortWeekdays[dateColIndex] = localeData.weekdaysMin(now);
const index = (firstDayOfWeek + dateColIndex) % DateConstants.DATE_COL_COUNT; weekDays[dateColIndex] = localeData.weekdaysShort(now);
now.day(index); }
veryShortWeekdays[dateColIndex] = localeData.weekdaysMin(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" <span class={`${prefixCls}-column-header-inner`}>x</span>
class={`${prefixCls}-column-header ${prefixCls}-week-number-header`} </th>
>
<span class={`${prefixCls}-column-header-inner`}>x</span>
</th>
);
}
const weekDaysEls = weekDays.map((day, xindex) => {
return (
<th key={xindex} role="columnheader" title={day} class={`${prefixCls}-column-header`}>
<span class={`${prefixCls}-column-header-inner`}>{veryShortWeekdays[xindex]}</span>
</th>
);
});
return (
<thead>
<tr role="row">
{showWeekNumberEl}
{weekDaysEls}
</tr>
</thead>
); );
}, }
const weekDaysEls = weekDays.map((day, xindex) => {
return (
<th key={xindex} role="columnheader" title={day} class={`${prefixCls}-column-header`}>
<span class={`${prefixCls}-column-header-inner`}>{veryShortWeekdays[xindex]}</span>
</th>
);
});
return (
<thead>
<tr role="row">
{showWeekNumberEl}
{weekDaysEls}
</tr>
</thead>
);
}; };
DateTHead.inheritAttrs = false;
export default DateTHead;

View File

@ -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) { return (
const { props, listeners = {} } = context; <table class={`${prefixCls}-table`} cellSpacing="0" role="grid">
const prefixCls = props.prefixCls; <DateTHead {...attrs} />
const bodyProps = { <DateTBody {...attrs} />
props, </table>
on: listeners, );
};
return (
<table class={`${prefixCls}-table`} cellSpacing="0" role="grid">
<DateTHead {...bodyProps} />
<DateTBody {...bodyProps} />
</table>
);
},
}; };
DateTable.inheritAttrs = false;
export default DateTable;

View File

@ -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,

View File

@ -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,

View File

@ -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}

View File

@ -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;
},
}, },
}; };