Tally UI

LinePopover

LinePopover shows a cart line's quantity or price and opens a keypad that edits it, as WCPOS v2's cart cells do.

Import

import { LinePopover } from '@tallyui/components';

Usage

<LinePopover
  kind="price"
  lineName={line.name}
  currency={sale.order.currency}
  value={line.unitPriceMinor}
  quickDiscounts={[5, 10, 15]}
  onApply={(amountMinor) => sale.setUnitPrice(line.id, amountMinor)}
/>

The trigger shows the value; tapping it opens a dialog named "Quantity for …" or "Price for …" with a Keypad, and focus moves into it. On the web the number keys, Backspace and (for a price) . or , type too. Apply passes the new value to onApply; a refusal it returns shows in the dialog, which stays open. Cancel, Escape or a press outside close without writing, and so does Apply when nothing was typed or the value is unchanged.

A quantity takes whole numbers only and has no decimal key. A price takes the currency's decimal places, and with quickDiscounts the first three valid percentages are keys, as on PriceForm: a key sets the price that much off value, rounded half up to the minor unit. Cart draws these with lineEditor="popover".

A price with regularValue above value shows the regular price struck through above the value, as a line on sale does in CartLine. actions draws a row of buttons above Apply and Cancel, such as the cart line's Discount and Remove; pressing one closes the popover, then calls its onPress.

With commit="close" the popover works as WCPOS v2's grow keypad: there is no Apply or Cancel, and a full-width Done writes what was typed (a refusal shows and the popover stays open). A quantity also gets a row of − and + between the value and the keypad; each press writes the shown quantity one lower or higher at once, and the popover stays open. At a shown quantity of 1 or less, − becomes Remove when onRemove is given, which closes without writing and calls it; without onRemove, − is disabled there. Escape closes without writing; any other close, such as a press outside, writes what was typed. The popover is already closing then, so a refusal on that path goes to onCloseRefused for the host to show.

The popover renders through a portal, so the app renders a PortalHost from @tallyui/primitives.

Props

PropTypeDefaultDescription
kind'quantity' | 'price'requiredWhat the popover edits
lineNamestringrequiredThe line's name, used in the trigger's and the dialog's accessible names
currencystringrequiredThe order's currency: the price's format and decimal places
valuenumberrequiredThe stored quantity, or the unit price in minor units
onApply(value: number) => string | nullrequiredWrites the new value; return a refusal to show, or null once applied
quickDiscountsreadonly number[]---Price only: percentages off value drawn as keys; values outside 0 < n ≤ 100 are dropped and only the first three are drawn
textClassNamestring---Classes for the trigger's text, e.g. the cell's alignment
regularValuenumber---Price only: the regular unit price in minor units, shown struck through above the value when it is above value
actionsReadonlyArray<{ id: string; label: string; onPress: () => void; destructive?: boolean }>---Buttons in the open panel above Apply and Cancel; pressing one closes the popover, then calls its onPress. destructive draws it in the destructive colour
commit'apply' | 'close''apply'apply: Apply and Cancel. close: Done, steppers on a quantity, Escape discards and any other close writes what was typed
onRemove() => void---Quantity with commit="close" only: − becomes Remove at a shown quantity of 1 or less, closes without writing and calls this
onCloseRefused(message: string) => void---commit="close" only: called with the refusal when the write on a close other than Done is refused; the popover is already closing, so the host shows it

On this page