forked from OurHike/OurHike
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaypointLanes.tsx
More file actions
68 lines (61 loc) · 2.24 KB
/
Copy pathWaypointLanes.tsx
File metadata and controls
68 lines (61 loc) · 2.24 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
// The three waypoint lanes under the elevation ribbon (WIREFRAMES.md §1.4).
//
// Positions are percentages in the same 0-100 space the ribbon's SVG uses, so
// a pin at 60% sits directly under the part of the profile it belongs to.
// Clustering lives in lib/waypointLanes.ts.
import { LANES, clusterWaypoints, type Waypoint } from '../lib/waypointLanes'
import { typeLabel } from './legendLabels'
const GLYPHS: Record<string, string> = {
water: '💧',
shelter: '⌂',
campsite: '△',
resupply: '⬢',
town: '▣',
parking: 'P',
crossing: '≈',
closure: '⊘',
'serious-warning': '⚠',
}
export interface WaypointLanesProps {
points: Waypoint[]
startMile: number
endMile: number
}
export function WaypointLanes({ points, startMile, endMile }: WaypointLanesProps) {
const lanes = clusterWaypoints(points, { startMile, endMile })
return (
<div className="waypoint-lanes">
{LANES.map((lane) => (
<div key={lane.id} className="waypoint-lane" data-testid={`lane-${lane.id}`}>
<span className="waypoint-lane__label">{lane.label}</span>
<div className="waypoint-lane__track">
{lanes[lane.id].map((cluster) => {
const name = typeLabel(cluster.type)
// A pill says how many it stands for; a lone pin just names
// itself, so "1" never appears as noise next to every glyph.
const accessibleName = cluster.count > 1 ? `${cluster.count} ${name}` : name
return (
<button
key={cluster.members[0].id}
type="button"
className="waypoint-pin"
style={{ left: `${cluster.positionPct}%` }}
>
<span className="visually-hidden">{accessibleName}</span>
<span aria-hidden="true" className="waypoint-pin__glyph">
{GLYPHS[cluster.type] ?? '•'}
</span>
{cluster.count > 1 && (
<span aria-hidden="true" className="waypoint-pin__count">
{cluster.count}
</span>
)}
</button>
)
})}
</div>
</div>
))}
</div>
)
}