| 7 | const MAP_URL = 'https://www.google.com/maps/search/?api=1&query=LATITUDE,LONGITUDE&zoom=ZOOM' |
| 8 | |
| 9 | const LocationMessage: React.FC<ILocationMessageProps> = ({ markerColor = 'red', target = '_blank', zoom = '14', ...props }) => { |
| 10 | const buildURL = (url: string) => { |
| 11 | return url |
| 12 | .replace(/LATITUDE/g, props?.data.latitude) |
| 13 | .replace(/LONGITUDE/g, props?.data.longitude) |
| 14 | .replace('MARKER_COLOR', markerColor) |
| 15 | .replace('ZOOM', zoom) |
| 16 | .replace('KEY', props.apiKey) |
| 17 | } |
| 18 | const className = () => { |
| 19 | var _className = classNames('rce-mbox-location', props.className) |
| 20 | |
| 21 | if (props.text) { |
| 22 | _className = classNames(_className, 'rce-mbox-location-has-text') |
| 23 | } |
| 24 | |
| 25 | return _className |
| 26 | } |
| 27 | |
| 28 | return ( |
| 29 | <div className='rce-container-lmsg'> |
| 30 | <a |
| 31 | onClick={props.onOpen} |
| 32 | target={target} |
| 33 | href={props.href || props.src || buildURL(props.data.mapURL || MAP_URL)} |
| 34 | className={className()} |
| 35 | > |
| 36 | <img |
| 37 | onError={props.onError} |
| 38 | className='rce-mbox-location-img' |
| 39 | src={props.src || buildURL(props.data.staticURL || STATIC_URL)} |
| 40 | /> |
| 41 | </a> |
| 42 | {props.text && <div className='rce-mbox-text rce-mbox-location-text'>{props.text}</div>} |
| 43 | </div> |
| 44 | ) |
| 45 | } |
| 46 | |
| 47 | export default LocationMessage |