import * as React from 'react'; import type { FC } from 'react'; import { useContext } from 'react'; import { Badge, Carousel, Skeleton, Typography } from 'antd'; import { createStyles, css, useTheme } from 'antd-style'; import classNames from 'classnames'; import useLocale from '../../../hooks/useLocale'; import SiteContext from '../../../theme/slots/SiteContext'; import type { Extra, Icon } from './util'; import { getCarouselStyle, useSiteData } from './util'; const useStyle = createStyles(({ token }) => { const { carousel } = getCarouselStyle(); const [, lang] = useLocale(); console.log('lang', lang); return { itemBase: css` display: flex; flex: 1 1 0; flex-direction: column; align-items: stretch; text-decoration: none; background-color: ${token.colorBgContainer}; border: ${token.lineWidth}px solid ${token.colorBorderSecondary}; border-radius: ${token.borderRadiusLG}px; transition: all ${token.motionDurationSlow}; padding-block: ${token.paddingMD}px; padding-inline: ${token.paddingLG}px; `, minHeight: lang === 'cn' ? css` min-height: calc(152px - ${token.paddingMD}px * 2); ` : css` min-height: calc(176px - ${token.paddingMD}px * 2); `, cardItem: css` &:hover { box-shadow: ${token.boxShadowCard}; } `, sliderItem: css` margin: 0 ${token.margin}px; text-align: start; `, container: css` display: flex; max-width: 1208px; margin-inline: auto; box-sizing: border-box; padding-inline: ${token.marginXXL}px; column-gap: ${token.paddingMD * 2}px; align-items: stretch; text-align: start; > * { width: calc((100% - ${token.marginXXL * 2}px) / 3); } `, carousel, }; }); interface RecommendItemProps { extra: Extra; index: number; icons: Icon[]; className?: string; } const RecommendItem: React.FC = ({ extra, index, icons, className }) => { const token = useTheme(); const { styles } = useStyle(); if (!extra) { return ; } const icon = icons.find((i) => i.name === extra.source); const card = ( {extra?.title} {extra.description}
{extra.date} {icon && banner}
); if (index === 0) { return ( {card} ); } return card; }; export const BannerRecommendsFallback: FC = () => { const { isMobile } = useContext(SiteContext); const { styles } = useStyle(); const list = Array(3).fill(1); return isMobile ? ( {list.map((_, index) => (
))}
) : (
{list.map((_, index) => ( ))}
); }; const BannerRecommends: React.FC = () => { const { styles } = useStyle(); const [, lang] = useLocale(); const { isMobile } = React.useContext(SiteContext); const data = useSiteData(); const extras = data?.extras?.[lang]; const icons = data?.icons || []; const first3 = !extras || extras.length === 0 ? Array(3).fill(null) : extras.slice(0, 3); return (
{isMobile ? ( {first3.map((extra, index) => (
))}
) : (
{first3.map((extra, index) => ( ))}
)}
); }; export default BannerRecommends;