Billing Address
billui/billing-addressFreeComponent
Composable address form with correct autocomplete attributes. Country and state selects are automatically linked.
Install it
npx shadcn@latest add https://billui.com/r/billing-address.jsonSource
1"use client";23import * as React from "react";4import { Input } from "@/components/ui/input";5import {6 Select,7 SelectContent,8 SelectItem,9 SelectTrigger,10 SelectValue,11} from "@/components/ui/select";12import {13 COUNTRIES,14 getStatesForCountry,15 type IState,16} from "@/lib/billing-address-data";17import { useControllableState } from "@/lib/use-controllable-state";18import { cn } from "@/lib/utils";1920interface BillingAddressContextValue {21 countryCode: string;22 setCountryCode: (code: string) => void;23 states: IState[];24}2526const BillingAddressContext =27 React.createContext<BillingAddressContextValue | null>(null);2829function useBillingAddressContext() {30 const context = React.useContext(BillingAddressContext);31 if (!context) {32 throw new Error(33 "BillingAddress components must be used within a BillingAddress provider",34 );35 }36 return context;37}3839interface BillingAddressProps40 extends Omit<React.HTMLAttributes<HTMLDivElement>, "defaultValue"> {41 /** Controlled country code (ISO 3166-1 alpha-2) */42 country?: string;43 /** Default country code for uncontrolled mode */44 defaultCountry?: string;45 /** Callback when country changes */46 onCountryChange?: (code: string) => void;47}4849const BillingAddress = React.forwardRef<HTMLDivElement, BillingAddressProps>(50 (51 {52 className,53 country,54 defaultCountry = "US",55 onCountryChange,56 children,57 ...props58 },59 ref,60 ) => {61 const [countryCode, setCountryCode] = useControllableState(62 country,63 defaultCountry,64 onCountryChange,65 );6667 const states = React.useMemo(68 () => getStatesForCountry(countryCode),69 [countryCode],70 );7172 const contextValue = React.useMemo(73 () => ({ countryCode, setCountryCode, states }),74 [countryCode, setCountryCode, states],75 );7677 return (78 <BillingAddressContext.Provider value={contextValue}>79 <div80 ref={ref}81 className={cn("flex flex-col gap-4", className)}82 {...props}83 >84 {children}85 </div>86 </BillingAddressContext.Provider>87 );88 },89);90BillingAddress.displayName = "BillingAddress";9192/**93 * Configuration for billing address fields.94 * Ensures proper browser autofill, accessibility, and UX.95 */96const billingFieldConfig = {97 name: {98 autocomplete: "billing name",99 inputMode: "text" as const,100 spellCheck: true,101 },102 line1: {103 autocomplete: "billing address-line1",104// … truncated
What it pulls in
Other registry items
Files it writes
More from billui
All 13 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Usage Cardanimated-usage-card | billui | Components | Free | 2 deps | |
| Card Iconscard-icons | billui | Components | Free | 1 dep | |
| Card Inputcard-input | billui | Components | Free | no deps | |
| Invoice Cardinvoice-card | billui | Components | Free | 2 deps | |
| Payment Methodpayment-method | billui | Components | Free | 2 deps | |
| Plan Cardplan-card | billui | Components | Free | 2 deps | |
| Plan Groupplan-group | billui | Components | Free | 1 dep | |
| Pricing Tablepricing-table | billui | Components | Free | 2 deps |
