ProductEngine

Engine codes with detailed tooltips showing specifications like power, displacement, dates, and more.

⚡ Performance-optimized: Uses Tippy.js delegation pattern - one global script handles all tooltips efficiently.

🔍 SEO-friendly: Engine codes rendered as static HTML (no client-side hydration required).

Single Engine Code

Display a single engine code with tooltip showing detailed engine information.

Setup:

1. Import the component:

import { ProductEngine } from 'spoko-design-system'

2. Initialize tooltips (one-time setup):

Create a tooltip script in your project:

// src/scripts/tooltips.ts
import 'spoko-design-system/scripts/tooltips';

Then import it in your layout’s <head>:

---
// In your layout file (e.g., HeadCommon.astro)
---
<head>
  <script src="/src/scripts/tooltips.ts"></script>
</head>

See Tooltips documentation for details.

Basic Usage (New API Structure):

CAYA CAYB
---
import { ProductEngine } from 'spoko-design-system';
---

<!-- New API structure (with built-in translations) -->
<ProductEngine engine={{
  code: 'CAYA',
  name: '1.6 TDI',
  serie: { value: 'EA189', label: 'Seria silnika' },
  power: { kw: 55, ps: 75, ps_label: 'KM', label: 'Moc' },
  displacement: { value: 1598, label: 'Pojemność' },
  euro: { value: 5, label: 'Norma Euro' }
}} />

<!-- Old API structure (backward compatible) -->
<ProductEngine
  engine={{ code: 'CAYA', name: '1.6 TDI', kw: 55, ps: 75, cc: 1598, serie: 3, euro: 5 }}
  translations={{ power: 'Moc', cc: 'Pojemność', euro: 'Euro', horsepowerUnit: 'KM' }}
/>

Special Engine Variants (Colored):

Engine codes for special editions are automatically color-coded:

GTI Engine (Red) CAVE
WRC Engine (Blue) CDLJ
Special Blue CPTA
<!-- GTI Engine - Red -->
<ProductEngine engine={{
  code: 'CAVE',
  name: '1.4 TSI',
  power: { kw: 132, ps: 180, ps_label: 'KM', label: 'Moc' },
  displacement: { value: 1390, label: 'Pojemność' },
  euro: { value: 5, label: 'Norma ' }
}} />

<!-- WRC Engine - Blue -->
<ProductEngine engine={{
  code: 'CDLJ',
  name: '1.6 TDI',
  power: { kw: 165, ps: 220, ps_label: 'KM', label: 'Moc' },
  displacement: { value: 1598, label: 'Pojemność' },
  euro: { value: 6, label: 'Norma ' }
}} />

Engine List

Display multiple engine codes from an array (from API response).

Import:

import { ProductEngines } from 'spoko-design-system'

Usage:

CAYA, CAYB, CAYC
---
import { ProductEngines } from 'spoko-design-system';
---

<ProductEngines engines={[
  {
    id: 13,
    code: 'CAYA',
    name: '1.6 TDI',
    serie: { value: 'EA189', label: 'Seria silnika' },
    power: { kw: 55, ps: 75, ps_label: 'KM', label: 'Moc' },
    displacement: { value: 1598, label: 'Pojemność' },
    euro: { value: 5, label: 'Norma ' }
  },
  {
    id: 14,
    code: 'CAYB',
    name: '1.6 TDI',
    serie: { value: 'EA189', label: 'Seria silnika' },
    power: { kw: 66, ps: 90, ps_label: 'KM', label: 'Moc' },
    displacement: { value: 1598, label: 'Pojemność' },
    euro: { value: 5, label: 'Norma ' }
  }
]} />

With API Data:

When using data from the API, pass the part_engines array directly. The component automatically extracts translations from the nested structure:

<ProductEngines
  engines={product.part_engines}
  isPdp={true}
/>

Note: The new API structure includes labels and translations, so you no longer need to pass the translations prop. The component will use labels from the API (e.g., “Moc”, “Pojemność”, “KM”).

API Response Structure:

{
  "part_engines": [
    {
      "id": 13,
      "code": "CAYA",
      "name": "1.6 TDI",
      "info": null,
      "serie": {
        "value": "EA189",
        "label": "Seria silnika"
      },
      "type": {
        "value": "diesel",
        "translated": "Diesel",
        "label": "Typ paliwa"
      },
      "power": {
        "kw": 55,
        "ps": 75,
        "ps_label": "KM",
        "label": "Moc"
      },
      "date": {
        "value": "03/2009–05/2010",
        "label": "Data produkcji"
      },
      "displacement": {
        "value": 1598,
        "label": "Pojemność"
      },
      "compression_ratio": {
        "value": "16,5:1",
        "label": "Stopień sprężania"
      },
      "valves": {
        "value": 16,
        "label": "Zawory"
      },
      "euro": {
        "value": 5,
        "formatted": "Norma Euro 5",
        "label": "Norma "
      }
    },
    {
      "id": 14,
      "code": "CAYB",
      "name": "1.6 TDI",
      "info": null,
      "serie": {
        "value": "EA189",
        "label": "Seria silnika"
      },
      "type": {
        "value": "diesel",
        "translated": "Diesel",
        "label": "Typ paliwa"
      },
      "power": {
        "kw": 66,
        "ps": 90,
        "ps_label": "KM",
        "label": "Moc"
      },
      "date": {
        "value": "03/2009–03/2014",
        "label": "Data produkcji"
      },
      "displacement": {
        "value": 1598,
        "label": "Pojemność"
      },
      "compression_ratio": {
        "value": "16,5:1",
        "label": "Stopień sprężania"
      },
      "valves": {
        "value": 16,
        "label": "Zawory"
      },
      "euro": {
        "value": 5,
        "formatted": "Norma Euro 5",
        "label": "Norma "
      }
    }
  ]
}

Props

ProductEngine Props:

PropTypeRequiredDefaultDescription
engineObjectYes-Engine object with nested structure from API
engine.codeStringYes-Engine code (e.g., “CAYA”)
engine.nameStringNo-Engine name (e.g., “1.6 TDI”)
engine.infoStringNo-Additional info shown in header
engine.serieObjectNo-Engine series object
engine.serie.valueStringNo-Series value (e.g., “EA189”, “EA288”)
engine.serie.labelStringNo-Series label (e.g., “Seria silnika”)
engine.powerObjectNo-Power object with kw, ps, labels
engine.power.kwNumberNo-Power in kilowatts
engine.power.psNumberNo-Power in horsepower
engine.power.ps_labelStringNo-Unit label (e.g., “KM”, “PS”)
engine.power.labelStringNo-Power label (e.g., “Moc”)
engine.displacementObjectNo-Displacement object
engine.displacement.valueNumberNo-Displacement in cm³
engine.displacement.labelStringNo-Label (e.g., “Pojemność”)
engine.euroObjectNo-Euro standard object
engine.euro.valueNumberNo-Euro standard number
engine.euro.labelStringNo-Label (e.g., “Norma Euro”)
engine.euro.formattedStringNo-Formatted string (e.g., “Norma Euro 5”)
showCommaBooleanNofalseShow comma after code (for lists)
translationsObjectNoAPI labelsFallback translations (used only with old API)

Note: The component supports both the new nested API structure (with built-in labels) and the old flat structure for backward compatibility.

ProductEngines Props:

PropTypeRequiredDefaultDescription
enginesArray<Object>Yes[]Array of engine objects (new nested structure)
isPdpBooleanNofalseProduct detail page styling
translationsObjectNoAPI labelsFallback translations (used only with old API)

Features

  • Rich Tooltips: Shows detailed engine specifications on hover (Tippy.js delegation)
  • Performance Optimized: One global script handles all tooltips efficiently
  • SEO-Friendly: Engine codes rendered as static HTML (no hydration)
  • API-Driven Translations: Labels and units come directly from API
  • Multi-language: Supports Polish (KM), German (PS), English (HP)
  • Two-Tone Design: Dark blue header with light body for better hierarchy
  • Semantic Colors: Automatic color coding for special engines (GTI, WRC, etc.)
  • Clean Layout: Flexbox-based design with semantic CSS classes
  • Smart Data: Only shows relevant fields (power, displacement, euro)
  • Auto-sorting: Engines automatically sorted alphabetically by code
  • Backward Compatible: Works with both new and old API structures
  • Touch Friendly: Works on mobile devices

Engine Color Coding

Special engine codes are automatically color-coded:

Engine CodesColorDescription
CAVE, CTHE, DAJA, DAYBRedGTI Performance engines
CDLJBlueWRC/R Street engines
CPTA, CZEALight BlueSpecial blue engines

Notes

  • Setup required: Import 'spoko-design-system/scripts/tooltips' once in your layout (see Tooltips docs)
  • Hover over any engine code to see full specifications in a detailed tooltip
  • Tooltips use Tippy.js delegation pattern (one global handler for all tooltips)
  • Performance: No client-side hydration needed - pure Astro components
  • New API structure: Labels come from API (e.g., “Moc”, “Pojemność”, “KM”)
  • No manual translations needed: The API provides all labels and units
  • The component automatically extracts series value from nested structure
  • Date field is not shown in tooltips (only power, displacement, and euro)
  • Missing data fields are gracefully hidden
  • Commas between engine codes are automatically handled in lists
  • Backward compatible: Still works with old flat API structure
  • Tooltip has dark blue header (#001e50) with light gray body (#f3f4f6)

Migration from Vue to Astro

If upgrading from the old Vue version:

  1. Remove client:load directive from all ProductEngine/ProductEngines usage
  2. Set up tooltips in your layout (see Tooltips documentation)
  3. Update imports to use Astro components (automatically handled by package exports)
  4. No other changes needed - props and API structure remain the same