import React from "react"; import { Button } from "../../button"; import { backgroundColorMap, SimpleCardProps } from "./types"; import { Link } from "@shared/components/link"; import { MaterialIcon } from "@shared/components/material-icon"; import { NextImage } from "@shared/components/next-image"; import { Text } from "@shared/components/text"; import { cx } from "@shared/utils"; import { SpeedCardBg } from "@shared/utils/speed-card-bg"; const ICON_SIZE = 60; const alignmentClasses: Record = { left: "flex w-full justify-start", right: "flex w-full justify-end", center: "flex w-full justify-center", }; const justifyClass: Record = { left: "justify-start", right: "justify-end", center: "justify-center", }; const formatPhoneHref = (phone: string): string => { const digits = (phone || "").replace(/\D/g, ""); return digits ? `tel:${digits}` : ""; }; export const SimpleCard: React.FC = ({ card, lgWidth, mdWidth, className, contentClassName, style, }) => { const view = card.imageView?.toLowerCase(); const fullSizeImage = view === "full"; const marginSizeImage = view === "margin"; const standardSizeImage = view === "standard"; const iconSizeImage = view === "icon" || view === "inset" || (!view && !!card.image); // Local @ui CalloutCard treats "standard" + "icon" as the new card design // that supports background color / pinwheel / inverted text via CSS vars. const hasNewDesign = standardSizeImage || iconSizeImage; const iconAlignment = card.iconAlignment?.toLowerCase() || card.imageAlignment?.toLowerCase() || "left"; const ctaAlignmentClass = (card.ctaAlignment && alignmentClasses[card.ctaAlignment]) || alignmentClasses.left; const ctaAlignmentBottomClass = (card.ctaAlignmentBottom && justifyClass[card.ctaAlignmentBottom]) || justifyClass.left; const pinwheelColorCode = card.pinwheelColor?.split("-")[1]; const useDynamicColors = hasNewDesign && card.applyCardBackgroundColor; const dynamicStyle: React.CSSProperties = { ...style, ...(useDynamicColors && card.backgroundColor ? ({ ["--scc-bg" as any]: card.backgroundColor } as React.CSSProperties) : {}), ...(useDynamicColors && card.textColor ? ({ ["--scc-fg" as any]: card.textColor } as React.CSSProperties) : {}), ...(useDynamicColors && card.backgroundColor ? { backgroundColor: "var(--scc-bg)" } : {}), ...(useDynamicColors && card.showBackgroundImage && pinwheelColorCode ? { backgroundImage: `url('data:image/svg+xml;utf8,${encodeURIComponent( SpeedCardBg(pinwheelColorCode) )}')`, backgroundPosition: "top left", backgroundSize: "684px 107px", backgroundRepeat: "no-repeat", } : {}), }; const renderFullImage = (margin: boolean) => { if (!card.image) return null; return (
); }; const renderIcon = () => { if (!card.image) return null; const imgWidth = standardSizeImage ? card.imageWidth || ICON_SIZE : ICON_SIZE; const imgHeight = standardSizeImage ? card.imageHeight || ICON_SIZE : ICON_SIZE; return (
); }; const textColorStyle = useDynamicColors && card.textColor ? { color: card.textColor } : undefined; const titleNode = card.title ? ( {card.title} ) : null; const titleWithLink = card.cta?.href && titleNode ? ( {titleNode} ) : ( titleNode ); const hasTable = (card.workingHours?.length ?? 0) > 0 || (card.phoneNumber?.length ?? 0) > 0; return (
{/* Top "location" CTA */} {card.ctaBottom?.title && card.ctaBottom?.href ? (
{card.ctaBottom.title}
) : null} {card.image && fullSizeImage ? renderFullImage(false) : null} {card.image && marginSizeImage ? renderFullImage(true) : null}
{card.image && !fullSizeImage && !marginSizeImage ? renderIcon() : null}
{titleWithLink} {card.titleLocation ? (
{card.titleLocation}
) : null} {hasTable ? (
{card.workingHours?.map((hours, index) => { const [label, value] = (hours ?? "").split("|"); return ( ); })} {card.phoneNumber?.map((phone, index) => ( ))}
{label} {value}
{phone}
) : null} {card.body ? ( {card.body} ) : null} {card.richText ? ( {card.richText} ) : null}
{card.cta ? (
) : null}
); }; export default SimpleCard;