Skip to content

Commit

Permalink
Optionally exposed raw address data
Browse files Browse the repository at this point in the history
  • Loading branch information
shtbik committed Jan 10, 2022
1 parent 45e182e commit 7f8ae5f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/WidgetInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ import React, {

import { AddressFinderWidgetSrc, ContainerPrefix, Country } from './constants';
import { addressMetaToAddress } from './helpers';
import { Address } from './types';
import { Address, AddressMeta } from './types';

import './widget.css';

interface WidgetInputProps
extends DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
id: string;
onSelected: (fullAddress: string, address: Address) => void;
onSelected: (fullAddress: string, address: Address | AddressMeta) => void;
addressFinderKey: string;
country?: Country;
container?: HTMLElement;
inputClassName?: string;
listClassName?: string;
itemClassName?: string;
hoverClassName?: string;
raw?: boolean;
}

export type Props = WidgetInputProps;
Expand All @@ -38,6 +39,7 @@ const WidgetInput: FC<WidgetInputProps> = ({
itemClassName = 'address-autocomplete__suggestions__item',
hoverClassName = 'address-autocomplete__suggestions__item--active',
addressFinderKey,
raw = false,
...props
}) => {
const [scriptLoaded, setScriptLoaded] = useState(false);
Expand Down Expand Up @@ -82,7 +84,13 @@ const WidgetInput: FC<WidgetInputProps> = ({
);

widget.on('address:select', (fullAddress, metaData) => {
onSelected(fullAddress, addressMetaToAddress(metaData, country));
let addressData: Address | AddressMeta = { ...metaData, country };

if (!raw) {
addressData = addressMetaToAddress(metaData, country);
}

onSelected(fullAddress, addressData);
});
}
}, [id, country, scriptLoaded]);
Expand Down

0 comments on commit 7f8ae5f

Please sign in to comment.