# Pre-fill billing address checkbox

Learn about customisation options for the pre-fill billing address checkbox.

## Styling

```kotlin
val prefillBillingAddressCheckboxConfig = PrefillBillingAddressCheckboxConfig(
    countrySelectionComponent = CountrySelectionComponent?,
    postcodeComponent = PostcodeComponent?,
    addressComponent = AddressComponent?,
    shippingAddress = ShippingAddress?,
    checked = Boolean,
    styles = PrefillBillingAddressCheckboxStyle,
    label = String,
    initialChecked = Boolean,
    style = CheckboxStyle?,
    annotatedLabel = AnnotatedString?,
    validations = CheckboxValidations
)
```

| Property | Description |
|  --- | --- |
| `countrySelectionComponent`CountrySelectionComponent? | Country selection component to be prefilled when the checkbox is checked. |
| `postcodeComponent`PostcodeComponent? | Postcode component to be prefilled when the checkbox is checked. |
| `addressComponent`AddressComponent? | Address component to be prefilled when the checkbox is checked. |
| `shippingAddress`ShippingAddress? | Shipping address data to use for prefill. |
| `checked`Boolean | Whether the checkbox is initially checked. Defaults to `false`. |
| `styles`PrefillBillingAddressCheckboxStyle | Visual style configuration. |
| `label`String | The label text displayed next to the checkbox. Defaults to `"Same as shipping address"`. |
| `initialChecked`Boolean | Whether the checkbox is initially checked when created. Inherited from `CheckboxConfig`. |
| `style`CheckboxStyle? | Styling configuration for the checkbox's appearance. Inherited from `CheckboxConfig`. |
| `annotatedLabel`AnnotatedString? | The rich text label with clickable links, used instead of the plain label when provided. Inherited from `CheckboxConfig`. |
| `validations`CheckboxValidations | Validation rules and messages for the checkbox component. Inherited from `CheckboxConfig`. |


## Callbacks

```kotlin
data class PrefillBillingAddressCheckboxConfig(
    val onToggleChanged: ((Boolean) -> Unit)? = null,
    val onFocus: (() -> Unit)? = null,
    val onBlur: (() -> Unit)? = null,
    val onFocusChange: ((Boolean) -> Unit)? = null,
    val onValidationPassed: ((List<ValidationResult>) -> Unit)? = null,
    val onValidationFailed: ((List<ValidationResult>) -> Unit)? = null,
    val onTriggerFieldValidation: ((ValidationResult) -> Unit)? = null,
    val onChange: (() -> Unit)? = null
)
```

| Callback | Description |
|  --- | --- |
| `onToggleChanged: ((Boolean) -> Unit)?` | Event handler for when the toggle state changes. |
| `onFocus: (() -> Unit)?` | Event handler for when the component receives focus. |
| `onBlur: (() -> Unit)?` | Event handler for when the component loses focus. |
| `onFocusChange: ((Boolean) -> Unit)?` | Event handler for when the component's focus state changes. |
| `onValidationPassed: ((List<ValidationResult>) -> Unit)?` | Event handler for when validation passes. |
| `onValidationFailed: ((List<ValidationResult>) -> Unit)?` | Event handler for when validation fails. |
| `onTriggerFieldValidation: ((ValidationResult) -> Unit)?` | Event handler for when field validation is triggered individually. |
| `onChange: (() -> Unit)?` | Event handler for when the field value changes. |


For more information about callbacks, see [Events](/guides/checkout/components/android/card/events).

## Example

```kotlin
import com.pxp.checkout.components.prefillbillingaddresscheckbox.PrefillBillingAddressCheckboxComponent
import com.pxp.checkout.components.prefillbillingaddresscheckbox.PrefillBillingAddressCheckboxConfig
import com.pxp.checkout.components.countryselection.CountrySelectionComponent
import com.pxp.checkout.components.postcode.PostcodeComponent
import com.pxp.checkout.components.address.AddressComponent
import com.pxp.checkout.models.ShippingAddress
import com.pxp.checkout.styles.PrefillBillingAddressCheckboxStyle

// Create shipping address data
val shippingAddress = ShippingAddress(
    countryCode = "US",
    postalCode = "10001",
    address = "123 Main Street"
)

// Optional: Create custom styling
val customStyle = PrefillBillingAddressCheckboxStyle(
    colors = PrefillBillingAddressCheckboxStyle.ColorStyles(
        checkedColor = Color.Blue,
        uncheckedColor = Color.Gray,
        checkmarkColor = Color.White
    ),
    textStyles = PrefillBillingAddressCheckboxStyle.TextStyles(
        checkedLabelStyle = TextStyle(
            color = Color.Blue,
            fontSize = 14.sp
        ),
        uncheckedLabelStyle = TextStyle(
            color = Color.Black,
            fontSize = 14.sp
        )
    )
)

val config = PrefillBillingAddressCheckboxConfig(
    // Component references for prefilling
    countrySelectionComponent = countrySelectionComponent,
    postcodeComponent = postcodeComponent,
    addressComponent = addressComponent,
    
    // Shipping address data source
    shippingAddress = shippingAddress,
    
    // Initial state
    checked = false,
    label = "Same as shipping address",
    
    // Styling (optional)
    styles = customStyle,
    
    // Validation (optional)
    validations = CheckboxValidations(
        required = "Please confirm billing address preference"
    )
)

val prefillCheckboxComponent = checkout.createComponent<PrefillBillingAddressCheckboxComponent, PrefillBillingAddressCheckboxConfig>(
    type = ComponentType.PREFILL_BILLING_ADDRESS_CHECKBOX,
    config = config
)
```