-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathDefaultPanel.tsx
More file actions
87 lines (83 loc) · 2.5 KB
/
Copy pathDefaultPanel.tsx
File metadata and controls
87 lines (83 loc) · 2.5 KB
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
import * as React from 'react';
import type { TourStepProps } from '../interface';
import classNames from 'classnames';
import pickAttrs from 'rc-util/lib/pickAttrs';
export type DefaultPanelProps = Exclude<TourStepProps, 'closable'> & {
closable: Exclude<TourStepProps['closable'], boolean>;
};
export default function DefaultPanel(props: DefaultPanelProps) {
const {
prefixCls,
current,
total,
title,
description,
onClose,
onPrev,
onNext,
onFinish,
className,
closable,
onClickSlider,
} = props;
const ariaProps = pickAttrs(closable || {}, true);
const closeIcon = closable?.closeIcon;
const mergedClosable = !!closable;
const handleClickSlider = (index: number, currentIndex: number) => {
if (index !== currentIndex) {
onClickSlider(index);
}
};
return (
<div className={classNames(`${prefixCls}-content`, className)}>
<div className={`${prefixCls}-inner`}>
{mergedClosable && (
<button
type="button"
onClick={onClose}
aria-label="Close"
{...ariaProps}
className={`${prefixCls}-close`}
>
{closeIcon}
</button>
)}
<div className={`${prefixCls}-header`}>
<div className={`${prefixCls}-title`}>{title}</div>
</div>
<div className={`${prefixCls}-description`}>{description}</div>
<div className={`${prefixCls}-footer`}>
<div className={`${prefixCls}-sliders`}>
{total > 1
? [...Array.from({ length: total }).keys()].map((item, index) => {
return (
<span
key={item}
className={index === current ? 'active' : ''}
onClick={() => handleClickSlider(index, current)}
/>
);
})
: null}
</div>
<div className={`${prefixCls}-buttons`}>
{current !== 0 ? (
<button className={`${prefixCls}-prev-btn`} onClick={onPrev}>
Prev
</button>
) : null}
{current === total - 1 ? (
<button className={`${prefixCls}-finish-btn`} onClick={onFinish}>
Finish
</button>
) : (
<button className={`${prefixCls}-next-btn`} onClick={onNext}>
Next
</button>
)}
</div>
</div>
</div>
</div>
);
}