@orsetra/shared-ui 1.11.8 → 1.11.9
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 { Dialog, DialogContent, DialogHeader, DialogTitle } from "./dialog"
|
|
6
6
|
import {
|
|
7
7
|
STATUS_IDLE_COLOR, STATUS_WAVE_COLOR, STATUS_WAVE_PERIOD_MS, STATUS_WAVE_SQUARES,
|
|
8
8
|
statusLabel, statusToneColor, waveDelayMs,
|
|
@@ -13,16 +13,13 @@ const SQUARE = 6
|
|
|
13
13
|
const GAP = 2
|
|
14
14
|
|
|
15
15
|
export interface StatusIndicatorProps {
|
|
16
|
-
loading?:
|
|
17
|
-
tone?:
|
|
18
|
-
label?:
|
|
19
|
-
|
|
16
|
+
loading?: boolean
|
|
17
|
+
tone?: StatusTone | null
|
|
18
|
+
label?: string
|
|
19
|
+
title?: string
|
|
20
|
+
details?: React.ReactNode
|
|
20
21
|
detailsClassName?: string
|
|
21
|
-
|
|
22
|
-
align?: "start" | "center" | "end"
|
|
23
|
-
openDelay?: number
|
|
24
|
-
closeDelay?: number
|
|
25
|
-
className?: string
|
|
22
|
+
className?: string
|
|
26
23
|
}
|
|
27
24
|
|
|
28
25
|
function Wave() {
|
|
@@ -53,36 +50,50 @@ function Settled({ tone }: { tone: StatusTone | null | undefined }) {
|
|
|
53
50
|
)
|
|
54
51
|
}
|
|
55
52
|
|
|
53
|
+
function Mark({ loading, tone }: { loading: boolean; tone: StatusTone | null | undefined }) {
|
|
54
|
+
return loading ? <Wave /> : <Settled tone={tone} />
|
|
55
|
+
}
|
|
56
|
+
|
|
56
57
|
export function StatusIndicator({
|
|
57
|
-
loading = false, tone, label, details, detailsClassName,
|
|
58
|
-
side = "bottom", align = "start", openDelay = 150, closeDelay = 120, className,
|
|
58
|
+
loading = false, tone, label, title, details, detailsClassName, className,
|
|
59
59
|
}: StatusIndicatorProps) {
|
|
60
|
+
const [open, setOpen] = React.useState(false)
|
|
60
61
|
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
|
-
)
|
|
66
62
|
|
|
67
|
-
if (!details)
|
|
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
|
+
}
|
|
68
70
|
|
|
69
71
|
return (
|
|
70
|
-
|
|
71
|
-
<
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
72
|
+
<>
|
|
73
|
+
<button
|
|
74
|
+
type="button"
|
|
75
|
+
aria-label={spoken}
|
|
76
|
+
aria-haspopup="dialog"
|
|
77
|
+
title={spoken}
|
|
78
|
+
onClick={event => { event.stopPropagation(); setOpen(true) }}
|
|
79
|
+
className={cn(
|
|
80
|
+
"inline-flex items-center align-middle p-1 -m-1 cursor-pointer focus:outline-none focus-visible:ring-2 focus-visible:ring-ibm-blue-60",
|
|
81
|
+
className,
|
|
82
|
+
)}
|
|
83
|
+
>
|
|
84
|
+
<Mark loading={loading} tone={tone} />
|
|
85
|
+
</button>
|
|
86
|
+
<Dialog open={open} onOpenChange={setOpen}>
|
|
87
|
+
<DialogContent className={cn("rounded-none sm:max-w-lg", detailsClassName)}>
|
|
88
|
+
<DialogHeader>
|
|
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
|
+
</>
|
|
87
98
|
)
|
|
88
99
|
}
|