Skip to main content

CartIconAndSidebar

A shopping cart icon with item count badge, hover totals tooltip, and a slide-in sidebar that displays cart contents. Designed for use in site headers.

Usage

Header icon with sidebar and totals tooltip

import CartIconAndSidebar from '@/components/propeller/CartIconAndSidebar';

function Header() {
const { cart } = useCart();
const router = useRouter();

return (
<CartIconAndSidebar
cart={cart}
showTotals={true}
showBadge={true}
cartCheckoutButton={true}
cartPageButton={true}
onCheckoutButtonClick={() => router.push('/checkout')}
onCartPageButtonClick={() => router.push('/cart')}
/>
);
}

Header icon with sidebar, no hover totals

<CartIconAndSidebar
cart={cart}
showTotals={false}
onCheckoutButtonClick={() => router.push('/checkout')}
onCartPageButtonClick={() => router.push('/cart')}
/>

Icon-only (no sidebar, custom click handler)

When showCartSidebarOnClick is false, clicking the icon fires onCartIconClick instead of opening the sidebar. Useful when you want to navigate directly to the cart page.

<CartIconAndSidebar
cart={cart}
showCartSidebarOnClick={false}
onCartIconClick={(cart) => router.push('/cart')}
/>

Custom labels

<CartIconAndSidebar
cart={cart}
cartSidebarTitle="Your Bag"
labels={{
totalLabel: 'Subtotal',
itemsLabel: 'products',
emptyCart: 'Nothing here yet.',
continueShopping: 'Keep Browsing',
qty: 'Quantity',
total: 'Order Total',
checkoutButton: 'Proceed to Checkout',
cartPageButton: 'View Full Cart',
cartIconLabel: 'Open cart',
closeLabel: 'Close cart',
}}
onCheckoutButtonClick={() => router.push('/checkout')}
onCartPageButtonClick={() => router.push('/cart')}
/>

Configuration

Core

PropTypeDefaultDescription
cartCartrequiredThe cart object from Propeller SDK.

Icon & Badge

PropTypeDefaultDescription
showBadgebooleantrueShow item count badge on the cart icon.
showTotalsbooleanfalseShow a totals tooltip when hovering the icon.
iconClassNamestringAdditional CSS class for the icon button.
PropTypeDefaultDescription
showCartSidebarOnClickbooleantrueOpen the sidebar on icon click. When false, fires onCartIconClick instead.
cartSidebarTitlestring'Shopping cart'Title displayed at the top of the sidebar.
cartCheckoutButtonbooleantrueShow the checkout button in the sidebar footer.
cartPageButtonbooleantrueShow the "View Cart Details" button in the sidebar footer.
sidebarClassNamestringAdditional CSS class for the sidebar panel.

Callbacks

PropTypeDescription
onCartIconClick(cart: Cart) => voidFired on icon click when showCartSidebarOnClick is false.
onCheckoutButtonClick(cart: Cart) => voidFired when the checkout button in the sidebar is clicked.
onCartPageButtonClick(cart: Cart) => voidFired when the cart page button in the sidebar is clicked.

Labels

PropTypeDefaultDescription
labelsRecord<string, string>Override any UI text. Keys: cartIconLabel, totalLabel, itemsLabel, emptyCart, continueShopping, qty, total, checkoutButton, cartPageButton, closeLabel, cartSidebarTitle.

Labels

KeyDefaultUsed in
cartIconLabel(cart icon label)Accessibility label for the cart icon button
totalLabel(total label)Label for the total price in the hover tooltip
itemsLabel(items label)Label for the item count in the hover tooltip
emptyCart(empty cart message)Message shown when the cart has no items
continueShopping(continue shopping text)Link text in the empty cart state
qty(quantity label)Label prefix for item quantity
total(total label)Label for the total price in the sidebar footer
checkoutButton(checkout button text)Checkout button label
cartPageButton(cart page button text)Cart page button label
closeLabel(close label)Close button accessibility label
cartSidebarTitle(sidebar title)Sidebar header title

Behavior

Icon badge

The badge displays the number of items in cart.items. It only renders when showBadge is true (the default) and the item count is greater than zero. The badge is hidden during server-side rendering and appears only after the component mounts (see Hydration guard below).

  • Opening: Clicking the cart icon opens the sidebar by default (showCartSidebarOnClick={true}). When set to false, the icon click fires onCartIconClick instead.
  • Closing: The sidebar closes when clicking the dark overlay behind it, clicking the close (X) button, or when a checkout/cart-page button is clicked (callbacks fire after the sidebar closes).
  • Animation: The sidebar slides in from the right with a 300ms CSS transition. The overlay uses backdrop-blur-sm for a blurred background effect.
  • Empty state: When the cart has no items, the sidebar shows an empty cart message with a "Continue Shopping" link that closes the sidebar.

Hover totals tooltip

When showTotals is true, hovering over the cart icon shows a small tooltip with the total price and item count. The tooltip appears below the icon and right-aligned.

Image fallback

When a product has no image URL (or the URL does not start with http), the component renders an inline SVG placeholder (a landscape/image icon) instead of a broken <img> tag. No external fallback image file is needed.

Bundle items

Cart items that contain bundle data (item.bundle) render differently from regular items. The bundle name and total price appear at the top, followed by an indented list showing the bundle leader product first, then remaining bundle items with their individual prices.

Hydration guard

The component uses an _isMounted state flag that starts as false and flips to true after the component mounts on the client. The item count badge and the entire sidebar content area are wrapped in a mount guard, preventing hydration mismatches when cart data comes from localStorage (which is unavailable during SSR).

Cart Data (SDK Fields Read)

This component is display-only. It receives a Cart object as a prop and reads the following fields:

FieldTypeUsed For
cart.itemsCartMainItem[]List of line items displayed in the sidebar. Item count for the badge.
cart.total.totalNetnumberTotal price (incl. VAT) shown in the hover tooltip and sidebar footer.
item.product.names[0].valuestringProduct display name.
item.product.media.images.items[0].imageVariants[0].urlstringProduct thumbnail in the sidebar.
item.product.slugs[0].valuestringUsed to build product/cluster URLs.
item.product.skustringSKU displayed beneath the product name.
item.product.classEnums.ProductClassDetermines URL format (/product/... vs /cluster/...).
item.product.productId / item.product.clusterIdnumberUsed in URL generation.
item.quantitynumberDisplayed as "Qty: N".
item.totalSumNetnumberLine item total price (incl. VAT).
item.childItemsCartBaseItem[]Cluster child items, displayed indented beneath the parent.
item.bundleBundleBundle data. When present, the item renders as a bundle with leader + non-leader items.
item.bundle.namestringBundle display name.
item.bundle.price.netnumberBundle total price.
item.bundle.items[].isLeaderEnums.YesNoIdentifies the bundle leader product.
item.bundle.items[].product.names[0].valuestringIndividual bundle item name.
item.bundle.items[].price.netnumberIndividual bundle item price.