import Link from 'next/link' import React, { PropsWithChildren } from 'react' import { IconChevronRight, IconLoader, cn } from 'ui' interface CardButtonProps { title?: string | React.ReactNode description?: string footer?: React.ReactNode url?: string linkHref?: string imgUrl?: string imgAlt?: string onClick?: () => void icon?: React.ReactNode loading?: boolean className?: string fixedHeight?: boolean hideChevron?: boolean titleClass?: string } // Define separate interfaces for each type of container interface LinkContainerProps extends Omit, 'title'> { href: string } interface UrlContainerProps extends Omit, 'title'> { href: string } interface NonLinkContainerProps extends Omit, 'title'> {} interface ButtonContainerProps extends Omit, 'title'> {} // Union of all container props type ContainerProps = | LinkContainerProps | UrlContainerProps | NonLinkContainerProps | ButtonContainerProps const CardButton = ({ title, description, children, footer, url = '', linkHref = '', imgUrl, imgAlt, icon, className, loading = false, fixedHeight = true, hideChevron = false, titleClass = '', ...props }: PropsWithChildren) => { const isLink = url || linkHref || props.onClick let Container: React.ElementType let containerProps: ContainerProps = {} if (props.onClick) { Container = 'button' containerProps = props } else if (linkHref) { Container = Link containerProps = { href: linkHref, ...props, } } else if (url) { Container = 'a' containerProps = { href: url, ...props, } } else { Container = 'div' containerProps = props } let containerClasses = [ 'group relative text-left', 'bg-surface-100', 'border border-surface', 'rounded-md p-5 flex flex-row', 'transition ease-in-out duration-150', ] if (isLink) { containerClasses = [ ...containerClasses, 'cursor-pointer', 'hover:bg-surface-200', 'hover:border-control', ] } if (fixedHeight) { containerClasses = [...containerClasses, 'h-32'] } const ImageContainer = ({ children }: { children: React.ReactNode }) => { return
{children}
} const contents = ( <> {imgUrl && ( {`${imgAlt}`} )} {icon && {icon}}
{typeof title === 'string' ? (
{title}
) : ( title )} {(children || description) && (

{description}

{children && children}
)} {footer &&
{footer}
}
{isLink && (
{loading ? ( ) : !hideChevron ? ( ) : ( <> )}
)} ) return ( {contents} ) } export default CardButton