Components/Profit & Loss

Profit & Loss

Headline value + change widget. Period selector (1D / 1W / 1M / 3M / YTD / 1Y / ALL), color-coded by direction, with an optional sparkline. Periods are fully customizable.


Total return

$48,294.00

+$4,494.00 (+10.26%)

Installation

npx ajaxui add profit-loss

Losing position

When currentValue < costBasis, the color and the sparkline gradient flip to rose automatically.

Today's change

$14,200.00

-$1,600.00 (-10.13%)

Sizes

Three size presets adjust the headline + change typography together.

Small

$1,240.00

+$60.00 (+5.08%)

Medium

$12,400.00

+$600.00 (+5.08%)

Large

$124,000.00

+$6,000.00 (+5.08%)

Custom periods

<ProfitLoss
  periods={[
    { label: "Day",   value: "1d" },
    { label: "Week",  value: "1w" },
    { label: "Quarter", value: "1q" },
  ]}
  defaultPeriod="1w"
/>

Props

PropTypeDefaultDescription
currentValuenumberCurrent market value.
costBasisnumberPurchase basis used to derive change.
currencystring"USD"ISO 4217 currency code.
localestring"en-US"Locale for Intl formatting.
seriesnumber[]Sparkline data. Hides when omitted or hideChart.
periodsProfitLossPeriod[]7 standardToggle options. Empty array hides the toggle.
selectedPeriodstringControlled period value.
defaultPeriodstringfirstUncontrolled initial period.
onPeriodChange(period: string) => voidFires when the user toggles a period.
labelstring"Total return"Card title.
size"sm" | "md" | "lg""md"Typography size preset.
hideChartbooleanfalseHide the sparkline.