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 | 2x 14x 14x 14x 14x 14x 14x | import React, { CSSProperties } from "react";
export interface CardProps {
title: React.ReactNode;
description?: React.ReactNode;
fadeInIdx?: number;
gradient?: "gradient" | "gradient2" | "false";
comps?: React.ReactNode[];
style?: React.CSSProperties; // replaces classes
}
export const Card: React.FC<CardProps> = ({
title,
description,
fadeInIdx = 0.33,
gradient = "gradient",
comps,
style = {},
}) => {
// Fade-in animation style
const animStyle: CSSProperties = {
animationName: "fadeInOpacity",
animationDuration: `${fadeInIdx}s`,
animationIterationCount: 1,
animationTimingFunction: "ease-in",
opacity: 1,
};
// Gradient background mapping
const gradientMapping: Record<string, string> = {
gradient:
"linear-gradient(90deg, rgba(2,0,36,1) 0%, rgba(9,9,121,1) 35%, rgba(0,212,255,1) 100%)",
gradient2:
"linear-gradient(90deg, rgba(2,0,36,1) 0%, rgb(78,78,110) 35%, rgb(131,232,252) 100%)",
};
// Container style
const containerStyle: CSSProperties = {
padding: 20, // p-[20px]
borderRadius: 8, // rounded-lg
color: "white",
background:
gradient && gradient !== "false" ? gradientMapping[gradient] : undefined,
transition: "transform 0.2s ease-in-out",
...animStyle,
...style,
};
// Title and description styles
const titleStyle: CSSProperties = {
fontSize: "1.25rem", // text-xl
fontWeight: "bold",
margin: 0,
};
const descriptionStyle: CSSProperties = {
fontSize: "1.125rem", // text-lg
marginTop: 8,
marginBottom: 8,
};
return (
<div
style={containerStyle}
onMouseEnter={(e) => (e.currentTarget.style.transform = "scale(1.01)")}
onMouseLeave={(e) => (e.currentTarget.style.transform = "scale(1)")}
>
<h3 style={titleStyle}>{title}</h3>
{description && <div style={descriptionStyle}>{description}</div>}
{comps}
{/* Inline keyframes using style injection */}
<style>
{`
@keyframes fadeInOpacity {
0% { opacity: 0.2; }
100% { opacity: 1; }
}
`}
</style>
</div>
);
};
|