|
| 1 | +import { Flex } from 'antd'; |
| 2 | +import { CSSProperties, memo } from 'react'; |
| 3 | + |
| 4 | +import Icon, { IconProps } from '@/Icon'; |
| 5 | +import Img from '@/Img'; |
| 6 | +import type { DivProps } from '@/types'; |
| 7 | + |
| 8 | +import { Center } from '@/DraggablePanel/DraggablePanel'; |
| 9 | +import { useStyles } from './style'; |
| 10 | + |
| 11 | +export interface FeatureItem { |
| 12 | + /** |
| 13 | + * @description The number of columns the item spans. |
| 14 | + */ |
| 15 | + column?: number; |
| 16 | + /** |
| 17 | + * @description The description of the feature item. |
| 18 | + */ |
| 19 | + description?: string; |
| 20 | + /** |
| 21 | + * @description Whether this item is a hero item. |
| 22 | + */ |
| 23 | + hero?: boolean; |
| 24 | + /** |
| 25 | + * @description The name of the icon to display on the feature item. |
| 26 | + */ |
| 27 | + icon?: IconProps['icon']; |
| 28 | + /** |
| 29 | + * @description The URL of the image to display on the feature item. |
| 30 | + */ |
| 31 | + image?: string; |
| 32 | + /** |
| 33 | + * @description The CSS style of the image to display on the feature item. |
| 34 | + */ |
| 35 | + imageStyle?: CSSProperties; |
| 36 | + /** |
| 37 | + * @description The type of the image to display on the feature item. |
| 38 | + * @default 'normal' |
| 39 | + */ |
| 40 | + imageType?: 'light' | 'primary' | 'soon'; |
| 41 | + /** |
| 42 | + * @description The link to navigate to when clicking on the feature item. |
| 43 | + */ |
| 44 | + link?: string; |
| 45 | + /** |
| 46 | + * @description Whether to open the link in a new tab when clicking on the feature item. |
| 47 | + * @default false |
| 48 | + */ |
| 49 | + openExternal?: boolean; |
| 50 | + /** |
| 51 | + * @description The number of rows the item spans. |
| 52 | + */ |
| 53 | + row?: number; |
| 54 | + /** |
| 55 | + * @description The title of the feature item. |
| 56 | + */ |
| 57 | + title: string; |
| 58 | +} |
| 59 | + |
| 60 | +// @ts-ignore |
| 61 | +export interface FeatureItemProps extends FeatureItem, DivProps {} |
| 62 | + |
| 63 | +const Image = memo<{ className?: string; image: string; style?: CSSProperties; title: string }>( |
| 64 | + ({ image, className, title, style }) => { |
| 65 | + return image.startsWith('http') ? ( |
| 66 | + <Img alt={title} className={className} src={image} style={style} /> |
| 67 | + ) : ( |
| 68 | + <Center className={className} style={style}> |
| 69 | + {image} |
| 70 | + </Center> |
| 71 | + ); |
| 72 | + }, |
| 73 | +); |
| 74 | + |
| 75 | +const Item = memo<FeatureItemProps>( |
| 76 | + ({ |
| 77 | + style, |
| 78 | + className, |
| 79 | + row, |
| 80 | + column, |
| 81 | + description, |
| 82 | + image, |
| 83 | + title, |
| 84 | + link, |
| 85 | + icon, |
| 86 | + imageStyle, |
| 87 | + openExternal, |
| 88 | + ...rest |
| 89 | + }) => { |
| 90 | + const rowNumber = row || 7; |
| 91 | + const { styles, cx } = useStyles({ hasLink: Boolean(link), rowNum: rowNumber }); |
| 92 | + |
| 93 | + return ( |
| 94 | + <div |
| 95 | + className={cx(styles.container, className)} |
| 96 | + style={{ |
| 97 | + gridColumn: `span ${column || 1}`, |
| 98 | + gridRow: `span ${rowNumber}`, |
| 99 | + ...style, |
| 100 | + }} |
| 101 | + {...rest} |
| 102 | + > |
| 103 | + <div className={styles.cell}> |
| 104 | + {image || |
| 105 | + (icon && ( |
| 106 | + <Center className={styles.imgContainer} style={imageStyle}> |
| 107 | + {icon && <Icon className={styles.img} icon={icon} />} |
| 108 | + {image && <Image className={styles.img} image={image} title={title} />} |
| 109 | + </Center> |
| 110 | + ))} |
| 111 | + {title && ( |
| 112 | + <Flex component="h3" align={'center'} className={styles.title} gap={8}> |
| 113 | + {title} |
| 114 | + </Flex> |
| 115 | + )} |
| 116 | + {description && ( |
| 117 | + <p className={styles.desc} dangerouslySetInnerHTML={{ __html: description }} /> |
| 118 | + )} |
| 119 | + {link && ( |
| 120 | + <div className={styles.link}> |
| 121 | + <a href={link} rel="noreferrer" target={openExternal ? '_blank' : undefined}> |
| 122 | + Read More |
| 123 | + </a> |
| 124 | + </div> |
| 125 | + )} |
| 126 | + </div> |
| 127 | + </div> |
| 128 | + ); |
| 129 | + }, |
| 130 | +); |
| 131 | + |
| 132 | +export default Item; |
0 commit comments