1.0.4 • Published 2 years ago

dgtek-autocomplete-address v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

dgtek-autocomplete-address

Package installation

yarn add dgtek-autocomplete-address

Start package

import DGtekAutocompleteAddress from 'dgtek-autocomplete-address'

window.customElements.define('dgtek-autocomplete-address', DGtekAutocompleteAddress)

Mount component

<dgtek-autocomplete-address />

or

const component = document.body
  .appendChild(document.createElement('dgtek-autocomplete-address'))

Styling elements

You can stylize elements:

document.getElementsByTagName('dgtek-autocomplete-address')[0]
  .setStyleOption('snackBar', 'backgroundColor', '#09b')
  .setStyleOption('snackBar', 'borderRadius', '0px')
  .setStyleOption('snackBar', 'borderColor', '#ff0')
  .setStyleOption('submitButton', 'backgroundColor', '#090')

There are some style properties which you can change:

ElementStyle propertyDefault value
submitButtonborderRadius4px
submitButtonborder4px solid transparent
submitButtonbackgroundColor#881f1a
submitButtonfontFamilyGilroy, "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif
submitButtonfontSize16px
submitButtoncolor#fff
submitButtonpadding4px 8px
inputwidth88%
inputpadding12px 16px
inputbordersolid 1px #bbb
inputborderRadius4px
inputfontFamilyGilroy, "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif
snackBarbackgroundColor#881f1aa0
snackBarborderColor#881f1a
snackBarborderRadius4px
snackBarmargin8px 16px
snackBarcolor#fff
snackBarfontSize.875rem
snackBarfontFamilyGilroy, "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif
linkfontFamilyGilroy, "Segoe UI", SegoeUI, "Helvetica Neue", Helvetica, Arial, sans-serif
linkfontSize14px
linkcolor#ddd

Catch events

Submit button event:

window.addEventListener('submit-address', function (event) {
  console.log(event.detail)
})

Example of event.detail content:

address: "45 CLARKE ST, SOUTHBANK VIC 3006"
addressComponents: { number1: '45', number2: '', number: '45', street: 'CLARKE', streetType: 'ST', …}
buildingId: null
coordinates: { lat: -37.8269008, lng: 144.9595298 }
estimatedServiceDeliveryTime: ""
status: "polygons-service-available"

The most important here is status

Status possible variants
if address was found in DB:

on-netdb-footprintdb-build-commenceddb-coming-soon

if the address belongs to some polygon

polygons-service-availablepolygons-build-commencedpolygons-coming-soon

otherwise

Failure events

During checking the address, a number of requests will be made to remote server.

Every request can fail.

window.addEventListener('server-error', function (event) {
  console.log(event.detail) /* { error: true, errorType: String, errorMessage: String } */
})

You can catch errors with handler for open-error-popup event:

window.addEventListener('open-error-popup', function (event) {
  console.log(event.detail) /* { error: true, errorType: String, errorMessage: String } */
})