All files / src/components/Card index.tsx

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

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                                                                                                                                                             
import React from "react";
 
import Tag from "@/components/Tag";
 
import { parseImgur, SizeMapping } from "@/utils/images";
 
import * as style from "./index.module.scss";
 
const CardHeader = ({
  url,
  image,
  title,
  index,
}: {
  url: string;
  image: string;
  title: string;
  index: number;
}) => {
  const imageUrl = parseImgur(image, SizeMapping.large);
 
  // 1枚目はeager loading(LCP)、2枚目以降はnative lazy loading
  return (
    <a href={url} className={index === 0 ? style.imageLink : undefined}>
      <span className="visually-hidden">{title}</span>
      <img
        src={imageUrl}
        alt=""
        className={style.wrapper}
        loading={index === 0 ? "eager" : "lazy"}
        {...{ fetchpriority: index === 0 ? "high" : "auto" }}
        data-testid="card-header"
      />
    </a>
  );
};
 
const Card = ({
  title,
  date,
  url,
  headerImage,
  description,
  tags = [],
  index,
}: {
  title: string;
  date: string;
  url: string;
  headerImage?: string;
  description: string;
  tags: readonly (string | undefined)[];
  index: number;
}) => (
  <div className="col-sm-12 pb-4" data-testid="card">
    <div className={style.customCard}>
      {headerImage && (
        <CardHeader url={url} image={headerImage} title={title} index={index} />
      )}
      <div className={style.data}>
        <div className={style.dataContent}>
          <div className={style.stats}>
            <span className={style.date}>{date?.split("T")[0]}</span>
            {tags.map((name, index) => (
              <Tag name={name || ""} key={`${name}-${index}`} />
            ))}
          </div>
          <a href={url}>
            <h3 className={style.title}>{title}</h3>
          </a>
          <p>{description}</p>
        </div>
      </div>
    </div>
  </div>
);
 
export default Card;