@orsetra/shared-ui 1.11.7 → 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.
|
@@ -3,40 +3,27 @@
|
|
|
3
3
|
import { useEffect, useRef } from "react"
|
|
4
4
|
import { usePathname } from "next/navigation"
|
|
5
5
|
import { useQuickAccess } from "../../../hooks/use-quick-access"
|
|
6
|
+
import { quickAccessHref } from "../../../lib/quick-access-href"
|
|
6
7
|
|
|
7
8
|
interface QuickAccessTrackerProps {
|
|
8
|
-
/** Human-readable label shown in the quick-access list */
|
|
9
9
|
label: string
|
|
10
|
-
/** Icon name (resolved via resolveIcon). Defaults to "Box". */
|
|
11
10
|
icon?: string
|
|
12
|
-
/** Set to false to skip tracking this page (e.g. list/index pages) */
|
|
13
11
|
enabled?: boolean
|
|
14
|
-
/**
|
|
15
|
-
* Canonical href for this resource — overrides the current page URL.
|
|
16
|
-
* Pass the resource root (e.g. "/my-app") so that visiting any tab of
|
|
17
|
-
* the same resource tracks a single entry instead of one per tab.
|
|
18
|
-
* Absolute URL or path relative to the current origin.
|
|
19
|
-
*/
|
|
20
12
|
href?: string
|
|
21
13
|
}
|
|
22
14
|
|
|
23
|
-
/**
|
|
24
|
-
* Drop this inside any page or layout to register that page in the
|
|
25
|
-
* sidebar's quick-access list. Tracks on mount and whenever pathname changes.
|
|
26
|
-
* Renders nothing.
|
|
27
|
-
*/
|
|
28
15
|
export function QuickAccessTracker({ label, icon, enabled = true, href: hrefProp }: QuickAccessTrackerProps) {
|
|
29
16
|
const pathname = usePathname()
|
|
30
17
|
const { addItem } = useQuickAccess()
|
|
31
|
-
// Stable ref so the effect doesn't re-run when addItem reference changes
|
|
32
18
|
const addRef = useRef(addItem)
|
|
33
19
|
addRef.current = addItem
|
|
34
20
|
|
|
35
21
|
useEffect(() => {
|
|
36
22
|
if (!enabled || !label || !pathname) return
|
|
37
|
-
const href =
|
|
38
|
-
|
|
39
|
-
|
|
23
|
+
const href = quickAccessHref(
|
|
24
|
+
{ origin: window.location.origin, locationPath: window.location.pathname, routerPath: pathname },
|
|
25
|
+
hrefProp,
|
|
26
|
+
)
|
|
40
27
|
addRef.current({ label, href, icon })
|
|
41
28
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
42
29
|
}, [pathname, label, icon, enabled, hrefProp])
|
|
@@ -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
|
}
|
package/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './lib/config-selection'
|
|
|
7
7
|
export * from './lib/environment-context'
|
|
8
8
|
export * from './lib/environment-controller'
|
|
9
9
|
export * from './lib/project-requirement'
|
|
10
|
+
export * from './lib/quick-access-href'
|
|
10
11
|
export * from './lib/status-indicator'
|
|
11
12
|
export { createPlatformConfigSource, templateFilter, configOfHit, environmentWithTargets, type ConfigSource } from './lib/config-source'
|
|
12
13
|
export { default as HttpClient, useHttpClient, ApiError } from './lib/http-client'
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface QuickAccessLocation {
|
|
2
|
+
origin: string
|
|
3
|
+
locationPath: string
|
|
4
|
+
routerPath: string
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const withoutTrailingSlash = (path: string): string => path.replace(/\/+$/, "")
|
|
8
|
+
|
|
9
|
+
export function appBasePath({ locationPath, routerPath }: Pick<QuickAccessLocation, "locationPath" | "routerPath">): string {
|
|
10
|
+
const full = withoutTrailingSlash(locationPath)
|
|
11
|
+
const inner = withoutTrailingSlash(routerPath)
|
|
12
|
+
if (!inner) return full
|
|
13
|
+
return full.endsWith(inner) ? full.slice(0, full.length - inner.length) : ""
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function quickAccessHref(location: QuickAccessLocation, target?: string): string {
|
|
17
|
+
if (!target) return location.origin + location.locationPath
|
|
18
|
+
if (/^https?:\/\//i.test(target)) return target
|
|
19
|
+
const path = target.startsWith("/") ? target : `/${target}`
|
|
20
|
+
return location.origin + appBasePath(location) + path
|
|
21
|
+
}
|