/** * External dependencies */ import { __ } from '@wordpress/i18n'; import { Fragment } from '@wordpress/element'; const hasAddress = ( { address, addressLine2, addressLine3, city, region, postal, country } ) => { return [ address, addressLine2, addressLine3, city, region, postal, country ].some( value => value !== '' ); }; const Address = ( { attributes: { address, addressLine2, addressLine3, city, region, postal, country }, } ) => ( { address && (
{ address }
) } { addressLine2 && (
{ addressLine2 }
) } { addressLine3 && (
{ addressLine3 }
) } { city && ! ( region || postal ) &&
{ city }
} { city && ( region || postal ) && (
{ [ { city }, ', ', { region }, ' ', { postal }, ] }
) } { ! city && ( region || postal ) && (
{ [ { region }, ' ', { postal }, ] }
) } { country &&
{ country }
}
); export const googleMapsUrl = ( { attributes: { address, addressLine2, addressLine3, city, region, postal, country }, } ) => { const addressUrl = address ? `${ address },` : ''; const addressLine2Url = addressLine2 ? `${ addressLine2 },` : ''; const addressLine3Url = addressLine3 ? `${ addressLine3 },` : ''; const cityUrl = city ? `+${ city },` : ''; let regionUrl = region ? `+${ region },` : ''; regionUrl = postal ? `${ regionUrl }+${ postal }` : regionUrl; const countryUrl = country ? `+${ country }` : ''; return `https://www.google.com/maps/search/${ addressUrl }${ addressLine2Url }${ addressLine3Url }${ cityUrl }${ regionUrl }${ countryUrl }`.replace( ' ', '+' ); }; const save = props => hasAddress( props.attributes ) && (
{ props.attributes.linkToGoogleMaps && (
) } { ! props.attributes.linkToGoogleMaps &&
}
); export default save;