Skip to main content

Order Lines

Headless components for displaying and managing order line items in a cart or order.

Purpose

This library provides components for displaying and managing order line items, including product information, quantities, pricing, and line item operations. It's designed as a headless component that provides all the order line logic while allowing complete UI customization. Use this when you need to display order lines from an active cart or a specific order, with the ability to adjust quantities and remove items.

Features

  • Order line display and management with context-based state
  • Quantity adjustment controls with validation
  • Price display with promotion and "from price" detection
  • Product image display from featured assets
  • Line item removal functionality
  • Flexible render prop pattern for complete UI control

Installation

npm install @haus-storefront-react/order-lines

Note: This is not a public package. Contact the Haus Tech Team for access.

API Reference

OrderLines.Root

Main container that provides order lines context and state. When no orderCode is provided, it fetches and manages the active order. When an orderCode is provided, it fetches and displays a specific order (read-only mode where adjusting and removing are disabled).

Props

PropTypeRequiredDefaultDescription
children(props: OrderLinesContextValue) => ReactNodeNo-Render prop that receives order lines data and functions
orderCodestringNo-Optional order code for fetching specific order
adjustablebooleanNotrueWhether quantities can be adjusted
removablebooleanNotrueWhether items can be removed
callbacks{ preAdjust?: (orderLineId: string, quantity: number) => Promise<void>; preRemove?: (lineId: string) => Promise<void> }No-Optional callbacks for order line operations

OrderLines.Item

Individual order line item component. Must be used within OrderLines.Root. Provides context for child components like OrderLines.Image, OrderLines.Price, OrderLines.Quantity, and OrderLines.Remove.

Props

PropTypeRequiredDefaultDescription
childrenReactNodeNo-Child components or content
orderLineOrderLineYes-The order line data to display

OrderLines.Image

Product image display component. Must be used within OrderLines.Item. Displays the featured asset preview for the order line. Returns null if no image is available.

PropTypeRequiredDefaultDescription
altstringNoorderLine.productVariant.nameAlt text for the image
asChildbooleanNofalseRender as child element
...imgPropsImgHTMLAttributes<HTMLImageElement>No-Standard image element props

OrderLines.Price

Price display component for an order line. Must be used within OrderLines.Item. Uses a render prop pattern to provide price information including base price, price with tax, currency code, promotion status, and "from price" detection.

Props

PropTypeRequiredDefaultDescription
children(props: PriceInfo) => ReactNodeNo-Function that receives price information and returns React nodes
withDiscountPricebooleanNofalseWhether to show discounted price and calculate promotion status
Price Info Object
{
price: Price
priceWithTax: Price
currencyCode: CurrencyCode
isPromotion: boolean
isFromPrice: boolean
}

OrderLines.Quantity

Quantity adjustment component for an order line. Must be used within OrderLines.Item. Provides a compound component structure with Root, Decrement, Input, Increment, and Remove sub-components.

OrderLines.Quantity.Root

PropTypeRequiredDefaultDescription
childrenReactNodeYes-Child components (Decrement, Input, Increment, Remove)
minnumberNo0Minimum quantity allowed
maxnumberNo-Maximum quantity allowed
stepnumberNo1Step size for quantity changes

Sub-components

  • OrderLines.Quantity.Decrement - Button to decrease quantity
  • OrderLines.Quantity.Input - Input field for direct quantity entry
  • OrderLines.Quantity.Increment - Button to increase quantity
  • OrderLines.Quantity.Remove - Button to remove the line item

OrderLines.Remove

Remove line item button component. Must be used within OrderLines.Item. Automatically handles removal logic and is hidden when isRemovable is false.

PropTypeRequiredDefaultDescription
childrenReactNodeNo-Button content
asChildbooleanNofalseRender as child element
...buttonPropsButtonHTMLAttributes<HTMLButtonElement>No-Standard button element props

useOrderLinesProps

Hook for managing order lines data and operations. Returns order data, loading states, error states, and functions for adjusting quantities and removing lines.

Parameters

ParameterTypeRequiredDescription
optionsUseOrderLinesOptionsNoConfiguration object for order lines management

Options Object

OptionTypeRequiredDefaultDescription
orderCodestringNo-Order code for fetching specific order
adjustablebooleanNotrueWhether quantities can be adjusted
removablebooleanNotrueWhether items can be removed
fetchActiveOrderbooleanNotrueWhether to fetch active order when no orderCode provided
minnumberNo0Minimum quantity allowed
maxnumberNo-Maximum quantity allowed
stepnumberNo1Step size for quantity changes
callbacks{ preAdjust?: (orderLineId: string, quantity: number) => Promise<void>; preRemove?: (lineId: string) => Promise<void> }No-Optional callbacks for operations

Returns

Return ValueTypeDescription
dataMaybe<Order> | undefinedThe loaded order data or undefined while loading
orderLinesOrderLine[] | undefinedExtracted order lines array from the order
isLoadingbooleanLoading state flag
errorError | nullError object if request failed
adjustOrderLine(orderLineId: string, quantity: number) => Promise<unknown>Function to adjust order line quantity
removeOrderLine(lineId: string) => Promise<unknown>Function to remove an order line
adjustErrorError | nullError from adjust operation
removeErrorError | nullError from remove operation
isAdjustingbooleanLoading state for adjust operation
isRemovingbooleanLoading state for remove operation
getRemoveProps(orderLineId: string, props?) => ButtonHTMLAttributesFunction to get props for remove button
getAdjustProps(props?) => InputHTMLAttributesFunction to get props for quantity input
getDecrementProps(props?) => ButtonHTMLAttributesFunction to get props for decrement button
getIncrementProps(props?) => ButtonHTMLAttributesFunction to get props for increment button
refetch() => Promise<void>Function to manually refetch data

createOrderLinesScope

Utility function for creating a scoped context for OrderLines components. Useful when nesting multiple OrderLines components or when you need to isolate component state.

Signature

function createOrderLinesScope(): [Scope]

Returns

Scope - A scope identifier for the OrderLines context

Basic Usage

Simple Order Lines Display

import { OrderLines } from '@haus-storefront-react/order-lines'

function MyOrderLines() {
return (
<OrderLines.Root>
{({ orderLines, isLoading, error }) => {
if (isLoading) return <div>Loading...</div>
if (error) return <div>Error: {error.message}</div>
if (!orderLines) return <div>No order</div>

return (
<div>
{orderLines.map((orderLine) => (
<OrderLines.Item key={orderLine.id} orderLine={orderLine}>
<OrderLines.Image />
<OrderLines.Price>
{({ price, priceWithTax, currencyCode }) => (
<Price.Root
price={price}
priceWithTax={priceWithTax}
currencyCode={currencyCode}
>
<Price.Amount />
<Price.Currency />
</Price.Root>
)}
</OrderLines.Price>
<OrderLines.Quantity.Root>
<OrderLines.Quantity.Decrement>-</OrderLines.Quantity.Decrement>
<OrderLines.Quantity.Input />
<OrderLines.Quantity.Increment>+</OrderLines.Quantity.Increment>
</OrderLines.Quantity.Root>
<OrderLines.Remove>Remove</OrderLines.Remove>
</OrderLines.Item>
))}
</div>
)
}}
</OrderLines.Root>
)
}

Basic Hook Usage

import { useOrderLinesProps } from '@haus-storefront-react/order-lines'

function MyComponent() {
const {
data: order,
orderLines,
isLoading,
error,
} = useOrderLinesProps({
fetchActiveOrder: true,
})

if (isLoading) return <div>Loading...</div>
if (error) return <div>Error: {error.message}</div>
if (!orderLines) return <div>No order lines</div>

return (
<div>
{orderLines.map((line) => (
<div key={line.id}>
<h3>{line.productVariant.product.name}</h3>
<p>Quantity: {line.quantity}</p>
</div>
))}
</div>
)
}

Advanced Usage

Complex Component Configuration

import {
OrderLines,
useOrderLinesProps,
} from '@haus-storefront-react/order-lines'
import { Price } from '@haus-storefront-react/common-ui'

function AdvancedOrderLines() {
const handlePreAdjust = async (orderLineId: string, quantity: number) => {
console.log(`Adjusting line ${orderLineId} to quantity ${quantity}`)
// Perform validation or other pre-adjustment logic
}

return (
<OrderLines.Root
adjustable={true}
removable={true}
callbacks={{ preAdjust: handlePreAdjust }}
>
{({
data: order,
orderLines,
isLoading,
error,
adjustOrderLine,
removeOrderLine,
}) => {
if (isLoading) {
return (
<div className='loading-state'>
<div className='spinner' />
<span>Loading items...</span>
</div>
)
}

if (error) {
return (
<div className='error-state'>
<h3>Error Loading Items</h3>
<p>{error.message}</p>
</div>
)
}

return (
<div className='order-lines-container'>
{orderLines?.map((orderLine) => (
<div key={orderLine.id} className='order-line-card'>
<OrderLines.Item orderLine={orderLine}>
<div className='line-item'>
<div className='item-image-section'>
<OrderLines.Image className='product-image' />
</div>

<div className='item-details-section'>
<h3>{orderLine.productVariant.product.name}</h3>
<p>{orderLine.productVariant.name}</p>
<p>SKU: {orderLine.productVariant.sku}</p>

<OrderLines.Price withDiscountPrice={true}>
{({
price,
priceWithTax,
currencyCode,
isPromotion,
isFromPrice,
}) => (
<div className='item-pricing'>
<div className='unit-price'>
<span>Unit Price:</span>
<Price.Root
price={price}
priceWithTax={priceWithTax}
currencyCode={currencyCode}
>
<Price.Amount />
</Price.Root>
</div>

<div className='line-total'>
<span>Total:</span>
{isFromPrice && <span>From </span>}
{isPromotion && (
<span className='sale-badge'>On Sale!</span>
)}
<Price.Root
price={price}
priceWithTax={priceWithTax}
currencyCode={currencyCode}
>
<Price.Amount />
</Price.Root>
</div>
</div>
)}
</OrderLines.Price>
</div>

<div className='item-controls-section'>
<div className='quantity-controls'>
<label>Quantity:</label>
<OrderLines.Quantity.Root min={1} max={99} step={1}>
<OrderLines.Quantity.Decrement className='qty-btn' />
<OrderLines.Quantity.Input className='qty-input' />
<OrderLines.Quantity.Increment className='qty-btn' />
</OrderLines.Quantity.Root>
</div>

<div className='item-actions'>
<OrderLines.Remove className='remove-btn'>
Remove Item
</OrderLines.Remove>
</div>
</div>
</div>
</OrderLines.Item>
</div>
))}
</div>
)
}}
</OrderLines.Root>
)
}

Conditional Rendering Patterns

import { OrderLines } from '@haus-storefront-react/order-lines'
import { Price } from '@haus-storefront-react/common-ui'

function ConditionalOrderLines({ orderCode }: { orderCode?: string }) {
return (
<OrderLines.Root
orderCode={orderCode}
adjustable={!orderCode}
removable={!orderCode}
>
{({ data: order, orderLines, isLoading }) => {
if (isLoading) {
return <div>Loading...</div>
}

if (!orderLines || orderLines.length === 0) {
return (
<div className='empty-state'>
<p>No items in {orderCode ? 'this order' : 'your cart'}</p>
</div>
)
}

return (
<div className='order-lines-list'>
{orderLines.map((orderLine) => (
<OrderLines.Item key={orderLine.id} orderLine={orderLine}>
<div className='order-line-content'>
<OrderLines.Image />
<div className='order-line-details'>
<h3>{orderLine.productVariant.product.name}</h3>
<OrderLines.Price>
{({ price, priceWithTax, currencyCode }) => (
<Price.Root
price={price}
priceWithTax={priceWithTax}
currencyCode={currencyCode}
>
<Price.Amount />
<Price.Currency />
</Price.Root>
)}
</OrderLines.Price>
{!orderCode && (
<>
<OrderLines.Quantity.Root>
<OrderLines.Quantity.Decrement />
<OrderLines.Quantity.Input />
<OrderLines.Quantity.Increment />
</OrderLines.Quantity.Root>
<OrderLines.Remove>Remove</OrderLines.Remove>
</>
)}
</div>
</div>
</OrderLines.Item>
))}
</div>
)
}}
</OrderLines.Root>
)
}

Made with ❤️ by Haus Tech Team