This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
/
Banner.tsx
118 lines (110 loc) · 2.88 KB
/
Banner.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
import React from 'react';
import Notification from './Notification';
import styles from './Banner.module.less';
import classNames from 'classnames';
import { useTranslation } from 'react-i18next';
interface Notification {
type: string;
title: string;
date: string;
link?: string;
}
interface BannerProps {
coverImage: React.ReactNode;
title: string;
description: string;
buttonText: string;
buttonHref: string;
notifications?: Notification[];
style?: React.CSSProperties;
className?: string;
}
const numImgs = [
'https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*ViOPRKPsVzoAAAAAAAAAAABkARQnAQ',
'https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*NFADS6PF0DYAAAAAAAAAAABkARQnAQ',
];
const backLeftBottom =
'https://gw.alipayobjects.com/zos/basement_prod/441d5eaf-e623-47cd-b9b9-2a581d9ce1e3.svg';
const Banner: React.FC<BannerProps> = ({
coverImage,
title,
description,
buttonText,
buttonHref,
notifications = [],
style = {},
className,
}) => {
const { t } = useTranslation();
const insNotifications: Notification[] = [
{
type: t('更新'),
title: t('L7 发布新版本,让地图动起来!'),
date: '2019.12.04',
link: '',
},
{
type: t('推荐'),
title: t('Kitchen 3.75,效率大幅提升!'),
date: '2019.12.03',
link: '',
},
];
if (notifications) {
notifications.forEach((noti, i) => {
insNotifications[i] = noti;
});
}
const getNotifications = () => {
const children = insNotifications.map((notification, i) => {
if (i > 1) return;
let cstyle;
switch (i) {
case 0: {
cstyle = styles.noti0;
break;
}
case 1: {
cstyle = styles.noti1;
break;
}
default: {
break;
}
}
return (
<a href={notification.link} key={i} className={styles.notiWrapper}>
<Notification
className={cstyle}
numImg={numImgs[i]}
notificationContent={notification}
/>
</a>
);
});
return children;
};
return (
<section className={classNames(styles.wrapper, className)} style={style}>
<div className={styles.content}>
<div className={styles.text}>
<div className={styles.title}>{title}</div>
<p className={styles.description}>{description}</p>
<a href={buttonHref} className={styles.amore}>
<button className={styles.more}>{buttonText}</button>
</a>
</div>
<div className={styles.notifications}>{getNotifications()}</div>
<div className={styles.teaser}>
<div className={styles.teaserimg}>{coverImage}</div>
</div>
<img
className={styles.backLeftBottom}
src={backLeftBottom}
alt="back"
/>
</div>
</section>
);
};
export default Banner;