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
29 changes: 26 additions & 3 deletions examples/basic/src/components/ControlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,34 @@ interface ControlPanelProps {
children: ReactNode;
}

/**
* The options of a sample, over the map.
*
* The title is a button that folds the panel away. Until someone presses it,
* the screen width decides (`auto`, in CSS): open beside a desktop map, folded
* to its title on a phone, where an open panel would cover most of the map.
* Deciding in CSS keeps the server-rendered page and the first paint the same.
* Folding only hides the body, so the controls keep their state.
*/
export function ControlPanel({ title, children }: ControlPanelProps) {
const [open, setOpen] = useState<boolean | null>(null);
const toggle = () => {
setOpen(current => {
if (current !== null) return !current;
// Still `auto`: flip whatever the screen width shows now.
return typeof window !== 'undefined' && window.matchMedia('(max-width: 760px)').matches;
});
};
const mode = open === null ? 'auto' : open ? 'open' : 'folded';
return (
<div className="control-panel">
<h3 className="control-panel-title">{title}</h3>
{children}
<div className={`control-panel control-panel-${mode}`}>
<button type="button" className="control-panel-header" aria-expanded={open ?? undefined} onClick={toggle}>
<h3 className="control-panel-title">{title}</h3>
<svg className="control-panel-chevron" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true">
<path d="M4 10l4-4 4 4" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
</svg>
</button>
<div className="control-panel-body">{children}</div>
</div>
);
}
Expand Down
81 changes: 79 additions & 2 deletions examples/basic/src/components/SamplePageLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ReactNode } from 'react';
import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react';
import type { SupportedLanguage } from '../samples/sampleRegistry';
import { SamplePageSeo } from '../samples/SamplePageSeo';
import { SampleDocumentation } from './SampleDocumentation';
Expand All @@ -16,6 +16,11 @@ export function SamplePageLayout({
language: SupportedLanguage;
children?: ReactNode;
}) {
const { stageRef, fullscreen, toggleFullscreen } = useMapFullscreen();
const labels = {
enter: translate(language, { en: 'Full screen', ja: '全画面表示', 'es-419': 'Pantalla completa', de: 'Vollbild', th: 'เต็มหน้าจอ', hi: 'फ़ुल स्क्रीन' }),
exit: translate(language, { en: 'Exit full screen', ja: '全画面表示を終了', 'es-419': 'Salir de pantalla completa', de: 'Vollbild beenden', th: 'ออกจากโหมดเต็มหน้าจอ', hi: 'फ़ुल स्क्रीन से बाहर निकलें' }),
};
// The Hello Map tutorial is a full-page article (its own live demo + steps),
// not the standard map-stage + documentation layout.
if (page === 'hello-map') {
Expand All @@ -31,7 +36,24 @@ export function SamplePageLayout({
<div className="sample-page-layout">
<SamplePageSeo page={page} provider={provider} language={language} />
<div className="sample-map-padding">
<div className="sample-map-stage">
<div ref={stageRef} className={`sample-map-stage${fullscreen ? ' is-fullscreen' : ''}`}>
{/* Camera Sync has its own full screen, for both of its maps. */}
{page !== 'camera-sync' && <button
type="button"
className="map-fullscreen-button"
aria-pressed={fullscreen}
aria-label={fullscreen ? labels.exit : labels.enter}
title={fullscreen ? labels.exit : labels.enter}
onClick={toggleFullscreen}
>
<svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true">
{fullscreen ? (
<path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
) : (
<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
)}
</svg>
</button>}
{children ?? (
<div className="sample-map-placeholder" aria-hidden="true">
{translate(
Expand All @@ -54,3 +76,58 @@ export function SamplePageLayout({
</div>
);
}

/**
* Full screen for the map stage. The Fullscreen API where there is one; where
* there is not (iPhone Safari has none for a div), the stage is fixed over the
* whole page instead. Escape leaves either way. The maps live inside the stage
* (SingletonMaps), so they grow with it.
*/
function useMapFullscreen() {
const stageRef = useRef<HTMLDivElement>(null);
const [fullscreen, setFullscreen] = useState(false);

// Maps that size themselves on window resize only (not every SDK watches its container).
const announceResize = () => requestAnimationFrame(() => window.dispatchEvent(new Event('resize')));

const toggleFullscreen = useCallback(() => {
const stage = stageRef.current;
if (!fullscreen) {
setFullscreen(true);
stage?.requestFullscreen?.().catch(() => {});
} else {
setFullscreen(false);
if (document.fullscreenElement) document.exitFullscreen().catch(() => {});
}
announceResize();
}, [fullscreen]);

useEffect(() => {
if (!fullscreen) return;
// Leaving native full screen (the system back gesture, Escape) ends ours too.
const onChange = () => {
if (!document.fullscreenElement) {
setFullscreen(false);
announceResize();
}
};
const onKey = (event: KeyboardEvent) => {
if (event.key === 'Escape' && !document.fullscreenElement) {
setFullscreen(false);
announceResize();
}
};
// The page behind must not scroll under the fixed stage.
const overflow = document.body.style.overflow;
document.body.style.overflow = 'hidden';
document.addEventListener('fullscreenchange', onChange);
document.addEventListener('keydown', onKey);
return () => {
document.body.style.overflow = overflow;
document.removeEventListener('fullscreenchange', onChange);
document.removeEventListener('keydown', onKey);
};
}, [fullscreen]);

return { stageRef, fullscreen, toggleFullscreen };
}
136 changes: 134 additions & 2 deletions examples/basic/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,87 @@ body,
.control-panel-title {
font-size: 1rem;
font-weight: 600;
margin: 0 0 12px;
margin: 0;
color: #333;
}

/* The title is the button that folds the panel; it must not look like the
panel's own buttons (`.control-panel button`). */
.control-panel .control-panel-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
width: 100%;
min-height: 0;
margin: 0;
padding: 0;
border: 0;
background: none;
color: #333;
text-align: left;
cursor: pointer;
}

.control-panel .control-panel-header:hover {
background: none;
}

.control-panel-chevron {
flex: none;
color: #64748b;
transition: transform 140ms ease;
}

.control-panel-body {
margin-top: 12px;
}

.control-panel-folded .control-panel-body {
display: none;
}

.control-panel-folded .control-panel-chevron {
transform: rotate(180deg);
}

/* Full screen for the map stage (SamplePageLayout). */
.map-fullscreen-button {
position: absolute;
top: 10px;
right: 10px;
z-index: 1300;
display: grid;
place-items: center;
width: 36px;
height: 36px;
padding: 0;
border: 1px solid #cbd5e1;
border-radius: 6px;
background: rgba(255, 255, 255, 0.95);
color: #1f2937;
box-shadow: 0 1px 4px rgba(15, 23, 42, 0.25);
cursor: pointer;
}

.map-fullscreen-button:hover {
background: #f1f5f9;
}

.sample-map-stage.is-fullscreen {
position: fixed;
inset: 0;
z-index: 4000;
width: 100vw;
height: 100vh;
height: 100dvh;
border: 0;
border-radius: 0;
}

.sample-map-stage:fullscreen {
width: 100%;
height: 100%;
}

.toggle-control {
Expand Down Expand Up @@ -866,8 +945,61 @@ body,
display: block;
}

/* The map is what a phone shows: under the header, one line of title, then a
stage that ends at the bottom of the screen, so the folded panel and the
map's own controls are in view without scrolling. The description stays in
the page for search engines but takes no room here. */
.sample-page-seo {
padding: 8px 10px 0;
}

.sample-page-seo h2 {
font-size: 0.95rem;
line-height: 1.3;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

.sample-page-seo p {
display: none;
}

.sample-map-padding {
padding: 6px 8px 8px;
}

.sample-map-stage {
height: clamp(360px, 62vh, 620px);
/* header 58 + title 33 + padding 14 */
height: clamp(360px, calc(100dvh - 105px), 900px);
}

/* Folded to its title until opened, and never over most of the map. */
.control-panel {
left: 8px;
right: auto;
/* Clear of the map's attribution line, which must stay readable. */
bottom: 30px;
max-width: calc(100% - 16px);
padding: 10px 12px;
}

.control-panel-title {
font-size: 0.9rem;
}

.control-panel-auto .control-panel-body {
display: none;
}

.control-panel-auto .control-panel-chevron {
transform: rotate(180deg);
}

.control-panel-open {
right: 8px;
max-height: 55%;
overflow-y: auto;
}

.desktop-sidebar {
Expand Down
24 changes: 21 additions & 3 deletions examples/basic/src/pages/map/camerasync/camera-sync-page.css
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,35 @@
width: 100%;
}

/* Two maps share a phone screen: keep only the selector and the numbers,
so most of each map stays in view. */
.camera-sync-provider {
width: min(86%, 300px);
top: 6px;
left: 6px;
width: auto;
max-width: calc(100% - 12px);
padding: 3px;
gap: 0;
font-size: 0;
}

.camera-sync-provider select {
min-height: 28px;
font-size: 0.8rem;
}

.camera-sync-info {
max-width: calc(100% - 20px);
left: 6px;
bottom: 6px;
min-width: 0;
max-width: calc(100% - 12px);
padding: 4px 7px;
grid-template-columns: repeat(2, minmax(0, auto));
column-gap: 10px;
font-size: 0.68rem;
}

.camera-sync-info strong {
grid-column: 1 / -1;
display: none;
}
}
Loading