You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/timeline/Timeline.jsx

100 lines
3.0 KiB

import classNames from 'classnames';
import PropTypes from '../_util/vue-types';
import {
getOptionProps,
initDefaultProps,
filterEmpty,
getComponentFromProp,
} from '../_util/props-util';
import { cloneElement } from '../_util/vnode';
import TimelineItem from './TimelineItem';
import Icon from '../icon';
import { ConfigConsumerProps } from '../config-provider';
7 years ago
export const TimelineProps = {
prefixCls: PropTypes.string,
/** 指定最后一个幽灵节点是否存在或内容 */
pending: PropTypes.any,
7 years ago
pendingDot: PropTypes.string,
reverse: PropTypes.bool,
mode: PropTypes.oneOf(['left', 'alternate', 'right']),
};
7 years ago
export default {
name: 'ATimeline',
7 years ago
props: initDefaultProps(TimelineProps, {
reverse: false,
7 years ago
}),
inject: {
configProvider: { default: () => ({}) },
},
render() {
const { prefixCls: customizePrefixCls, reverse, mode, ...restProps } = getOptionProps(this);
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
const prefixCls = getPrefixCls('timeline', customizePrefixCls);
const pendingDot = getComponentFromProp(this, 'pendingDot');
const pending = getComponentFromProp(this, 'pending');
const pendingNode = typeof pending === 'boolean' ? null : pending;
7 years ago
const classString = classNames(prefixCls, {
[`${prefixCls}-pending`]: !!pending,
[`${prefixCls}-reverse`]: !!reverse,
[`${prefixCls}-${mode}`]: !!mode,
});
const children = filterEmpty(this.$slots.default);
// // Remove falsy items
// const falsylessItems = filterEmpty(this.$slots.default)
// const items = falsylessItems.map((item, idx) => {
// return cloneElement(item, {
// props: {
// last: falsylessItems.length - 1 === idx,
// },
// })
// })
const pendingItem = !!pending ? (
<TimelineItem pending={!!pending}>
<template slot="dot">{pendingDot || <Icon type="loading" />}</template>
7 years ago
{pendingNode}
</TimelineItem>
) : null;
const timeLineItems = !!reverse
? [pendingItem, ...children.reverse()]
: [...children, pendingItem];
// Remove falsy items
const truthyItems = timeLineItems.filter(item => !!item);
const itemsCount = truthyItems.length;
const lastCls = `${prefixCls}-item-last`;
const items = truthyItems.map((ele, idx) =>
cloneElement(ele, {
class: classNames([
!reverse && !!pending
? idx === itemsCount - 2
? lastCls
: ''
: idx === itemsCount - 1
? lastCls
: '',
mode === 'alternate'
? idx % 2 === 0
? `${prefixCls}-item-left`
: `${prefixCls}-item-right`
: mode === 'right'
? `${prefixCls}-item-right`
: '',
]),
}),
);
7 years ago
const timelineProps = {
props: {
...restProps,
},
class: classString,
on: this.$listeners,
};
return <ul {...timelineProps}>{items}</ul>;
7 years ago
},
};