import React, { FC, ReactNode, ReactType } from 'react'; import DefaultImage, { ImageProps } from '../Image'; import css from './index.module.css'; import { LinkProps } from '../Link'; import classNames from 'classnames'; import ArrowSVG from '../../assets/icons/icon-arrow-left.svg'; import Ribbon from '../../components/Ribbon'; export interface CardProps { ImageProps?: ImageProps; Image?: ReactType; LinkProps?: LinkProps; title?: string; children?: ReactNode; id: string; variant: 'normal' | 'redesign' | 'card-normal' | 'card-small'; urlName?: string; Link?: ReactType; backgroundColor: string; campaign?: string; } const WithLink = ({ Link, LinkProps, children }): any => Link && LinkProps ? {children} : children; const getContrastYIQ = (hexcolor): string => { hexcolor = hexcolor.replace('#', ''); const r = parseInt(hexcolor.substr(0, 2), 16); const g = parseInt(hexcolor.substr(2, 2), 16); const b = parseInt(hexcolor.substr(4, 2), 16); const yiq = (r * 299 + g * 587 + b * 114) / 1000; return yiq >= 128 ? '#142046' : 'white'; }; const Card: FC = ({ children, title, Image = DefaultImage, ImageProps, variant, Link, LinkProps, urlName, backgroundColor, campaign, }) => { const isSvgImage = ImageProps && ImageProps?.file?.contentType === 'image/svg+xml'; const isSvgFromUrl = ImageProps?.src?.split('.').pop() === 'svg'; return ( <>
{!isSvgImage && !isSvgFromUrl && Image && ImageProps && (
)} {!isSvgImage && isSvgFromUrl && ImageProps && (
)} {isSvgImage && ImageProps && ImageProps.svg && (
)} {campaign && } {(title || children) && (

{title}

{children &&
{children}
} {Link && LinkProps && (
{urlName}
)}
)}
); }; export default Card;