Tally UI

AddressFields

AddressFields edits one CustomerAddress, every part optional, with Country and State pickers when the app passes their options.

Import

import { AddressFields, ShippingAddressFields } from '@tallyui/components';

Usage

<AddressFields value={billing} onChange={setBilling} countries={countries} statesFor={statesFor} showEmail />

Each part is a labelled field with the placeholder Add {label}, in one column. A part emptied by the cashier leaves the address: onChange never carries '' or undefined. With countries, Country is a searchable picker, otherwise a text field; State is a picker while statesFor gives the chosen country a list. Picking a country whose list lacks the current state drops the state. Email shows only with showEmail.

Props

PropTypeDefaultDescription
value / onChangeCustomerAddress / (next: CustomerAddress) => voidrequiredThe address, and every edit as the whole next address
countriesreadonly { value: string; label: string }[]---ISO alpha-2 country options; absent, Country is a text field
statesFor(country: string) => readonly { value: string; label: string }[] | undefined---A country's states; none, State is a text field
showEmail / testIDboolean / stringfalse / 'address-fields'Show Email (billing only); testID prefix

ShippingAddressFields

Shipping reads "Same as billing" while value is empty or billing's copy (email aside), read once at mount: key it by order. "Use a different address" calls onChange with billing's copy without its email and shows the parts; "Same as billing" calls onChange(undefined).

PropTypeDefaultDescription
billing / valueCustomerAddress | undefinedrequiredBilling, and the shipping address
onChange(next: CustomerAddress | undefined) => voidrequiredundefined folds shipping back to billing
countries / statesFor / testIDas AddressFields'shipping-address'Passed to the parts; testID prefix