0.4.0 • Published 6 years ago

material-ui-address-input v0.4.0

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

material-ui-address-input

Build Status NpmVersion JavaScript Style Guide

This component is an address picker component for Material-UI.

Demo

Installation

npm install --save material-ui-address-input

Note: material-ui-address-input only supports Material-UI 1.0.0 or later. There is not planned support for Material-UI 0.x. If you are using an earlier version of Material-UI, you should consider upgrading to v1.

Usage

The component only supports controlled input at the moment.

import React, {Component} from 'react'
import AddressInput from 'material-ui-address-input'

class ControlledAddressInput extends Component {
    constructor (props) {
        super(props)
        this.state = {
            address: '',
            addresses: []
        }
    }

    handleAddAddress = address => {
        this.setState({
            addresses: [...this.state.addresses, address]
        })
    }

    handleChangeAddress = addressIndex => {
        this.setState({
            address: addressIndex
        })
    }

    render () {
        return (
            <AddressInput
                onAdd={this.handleAddAddress}
                onChange={this.handleChangeAddress}
                value={this.state.address}
                allAddresses={this.state.addresses}
            />
        )
    }
}

export default ControlledAddressInput

Props

NameTypeDefaultDescription
addressLabelsshape{ houseNameNumber: 'House Name/Number', addressLine1: 'Address Line 1', addressLine2: 'Address Line 2', city: 'City', region: 'State/Province/Region', zip: 'ZIP/Postal Code', country: 'Country' }Custom labels to display when the user creates a new address. Note that if you wish to use custom labels you must specify each of the labels.
addressResolverfuncIf specified, the component will offer the user a choice to find their address automatically given their house name/number and zip/postal code (and their country if displayCountry is set to true). When the user types in this information and clicks 'Find Address', this function will be called. This function should add the resolved address and change the value of this component to correctly input the new address. Signature: function(houseNameNumber: string, zip: string, country: string) => void
allAddresses*arrayArray containing all of the address objects that the user can choose from. Addresses should be of the form {addressLine1: string, addressLine2: string, city: string, region: string, zip: string, country: string}
disabledboolfalseIf true, the label, input and helper text should be displayed in a disabled state.
displayCountrybooltrueWhether the address selector should allow users to choose their country. Often disabled if your application typically has users from a single country.
errorboolIf true the address dropdown will be in an error state and appear red.
helperTextnodeThe helper text content
idstring'address'The id to be passed to the select element.
labelstring'Address'The label to be shown on the address picker component.
marginenum: 'none' | 'dense' | 'normal''none'If dense or normal, will adjust vertical spacing of this component.
namestring'address'The name to be passed to the select element.
nativeboolfalseIf true, a native <select> element will be rendered.
onAdd*funcCallback that is fired when the user adds a new address. This function should add the new address to the allAddresses prop. The function is called with a single parameter address with the following shape: address: {addressLine1: string, addressLine2: string, city: string, region: string, zip: string, country: string}
onChange*funcCallback that is fired when the user changes the active address using the dropdown box. There is a single parameter addressIndex which represents the index in the array of all addresses that the selected address represents.
requiredboolfalseIf true, the label will indicate that the user must select an address from this component. Note that HTML5 validations for this feature only work with native set to true.
value*union: string | numberThe index of the selected address in the array of all addresses. If you desire 'no address selected', then value should be the empty string ''.

Contributing

PRs are welcome! :tada:

0.4.0

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago