2022-11-24 20:11:50 +08:00
|
|
|
import React from 'react';
|
2023-01-11 23:21:14 +08:00
|
|
|
import { ExclamationCircleOutlined } from '@ant-design/icons';
|
2024-04-16 10:31:13 +08:00
|
|
|
import { Col, Row, Tooltip, Card, Typography } from 'antd';
|
2024-04-06 16:11:17 +08:00
|
|
|
import { createStyles } from 'antd-style';
|
2023-01-11 23:21:14 +08:00
|
|
|
import useLocale from '../../../hooks/useLocale';
|
2022-11-09 12:28:04 +08:00
|
|
|
|
2024-04-16 10:31:13 +08:00
|
|
|
const { Paragraph } = Typography;
|
2022-11-09 12:28:04 +08:00
|
|
|
|
2024-04-16 10:31:13 +08:00
|
|
|
const useStyle = createStyles(({ token, css }) => ({
|
|
|
|
card: css`
|
2022-11-09 12:28:04 +08:00
|
|
|
position: relative;
|
2024-04-16 10:31:13 +08:00
|
|
|
overflow: hidden;
|
2022-11-09 12:28:04 +08:00
|
|
|
|
2024-04-16 10:31:13 +08:00
|
|
|
.ant-card-cover {
|
|
|
|
overflow: hidden;
|
2022-11-09 12:28:04 +08:00
|
|
|
}
|
2024-04-16 10:31:13 +08:00
|
|
|
img {
|
|
|
|
transition: all ${token.motionDurationSlow} ease-out;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover img {
|
|
|
|
transform: scale(1.3);
|
|
|
|
`,
|
|
|
|
badge: css`
|
2022-11-09 12:28:04 +08:00
|
|
|
position: absolute;
|
|
|
|
top: 8px;
|
|
|
|
right: 8px;
|
2024-04-06 16:11:17 +08:00
|
|
|
padding: ${token.paddingXXS}px ${token.paddingXS}px;
|
2022-11-09 12:28:04 +08:00
|
|
|
color: #fff;
|
2024-04-06 16:11:17 +08:00
|
|
|
font-size: ${token.fontSizeSM}px;
|
2022-11-09 12:28:04 +08:00
|
|
|
line-height: 1;
|
|
|
|
background: rgba(0, 0, 0, 0.65);
|
2024-04-16 10:31:13 +08:00
|
|
|
border-radius: ${token.borderRadiusLG}px;
|
2022-11-09 12:28:04 +08:00
|
|
|
box-shadow: 0 0 2px rgba(255, 255, 255, 0.2);
|
2023-01-11 23:21:14 +08:00
|
|
|
display: inline-flex;
|
2024-04-10 11:47:30 +08:00
|
|
|
column-gap: ${token.paddingXXS}px;
|
2022-11-09 12:28:04 +08:00
|
|
|
`,
|
2024-04-16 10:31:13 +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',
|
2024-01-05 23:00:32 +08:00
|
|
|
thirdPart: 'Third Party',
|
2023-01-11 23:21:14 +08:00
|
|
|
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
|
|
|
|
2024-04-16 10:31:13 +08:00
|
|
|
const { title, description, cover, src, official } = resource;
|
2022-11-09 12:28:04 +08:00
|
|
|
|
2024-04-16 10:31:13 +08:00
|
|
|
const badge = official ? (
|
|
|
|
<div className={styles.badge}>{locale.official}</div>
|
|
|
|
) : (
|
|
|
|
<Tooltip title={locale.thirdPartDesc}>
|
|
|
|
<div className={styles.badge}>
|
|
|
|
<ExclamationCircleOutlined />
|
|
|
|
{locale.thirdPart}
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
2022-11-09 12:28:04 +08:00
|
|
|
|
|
|
|
return (
|
2024-04-16 10:31:13 +08:00
|
|
|
<Col xs={24} sm={12} md={8} lg={6}>
|
2023-07-20 19:27:33 +08:00
|
|
|
<a className={styles.card} target="_blank" href={src} rel="noreferrer">
|
2024-04-16 10:31:13 +08:00
|
|
|
<Card hoverable className={styles.card} cover={<img src={cover} alt={title} />}>
|
|
|
|
<Card.Meta
|
|
|
|
title={title}
|
|
|
|
description={
|
|
|
|
<Paragraph style={{ marginBottom: 0 }} ellipsis={{ rows: 1 }} title={description}>
|
|
|
|
{description}
|
|
|
|
</Paragraph>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
{badge}
|
|
|
|
</Card>
|
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 }) => (
|
2024-04-16 10:31:13 +08:00
|
|
|
<Row gutter={[24, 24]}>
|
2022-11-30 11:05:41 +08:00
|
|
|
{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;
|