@molecule/app-currency-display-solid

Feature · currency-display · App (browser) · v1.1.1 · Apache-2.0

Currency amount formatting + CurrencyDisplay with optional original price + savings badge

npm install @molecule/app-currency-display-solid

npm · Source on GitHub

How it works

@molecule/app-currency-display-solid is a ready-made currency-display feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

import { CurrencyDisplay, formatCurrency } from '@molecule/app-currency-display-solid'

// Basic amount
<CurrencyDisplay amount={49.99} currency="USD" size="lg" />

// With original price and savings chip
<CurrencyDisplay amount={29.99} originalAmount={49.99} currency="USD" showSavings />

// Compact notation: "$29.99K"
<CurrencyDisplay amount={29990} currency="USD" compact size="xl" />

// Plain string utility
const label = formatCurrency(1234.56, 'EUR', 'de-DE') // "1.234,56 €"

Works with: @molecule/app-solid, @molecule/app-ui, @molecule/app-ui-solid

Reference

Solid currency display and formatting utilities.

Exports:

  • formatCurrency(amount, currency?, locale?) — plain string via Intl.NumberFormat.
  • formatCurrencyCompact(amount, currency?, locale?) — compact notation ($12.3K).
  • CurrencyDisplay — rendered amount with optional strikethrough original price + savings chip.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

import { CurrencyDisplay, formatCurrency } from '@molecule/app-currency-display-solid'

// Basic amount
<CurrencyDisplay amount={49.99} currency="USD" size="lg" />

// With original price and savings chip
<CurrencyDisplay amount={29.99} originalAmount={49.99} currency="USD" showSavings />

// Compact notation: "$29.99K"
<CurrencyDisplay amount={29990} currency="USD" compact size="xl" />

// Plain string utility
const label = formatCurrency(1234.56, 'EUR', 'de-DE') // "1.234,56 €"

Type

feature

Installation

npm install @molecule/app-currency-display-solid @molecule/app-solid @molecule/app-ui @molecule/app-ui-solid solid-js

API

Interfaces

CurrencyDisplayProps

Props for CurrencyDisplay.

interface CurrencyDisplayProps {
  /** Current amount in major units. */
  amount: number
  /** Optional original amount — rendered strikethrough to show a discount. */
  originalAmount?: number
  /** ISO 4217 currency code. */
  currency?: string
  /** Locale override. */
  locale?: string
  /** Display size. */
  size?: 'sm' | 'md' | 'lg' | 'xl'
  /** Compact notation (`$12.3K`) instead of full. */
  compact?: boolean
  /** Show a savings chip when `originalAmount > amount`. */
  showSavings?: boolean
  /** Custom savings label renderer. */
  savingsLabel?: (saved: number, pct: number) => string
  /** Extra classes. */
  className?: string
}

Functions

CurrencyDisplay(props)

Display a monetary amount with optional original price (strikethrough) and a "saved X%" chip. Uses Intl.NumberFormat under the hood.

This is the Solid counterpart of @molecule/app-currency-display-react's CurrencyDisplay: the same props (React names), the same ClassMap tokens, and the same DOM for the same input.

Use the formatCurrency / formatCurrencyCompact utilities directly when you just need a string without rendering chrome.

function CurrencyDisplay(props: CurrencyDisplayProps): JSX.Element
  • props — Component props (see CurrencyDisplayProps).

Returns: The rendered amount.

formatCurrency(amount, currency, locale)

Formats a numeric amount as currency using Intl.NumberFormat.

function formatCurrency(amount: number, currency?: string, locale?: string): string
  • amount — Amount in major units (e.g. dollars, not cents). Pass amount / 100 if your stored value is in cents.
  • currency — ISO 4217 currency code. Defaults to "USD".
  • locale — BCP 47 locale tag. Defaults to the runtime default (undefined).

Returns: Formatted currency string.

formatCurrencyCompact(amount, currency, locale)

Formats a numeric amount as currency in a compact form (e.g. "$12.3K"). Uses Intl.NumberFormat with notation: 'compact' when supported.

function formatCurrencyCompact(amount: number, currency?: string, locale?: string): string
  • amount — Amount in major units.
  • currency — ISO 4217 currency code. Defaults to "USD".
  • locale — BCP 47 locale tag. Defaults to the runtime default (undefined).

Returns: Formatted compact currency string.

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-solid ^3.5.0 || ^4.0.0
  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-solid ^1.1.0
  • solid-js ^1.8.0

Runtime Dependencies

  • @molecule/app-solid
  • @molecule/app-ui
  • @molecule/app-ui-solid
  • solid-js

Amounts are in MAJOR units (dollars, not cents) — divide stored cents by 100 first. showSavings defaults to true, so a savings chip appears whenever originalAmount > amount; pass showSavings={false} for plain was/now price display. Formatting is Intl.NumberFormat (locale-aware, no i18n keys needed); savingsLabel(saved, pct) lets you localize the chip text.