Skip to content
Snippets Groups Projects
Card.tsx 1.54 KiB
Newer Older
import React from "react";
import { Link } from "gatsby";
tovo's avatar
tovo committed
import { IGatsbyImageData } from "gatsby-plugin-image";

import CardImage from "./card/CardImage";


interface Props {
  title?: string;
  content?: string;
tovo's avatar
tovo committed
  image?: string | IGatsbyImageData;
  to?: string;
  anime?: boolean;
  layout?: "top" | "left";
  className?: string;
tovo's avatar
tovo committed
const oSize = {
  'top': {
    main: 'max-w-xs ',
    content: 'h-24',
    image: 'h-56'
  },
  'left': {
    main: 'h-52 w-full ',
    content: '',
    image: 'min-w-[320px] max-w-[320px]'
  }
}

tovo's avatar
tovo committed

const Card = (props: Props) => {
  const {
    to = "#",
    className = "",
    anime = true,
tovo's avatar
tovo committed
    layout = 'top',
tovo's avatar
tovo committed
    image
  } = props;

  const transition = anime
    ? "lg:transition duration-200 ease-in-out lg:hover:-translate-y-2 lg:hover:shadow-2xl "
    : "";

tovo's avatar
tovo committed
  const cardside = (layout == 'left') ? "card-side " : "";
tovo's avatar
tovo committed
  const size = oSize[layout];

  return (
    <Link
      to={to}
      className={
tovo's avatar
tovo committed
        "card card-compact shadow-xl bg-base-100 text-neutral " +
tovo's avatar
tovo committed
        size.main +
        transition +
        cardside +
        className
      }
    >
tovo's avatar
tovo committed
      <div className={size.image}>
        <CardImage 
          image={image}
        />
      </div>
      {title ? (
tovo's avatar
tovo committed
        <div className="card-body">
          <h2 className="card-title uppercase">{title}</h2>
tovo's avatar
tovo committed
            {content ? <p className={`${size.content} text-ellipsis overflow-hidden text-justify`} dangerouslySetInnerHTML={{ __html: content }}></p> : null}
        </div>
      ) : null}
    </Link>
  );
};

tovo's avatar
tovo committed
export default Card;