Skip to main content

CartCarriers

Displays the available shipping carriers for a shopping cart, letting the user pick one. Each carrier card shows the carrier name, optional logo, price, and delivery deadline.

Usage

Basic

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

<CartCarriers
cart={cart}
onCarrierSelect={(carrier) => console.log('Selected:', carrier.name)}
/>

With custom price formatting and labels

<CartCarriers
cart={cart}
onCarrierSelect={handleCarrierSelect}
formatPrice={(price) => `$ ${price.toFixed(2)}`}
labels={{
noCarriers: 'No shipping options available for your order.',
deliveryDeadline: 'Estimated delivery:',
}}
/>

Hide logos and prices (name-only cards)

<CartCarriers
cart={cart}
showCarrierLogo={false}
showPrice={false}
onCarrierSelect={handleCarrierSelect}
/>

Inside a checkout flow with carrier persistence

const handleCarrierSelect = async (carrier: CartCarrier) => {
// Update the cart with the selected carrier via CartService
await cartService.setCarrier(cart.cartId, carrier.name);
// Refresh local cart state
const updatedCart = await cartService.getCart(cart.cartId);
saveCart(updatedCart);
};

<CartCarriers
cart={cart}
onCarrierSelect={handleCarrierSelect}
carriersContainerClass="checkout-carriers mt-4"
/>

Configuration

Required

PropTypeDescription
cartCartShopping cart object. The component reads cart.carriers to render the list.

Display

PropTypeDefaultDescription
showCarrierLogobooleantrueShow the carrier logo image when the carrier has a logo URL.
showPricebooleantrueShow the carrier shipping price next to the name.
carriersContainerClassstring'cart-carriers'CSS class applied to the outermost wrapper div.

Callbacks

PropTypeDescription
onCarrierSelect(carrier: CartCarrier) => voidFired when the user clicks a carrier card. Receives the full CartCarrier object.

Formatting and labels

PropTypeDefaultDescription
formatPrice(price: number) => stringFormats as EUR X.XXOverride the default price formatter.
labelsRecord<string, string>Override UI strings. Supported keys: noCarriers (empty-state message), deliveryDeadline (prefix before the deadline value).

Labels

KeyDefaultUsed in
noCarriers(empty-state message)Shown when cart.carriers is empty or undefined
deliveryDeadline(prefix before the deadline value)Displayed before the carrier's delivery deadline

Behavior

  • Renders a responsive grid of carrier cards (1 column on mobile, 2 on small screens, 3 on large).
  • Clicking a card selects it visually (highlighted border and background) and fires onCarrierSelect.
  • Only one carrier can be selected at a time; selecting a new one deselects the previous.
  • Selection is local UI state only. The component does not call the API -- the parent must handle persistence via onCarrierSelect.
  • When cart.carriers is empty or missing, an empty-state message is shown (customizable via labels.noCarriers).
  • Carrier logos are displayed as small images (h-6) when showCarrierLogo is true and the carrier has a logo URL.
  • The deliveryDeadline line only appears for carriers that have that field set.
  • Prices default to EUR formatting (EUR X.XX) and can be overridden with formatPrice.

GraphQL

Query: cart with carriers

query CartWithCarriers($cartId: String!) {
cart(cartId: $cartId) {
cartId
carriers {
name
price
logo
deliveryDeadline
}
postageData {
price
carrier
}
}
}

Mutation: set carrier on cart

mutation SetCartCarrier($cartId: String!, $carrier: String!) {
cartSetCarrier(input: { cartId: $cartId, carrier: $carrier }) {
cartId
postageData {
price
carrier
}
}
}

SDK Services

CartCarriers is a presentation-only component. It reads carriers from the Cart object but does not call the SDK itself. The parent is responsible for fetching the cart (which includes carriers) and for persisting the user's selection.

Fetching a cart with carriers

Use CartService.getCart() to retrieve a cart. The response includes the carriers array when the backend has shipping options configured for the cart's contents and delivery address.

import { CartService } from 'propeller-sdk-v2';

const cartService = new CartService(graphqlClient);
const cart = await cartService.getCart(cartId);
// cart.carriers -> CartCarrier[]

Setting the selected carrier

After the user selects a carrier via onCarrierSelect, persist the choice back to the API:

await cartService.setCarrier(cartId, carrier.name);

This updates the cart server-side so that cart.postageData reflects the selected carrier's shipping cost.