ChargeForm
ChargeForm enters a fee, shipping charge, or custom item with name, amount, tax choices, and inline feedback on invalid or refused entries.
Import
import { ChargeForm } from '@tallyui/components';Usage
<ChargeForm
currency="EUR"
lineTax={{ none: true, classes: true }}
taxClasses={[{ id: 'reduced', label: 'Reduced rate' }]}
onApply={(charge) => applyCharge(charge)}
onClose={() => setChargeOpen(false)}
/>Renders a fee, shipping, or custom item selector with name and amount inputs, available tax choices, and submit and Cancel buttons. The submit button reads "Add to Cart" when adding, as WCPOS v2's add dialogs do, and "Save" when initial is given. An invalid amount or a refusal from onApply is shown inline; successful application calls onClose. As in WCPOS v2, a blank name takes the kind's default (Fee, Shipping, or Product), and a fee must be above zero.
Pass kind to open the form on one kind without the selector, as WCPOS v2's cart "+" menu does with its separate Add Fee, Add Shipping, and Add Miscellaneous Product entries.
As in WCPOS v2's Add Fee and Add Shipping, allowPercent adds a currency-or-% unit toggle to the fee kind, and pricesIncludeTax adds an Amount Includes Tax switch to the fee and shipping kinds that starts at the store's tax mode. The switch is hidden on a percent fee, which is always of the cart in the store's mode, and amountIncludesTax is then not sent. percent and amountIncludesTax reach onApply only when they carry a value.
As in WCPOS v2's Misc product dialog, sku adds a "+ SKU" row to the custom kind, and the SKU reaches onApply only when one is entered.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
currency | string | required | Currency used to parse the amount into minor units and label its input |
lineTax | { none: boolean; classes: boolean } | --- | Enables the No tax switch and tax class choices when shipping tax is not taken from the store |
taxClasses | ReadonlyArray<{ id: string; label: string }> | --- | Tax class choices shown when lineTax.classes is enabled and the list is nonempty |
shippingTaxFromStore | boolean | --- | For shipping, replaces tax controls with a store tax class notice and omits tax overrides from the submitted charge, unless shippingNoTax is set |
shippingNoTax | boolean | --- | With shippingTaxFromStore, the shipping kind also shows the No tax switch and sends taxStatus: 'none' when it is on; the tax class stays the store's |
kind | 'fee' | 'shipping' | 'custom' | --- | Fixes the form to one kind, hides the kind selector, and names the form Add fee, Add shipping, or Add custom item; without it the form opens on Fee with the selector |
initial | { name: string; amountMinor: number; taxStatus?: 'taxable' | 'none'; taxClass?: string; percent?: number; amountIncludesTax?: boolean; sku?: string } | --- | Edits that charge: the form is prefilled and titled Edit <name> |
sku | boolean | --- | On the custom kind, shows the "+ SKU" row after the tax rows; pressing it shows the SKU field, and a SKU entered is sent in onApply as sku |
allowPercent | boolean | --- | Shows the amount-unit toggle (currency symbol or %) on the fee kind; a percent fee applies with amountMinor 0 and percent |
pricesIncludeTax | boolean | --- | The store's tax mode; given, the fee and shipping kinds show the Amount Includes Tax switch, starting at this value, and amountIncludesTax is sent only when the switch differs from it; on a percent fee the switch is hidden and amountIncludesTax is not sent |
onApply | (charge: { kind: 'fee' | 'shipping' | 'custom'; name: string; amountMinor: number; taxStatus?: 'none'; taxClass?: string; percent?: number; amountIncludesTax?: boolean; sku?: string }) => string | null | required | Receives the charge with a trimmed name and amount in minor units; return a refusal or null once applied |
onClose | () => void | required | Called on Cancel or after onApply returns null |