2022-11-24 20:11:50 +08:00
|
|
|
import React from 'react';
|
2023-07-20 19:27:33 +08:00
|
|
|
import { createStyles } from 'antd-style';
|
2023-01-11 23:21:14 +08:00
|
|
|
import { ExclamationCircleOutlined } from '@ant-design/icons';
|
2023-07-28 16:17:43 +08:00
|
|
|
import { Col, Row, Tooltip } from 'antd';
|
2023-01-11 23:21:14 +08:00
|
|
|
import useLocale from '../../../hooks/useLocale';
|
2022-11-09 12:28:04 +08:00
|
|
|
|
2023-07-20 19:27:33 +08:00
|
|
|
const useStyle = createStyles(({ token, css }) => {
|
2022-11-09 12:28:04 +08:00
|
|
|
const { boxShadowSecondary } = token;
|
|
|
|
|
|
|
|
return {
|
|
|
|
card: css`
|
|
|
|
position: relative;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
height: 100%;
|
|
|
|
color: inherit;
|
|
|
|
list-style: none;
|
|
|
|
border: 1px solid #e6e6e6;
|
|
|
|
border-radius: 2px;
|
|
|
|
cursor: pointer;
|
|
|
|
transition: box-shadow 0.3s;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
box-shadow: ${boxShadowSecondary};
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
image: css`
|
|
|
|
width: calc(100% + 2px);
|
|
|
|
max-width: none;
|
|
|
|
height: 184px;
|
|
|
|
margin: -1px -1px 0;
|
|
|
|
object-fit: cover;
|
|
|
|
`,
|
|
|
|
badge: css`
|
|
|
|
position: absolute;
|
|
|
|
top: 8px;
|
|
|
|
right: 8px;
|
|
|
|
padding: 4px 8px;
|
|
|
|
color: #fff;
|
|
|
|
font-size: 12px;
|
|
|
|
line-height: 1;
|
|
|
|
background: rgba(0, 0, 0, 0.65);
|
|
|
|
border-radius: 1px;
|
|
|
|
box-shadow: 0 0 2px rgba(255, 255, 255, 0.2);
|
2023-01-11 23:21:14 +08:00
|
|
|
display: inline-flex;
|
|
|
|
column-gap: 4px;
|
2022-11-09 12:28:04 +08:00
|
|
|
`,
|
|
|
|
title: css`
|
|
|
|
margin: 16px 20px 8px;
|
|
|
|
color: #0d1a26;
|
|
|
|
font-size: 20px;
|
|
|
|
line-height: 28px;
|
|
|
|
`,
|
|
|
|
description: css`
|
|
|
|
margin: 0 20px 20px;
|
|
|
|
color: #697b8c;
|
|
|
|
font-size: 14px;
|
|
|
|
line-height: 22px;
|
|
|
|
`,
|
|
|
|
};
|
2023-07-20 19:27:33 +08:00
|
|
|
});
|
2022-11-09 12:28:04 +08:00
|
|
|
|
|
|
|
export type Resource = {
|
|
|
|
title: string;
|
|
|
|
description: string;
|
|
|
|
cover: string;
|
|
|
|
src: string;
|
|
|
|
official?: boolean;
|
|
|
|
};
|
|
|
|
|
2023-01-11 23:21:14 +08:00
|
|
|
const locales = {
|
|
|
|
cn: {
|
|
|
|
official: '官方',
|
|
|
|
thirdPart: '非官方',
|
|
|
|
thirdPartDesc: '非官方产品,请自行确认可用性',
|
|
|
|
},
|
|
|
|
en: {
|
|
|
|
official: 'Official',
|
|
|
|
thirdPart: 'Third Part',
|
|
|
|
thirdPartDesc: 'Unofficial product, please take care confirm availability',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-11-09 12:28:04 +08:00
|
|
|
export type ResourceCardProps = {
|
|
|
|
resource: Resource;
|
|
|
|
};
|
|
|
|
|
2022-11-24 20:11:50 +08:00
|
|
|
const ResourceCard: React.FC<ResourceCardProps> = ({ resource }) => {
|
2023-07-20 19:27:33 +08:00
|
|
|
const { styles } = useStyle();
|
2023-01-11 23:21:14 +08:00
|
|
|
const [locale] = useLocale(locales);
|
2022-11-09 12:28:04 +08:00
|
|
|
|
|
|
|
const { title: titleStr, description, cover, src, official } = resource;
|
|
|
|
|
|
|
|
let coverColor: string | null = null;
|
|
|
|
let title: string = titleStr;
|
|
|
|
const titleMatch = titleStr.match(/(.*)(#[\dA-Fa-f]{6})/);
|
|
|
|
if (titleMatch) {
|
|
|
|
title = titleMatch[1].trim();
|
|
|
|
// eslint-disable-next-line prefer-destructuring
|
|
|
|
coverColor = titleMatch[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Col xs={24} sm={12} md={8} lg={6} style={{ padding: 12 }}>
|
2023-07-20 19:27:33 +08:00
|
|
|
<a className={styles.card} target="_blank" href={src} rel="noreferrer">
|
2022-11-09 12:28:04 +08:00
|
|
|
<img
|
2023-07-20 19:27:33 +08:00
|
|
|
className={styles.image}
|
2022-11-09 12:28:04 +08:00
|
|
|
src={cover}
|
|
|
|
alt={title}
|
|
|
|
style={coverColor ? { backgroundColor: coverColor } : {}}
|
|
|
|
/>
|
2023-01-11 23:21:14 +08:00
|
|
|
{official ? (
|
2023-07-20 19:27:33 +08:00
|
|
|
<div className={styles.badge}>{locale.official}</div>
|
2023-01-11 23:21:14 +08:00
|
|
|
) : (
|
|
|
|
<Tooltip title={locale.thirdPartDesc}>
|
2023-07-20 19:27:33 +08:00
|
|
|
<div className={styles.badge}>
|
2023-01-11 23:21:14 +08:00
|
|
|
<ExclamationCircleOutlined />
|
|
|
|
{locale.thirdPart}
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
2023-07-20 19:27:33 +08:00
|
|
|
<p className={styles?.title}>{title}</p>
|
|
|
|
<p className={styles.description}>{description}</p>
|
2022-11-09 12:28:04 +08:00
|
|
|
</a>
|
|
|
|
</Col>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export type ResourceCardsProps = {
|
|
|
|
resources: Resource[];
|
|
|
|
};
|
|
|
|
|
2022-11-30 11:05:41 +08:00
|
|
|
const ResourceCards: React.FC<ResourceCardsProps> = ({ resources }) => (
|
|
|
|
<Row style={{ margin: '-12px -12px 0 -12px' }}>
|
|
|
|
{resources.map((item) => (
|
2022-12-01 12:21:42 +08:00
|
|
|
<ResourceCard resource={item} key={item?.title} />
|
2022-11-30 11:05:41 +08:00
|
|
|
))}
|
|
|
|
</Row>
|
|
|
|
);
|
2022-11-09 12:28:04 +08:00
|
|
|
|
|
|
|
export default ResourceCards;
|