Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | import { Text, TruncateText } from "@common/Text";
import { Box, Stack, styled } from "@mui/material";
import { palette } from "@palette";
import { ITextProps } from "@common/Text/Text";
import { InfinityIcon } from "@phosphor-icons/react";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
import React, { useRef, useState } from "react";
type EventCardProps = {
title: string;
price: string;
sold: number;
available: number;
enabled: boolean;
};
const EventCard = ({ title, sold, available }: EventCardProps) => {
const isInfinite = available === null;
const [isTextTruncated, setIsTextTruncated] = useState(false);
const containerRef = useRef<HTMLDivElement>(null);
const checkTruncation = () => {
if (!containerRef.current) return;
// Get the actual text element (GiveTruncateText renders a Typography/span)
const el = containerRef.current.firstElementChild as HTMLElement;
if (!el) return;
// For line-clamp truncation, check vertical overflow (scrollHeight > clientHeight)
const isTruncated = el.scrollHeight > el.clientHeight;
setIsTextTruncated(isTruncated);
};
React.useLayoutEffect(() => {
checkTruncation();
}, [title]);
return (
<StyledContainer>
<Stack
p={2}
pt={1}
direction="row"
alignItems="flex-start"
justifyContent="space-between"
sx={{
border: `1px solid ${palette.neutral[10]}`,
borderRadius: "8px 8px 0 0",
}}
>
<GiveTooltip
title={title}
disableHoverListener={!isTextTruncated}
disableFocusListener={!isTextTruncated}
fluidWidth
slotProps={{
tooltip: {
sx: {
wordBreak: "break-word",
whiteSpace: "normal",
},
},
}}
>
<Box
ref={containerRef}
sx={{
minWidth: 0,
flex: 1,
maxWidth: "100%",
overflow: "hidden",
}}
>
<TruncateText
width={175}
height={33}
fontSize={14}
lineClamp={2}
variant="body"
fontWeight="light"
lineHeight="16.8px"
color={palette.neutral[70]}
>
{title}
</TruncateText>
</Box>
</GiveTooltip>
</Stack>
<StyledBottomContainer px={2} py={1} gap={0.5} direction={"row"}>
<Stack direction="row" gap="8px">
<ValueText>
Available
{!isInfinite && <ValueSpan>{available}</ValueSpan>}
</ValueText>
{isInfinite && <InfinityIcon size={18} />}
</Stack>
<ValueText>
Sold<ValueSpan>{sold}</ValueSpan>
</ValueText>
</StyledBottomContainer>
</StyledContainer>
);
};
const StyledContainer = styled(Stack)({
width: 255,
borderRadius: 8,
backgroundColor: "white",
});
const StyledBottomContainer = styled(Stack)({
borderRadius: "0 0 8px 8px",
justifyContent: "space-between",
backgroundColor: palette.neutral[10],
boxShadow: "0px 5px 10px rgba(0, 0, 0, 0.05)",
borderImage:
"linear-gradient(64.18deg, #FDF87E 0%, #80E8F7 0%, #6C9CF8 50%) 1",
borderTopWidth: "2px",
borderTopStyle: "solid",
});
const ValueText = (props: ITextProps) => (
<Text
fontSize={14}
color={palette.neutral[80]}
lineHeight={"16.8px"}
variant="body"
fontWeight={"book"}
sx={{ minWidth: "fit-content" }}
{...props}
/>
);
const ValueSpan = styled("span")({
fontSize: 18,
marginLeft: 8,
});
export default EventCard;
|