@get-asset/sdk

Operating Expenses Card

Headless compound surfacing the top Nexpense categories for a period, each with a proportional bar. Categories come from P&L report leaf records under the operating-expenses group. The reporting range defaults to the AssetProvider's shared range, which the DatePicker drives.

Anatomy

Import the primitive and compose the parts you need.

<OperatingExpensesCard.Root dateFrom="2026-01-01" dateTo="2026-12-31" limit={5}>
<OperatingExpensesCard.Success>
<OperatingExpensesCard.Period />
<OperatingExpensesCard.Total />
<OperatingExpensesCard.Categories>
<OperatingExpensesCard.CategoryName />
<OperatingExpensesCard.CategoryAmount />
<OperatingExpensesCard.CategoryBar />
</OperatingExpensesCard.Categories>
</OperatingExpensesCard.Success>
</OperatingExpensesCard.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. Categories are scoped to whatever range resolves.
limitnumber5Maximum categories to display.
categoriesOperatingExpenseCategoryOverride[]Override fetched data. Each entry: { name, amount }.
scalenumberOverride the bar chart maximum.
state"loading" | "error" | "empty"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.
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
OperatingExpensesCard.RootFetches the P&L report, extracts expense leaves, and provides context.
OperatingExpensesCard.Basis
asChild?
Renders the active basis as text ("Accrual" / "Cash") and sets data-basis. Rendered whether or not the toggle is enabled.
OperatingExpensesCard.BasisSelectWires basis state to a Select-Root-shaped child (injects value + onValueChange). Renders nothing unless basisToggle is enabled.
OperatingExpensesCard.BasisItemsIterates the Accrual / Cash options, providing per-option context.
OperatingExpensesCard.BasisItem
asChild?
Renders one basis option. Injects value and the option label.

Success

Renders when categories are available.

PartDescription
OperatingExpensesCard.SuccessState wrapper. Compose the category list inside.
OperatingExpensesCard.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.
OperatingExpensesCard.Total
asChild?
Sum of the categories displayed.
OperatingExpensesCard.CategoriesIterates children once per category, up to limit.
OperatingExpensesCard.CategoryName
asChild?
Name of the current category.
OperatingExpensesCard.CategoryAmount
asChild?
Amount of the current category.
OperatingExpensesCard.CategoryBar
style?, className?
Bar sized by amount / scale.

Loading

Renders while the fetch is in flight.

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

Empty

Renders when there are no expense categories.

PartDescription
OperatingExpensesCard.EmptyState wrapper. Render an empty-state message inside.

Error

Renders on fetch error.

PartDescription
OperatingExpensesCard.ErrorState wrapper. Compose the error UI inside.
OperatingExpensesCard.ErrorMessage
asChild?
Renders the error message string.
OperatingExpensesCard.Retry
asChild?
Button that re-runs the fetch.

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
OperatingExpensesCard.LockedState wrapper. Compose the upgrade / upsell UI inside — see LockedUpsell.

Unlocked

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

PartDescription
OperatingExpensesCard.UnlockedState wrapper. Useful for gating extras (like the insights panel) that should also disappear while locked.

Hooks

PartDescription
useOperatingExpensesCard()Hook returning range, period, categories, total, scale, basis, setBasis, loading, error, locked, retry.
useOperatingExpenseCategory()Hook for components inside a Categories iteration.

Accounting basis

OperatingExpensesCard 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: OperatingExpensesCard.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.

OperatingExpensesCard.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.