|
| 1 | +/* |
| 2 | + * @license |
| 3 | + * Copyright 2025 Google LLC. All Rights Reserved. |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | +// [START react_ui_kit_place_details] |
| 7 | +import React from 'react'; |
| 8 | +import {createRoot} from 'react-dom/client'; |
| 9 | +import {APIProvider, useMapsLibrary} from '@vis.gl/react-google-maps'; |
| 10 | + |
| 11 | +import './styles.css'; |
| 12 | + |
| 13 | +const API_KEY = |
| 14 | + globalThis.GOOGLE_MAPS_API_KEY ?? (process.env.GOOGLE_MAPS_API_KEY as string); |
| 15 | + |
| 16 | +if (!API_KEY) { |
| 17 | + console.error('Missing Google Maps API key'); |
| 18 | +} |
| 19 | + |
| 20 | +type PlaceDetailsProps = { |
| 21 | + placeId: string; |
| 22 | +}; |
| 23 | + |
| 24 | +// Renders place details using a place ID. |
| 25 | +const PlaceDetails = ({placeId}: PlaceDetailsProps) => { |
| 26 | + const places = useMapsLibrary('places'); |
| 27 | + |
| 28 | + // Wait for the places library to load. |
| 29 | + if (!places) { |
| 30 | + return null; |
| 31 | + } |
| 32 | + |
| 33 | + return ( |
| 34 | + <div className="place-details-container"> |
| 35 | + <gmp-place-details> |
| 36 | + <gmp-place-details-place-request place={placeId} /> |
| 37 | + <gmp-place-content-config> |
| 38 | + <gmp-place-address></gmp-place-address> |
| 39 | + <gmp-place-rating></gmp-place-rating> |
| 40 | + <gmp-place-type></gmp-place-type> |
| 41 | + <gmp-place-price></gmp-place-price> |
| 42 | + <gmp-place-accessible-entrance-icon></gmp-place-accessible-entrance-icon> |
| 43 | + <gmp-place-opening-hours></gmp-place-opening-hours> |
| 44 | + <gmp-place-website></gmp-place-website> |
| 45 | + <gmp-place-phone-number></gmp-place-phone-number> |
| 46 | + <gmp-place-summary></gmp-place-summary> |
| 47 | + <gmp-place-type-specific-highlights></gmp-place-type-specific-highlights> |
| 48 | + <gmp-place-reviews></gmp-place-reviews> |
| 49 | + <gmp-place-feature-list></gmp-place-feature-list> |
| 50 | + <gmp-place-media lightbox-preferred></gmp-place-media> |
| 51 | + <gmp-place-attribution |
| 52 | + light-scheme-color="gray" |
| 53 | + dark-scheme-color="white"></gmp-place-attribution> |
| 54 | + </gmp-place-content-config> |
| 55 | + </gmp-place-details> |
| 56 | + </div> |
| 57 | + ); |
| 58 | +}; |
| 59 | + |
| 60 | +const App = () => { |
| 61 | + return ( |
| 62 | + <APIProvider apiKey={API_KEY} libraries={['places']}> |
| 63 | + <div className="places-ui-kit"> |
| 64 | + <PlaceDetails placeId="ChIJC8HakaIRkFQRiOgkgdHmqkk" /> |
| 65 | + </div> |
| 66 | + </APIProvider> |
| 67 | + ); |
| 68 | +}; |
| 69 | + |
| 70 | +export default App; |
| 71 | + |
| 72 | +export function renderToDom(container: HTMLElement) { |
| 73 | + const root = createRoot(container); |
| 74 | + |
| 75 | + root.render( |
| 76 | + <React.StrictMode> |
| 77 | + <App /> |
| 78 | + </React.StrictMode> |
| 79 | + ); |
| 80 | +} |
| 81 | +// [END react_ui_kit_place_details] |
| 82 | + |
0 commit comments