Skip to main content

ItemStock

Displays product stock status and availability as color-coded badges. Reads from a ProductInventory object and renders up to two inline badges: an availability indicator (available / not available) and a stock level indicator (in stock / low stock / out of stock) with the exact quantity.

Usage

Default (both badges visible)

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

<ItemStock inventory={product.inventory} />

Availability badge only (hide stock quantity)

<ItemStock
inventory={product.inventory}
showStock={false}
/>

Stock quantity only (hide availability badge)

<ItemStock
inventory={product.inventory}
showAvailability={false}
/>

With custom labels (localization)

<ItemStock
inventory={product.inventory}
labels={{
inStock: 'Op voorraad',
outOfStock: 'Niet op voorraad',
lowStock: 'Beperkte voorraad',
available: 'Beschikbaar',
notAvailable: 'Niet beschikbaar',
pieces: 'stuks',
}}
/>

Inside a product card with extra styling

<ItemStock
inventory={product.inventory}
className="mt-2"
/>

Configuration

Data

PropTypeRequiredDefaultDescription
inventoryProductInventoryYes--Product inventory object that drives all stock calculations and display logic

Display toggles

PropTypeDefaultDescription
showAvailabilitybooleantrueShow the availability badge (Available / Not available)
showStockbooleantrueShow the stock level badge with quantity

Customization

PropTypeDefaultDescription
labelsRecord<string, string>See labels table belowOverride any display label
classNamestring''Extra CSS class applied to the root wrapper element

Labels

All text labels can be overridden via the labels prop. Pass a Record<string, string> with any of these keys:

KeyDefault valueUsed in
inStockIn stockStock badge when quantity > 5
outOfStockOut of stockStock badge when quantity is 0
lowStockLow stockStock badge when quantity is 1--5
availableAvailableAvailability badge when quantity > 0
notAvailableNot availableAvailability badge when quantity is 0
piecespcsUnit label shown in parentheses after the stock quantity

Behavior

Rendering guard

The component renders nothing when:

  • The inventory prop is falsy (null or undefined)
  • totalQuantity is undefined or null (interpreted as "no inventory data available")

When totalQuantity is 0 or a positive number, the component renders.

Stock level classification

The stock quantity determines the status label and color coding:

QuantityStatus labelBadge colors
> 5In stockGreen text, green background, green border
1 -- 5Low stockAmber text, amber background, amber border
0Out of stockRed text, red background, red border

When the quantity is greater than 0, the exact count is shown in parentheses after the status label (e.g., "In stock (42 pcs)"). When the quantity is 0, only the "Out of stock" label is shown without a count.

Availability display

The availability badge shows a simple binary state:

ConditionLabelDot colorBadge colors
Quantity > 0AvailableGreen dotGreen text, green background, green border
Quantity = 0Not availableRed dotRed text, red background, red border

The availability dot is a small circular indicator rendered inline before the label text.

Layout

The component renders as a horizontal flex container with flex-wrap enabled. The two badges (availability and stock) sit side by side and wrap to the next line on narrow containers. Each badge is a rounded pill (rounded-full) with a small border, compact padding, and 11px font size.

SDK Services

ItemStock is a display-only component -- it does not call any SDK services itself. It receives a ProductInventory object as a prop and reads the following field:

ProductInventory fields used

FieldTypePurpose
inventory.totalQuantitynumberThe total available stock quantity across all warehouses. Drives both the availability check and the stock level classification.

The ProductInventory type is imported from propeller-sdk-v2. When fetching product data, ensure the inventory field with totalQuantity is included in your query.

GraphQL Queries and Mutations

To fetch inventory data alongside a product:

query Product($productId: Int!) {
product(id: $productId) {
productId
name {
value
}
inventory {
totalQuantity
}
}
}

Or when fetching products within a category:

query Products($categoryId: Int!, $offset: Int, $limit: Int) {
products(categoryId: $categoryId, offset: $offset, limit: $limit) {
items {
productId
name {
value
}
inventory {
totalQuantity
}
}
}
}