All files / src/components/RelatedCard index.tsx

100% Statements 7/7
50% Branches 2/4
100% Functions 4/4
100% Lines 7/7

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                1x 1x   1x                 1x                 1x                               1x               1x                                        
import React from "react";
import { Link, withPrefix } from "gatsby";
 
import { parseImgur, SizeMapping } from "@/utils/images";
 
import * as style from "./index.module.scss";
import Tag from "@/components/Tag";
 
const imageStyle = (headerImage: string) =>
  `${parseImgur(headerImage, SizeMapping.large)}`;
 
const CardHeader = ({
  url,
  image,
  title,
}: {
  url: string;
  image: string;
  title: string;
}) => (
  <Link to={url}>
    <span className="visually-hidden">{title}</span>
    <div
      className={style.wrapper + " lozad"}
      data-background-image={imageStyle(image)}
    />
  </Link>
);
 
const RelatedCard = ({
  title,
  url,
  tags = [],
  date,
  headerImage = "",
  description,
}: {
  title: string;
  url: string;
  tags: readonly (string | undefined)[];
  date: string;
  headerImage?: string;
  headerBackgroundColor?: string;
  description?: string;
}) => (
  <div className="col-sm-12 pb-4">
    <Link to={withPrefix(url)}>
      <div className={style.customCard}>
        <div className={style.data}>
          <div className={style.content}>
            <div className={style.stats}>
              <span className={style.date}>{date.split("T")[0]}</span>
              {tags.map((name) => (
                <Tag name={name || ""} key={name} />
              ))}
            </div>
            <CardHeader
              url={withPrefix(url)}
              image={headerImage}
              title={title}
            />
            <Link to={withPrefix(url)}>
              <h4 className={style.title}>{title}</h4>
            </Link>
            <p>{description}</p>
          </div>
        </div>
      </div>
    </Link>
  </div>
);
 
export default RelatedCard;