-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathapp.tsx
More file actions
88 lines (71 loc) · 2.64 KB
/
app.tsx
File metadata and controls
88 lines (71 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* @license
* Copyright 2025 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
{/* [START maps_react_ui_kit_place_details_compact] */}
import React, {useEffect, useRef} from 'react';
import {createRoot} from 'react-dom/client';
import {APIProvider, useMapsLibrary} from '@vis.gl/react-google-maps';
import './styles.css';
const API_KEY = "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8";
type PlaceDetailsProps = {
placeId: string;
};
// Renders place details using a place ID.
const PlaceDetails = ({placeId}: PlaceDetailsProps) => {
const places = useMapsLibrary('places');
const containerRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!places || !containerRef.current) {
return;
}
// Create the gmp-place-details-compact element.
const placeDetails = document.createElement('gmp-place-details-compact');
// Set the orientation.
placeDetails.setAttribute('orientation', 'horizontal');
// Create the gmp-place-details-place-request element.
const placeRequest = document.createElement(
'gmp-place-details-place-request',
);
// Set the place on the place request element.
placeRequest.setAttribute('place', placeId);
// Append the place request to the place details element.
placeDetails.appendChild(placeRequest);
// Create and append the content config and its children.
const contentConfig = document.createElement('gmp-place-content-config');
contentConfig.innerHTML = `
<gmp-place-media lightbox-preferred></gmp-place-media>
<gmp-place-rating></gmp-place-rating>
<gmp-place-type></gmp-place-type>
<gmp-place-price></gmp-place-price>
<gmp-place-accessible-entrance-icon></gmp-place-accessible-entrance-icon>
<gmp-place-open-now-status></gmp-place-open-now-status>
<gmp-place-attribution></gmp-place-attribution>
`;
placeDetails.appendChild(contentConfig);
// Append the place details element to the container.
containerRef.current.innerHTML = ''; // Clear previous content
containerRef.current.appendChild(placeDetails);
}, [places, placeId]);
return <div ref={containerRef} className="place-details-container" />;
};
const App = () => {
return (
<APIProvider apiKey={API_KEY} libraries={['places']}>
<div className="places-ui-kit">
<PlaceDetails placeId="ChIJ5bx0qiVu5kcRs_dMpI5ttiY" />
</div>
</APIProvider>
);
};
export default App;
export function renderToDom(container: HTMLElement) {
const root = createRoot(container);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
}
{/* [END maps_react_ui_kit_place_details_compact] */}