@orsetra/shared-ui 1.11.9 → 1.11.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import * as React from "react"
|
|
4
4
|
import { cn } from "../../lib/utils"
|
|
5
|
-
import {
|
|
5
|
+
import { HoverCard, HoverCardContent, HoverCardTrigger } from "./hover-card"
|
|
6
6
|
import {
|
|
7
7
|
STATUS_IDLE_COLOR, STATUS_WAVE_COLOR, STATUS_WAVE_PERIOD_MS, STATUS_WAVE_SQUARES,
|
|
8
8
|
statusLabel, statusToneColor, waveDelayMs,
|
|
@@ -13,13 +13,16 @@ const SQUARE = 6
|
|
|
13
13
|
const GAP = 2
|
|
14
14
|
|
|
15
15
|
export interface StatusIndicatorProps {
|
|
16
|
-
loading?:
|
|
17
|
-
tone?:
|
|
18
|
-
label?:
|
|
19
|
-
|
|
20
|
-
details?: React.ReactNode
|
|
16
|
+
loading?: boolean
|
|
17
|
+
tone?: StatusTone | null
|
|
18
|
+
label?: string
|
|
19
|
+
details?: React.ReactNode
|
|
21
20
|
detailsClassName?: string
|
|
22
|
-
|
|
21
|
+
side?: "top" | "right" | "bottom" | "left"
|
|
22
|
+
align?: "start" | "center" | "end"
|
|
23
|
+
openDelay?: number
|
|
24
|
+
closeDelay?: number
|
|
25
|
+
className?: string
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
function Wave() {
|
|
@@ -50,50 +53,36 @@ function Settled({ tone }: { tone: StatusTone | null | undefined }) {
|
|
|
50
53
|
)
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
function Mark({ loading, tone }: { loading: boolean; tone: StatusTone | null | undefined }) {
|
|
54
|
-
return loading ? <Wave /> : <Settled tone={tone} />
|
|
55
|
-
}
|
|
56
|
-
|
|
57
56
|
export function StatusIndicator({
|
|
58
|
-
loading = false, tone, label,
|
|
57
|
+
loading = false, tone, label, details, detailsClassName,
|
|
58
|
+
side = "bottom", align = "start", openDelay = 150, closeDelay = 120, className,
|
|
59
59
|
}: StatusIndicatorProps) {
|
|
60
|
-
const [open, setOpen] = React.useState(false)
|
|
61
60
|
const spoken = statusLabel(loading, tone, label)
|
|
61
|
+
const mark = (
|
|
62
|
+
<span role="status" aria-label={spoken} className={cn("inline-flex items-center align-middle", className)}>
|
|
63
|
+
{loading ? <Wave /> : <Settled tone={tone} />}
|
|
64
|
+
</span>
|
|
65
|
+
)
|
|
62
66
|
|
|
63
|
-
if (!details)
|
|
64
|
-
return (
|
|
65
|
-
<span role="status" aria-label={spoken} className={cn("inline-flex items-center align-middle", className)}>
|
|
66
|
-
<Mark loading={loading} tone={tone} />
|
|
67
|
-
</span>
|
|
68
|
-
)
|
|
69
|
-
}
|
|
67
|
+
if (!details) return mark
|
|
70
68
|
|
|
71
69
|
return (
|
|
72
|
-
|
|
73
|
-
<
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
<DialogTitle className="flex items-center gap-2 text-base font-semibold text-ibm-gray-100">
|
|
90
|
-
<Mark loading={loading} tone={tone} />
|
|
91
|
-
{title ?? spoken}
|
|
92
|
-
</DialogTitle>
|
|
93
|
-
</DialogHeader>
|
|
94
|
-
{open && details}
|
|
95
|
-
</DialogContent>
|
|
96
|
-
</Dialog>
|
|
97
|
-
</>
|
|
70
|
+
<HoverCard openDelay={openDelay} closeDelay={closeDelay}>
|
|
71
|
+
<HoverCardTrigger asChild>
|
|
72
|
+
<button
|
|
73
|
+
type="button"
|
|
74
|
+
aria-label={spoken}
|
|
75
|
+
className={cn(
|
|
76
|
+
"inline-flex items-center align-middle p-1 -m-1 cursor-default focus:outline-none focus-visible:ring-2 focus-visible:ring-ibm-blue-60",
|
|
77
|
+
className,
|
|
78
|
+
)}
|
|
79
|
+
>
|
|
80
|
+
{loading ? <Wave /> : <Settled tone={tone} />}
|
|
81
|
+
</button>
|
|
82
|
+
</HoverCardTrigger>
|
|
83
|
+
<HoverCardContent side={side} align={align} className={cn("w-80 rounded-none p-4 text-sm", detailsClassName)}>
|
|
84
|
+
{details}
|
|
85
|
+
</HoverCardContent>
|
|
86
|
+
</HoverCard>
|
|
98
87
|
)
|
|
99
88
|
}
|