Stats C

Component that represents statistics, numbers,...

Preview

Revenue

$245k

Revenue

$245k

Revenue

$245k

Revenue

$245k

Code

import styles from "./stats-c.module.css"; type ActionType = { icon?: React.ReactElement; title?: string; showTitle?: boolean; onClick?: () => void; }; type Props = { className?: string; children?: React.ReactNode; icon?: React.ReactNode; footerLeftElement?: React.ReactNode; footerRightElement?: React.ReactNode; imageSrc?: string; aspect?: "auto" | "square"; horizontalAlign?: "left" | "start" | "center" | "right" | "end"; rounded?: "none" | "small" | "medium" | "large"; variant?: "default" | "gradient-orange" | "gradient-blue"; actions?: ActionType[]; }; export default function StatsC({ className, children, imageSrc, icon, footerLeftElement, footerRightElement, actions, rounded = "medium", aspect = "auto", horizontalAlign = "start", variant, }: Props) { return ( <div className={[ styles["wrapper"], styles[`ar-${aspect}`], styles[`r-${rounded}`], styles[`ha-${horizontalAlign}`], styles[`variant-${variant}`], className, ].join(" ")} > <div className={styles["content"]}> {/* If you use Next.js, replace 'img' with 'Image' element */} {imageSrc && ( <img className={[styles["image"]].join(" ")} src={imageSrc} alt={"Background"} width={360} height={360} loading="lazy" /> )} {actions && ( <div className={styles["actions"]}> {actions.map((action, index) => { return ( <button key={`action-${index}`} type="button" className={styles["action-button"]} title={action.title} onClick={() => { action.onClick && action.onClick(); }} > {action.showTitle && ( <div className={styles["text"]}>{action.title}</div> )} <div className={styles["icon"]}>{action.icon}</div> </button> ); })} </div> )} {/* You can replace this content */} {icon && <div className={styles["icon-wrapper"]}>{icon}</div>} {children && ( <div className={styles["child-content"]}> <div className={styles["cc-wrapper"]}>{children}</div> </div> )} </div> {(footerLeftElement || footerRightElement) && ( <div className={styles["footer"]}> <div className={styles["f-left"]}>{footerLeftElement}</div> <div className={styles["f-right"]}>{footerRightElement}</div> </div> )} </div> ); }

Design

Figma design file:

Documentation

Properties

Props of the component:

  • className (string): Specifies the CSS class of the component.
  • children (ReactNode): React children of the component. Specifies the ReactNode placed inside the component.
  • icon (ReactNode): Specifies the main icon component.
  • footerLeftElement (ReactNode): Specifies the component placed at the bottom left.
  • footerRightElement (ReactNode): Specifies the component placed at the bottom right.
  • imageSrc (string): Specifies the URL of the image.
  • aspect ("auto" | "square"): Specifies the aspect ratio of the frame.
  • horizontalAlign ("left" | "start" | "center" | "right" | "end"): Specifies the horizontal alignment of the content.
  • rounded ("none" | "small" | "medium" | "large"): Specifies the border radius of the frame.
  • variant ("default" | "gradient-orange" | "gradient-blue" or a customized value): Specifies the color or theme variant of the component. Check out the "Sample CSS customization" below for an example of how to use it.
  • actions (Array of ActionType): Specifies the action buttons placed on the top of the component.
ActionType item arguments
  • icon (ReactNode): Specifies the action icon component.
  • title (string): Specifies the action title text.
  • showTitle (boolean): Show or hide title.
  • onClick (function): Fires when the action button is clicked.
Sample CSS customization
.variant-gradient-blue { --fg-color: #ffffff; --bg-color: #2a57fa; } .variant-gradient-blue { background: linear-gradient(to top right, #2a57fa, #5ab8ff); }