Skip to main content

Vendure Product Badges Component

Headless badge rendering component for Vendure products and search results.

Purpose

ProductBadge provides a composable API for rendering badge assets injected by VendureBadgePlugin. It keeps layout control in the UI layer while exposing grouped badges by position.

Features

  • Renders badges from Product or SearchResult
  • Position-based grouping (top-left, top-right, etc.)
  • Compound components for root, groups, items, and images
  • Works with asChild composition patterns
  • Returns null when the badge plugin is disabled or no badges are available

Installation

npm install @haus-storefront-react/vendure-plugin-configs

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

API Reference

Components

ProductBadge.Root

Root provider that computes grouped badge positions and shares context to descendants.

PropTypeRequiredDefaultDescription
productProduct | SearchResultYes-Product or search result that contains badges
asChildbooleanNofalseRender as child component
children(context: ProductBadgeContextValue) => React.ReactNodeNo-Render function receiving grouped badge context

ProductBadge.Group

Renders badges for a specific position inside ProductBadge.Root.

PropTypeRequiredDefaultDescription
positionstringYes-Badge position key
asChildbooleanNofalseRender as child component
children(context: { badges: Badge[]; position: string }) => React.ReactNodeNo-Render function receiving badges at position

ProductBadge.Item

Wrapper for individual badge content.

PropTypeRequiredDefaultDescription
badgeBadgeNo-Badge metadata
asChildbooleanNofalseRender as child component

ProductBadge.Image

Renders the badge asset image.

PropTypeRequiredDefaultDescription
badgeBadgeYes-Badge containing image asset
asChildbooleanNofalseRender as child component

Basic Usage

Render product badges

import { ProductBadge } from '@haus-storefront-react/vendure-plugin-configs/badge'

function ProductCard({ product }) {
return (
<ProductBadge.Root product={product}>
{({ positions }) => (
<>
{positions.map((position) => (
<ProductBadge.Group key={position} position={position}>
{({ badges }) => (
<>
{badges.map((badge) => (
<ProductBadge.Item key={badge.id} badge={badge}>
<ProductBadge.Image badge={badge} />
</ProductBadge.Item>
))}
</>
)}
</ProductBadge.Group>
))}
</>
)}
</ProductBadge.Root>
)
}

Advanced Usage

Restrict by position in UI

import { ProductBadge } from '@haus-storefront-react/vendure-plugin-configs/badge'

function ProductBadgesTopLeft({ product }) {
return (
<ProductBadge.Root product={product}>
<ProductBadge.Group position='top-left'>
{({ badges }) =>
badges.map((badge) => (
<ProductBadge.Item key={badge.id} badge={badge}>
<ProductBadge.Image badge={badge} />
</ProductBadge.Item>
))
}
</ProductBadge.Group>
</ProductBadge.Root>
)
}

Made with ❤️ by Haus Tech Team