|
| 1 | +import { Text, VStack, StackProps, HStack, Image, Heading } from "@chakra-ui/react"; |
| 2 | +import { IoMdTime } from "react-icons/io"; |
| 3 | +import { formatDate } from "@lib/."; |
| 4 | +import { HiNewspaper } from "react-icons/hi2"; |
| 5 | +import { useColors } from "@hook/useColors"; |
| 6 | +import sanitize from "sanitize-html"; |
| 7 | +import Link from "./Link"; |
| 8 | + |
| 9 | +const maxChars = 180; |
| 10 | + |
| 11 | +export interface NewsCardProps extends StackProps { |
| 12 | + header?: string; |
| 13 | + date?: string | null; |
| 14 | + html: string; |
| 15 | + id: string; |
| 16 | + image?: string | null; |
| 17 | + author?: string | null; |
| 18 | +} |
| 19 | + |
| 20 | +export const NewsCard = ({ date, html, header, image, id, author, ...props }: NewsCardProps) => { |
| 21 | + const { newsBgColor, textColor } = useColors(); |
| 22 | + |
| 23 | + return ( |
| 24 | + <HStack color={textColor} bgColor={newsBgColor} gap={10} borderRadius="md" padding={5} align="start" {...props}> |
| 25 | + <Link href={`/news/${id}`}> |
| 26 | + <Image |
| 27 | + src={image ?? "https://archive.org/download/placeholder-image/placeholder-image.jpg"} |
| 28 | + maxW="200px" |
| 29 | + alt="news image" |
| 30 | + borderRadius="md" |
| 31 | + /> |
| 32 | + </Link> |
| 33 | + <VStack align="start" maxW="100%"> |
| 34 | + <Heading size="md">{header}</Heading> |
| 35 | + <Text color={textColor} opacity="0.6" fontSize="xs"> |
| 36 | + By {author ?? "admin"} |
| 37 | + </Text> |
| 38 | + <Text |
| 39 | + w="full" |
| 40 | + maxW="100%" |
| 41 | + marginTop={2} |
| 42 | + overflowWrap="break-word" |
| 43 | + whiteSpace="normal" |
| 44 | + wordBreak="break-word" |
| 45 | + fontSize="sm" |
| 46 | + dangerouslySetInnerHTML={{ __html: sanitize(html.length > maxChars ? html.slice(0, maxChars) + "..." : html) }} |
| 47 | + /> |
| 48 | + </VStack> |
| 49 | + {/* <Flex bgColor={bgColor} borderBottomWidth="1px" borderTopWidth="1px" borderColor="#ddd" borderRadius={borderRadius}> |
| 50 | + <Grid margin="10px" width="100%" templateColumns="1fr auto"> |
| 51 | + <Flex flexDirection="row" alignItems="center" gap="5px"> |
| 52 | + <HiNewspaper /> |
| 53 | + <Text color={textColor}>{header}</Text> |
| 54 | + </Flex> |
| 55 | + {date && ( |
| 56 | + <Box display="flex" alignItems="center" justifyContent="flex-end"> |
| 57 | + <IoMdTime /> |
| 58 | + <Text>{formatDate(date)}</Text> |
| 59 | + </Box> |
| 60 | + )} |
| 61 | + </Grid> |
| 62 | + </Flex> |
| 63 | + <Box padding="10px">{isLoading ? <Loader /> : children}</Box> */} |
| 64 | + </HStack> |
| 65 | + ); |
| 66 | +}; |
0 commit comments