parent
19e999a1b5
commit
3975cdea78
|
@ -1,3 +1,4 @@
|
||||||
|
import { inject, cloneVNode } from 'vue';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import {
|
import {
|
||||||
|
@ -5,10 +6,8 @@ import {
|
||||||
getPropsData,
|
getPropsData,
|
||||||
initDefaultProps,
|
initDefaultProps,
|
||||||
filterEmpty,
|
filterEmpty,
|
||||||
getComponentFromProp,
|
getComponent,
|
||||||
getListeners,
|
|
||||||
} from '../_util/props-util';
|
} from '../_util/props-util';
|
||||||
import { cloneElement } from '../_util/vnode';
|
|
||||||
import TimelineItem from './TimelineItem';
|
import TimelineItem from './TimelineItem';
|
||||||
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined';
|
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined';
|
||||||
import { ConfigConsumerProps } from '../config-provider';
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
|
@ -28,23 +27,26 @@ export default {
|
||||||
reverse: false,
|
reverse: false,
|
||||||
mode: '',
|
mode: '',
|
||||||
}),
|
}),
|
||||||
inject: {
|
setup() {
|
||||||
configProvider: { default: () => ConfigConsumerProps },
|
const configProvider = inject('configProvider', ConfigConsumerProps);
|
||||||
|
return {
|
||||||
|
configProvider,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
const { prefixCls: customizePrefixCls, reverse, mode, ...restProps } = getOptionProps(this);
|
const { prefixCls: customizePrefixCls, reverse, mode, ...restProps } = getOptionProps(this);
|
||||||
const getPrefixCls = this.configProvider.getPrefixCls;
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
||||||
const prefixCls = getPrefixCls('timeline', customizePrefixCls);
|
const prefixCls = getPrefixCls('timeline', customizePrefixCls);
|
||||||
|
|
||||||
const pendingDot = getComponentFromProp(this, 'pendingDot');
|
const pendingDot = getComponent(this, 'pendingDot');
|
||||||
const pending = getComponentFromProp(this, 'pending');
|
const pending = getComponent(this, 'pending');
|
||||||
const pendingNode = typeof pending === 'boolean' ? null : pending;
|
const pendingNode = typeof pending === 'boolean' ? null : pending;
|
||||||
const classString = classNames(prefixCls, {
|
const classString = classNames(prefixCls, {
|
||||||
[`${prefixCls}-pending`]: !!pending,
|
[`${prefixCls}-pending`]: !!pending,
|
||||||
[`${prefixCls}-reverse`]: !!reverse,
|
[`${prefixCls}-reverse`]: !!reverse,
|
||||||
[`${prefixCls}-${mode}`]: !!mode,
|
[`${prefixCls}-${mode}`]: !!mode,
|
||||||
});
|
});
|
||||||
const children = filterEmpty(this.$slots.default);
|
const children = filterEmpty(this.$slots.default && this.$slots.default());
|
||||||
// // Remove falsy items
|
// // Remove falsy items
|
||||||
// const falsylessItems = filterEmpty(this.$slots.default)
|
// const falsylessItems = filterEmpty(this.$slots.default)
|
||||||
// const items = falsylessItems.map((item, idx) => {
|
// const items = falsylessItems.map((item, idx) => {
|
||||||
|
@ -85,7 +87,7 @@ export default {
|
||||||
const items = truthyItems.map((ele, idx) => {
|
const items = truthyItems.map((ele, idx) => {
|
||||||
const pendingClass = idx === itemsCount - 2 ? lastCls : '';
|
const pendingClass = idx === itemsCount - 2 ? lastCls : '';
|
||||||
const readyClass = idx === itemsCount - 1 ? lastCls : '';
|
const readyClass = idx === itemsCount - 1 ? lastCls : '';
|
||||||
return cloneElement(ele, {
|
return cloneVNode(ele, {
|
||||||
class: classNames([
|
class: classNames([
|
||||||
!reverse && !!pending ? pendingClass : readyClass,
|
!reverse && !!pending ? pendingClass : readyClass,
|
||||||
getPositionCls(ele, idx),
|
getPositionCls(ele, idx),
|
||||||
|
@ -98,7 +100,6 @@ export default {
|
||||||
...restProps,
|
...restProps,
|
||||||
},
|
},
|
||||||
class: classString,
|
class: classString,
|
||||||
on: getListeners(this),
|
|
||||||
};
|
};
|
||||||
return <ul {...timelineProps}>{items}</ul>;
|
return <ul {...timelineProps}>{items}</ul>;
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
|
import { inject } from 'vue';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import {
|
import { getOptionProps, initDefaultProps, getComponent } from '../_util/props-util';
|
||||||
getOptionProps,
|
|
||||||
initDefaultProps,
|
|
||||||
getComponentFromProp,
|
|
||||||
getListeners,
|
|
||||||
} from '../_util/props-util';
|
|
||||||
import { ConfigConsumerProps } from '../config-provider';
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
|
|
||||||
export const TimeLineItemProps = {
|
export const TimeLineItemProps = {
|
||||||
|
@ -22,15 +18,18 @@ export default {
|
||||||
color: 'blue',
|
color: 'blue',
|
||||||
pending: false,
|
pending: false,
|
||||||
}),
|
}),
|
||||||
inject: {
|
setup() {
|
||||||
configProvider: { default: () => ConfigConsumerProps },
|
const configProvider = inject('configProvider', ConfigConsumerProps);
|
||||||
|
return {
|
||||||
|
configProvider,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
const { prefixCls: customizePrefixCls, color = '', pending } = getOptionProps(this);
|
const { prefixCls: customizePrefixCls, color = '', pending } = getOptionProps(this);
|
||||||
const getPrefixCls = this.configProvider.getPrefixCls;
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
||||||
const prefixCls = getPrefixCls('timeline', customizePrefixCls);
|
const prefixCls = getPrefixCls('timeline', customizePrefixCls);
|
||||||
|
|
||||||
const dot = getComponentFromProp(this, 'dot');
|
const dot = getComponent(this, 'dot');
|
||||||
const itemClassName = classNames({
|
const itemClassName = classNames({
|
||||||
[`${prefixCls}-item`]: true,
|
[`${prefixCls}-item`]: true,
|
||||||
[`${prefixCls}-item-pending`]: pending,
|
[`${prefixCls}-item-pending`]: pending,
|
||||||
|
@ -43,7 +42,6 @@ export default {
|
||||||
});
|
});
|
||||||
const liProps = {
|
const liProps = {
|
||||||
class: itemClassName,
|
class: itemClassName,
|
||||||
on: getListeners(this),
|
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<li {...liProps}>
|
<li {...liProps}>
|
||||||
|
@ -54,7 +52,9 @@ export default {
|
||||||
>
|
>
|
||||||
{dot}
|
{dot}
|
||||||
</div>
|
</div>
|
||||||
<div class={`${prefixCls}-item-content`}>{this.$slots.default}</div>
|
<div class={`${prefixCls}-item-content`}>
|
||||||
|
{this.$slots.default && this.$slots.default()}
|
||||||
|
</div>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,10 +8,10 @@ export { TimeLineItemProps } from './TimelineItem';
|
||||||
Timeline.Item = TimelineItem;
|
Timeline.Item = TimelineItem;
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
Timeline.install = function(Vue) {
|
Timeline.install = function(app) {
|
||||||
Vue.use(Base);
|
app.use(Base);
|
||||||
Vue.component(Timeline.name, Timeline);
|
app.component(Timeline.name, Timeline);
|
||||||
Vue.component(TimelineItem.name, TimelineItem);
|
app.component(TimelineItem.name, TimelineItem);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Timeline;
|
export default Timeline;
|
||||||
|
|
|
@ -10,6 +10,7 @@ import ConfigProvider from 'ant-design-vue/config-provider';
|
||||||
import Result from 'ant-design-vue/result';
|
import Result from 'ant-design-vue/result';
|
||||||
import Spin from 'ant-design-vue/spin';
|
import Spin from 'ant-design-vue/spin';
|
||||||
import Empty from 'ant-design-vue/empty';
|
import Empty from 'ant-design-vue/empty';
|
||||||
|
import Timeline from 'ant-design-vue/timeline';
|
||||||
import 'ant-design-vue/style.js';
|
import 'ant-design-vue/style.js';
|
||||||
|
|
||||||
createApp(App)
|
createApp(App)
|
||||||
|
@ -22,4 +23,5 @@ createApp(App)
|
||||||
.use(Result)
|
.use(Result)
|
||||||
.use(Spin)
|
.use(Spin)
|
||||||
.use(Empty)
|
.use(Empty)
|
||||||
|
.use(Timeline)
|
||||||
.mount('#app');
|
.mount('#app');
|
||||||
|
|
Loading…
Reference in New Issue