ant-design-vue/components/timeline/TimelineItem.tsx

57 lines
1.9 KiB
Vue
Raw Normal View History

2021-06-26 01:35:40 +00:00
import type { ExtractPropTypes } from 'vue';
2021-08-30 02:42:07 +00:00
import { defineComponent } from 'vue';
2020-08-31 08:53:19 +00:00
import classNames from '../_util/classNames';
2019-01-12 03:33:27 +00:00
import PropTypes from '../_util/vue-types';
2020-10-20 05:02:18 +00:00
import initDefaultProps from '../_util/props-util/initDefaultProps';
import { tuple } from '../_util/type';
2021-08-30 02:42:07 +00:00
import useConfigInject from '../_util/hooks/useConfigInject';
2018-04-03 07:51:44 +00:00
2021-08-30 02:42:07 +00:00
export const timelineItemProps = () => ({
2018-04-03 07:51:44 +00:00
prefixCls: PropTypes.string,
color: PropTypes.string,
dot: PropTypes.any,
pending: PropTypes.looseBool,
2020-10-20 05:02:18 +00:00
position: PropTypes.oneOf(tuple('left', 'right', '')).def(''),
2021-08-30 02:42:07 +00:00
label: PropTypes.any,
});
2018-04-03 07:51:44 +00:00
2021-08-30 02:42:07 +00:00
export type TimelineItemProps = Partial<ExtractPropTypes<ReturnType<typeof timelineItemProps>>>;
2020-10-20 05:02:18 +00:00
export default defineComponent({
2018-04-08 13:17:20 +00:00
name: 'ATimelineItem',
2021-08-30 02:42:07 +00:00
props: initDefaultProps(timelineItemProps(), {
2018-04-03 07:51:44 +00:00
color: 'blue',
pending: false,
}),
2021-08-30 02:42:07 +00:00
slots: ['dot', 'label'],
setup(props, { slots }) {
const { prefixCls } = useConfigInject('timeline', props);
return () => {
const { color = '', pending, label = slots.label?.(), dot = slots.dot?.() } = props;
const itemClassName = classNames({
[`${prefixCls.value}-item`]: true,
[`${prefixCls.value}-item-pending`]: pending,
});
2019-03-18 12:35:24 +00:00
2021-08-30 02:42:07 +00:00
const dotClassName = classNames({
[`${prefixCls.value}-item-head`]: true,
[`${prefixCls.value}-item-head-custom`]: dot,
[`${prefixCls.value}-item-head-${color}`]: true,
});
return (
<li class={itemClassName}>
{label && <div class={`${prefixCls.value}-item-label`}>{label}</div>}
<div class={`${prefixCls.value}-item-tail`} />
<div
class={dotClassName}
style={{ borderColor: /blue|red|green|gray/.test(color) ? undefined : color }}
>
{dot}
</div>
<div class={`${prefixCls.value}-item-content`}>{slots.default?.()}</div>
</li>
);
};
2018-04-03 07:51:44 +00:00
},
2020-10-20 05:02:18 +00:00
});