@get-asset/sdk

Expenses Card

Headless compound for the period's expenses and the change versus the prior period. A decrease reads as a positive tone; an increase as negative. The reporting range defaults to the AssetProvider's shared range (driven by the DatePicker), and the prior period mirrors it — the previous month, quarter, or year for a period-shaped range, or the same number of days immediately before a custom one.

Anatomy

Import the primitive and compose the parts you need.

<ExpensesCard.Root
dateFrom="2026-01-01"
dateTo="2026-12-31"
onViewDetails={({ period, basis }) => router.push(`/reports?year=${period?.year}&basis=${basis}`)}
>
<ExpensesCard.ViewDetails>View details</ExpensesCard.ViewDetails>
<ExpensesCard.Loading></ExpensesCard.Loading>
<ExpensesCard.Error>
<ExpensesCard.ErrorMessage />
<ExpensesCard.Retry />
</ExpensesCard.Error>
<ExpensesCard.Success>
<ExpensesCard.Period />
<ExpensesCard.Expenses />
<ExpensesCard.Change />
<ExpensesCard.Tone>{/* data-tone="positive" */}</ExpensesCard.Tone>
</ExpensesCard.Success>
</ExpensesCard.Root>

Required scopes

The access token used by AssetProvider must include these scopes for this primitive to fetch data successfully:

  • report:read
  • business:read

API reference

Root props

PropTypeDefaultDescription
dateFromCalendarDateStringInclusive start (YYYY-MM-DD) of a fixed reporting range. Detaches the card from the AssetProvider's shared range entirely — pass it together with dateTo; one without the other throws. Use periodDateRange to derive the pair from a month, quarter, or year. Omit both and the card follows the provider's range, which the DatePicker drives.
dateToCalendarDateStringInclusive end (YYYY-MM-DD) of the fixed reporting range. Must be paired with dateFrom. The prior-period baseline mirrors whatever range resolves — the previous month, quarter, or year for a period-shaped range, or the same number of days immediately before a custom one.
expensesnumberOverride fetched expenses total (positive number). Skips the API call.
previousExpensesnumberOverride fetched prior-period expenses.
state"loading" | "error"Force a specific state for testing.
lockedbooleanGate the report for an unentitled viewer. Activates the Locked state and skips the API fetch. See /docs/sdk/locked-upsell.
upsell{ title?, description?, ctaLabel?, onUpgrade? }Locked-state copy + upgrade handler; merged field-by-field over the card's default copy, then the generic fallback.
onViewDetails(ctx: { range, period, basis }) => voidCallback fired when the viewer asks to see more details (e.g. to navigate to the full report). Makes ExpensesCard.ViewDetails render. Receives the card's resolved range, the exact period it represents (or null for a custom range) and the accounting basis, so the destination can open on the same window the card shows.
basis"accrual" | "modified_cash"Report on a specific accounting basis. Omit to inherit the AssetProvider's basis, which itself falls back to the Business's country — Canadian Businesses report on Accrual, everyone else on Cash (see Accounting basis).
basisTogglebooleanLet the end user flip between Cash and Accrual. Off by default — BasisSelect renders nothing until it's set. Flipping the control moves every component that inherits the provider's basis, so it can't leave a screen half cash and half accrual (see Accounting basis).
childrenrequiredReactNodeCompound parts.

Parts

Container

Always rendered. Provides data and context to its children.

PartDescription
ExpensesCard.RootFetches the current and previous period P&L and provides context.
ExpensesCard.Basis
asChild?
Renders the active basis as text ("Accrual" / "Cash") and sets data-basis. Rendered whether or not the toggle is enabled.
ExpensesCard.BasisSelectWires basis state to a Select-Root-shaped child (injects value + onValueChange). Renders nothing unless basisToggle is enabled.
ExpensesCard.BasisItemsIterates the Accrual / Cash options, providing per-option context.
ExpensesCard.BasisItem
asChild?
Renders one basis option. Injects value and the option label.
ExpensesCard.ViewDetails
asChild?
Button that fires Root's onViewDetails callback with the card's resolved { range, period, basis } — the viewer's way to ask for more details (e.g. the full report). Renders nothing unless onViewDetails is set. Use asChild to slot a router Link or anchor instead; the handler still fires.

Success

Renders children when expenses data is available.

PartDescription
ExpensesCard.SuccessState wrapper. Compose the value UI inside.
ExpensesCard.Period
asChild?
Renders the resolved period — defaults to MMM YYYY, Q<N> YYYY, or YYYY, falling back to the range label (e.g. 7 – 14 Jan 26) for a custom range. Pass format(range, period) to override.
ExpensesCard.Expenses
asChild?
Renders the current-period expenses total.
ExpensesCard.Change
asChild?
Renders the period-over-period percent change.
ExpensesCard.Tone
asChild?
Wrapper that adds data-tone="positive" | "negative" | "neutral" to its child. Tone is inverted vs. Revenue — a drop in expenses is "positive".

Loading

Renders children only while the fetch is in flight.

PartDescription
ExpensesCard.LoadingState wrapper. Render any skeleton or placeholder UI inside.

Error

Renders children when the fetch fails.

PartDescription
ExpensesCard.ErrorState wrapper. Compose the error UI inside.
ExpensesCard.ErrorMessage
asChild?
Renders the error's message string.
ExpensesCard.Retry
asChild?
Button that re-runs the fetch on click.

Locked

Renders when `locked` is set — the viewer isn't entitled to the report. Mutually exclusive with the other states, and no data is fetched. See the Locked / upsell guide for composing the teaser + upgrade UI.

PartDescription
ExpensesCard.LockedState wrapper. Compose the upgrade / upsell UI inside — see LockedUpsell.

Unlocked

Renders whenever the card is NOT locked — the inverse of Locked.

PartDescription
ExpensesCard.UnlockedState wrapper. Renders children whenever the card isn't locked.

Hooks

PartDescription
useExpensesCard()Hook returning the full context value (range, period, previousRange, previousPeriod, expenses, previousExpenses, percentChange, tone, basis, setBasis, onViewDetails, loading, error, locked, retry).

Accounting basis

ExpensesCard reports on one of two accounting bases: Accrual (accrual on the wire), which counts invoices and bills when they are issued, or Cash (modified_cash), which counts them when the money moves. Cashflow components take no basis — cashflow is a cash concept.

The basis is resolved per component, first match winning:

  • the card's own basis prop;
  • the provider's basis — defaultBasis on AssetProvider, or whatever the toggle was last flipped to;
  • the Business's country — Canadian Businesses report on Accrual, everyone else on Cash.

Only the last step costs a request — a Business read, which is why every basis-aware component's scopes includes business:read — and it is serial: the card holds its own fetch until the Business answers. One request is shared across every basis-aware component on the screen, but pass defaultBasis on AssetProvider when you already know the basis and skip it entirely. If the lookup fails the card falls back to Cash and stays there — retry() re-runs the report query, not the basis lookup.

basisToggle is off by default: ExpensesCard.BasisSelect renders nothing and the card reports on its resolved basis. Turn it on and flipping the control moves every basis-aware component under the provider with it, so the toggle can never leave a screen half cash and half accrual. A component pinned with its own basis prop is the exception — it keeps the basis you gave it and renders no toggle of its own, which is how you show both bases side by side on purpose.

ExpensesCard.Basisrenders the active basis as text ("Accrual" / "Cash") and sets data-basis, whether or not the toggle is enabled — use it to label the figures even on a screen that offers no control.