Skip to content

SKU Selector

A core e-commerce component for product detail pages. It provides Text / Image / Color display modes, inventory-linked selection based on a SKU matrix, selected-spec summary, and full CSS theming support.

Basic Usage

Automatically computes selectable states from selected values. Combinations with zero stock are automatically disabled.

Color
Size

Please select all specs

Stock: --

SKU Matrix & Inventory Sync

Image Preview Mode

Pass an image field in the spec value with mode: 'image' on the spec to render clickable image swatches.

Color
Size
Image Preview Mode

Color Swatch Mode

Set mode: 'color' and pass a color field on each value to render color pickers for fashion/lifestyle products.

Color
Color Swatch Mode

Selected Summary

Enable show-selected-summary to display a summary of the currently selected specs above the selector, common in e-commerce detail pages.

Select specifications
Color
Size
Selected Spec Summary

Usage in Nuxt

YhSkuSelector is fully SSR-compatible with Nuxt 3. No extra configuration needed when using the yh-ui/nuxt module.

Color
Nuxt Integration
ts
// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['yh-ui/nuxt']
})

API

Props

PropDescriptionTypeDefault
model-value / v-modelCurrently selected spec value IDsArray<string | number>[]
specsSpec group listSkuSpec[][]
skusSKU combination listSkuItem[][]
check-stockAuto-disable items with zero inventorybooleantrue
disabledGlobally disable the selectorbooleanfalse
allow-unselectAllow clicking active item to deselectbooleantrue
sizeSpec button size'small' | 'default' | 'large''default'
image-sizeImage size in px (image mode)number80
show-selected-summaryDisplay selected spec summary at topbooleanfalse
summary-prefixPrefix text for summary labelstring''
theme-overridesCSS variable overridesRecord<string, string>{}

Events

EventDescriptionCallback
update:modelValuev-model binding(value: Array<string | number>) => void
changeFires on every selection change; sku is null if not fully selected(sku: SkuItem | null, selectedValues: Array<string | number>) => void
selectFires on click of any value (including disabled)(spec: SkuSpec, value: SkuSpecValue) => void

Slots

SlotDescriptionScope
labelCustom spec title{ spec: SkuSpec }
valueFully custom spec value cell{ value: SkuSpecValue, spec: SkuSpec, active: boolean, disabled: boolean }
summaryCustom selected summary area{ summary: string, sku: SkuItem | null }

Expose

This component does not expose public instance methods or properties.

SkuSpec Interface

ts
interface SkuSpec {
  id: string | number
  name: string
  values: SkuSpecValue[]
  /** Display mode: 'text' (default) | 'image' | 'color' */
  mode?: 'text' | 'image' | 'color'
}

SkuSpecValue Interface

ts
interface SkuSpecValue {
  id: string | number
  name: string
  image?: string // used when mode='image'
  color?: string // used when mode='color'
  disabled?: boolean
  tag?: string // badge label, e.g. "Hot", "New"
  [key: string]: unknown
}

SkuItem Interface

ts
interface SkuItem {
  id: string | number
  specValueIds: Array<string | number>
  price: number
  stock: number
  marketPrice?: number
  image?: string
  skuNo?: string
  [key: string]: unknown // extensible custom fields
}

Theme Variables

Override the following CSS variables using theme-overrides:

VariableDescriptionDefault
--yh-sku-label-colorSpec title text colorvar(--yh-text-color-secondary)
--yh-sku-label-sizeSpec title font sizevar(--yh-font-size-sm)
--yh-sku-label-weightSpec title font weightvar(--yh-font-weight-medium)
--yh-sku-value-bgDefault spec cell backgroundvar(--yh-fill-color-light)
--yh-sku-value-colorDefault spec cell text colorvar(--yh-text-color-primary)
--yh-sku-value-borderDefault spec cell border colorvar(--yh-border-color-light)
--yh-sku-value-hover-bgHovered spec cell backgroundvar(--yh-fill-color-dark)
--yh-sku-value-active-bgActive cell backgroundvar(--yh-color-primary-light-9)
--yh-sku-value-active-colorActive cell text/border colorvar(--yh-color-primary)
--yh-sku-value-active-borderActive cell border colorvar(--yh-color-primary)
--yh-sku-value-disabled-bgDisabled cell backgroundvar(--yh-fill-color-extra-light)
--yh-sku-value-disabled-colorDisabled cell text colorvar(--yh-text-color-disabled)
--yh-sku-value-radiusSpec cell border radiusvar(--yh-radius-base)
--yh-sku-img-sizeImage swatch size80px
--yh-sku-color-swatch-sizeColor swatch size24px
--yh-sku-gapRow spacingvar(--yh-spacing-md)

Type Exports

NameDescription
YhSkuSelectorPropsComponent props type
YhSkuSelectorEmitsComponent emits type
YhSkuSelectorSlotsComponent slots type
YhSkuSpecSpec group type
YhSkuSpecValueSpec value type
YhSkuItemSKU data type
YhSkuSelectorInstanceComponent instance type

Released under the MIT License.