Skip to content

feat: update timeline #2364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions components/timeline/Timeline.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { inject, cloneVNode } from 'vue';
import classNames from 'classnames';
import PropTypes from '../_util/vue-types';
import {
getOptionProps,
getPropsData,
initDefaultProps,
filterEmpty,
getComponentFromProp,
getListeners,
getComponent,
} from '../_util/props-util';
import { cloneElement } from '../_util/vnode';
import TimelineItem from './TimelineItem';
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined';
import { ConfigConsumerProps } from '../config-provider';
Expand All @@ -28,23 +27,26 @@ export default {
reverse: false,
mode: '',
}),
inject: {
configProvider: { default: () => ConfigConsumerProps },
setup() {
const configProvider = inject('configProvider', ConfigConsumerProps);
return {
configProvider,
};
},
render() {
const { prefixCls: customizePrefixCls, reverse, mode, ...restProps } = getOptionProps(this);
const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('timeline', customizePrefixCls);

const pendingDot = getComponentFromProp(this, 'pendingDot');
const pending = getComponentFromProp(this, 'pending');
const pendingDot = getComponent(this, 'pendingDot');
const pending = getComponent(this, 'pending');
const pendingNode = typeof pending === 'boolean' ? null : pending;
const classString = classNames(prefixCls, {
[`${prefixCls}-pending`]: !!pending,
[`${prefixCls}-reverse`]: !!reverse,
[`${prefixCls}-${mode}`]: !!mode,
});
const children = filterEmpty(this.$slots.default);
const children = filterEmpty(this.$slots.default && this.$slots.default());
// // Remove falsy items
// const falsylessItems = filterEmpty(this.$slots.default)
// const items = falsylessItems.map((item, idx) => {
Expand Down Expand Up @@ -85,7 +87,7 @@ export default {
const items = truthyItems.map((ele, idx) => {
const pendingClass = idx === itemsCount - 2 ? lastCls : '';
const readyClass = idx === itemsCount - 1 ? lastCls : '';
return cloneElement(ele, {
return cloneVNode(ele, {
class: classNames([
!reverse && !!pending ? pendingClass : readyClass,
getPositionCls(ele, idx),
Expand All @@ -98,7 +100,6 @@ export default {
...restProps,
},
class: classString,
on: getListeners(this),
};
return <ul {...timelineProps}>{items}</ul>;
},
Expand Down
22 changes: 11 additions & 11 deletions components/timeline/TimelineItem.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { inject } from 'vue';
import classNames from 'classnames';
import PropTypes from '../_util/vue-types';
import {
getOptionProps,
initDefaultProps,
getComponentFromProp,
getListeners,
} from '../_util/props-util';
import { getOptionProps, initDefaultProps, getComponent } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';

export const TimeLineItemProps = {
Expand All @@ -22,15 +18,18 @@ export default {
color: 'blue',
pending: false,
}),
inject: {
configProvider: { default: () => ConfigConsumerProps },
setup() {
const configProvider = inject('configProvider', ConfigConsumerProps);
return {
configProvider,
};
},
render() {
const { prefixCls: customizePrefixCls, color = '', pending } = getOptionProps(this);
const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('timeline', customizePrefixCls);

const dot = getComponentFromProp(this, 'dot');
const dot = getComponent(this, 'dot');
const itemClassName = classNames({
[`${prefixCls}-item`]: true,
[`${prefixCls}-item-pending`]: pending,
Expand All @@ -43,7 +42,6 @@ export default {
});
const liProps = {
class: itemClassName,
on: getListeners(this),
};
return (
<li {...liProps}>
Expand All @@ -54,7 +52,9 @@ export default {
>
{dot}
</div>
<div class={`${prefixCls}-item-content`}>{this.$slots.default}</div>
<div class={`${prefixCls}-item-content`}>
{this.$slots.default && this.$slots.default()}
</div>
</li>
);
},
Expand Down
8 changes: 4 additions & 4 deletions components/timeline/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export { TimeLineItemProps } from './TimelineItem';
Timeline.Item = TimelineItem;

/* istanbul ignore next */
Timeline.install = function(Vue) {
Vue.use(Base);
Vue.component(Timeline.name, Timeline);
Vue.component(TimelineItem.name, TimelineItem);
Timeline.install = function(app) {
app.use(Base);
app.component(Timeline.name, Timeline);
app.component(TimelineItem.name, TimelineItem);
};

export default Timeline;
2 changes: 2 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Affix from 'ant-design-vue/affix';
import Alert from 'ant-design-vue/alert';
import ConfigProvider from 'ant-design-vue/config-provider';
import Spin from 'ant-design-vue/Spin';
import Timeline from 'ant-design-vue/Timeline';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import Timeline from 'ant-design-vue/Timeline';
import Timeline from 'ant-design-vue/timeline';

import 'ant-design-vue/style.js';

createApp(App)
Expand All @@ -16,4 +17,5 @@ createApp(App)
.use(Affix)
.use(Alert)
.use(Spin)
.use(Timeline)
.mount('#app');