import type { HTMLAttributes, PropsWithChildren, ReactNode } from 'react' import React from 'react' import { Alert, Badge, type OverlayProps, SlideOver, SlideOverHeader, useFadeEffect, useUI, } from '../../' import type { SlideOverDirection, SlideOverWidthSize } from '../SlideOver' export interface CartSidebarProps extends HTMLAttributes { /** * ID to find this component in testing tools (e.g.: cypress, * testing-library, and jest). */ testId?: string /** * Title for the CartSidebar component. */ title?: string /** * Represents the side that the CartSidebar comes from. */ direction?: SlideOverDirection /** * Represents the size of the CartSidebar. */ size?: SlideOverWidthSize /** * Total of item in the Cart. */ totalItems: number /** * A React component that will be rendered as an icon on the Alert component. */ alertIcon?: ReactNode /** * The content for Alert component. */ alertText?: string /** * Props forwarded to the `Overlay` component. */ overlayProps?: OverlayProps /** * Function called when Close Button is clicked. */ onClose: () => void } function CartSidebar({ testId = 'fs-cart-sidebar', title = 'Your Cart', size = 'partial', direction = 'rightSide', totalItems, children, alertIcon, alertText, overlayProps, onClose, ...otherProps }: PropsWithChildren) { const { fade, fadeOut } = useFadeEffect() const { closeCart } = useUI() return ( fade === 'out' && closeCart()} testId={testId} overlayProps={overlayProps} {...otherProps} > { onClose() fadeOut() }} >

{title} {totalItems}

{alertText && {alertText}} {children}
) } export default CartSidebar