-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectedRoutesStopsPanel.tsx
More file actions
130 lines (128 loc) · 4.13 KB
/
Copy pathSelectedRoutesStopsPanel.tsx
File metadata and controls
130 lines (128 loc) · 4.13 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { Box, Typography, useTheme } from '@mui/material';
import { useRef } from 'react';
import Draggable from 'react-draggable';
import { useTranslations } from 'next-intl';
import { type MapStopElement } from '../MapElement';
interface SelectedRoutesStopsPanelProps {
filteredRoutes: string[];
selectedRouteStops: MapStopElement[];
selectedStopId: string | null;
focusStopFromPanel: (stop: MapStopElement) => void;
}
export const SelectedRoutesStopsPanel = (
props: React.PropsWithChildren<SelectedRoutesStopsPanelProps>,
): React.ReactElement => {
const {
filteredRoutes,
selectedRouteStops,
selectedStopId,
focusStopFromPanel,
} = props;
const theme = useTheme();
const routeStopsPanelNodeRef = useRef<HTMLDivElement | null>(null);
const t = useTranslations('feeds');
return (
<Draggable
nodeRef={routeStopsPanelNodeRef}
handle='.drag-handle'
bounds='parent'
>
<Box
ref={routeStopsPanelNodeRef}
sx={{
position: 'absolute',
right: '10px',
top: '25%',
height: '50%',
width: 250,
transform: 'translateY(-0%)',
zIndex: 1000,
bgcolor: theme.vars.palette.background.default,
borderRadius: '12px',
boxShadow: '1px 1px 8px rgba(0,0,0,0.25)',
display: 'flex',
flexDirection: 'column',
overflow: 'hidden',
}}
>
<Box
sx={{
p: 1.5,
borderBottom: `1px solid ${theme.vars.palette.divider}`,
cursor: 'move',
}}
className='drag-handle'
>
<Typography variant='subtitle2' sx={{ fontWeight: 600 }}>
{t('selectedRouteStops.title_one', {
count: filteredRoutes.length,
})}{' '}
({selectedRouteStops.length})
</Typography>
<Typography
variant='caption'
sx={{ color: theme.vars.palette.text.secondary }}
>
{t('selectedRouteStops.routeIds_one', {
count: filteredRoutes.length,
})}
: {filteredRoutes.join(' | ')}
</Typography>
</Box>
<Box sx={{ flex: 1, overflowY: 'auto', p: 1 }}>
{selectedRouteStops.map((s) => {
const isActive = selectedStopId === s.stopId;
return (
<Box
key={s.stopId}
role='button'
tabIndex={0}
aria-pressed={isActive ? 'true' : 'false'}
onClick={() => {
focusStopFromPanel(s);
}}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') focusStopFromPanel(s);
}}
sx={{
py: 0.9,
px: 1.1,
mb: 0.5,
borderRadius: '10px',
border: isActive
? `2px solid ${theme.vars.palette.primary.main}`
: `1px solid ${theme.vars.palette.divider}`,
backgroundColor: isActive
? theme.vars.palette.action.selected
: 'transparent',
transition:
'background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease',
cursor: 'pointer',
'&:hover': {
backgroundColor: theme.vars.palette.action.hover,
},
boxShadow: isActive
? '0 0 0 2px rgba(0,0,0,0.06) inset'
: 'none',
}}
>
<Typography
variant='body2'
sx={{ fontWeight: 700, lineHeight: 1.2 }}
>
{s.name}
</Typography>
<Typography
variant='caption'
sx={{ color: theme.vars.palette.text.secondary }}
>
{t('selectedRouteStops.stopId')} {s.stopId}
</Typography>
</Box>
);
})}
</Box>
</Box>
</Draggable>
);
};