Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 54 additions & 30 deletions samples/rgm-college-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,24 @@
import React, { useState, useRef } from 'react';
import ReactDOM from 'react-dom/client';
import { AdvancedMarker, Map, Pin, APIProvider } from '@vis.gl/react-google-maps';
import * as GMPX from '@googlemaps/extended-component-library/react';
import { OverlayLayout } from '@googlemaps/extended-component-library/overlay_layout.js';
import { PlacePicker } from '@googlemaps/extended-component-library/place_picker.js';
import {
PlaceReviews,
PlaceDataProvider,
PlaceDirectionsButton,
IconButton,
PlaceOverview,
SplitLayout,
OverlayLayout,
PlacePicker
} from '@googlemaps/extended-component-library/react';
// The below imports are necessary because we are creating refs of
// the OverlayLayout and PlacePicker components.
// You need to pass the ref property a web component type object.
// Imports from @googlemaps/extended-component-library/react are
// wrappers around web components, not the components themselves.
// For the ref property we import the actual components and alias them for clarity.
import { OverlayLayout as TOverlayLayout } from '@googlemaps/extended-component-library/overlay_layout.js';
import { PlacePicker as TPlacePicker } from '@googlemaps/extended-component-library/place_picker.js';

const API_KEY =
globalThis.GOOGLE_MAPS_API_KEY ?? ("YOUR_API_KEY");
Expand All @@ -22,18 +37,20 @@ const DEFAULT_ZOOM_WITH_LOCATION = 16;
* as ratings, photos, and reviews displayed on the side.
*/
const App = () => {
const overlayLayoutRef = useRef<OverlayLayout>(null);
const pickerRef = useRef<PlacePicker>(null);
const overlayLayoutRef = useRef<TOverlayLayout>(null);
const pickerRef = useRef<TPlacePicker>(null);
const [college, setCollege] = useState<google.maps.places.Place | undefined>(undefined);

// See https://lit.dev/docs/frameworks/react/#using-slots for why
// we need to wrap our custom elements in a div with a slot attribute.
return (
<div className="App">
<APIProvider apiKey={API_KEY} version='beta' >
<GMPX.SplitLayout rowReverse rowLayoutMinWidth={700}>
<div className="SplitLayoutContainer" slot="fixed">
<GMPX.OverlayLayout ref={overlayLayoutRef}>
<div className="MainContainer" slot="main">
<GMPX.PlacePicker
<SplitLayout rowReverse rowLayoutMinWidth={700}>
<div className="SlotDiv" slot="fixed">
<OverlayLayout ref={overlayLayoutRef}>
<div className="SlotDiv" slot="main">
<PlacePicker
className="CollegePicker"
ref={pickerRef}
forMap="gmap"
Expand All @@ -48,42 +65,49 @@ const App = () => {
}
}}
/>
<GMPX.PlaceOverview
<PlaceOverview
size="large"
place={college}
googleLogoAlreadyDisplayed
>
<GMPX.IconButton
slot="action"
variant="filled"
onClick={() => overlayLayoutRef.current?.showOverlay()}
>
See Reviews
</GMPX.IconButton>
<GMPX.PlaceDirectionsButton slot="action" variant="filled">
Directions
</GMPX.PlaceDirectionsButton>
</GMPX.PlaceOverview>
<div slot="action" className="SlotDiv">
<IconButton
slot="action"
variant="filled"
onClick={() => overlayLayoutRef.current?.showOverlay()}
>
See Reviews
</IconButton>
</div>
<div slot="action" className="SlotDiv">
<PlaceDirectionsButton slot="action" variant="filled">
Directions
</PlaceDirectionsButton>
</div>
</PlaceOverview>
</div>
<div slot="overlay">
<GMPX.IconButton
<div slot="overlay" className="SlotDiv">
<IconButton
className="CloseButton"
onClick={() => overlayLayoutRef.current?.hideOverlay()}
>
Close
</GMPX.IconButton>
<GMPX.PlaceDataProvider place={college}>
<GMPX.PlaceReviews />
</GMPX.PlaceDataProvider>
</IconButton>
<PlaceDataProvider place={college}>
<PlaceReviews />
</PlaceDataProvider>
</div>
</GMPX.OverlayLayout>
</OverlayLayout>
</div>
<div className="SplitLayoutContainer" slot="main">
<Map
id="gmap"
mapId="8c732c82e4ec29d9"
center={college?.location ?? DEFAULT_CENTER}
zoom={college?.location ? DEFAULT_ZOOM_WITH_LOCATION : DEFAULT_ZOOM}
gestureHandling="none"
fullscreenControl={false}
zoomControl={false}
>
{college?.location && (
<AdvancedMarker position={college?.location}>
Expand All @@ -92,7 +116,7 @@ const App = () => {
)}
</Map>
</div>
</GMPX.SplitLayout>
</SplitLayout>
</APIProvider>
</div>
);
Expand Down
81 changes: 43 additions & 38 deletions samples/rgm-college-picker/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,51 @@

/* [START maps_rgm_college_picker] */
body {
margin: 0;
font-family: sans-serif;
}
#root {
width: 100vw;
height: 100vh;
}
margin: 0;
font-family: sans-serif;
}
#root {
width: 100vw;
height: 100vh;
}

.App {
--gmpx-color-surface: #f6f5ff;
--gmpx-color-on-primary: #f8e8ff;
--gmpx-color-on-surface: #000;
--gmpx-color-on-surface-variant: #636268;
--gmpx-color-primary: #8a5cf4;
--gmpx-fixed-panel-height-column-layout: 420px;
--gmpx-fixed-panel-width-row-layout: 340px;
background: var(--gmpx-color-surface);
inset: 0;
position: fixed;
}

.MainContainer {
display: flex;
flex-direction: column;
}
.SplitLayoutContainer {
height: 100%;
}
.CollegePicker {
--gmpx-color-surface: #fff;
flex-grow: 1;
margin: 1rem;
}

.CloseButton {
display: block;
margin: 1rem;
}
.App {
--gmpx-color-surface: #f6f5ff;
--gmpx-color-on-primary: #f8e8ff;
--gmpx-color-on-surface: #000;
--gmpx-color-on-surface-variant: #636268;
--gmpx-color-primary: #8a5cf4;
--gmpx-fixed-panel-height-column-layout: 420px;
--gmpx-fixed-panel-width-row-layout: 340px;
background: var(--gmpx-color-surface);
inset: 0;
position: fixed;
}

.MainContainer {
display: flex;
flex-direction: column;
}

.SplitLayoutContainer {
height: 100%;
}

.CollegePicker {
--gmpx-color-surface: #fff;
flex-grow: 1;
margin: 1rem;
}

.CloseButton {
display: block;
margin: 1rem;
}

.SlotDiv {
display: contents;
}
/* [END maps_rgm_college_picker] */