|
1 | 1 | import { useTheme } from "@emotion/react"; |
2 | 2 | import CircularProgress from "@mui/material/CircularProgress"; |
3 | 3 | import Tooltip from "@mui/material/Tooltip"; |
4 | | -import { visuallyHidden } from "@mui/utils"; |
5 | 4 | import { Abbr } from "components/Abbr/Abbr"; |
6 | 5 | import { CircleHelpIcon } from "lucide-react"; |
7 | 6 | import type { FC } from "react"; |
| 7 | +import { cn } from "utils/cn"; |
8 | 8 | import { getLatencyColor } from "utils/latency"; |
9 | 9 |
|
10 | 10 | interface LatencyProps { |
11 | 11 | latency?: number; |
12 | 12 | isLoading?: boolean; |
13 | | - size?: number; |
| 13 | + className?: string; |
| 14 | + iconClassName?: string; |
14 | 15 | } |
15 | 16 |
|
16 | 17 | export const Latency: FC<LatencyProps> = ({ |
17 | 18 | latency, |
18 | 19 | isLoading, |
19 | | - size = 14, |
| 20 | + className, |
| 21 | + iconClassName, |
20 | 22 | }) => { |
21 | 23 | const theme = useTheme(); |
22 | 24 | // Always use the no latency color for loading. |
23 | 25 | const color = getLatencyColor(theme, isLoading ? undefined : latency); |
24 | 26 |
|
25 | 27 | if (isLoading) { |
26 | 28 | return ( |
27 | | - <Tooltip title="Loading latency..."> |
28 | | - <CircularProgress size={size} className="ml-auto" style={{ color }} /> |
| 29 | + <Tooltip title="Loading latency..." className={className}> |
| 30 | + <CircularProgress |
| 31 | + className={cn("!size-icon-xs", iconClassName)} |
| 32 | + style={{ color }} |
| 33 | + /> |
29 | 34 | </Tooltip> |
30 | 35 | ); |
31 | 36 | } |
32 | 37 |
|
33 | 38 | if (!latency) { |
34 | | - const notAvailableText = "Latency not available"; |
35 | 39 | return ( |
36 | | - <Tooltip title={notAvailableText}> |
37 | | - <> |
38 | | - <span css={{ ...visuallyHidden }}>{notAvailableText}</span> |
39 | | - |
40 | | - <CircleHelpIcon className="ml-auto size-icon-sm" style={{ color }} /> |
41 | | - </> |
| 40 | + <Tooltip title="Latency not available" className={className}> |
| 41 | + <CircleHelpIcon |
| 42 | + className={cn("!size-icon-sm", iconClassName)} |
| 43 | + style={{ color }} |
| 44 | + /> |
42 | 45 | </Tooltip> |
43 | 46 | ); |
44 | 47 | } |
45 | 48 |
|
46 | 49 | return ( |
47 | | - <div className="ml-auto text-sm" style={{ color }}> |
48 | | - <span css={{ ...visuallyHidden }}>Latency: </span> |
| 50 | + <div className={cn("text-sm", className)} style={{ color }}> |
| 51 | + <span className="sr-only">Latency: </span> |
49 | 52 | {latency.toFixed(0)} |
50 | 53 | <Abbr title="milliseconds">ms</Abbr> |
51 | 54 | </div> |
|
0 commit comments