forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanelRender.tsx
146 lines (130 loc) · 4.85 KB
/
panelRender.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { computed, defineComponent, toRefs } from 'vue';
import classNames from '../_util/classNames';
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
import { tourStepProps } from './interface';
import type { TourBtnProps } from './interface';
import LocaleReceiver from '../locale/LocaleReceiver';
import Button from '../button';
import type { ButtonProps } from '../button';
import defaultLocale from '../locale/en_US';
import type { VueNode } from '../_util/type';
const panelRender = defineComponent({
name: 'ATourPanel',
inheritAttrs: false,
props: tourStepProps(),
setup(props, { attrs, slots }) {
const { current, total } = toRefs(props);
const isLastStep = computed(() => current.value === total.value - 1);
const prevBtnClick = e => {
const prevButtonProps = props.prevButtonProps as TourBtnProps;
props.onPrev?.(e);
if (typeof prevButtonProps?.onClick === 'function') {
prevButtonProps?.onClick();
}
};
const nextBtnClick = e => {
const nextButtonProps = props.nextButtonProps as TourBtnProps;
if (isLastStep.value) {
props.onFinish?.(e);
} else {
props.onNext?.(e);
}
if (typeof nextButtonProps?.onClick === 'function') {
nextButtonProps?.onClick();
}
};
return () => {
const { prefixCls, title, onClose, cover, description, type: stepType, arrow } = props;
const prevButtonProps = props.prevButtonProps as TourBtnProps;
const nextButtonProps = props.nextButtonProps as TourBtnProps;
let headerNode: VueNode;
if (title) {
headerNode = (
<div class={`${prefixCls}-header`}>
<div class={`${prefixCls}-title`}>{title}</div>
</div>
);
}
let descriptionNode: VueNode;
if (description) {
descriptionNode = <div class={`${prefixCls}-description`}>{description}</div>;
}
let coverNode: VueNode;
if (cover) {
coverNode = <div class={`${prefixCls}-cover`}>{cover}</div>;
}
let mergeIndicatorNode: VueNode;
if (slots.indicatorsRender) {
mergeIndicatorNode = slots.indicatorsRender({ current: current.value, total });
} else {
mergeIndicatorNode = [...Array.from({ length: total.value }).keys()].map(
(stepItem, index) => (
<span
key={stepItem}
class={classNames(
index === current.value && `${prefixCls}-indicator-active`,
`${prefixCls}-indicator`,
)}
/>
),
);
}
const mainBtnType = stepType === 'primary' ? 'default' : 'primary';
const secondaryBtnProps: ButtonProps = {
type: 'default',
ghost: stepType === 'primary',
};
return (
<LocaleReceiver componentName="Tour" defaultLocale={defaultLocale.Tour}>
{contextLocale => (
<div
{...attrs}
class={classNames(
stepType === 'primary' ? `${prefixCls}-primary` : '',
attrs.class,
`${prefixCls}-content`,
)}
>
{arrow && <div class={`${prefixCls}-arrow`} key="arrow" />}
<div class={`${prefixCls}-inner`}>
<CloseOutlined class={`${prefixCls}-close`} onClick={onClose} />
{coverNode}
{headerNode}
{descriptionNode}
<div class={`${prefixCls}-footer`}>
{total.value > 1 && (
<div class={`${prefixCls}-indicators`}>{mergeIndicatorNode}</div>
)}
<div class={`${prefixCls}-buttons`}>
{current.value !== 0 ? (
<Button
{...secondaryBtnProps}
{...prevButtonProps}
onClick={prevBtnClick}
size="small"
class={classNames(`${prefixCls}-prev-btn`, prevButtonProps?.className)}
>
{prevButtonProps?.children ? prevButtonProps?.children() : contextLocale.Previous}
</Button>
) : null}
<Button
type={mainBtnType}
{...nextButtonProps}
onClick={nextBtnClick}
size="small"
class={classNames(`${prefixCls}-next-btn`, nextButtonProps?.className)}
>
{nextButtonProps?.children ? nextButtonProps?.children() :
(isLastStep.value ? contextLocale.Finish : contextLocale.Next)}
</Button>
</div>
</div>
</div>
</div>
)}
</LocaleReceiver>
);
};
},
});
export default panelRender;