blob: 96d0af0100b33ec03961887a88d4eb1e62d3f2d7 (
plain)
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
|
import React, { useMemo } from "react";
import { useTranslation } from "react-i18next";
import LineIcon from "~/components/LineIcon";
import { type Arrival } from "../../api/schema";
import "./ArrivalCard.css";
interface ArrivalCardProps {
arrival: Arrival;
reduced?: boolean;
}
export const ArrivalCard: React.FC<ArrivalCardProps> = ({
arrival,
reduced,
}) => {
const { t } = useTranslation();
const { route, headsign, estimate } = arrival;
const etaValue = Math.max(0, Math.round(estimate.minutes)).toString();
const etaUnit = t("estimates.minutes", "min");
const timeClass = useMemo(() => {
switch (estimate.precission) {
case "confident":
return "time-running";
case "unsure":
return "time-delayed";
case "past":
return "time-past";
default:
return "time-scheduled";
}
}, [estimate.precission]);
return (
<div
className={`
flex-none flex items-center gap-2.5 min-h-12
bg-(--message-background-color) border border-(--border-color)
rounded-xl px-3 py-2.5 transition-all
${reduced ? "reduced" : ""}
`.trim()}
>
<div className="shrink-0 min-w-[7ch]">
<LineIcon
line={route.shortName}
colour={route.colour}
textColour={route.textColour}
mode="pill"
/>
</div>
<div className="flex-1 min-w-0 flex flex-col gap-1">
<strong className="text-base text-(--text-color) overflow-hidden text-ellipsis line-clamp-2 leading-tight">
{headsign.destination}
</strong>
</div>
<div
className={`
inline-flex items-center justify-center px-2 py-1.5 rounded-xl shrink-0
${timeClass}
`.trim()}
>
<div className="flex flex-col items-center leading-none">
<span className="text-lg font-bold leading-none">{etaValue}</span>
<span className="text-[0.65rem] uppercase tracking-wider mt-0.5 opacity-90">
{etaUnit}
</span>
</div>
</div>
</div>
);
};
|