import React, { Children, ReactElement, cloneElement, useState, useEffect, } from "react"; import classNames from "classnames"; import { SizingKeys } from "../../types"; import { bem } from "../../utilities/bem"; import { Box, BoxProps } from "../Box"; import { Icon, IconType } from "../Icon"; const cn = "VendorLogo"; export type VendorLogoSize = SizingKeys; interface VendorLogoBadgeProps extends BoxProps { icon: IconType; size?: VendorLogoSize; } interface VendorLogoProps extends BoxProps { /** * Name of the vendor. If a logo image src is not provided, a tile with the * first letter of the `vendorName` will be shown instead */ vendorName: string; /** * Specifies the path to the logo image */ src?: string; /** * Specifies an alternate label for the image */ alt?: string; /** * Sets the size of logo; uses Tailwind sizing keys, whose output value will * be a mutiple of 4 */ size?: VendorLogoSize; /** * Optional `VendorLogo.Badge` */ children?: ReactElement; } /** * @deprecated */ const VendorLogoBadge = ({ icon, size = 10, className, ...rest }: VendorLogoBadgeProps) => { return ( ); }; /** * @deprecated */ export const VendorLogo = ({ src, vendorName, alt, className, size = 10, children, ...rest }: VendorLogoProps) => { const [loadSuccess, setLoadSuccess] = useState(!!src); const firstLetter = vendorName && vendorName.length > 0 ? vendorName[0] : ""; useEffect(() => { setLoadSuccess(!!src); }, [src]); return ( {loadSuccess ? ( {alt { setLoadSuccess(false); }} /> ) : ( {firstLetter.toUpperCase()} )} {Children.map(children, (child) => { return cloneElement(child as ReactElement, { size, }); })} ); }; VendorLogo.Badge = VendorLogoBadge;