Skip to content

Commit 974834b

Browse files
committed
feat: add help button
1 parent f46efe4 commit 974834b

File tree

3 files changed

+48
-39
lines changed

3 files changed

+48
-39
lines changed

src/components/Buttons.jsx

+37-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import { useId } from 'preact/hooks'
2-
import { LuEye, LuHome, LuLayers, LuVideo } from 'react-icons/lu'
3-
import { useToggle } from '../lib/hooks.js'
1+
import { LuEye, LuHome, LuLayers, LuHelpCircle } from 'react-icons/lu'
2+
import { useState } from 'preact/hooks'
43
import { clsx } from '../lib/utils.js'
54
import { GridAnimation } from './Animations.jsx'
65
import { toChildArray } from 'preact'
76

87
const FLOOR_LABELS = ['Piano Terra', '1° Piano', '2° Piano']
98
const GROUP_LABELS = ['Edifici A e B', 'Edificio ex-Albergo']
109

11-
const LayerFloor = ({ label, cameraToViewpoint, data: { viewpoint, visible, toggle } }) => {
10+
const LayerFloor = ({ label, cameraToViewpoint, data: { viewpoint } }) => {
1211
return (
1312
<div class="row">
1413
<div class="icon" role="button" onClick={() => cameraToViewpoint(viewpoint)}>
@@ -32,9 +31,7 @@ const LayerGroup = ({ label, data: { floors }, cameraToViewpoint }) => {
3231
)
3332
}
3433

35-
const CollapsibleIconPanel = ({ children }) => {
36-
const [layersPopup, toggleLayersPopup] = useToggle(false)
37-
34+
const CollapsibleIconPanel = ({ layersPopup, toggleLayersPopup, children }) => {
3835
// extracts jsx nodes from the "children" prop
3936
const [iconJsx, labelJsx, contentJsx] = toChildArray(children)
4037

@@ -75,6 +72,11 @@ const CollapsibleIconButton = ({ onClick, children }) => {
7572
}
7673

7774
export const Buttons = ({ planimetriaRef, reset, layerToggles: { dip, exdma }, showOnlyRegion }) => {
75+
// we only want to have one uncollapsed panel at a time
76+
// so we need to keep track of which panel is open
77+
// and close it when another one is opened
78+
const [layersPopup, setLayersPopup] = useState(null)
79+
7880
const onResetView = () => {
7981
if (planimetriaRef.current) {
8082
planimetriaRef.current.animateCameraToViewpoint('home')
@@ -89,7 +91,10 @@ export const Buttons = ({ planimetriaRef, reset, layerToggles: { dip, exdma }, s
8991

9092
return (
9193
<div class="buttons">
92-
<CollapsibleIconPanel>
94+
<CollapsibleIconPanel
95+
layersPopup={layersPopup === 'layers'}
96+
toggleLayersPopup={() => setLayersPopup(layersPopup === 'layers' ? null : 'layers')}
97+
>
9398
<LuLayers />
9499
<div class="label">
95100
<div class="fix-text">Livelli</div>
@@ -106,6 +111,30 @@ export const Buttons = ({ planimetriaRef, reset, layerToggles: { dip, exdma }, s
106111
<div class="fix-text">Reimposta Vista</div>
107112
</div>
108113
</CollapsibleIconButton>
114+
<CollapsibleIconPanel
115+
layersPopup={layersPopup === 'help'}
116+
toggleLayersPopup={() => setLayersPopup(layersPopup === 'help' ? null : 'help')}
117+
>
118+
<LuHelpCircle />
119+
<div class="label">
120+
<div class="fix-text">Help</div>
121+
</div>
122+
<div class="content">
123+
<div class="title">Come navigare la mappa</div>
124+
<ul>
125+
<li>Per spostare la mappa, trascina con il mouse o con un dito.</li>
126+
<li>Per zoomare, usa la rotellina del mouse o i gesti di pinch-to-zoom.</li>
127+
<li>Per ruotare, clicca e trascina con il tasto destro del mouse o con due dita.</li>
128+
<li>
129+
Per selezionare un piano, clicca sull'icona dell'occhio corrispondente dentro il
130+
pannello <LuLayers />.
131+
</li>
132+
<li>
133+
Per tornare alla vista iniziale, clicca su <LuHome />.
134+
</li>
135+
</ul>
136+
</div>
137+
</CollapsibleIconPanel>
109138
</div>
110139
)
111140
}

src/element.jsx

-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { memo } from 'preact/compat'
22

3-
import { LuHelpCircle } from 'react-icons/lu'
4-
53
import { PlanimetrieViewer } from './dm-planimetrie/PlanimetrieViewer.js'
64

75
import styles from './element.scss?inline'
@@ -216,13 +214,6 @@ export const Planimetrie = ({ selectedRoom }) => {
216214
},
217215
}}
218216
/>
219-
<div className="help-message">
220-
<LuHelpCircle />
221-
<span>
222-
Clicca e trascina per spostarti, trascina col tasto destro per orbitare e usa la
223-
rotellina del mouse per zoomare.
224-
</span>
225-
</div>
226217
</div>
227218
</div>
228219
</>

src/element.scss

+11-22
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ code {
176176
}
177177

178178
.tooltip {
179+
z-index: 5;
179180
position: absolute;
180181
inset: 0;
181182

@@ -341,8 +342,8 @@ code {
341342

342343
justify-items: start;
343344

344-
pointer-events: none;
345-
345+
pointer-events: auto;
346+
max-width: calc(100vw - 2rem);
346347
.button-group {
347348
display: grid;
348349

@@ -442,6 +443,14 @@ code {
442443
gap: 0.25rem;
443444

444445
min-width: 15rem;
446+
max-width: 20rem;
447+
448+
text-wrap: wrap;
449+
line-height: 1.35;
450+
451+
ul {
452+
padding-left: 1.25rem;
453+
}
445454

446455
.title {
447456
display: flex;
@@ -737,22 +746,6 @@ code {
737746
}
738747
}
739748
}
740-
741-
.help-message {
742-
position: absolute;
743-
top: 100%;
744-
left: 0;
745-
746-
width: 100%;
747-
padding: 0.25rem 0.125rem;
748-
749-
color: #444;
750-
font-size: 19px;
751-
752-
display: flex;
753-
align-items: center;
754-
gap: 0.25rem;
755-
}
756749
}
757750
}
758751

@@ -883,10 +876,6 @@ code {
883876
}
884877
}
885878
}
886-
887-
.help-message {
888-
display: none;
889-
}
890879
}
891880
}
892881
}

0 commit comments

Comments
 (0)