@orsetra/shared-ui 1.12.1 → 1.13.0

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.
@@ -1,6 +1,7 @@
1
1
  // Layout components exports
2
2
  export { MainSidebar, type SidebarMode } from './sidebar/main-sidebar'
3
- export { resolveIcon, type MainMenuItem, type SubMenuItem, type SidebarMenus, type SidebarMenuMeta, type MenuApiResponse, type ApiMenuData, type ApiMainMenuItem, type ApiSubMenuItem, type ApiSubMenu, type OrgInfo, type Project } from './sidebar/data'
3
+ export { MenuBadge } from './sidebar/menu-badge'
4
+ export { resolveIcon, type MenuBadge as MenuBadgeData, type MainMenuItem, type SubMenuItem, type SidebarMenus, type SidebarMenuMeta, type MenuApiResponse, type ApiMenuData, type ApiMainMenuItem, type ApiSubMenuItem, type ApiSubMenu, type OrgInfo, type Project } from './sidebar/data'
4
5
  export { QuickAccessTracker } from './sidebar/quick-access-tracker'
5
6
  export {
6
7
  Sidebar,
@@ -75,6 +75,7 @@ function LayoutContent({
75
75
  description: item.description,
76
76
  icon: resolveIcon(item.icon),
77
77
  href: item.href,
78
+ badge: item.badge,
78
79
  }))
79
80
  )
80
81
 
@@ -89,6 +90,7 @@ function LayoutContent({
89
90
  href: item.href,
90
91
  icon: resolveIcon(item.icon),
91
92
  target: item.target,
93
+ badge: item.badge,
92
94
  }))
93
95
  labels[key] = subMenu.header
94
96
  meta[key] = {
@@ -39,12 +39,22 @@ import {
39
39
  LifeBuoy,
40
40
  } from "lucide-react"
41
41
 
42
+ /**
43
+ * A badge on a menu item: a text, shown as it is given and never translated, and a color among
44
+ * blue, orange, yellow, green, red, purple, teal and gray (another color is drawn in gray).
45
+ */
46
+ export interface MenuBadge {
47
+ text: string
48
+ color: string
49
+ }
50
+
42
51
  export interface MainMenuItem {
43
52
  id: string
44
53
  label: string
45
54
  description?: string
46
55
  icon: LucideIcon
47
56
  href: string
57
+ badge?: MenuBadge
48
58
  }
49
59
 
50
60
  export interface SubMenuItem {
@@ -57,6 +67,7 @@ export interface SubMenuItem {
57
67
  target?: string
58
68
  /** True when the href still has an unresolved "${...}" placeholder (e.g. no project/environment selected yet) — render as non-navigable. */
59
69
  disabled?: boolean
70
+ badge?: MenuBadge
60
71
  }
61
72
 
62
73
  export interface SidebarMenus {
@@ -81,6 +92,7 @@ export interface ApiMainMenuItem {
81
92
  description?: string
82
93
  icon: string
83
94
  href: string
95
+ badge?: MenuBadge
84
96
  }
85
97
 
86
98
  export interface ApiSubMenuItem {
@@ -90,6 +102,7 @@ export interface ApiSubMenuItem {
90
102
  href: string
91
103
  icon: string
92
104
  target?: string
105
+ badge?: MenuBadge
93
106
  }
94
107
 
95
108
  export interface ApiSubMenu {
@@ -6,6 +6,7 @@ import type { MainMenuItem, SubMenuItem } from "./data"
6
6
  import { resolveIcon } from "./data"
7
7
  import { Home, ExternalLink, type LucideIcon } from "lucide-react"
8
8
  import type { QuickAccessItem } from "../../../hooks/use-quick-access"
9
+ import { MenuBadge } from "./menu-badge"
9
10
 
10
11
  export interface FlyoutDefaultLink {
11
12
  label: string
@@ -83,7 +84,7 @@ export function MainSidebarFlyout({
83
84
  title={sub.disabled ? "Select a project/environment first" : undefined}
84
85
  onClick={(e) => { if (sub.disabled) e.preventDefault() }}
85
86
  className={cn(
86
- "flex items-start transition-colors border-l-4",
87
+ "relative flex items-start transition-colors border-l-4",
87
88
  "px-2 lg:px-3 py-2 gap-x-3",
88
89
  sub.disabled
89
90
  ? "opacity-40 cursor-not-allowed border-transparent"
@@ -97,6 +98,7 @@ export function MainSidebarFlyout({
97
98
  <p className="text-xs text-text-secondary leading-relaxed mt-0.5 line-clamp-2">{sub.description}</p>
98
99
  )}
99
100
  </div>
101
+ <MenuBadge badge={sub.badge} />
100
102
  </a>
101
103
  )
102
104
  })}
@@ -12,6 +12,7 @@ import { useIsMobile } from "../../../hooks/use-mobile"
12
12
  import { MainSidebarFlyout, type FlyoutDefaultLink } from "./main-sidebar-flyout"
13
13
  import { useQuickAccess } from "../../../hooks/use-quick-access"
14
14
  import { resolveTemplateVars } from "./template-vars"
15
+ import { MenuBadge } from "./menu-badge"
15
16
 
16
17
  export type { FlyoutDefaultLink }
17
18
 
@@ -215,7 +216,7 @@ export function MainSidebar({
215
216
  : undefined
216
217
 
217
218
  const itemCls = cn(
218
- "w-full flex items-center text-left transition-all duration-150 font-medium",
219
+ "relative w-full flex items-center text-left transition-all duration-150 font-medium",
219
220
  isMinimized ? "justify-center p-2 lg:p-3" : "gap-2 lg:gap-3 px-2 lg:px-3 py-1.5 lg:py-2",
220
221
  isActive || isFlyActive
221
222
  ? "bg-ibm-blue-10 text-interactive border-l-4 border-interactive"
@@ -238,6 +239,7 @@ export function MainSidebar({
238
239
  )}
239
240
  </>
240
241
  )}
242
+ <MenuBadge badge={item.badge} dot={isMinimized} />
241
243
  </>
242
244
  )
243
245
 
@@ -284,7 +286,7 @@ export function MainSidebar({
284
286
  handleSubMenuClick(e, item.id, subItem.href, subItem.target)
285
287
  }}
286
288
  className={cn(
287
- "flex items-center gap-2 lg:gap-3 px-2 lg:px-3 py-1.5 lg:py-2 text-sm transition-colors no-underline border-l-2",
289
+ "relative flex items-center gap-2 lg:gap-3 px-2 lg:px-3 py-1.5 lg:py-2 text-sm transition-colors no-underline border-l-2",
288
290
  subDisabled
289
291
  ? "text-text-secondary/40 border-ui-border cursor-not-allowed"
290
292
  : "text-text-secondary hover:bg-ui-background hover:text-text-primary border-ui-border hover:border-interactive",
@@ -292,6 +294,7 @@ export function MainSidebar({
292
294
  >
293
295
  <subItem.icon className="h-4 w-4 flex-shrink-0 text-text-secondary" />
294
296
  {subItem.name}
297
+ <MenuBadge badge={subItem.badge} />
295
298
  </a>
296
299
  )
297
300
  })}
@@ -0,0 +1,48 @@
1
+ "use client"
2
+
3
+ import { cn } from "../../../lib/utils"
4
+ import { type MenuBadge as MenuBadgeData } from "./data"
5
+
6
+ /** Carbon colors a badge is drawn in; a color it does not know is drawn in gray. */
7
+ const COLORS: Record<string, { background: string; text: string }> = {
8
+ blue: { background: "#0f62fe", text: "#ffffff" },
9
+ orange: { background: "#ff832b", text: "#161616" },
10
+ yellow: { background: "#f1c21b", text: "#161616" },
11
+ green: { background: "#24a148", text: "#ffffff" },
12
+ red: { background: "#da1e28", text: "#ffffff" },
13
+ purple: { background: "#8a3ffc", text: "#ffffff" },
14
+ teal: { background: "#009d9a", text: "#ffffff" },
15
+ gray: { background: "#6f6f6f", text: "#ffffff" },
16
+ }
17
+
18
+ /**
19
+ * A menu item's badge, in the top right corner of the item (which is `relative`). Its text is
20
+ * shown as it is given, never translated. `dot` draws it as a dot, for an item shown as an icon.
21
+ */
22
+ export function MenuBadge({ badge, dot = false, className }: { badge?: MenuBadgeData; dot?: boolean; className?: string }) {
23
+ if (!badge?.text) return null
24
+ const color = COLORS[badge.color] ?? COLORS.gray
25
+
26
+ if (dot) {
27
+ return (
28
+ <span
29
+ aria-label={badge.text}
30
+ title={badge.text}
31
+ className={cn("absolute top-1 right-1 h-2 w-2 pointer-events-none", className)}
32
+ style={{ background: color.background }}
33
+ />
34
+ )
35
+ }
36
+
37
+ return (
38
+ <span
39
+ className={cn(
40
+ "absolute top-0.5 right-1 px-1 py-px text-[9px] font-medium uppercase leading-none tracking-wide pointer-events-none select-none",
41
+ className,
42
+ )}
43
+ style={{ background: color.background, color: color.text }}
44
+ >
45
+ {badge.text}
46
+ </span>
47
+ )
48
+ }
@@ -21,6 +21,7 @@ import {
21
21
  import { type SidebarMenus, type SubMenuItem, type MainMenuItem } from "./data"
22
22
  import { Skeleton } from "../skeleton"
23
23
  import { resolveTemplateVars } from "./template-vars"
24
+ import { MenuBadge } from "./menu-badge"
24
25
 
25
26
  // ── Dynamic secondary navigation ──────────────────────────────────────────────
26
27
 
@@ -347,7 +348,7 @@ function Sidebar({ currentMenu, sidebarMenus = {}, main_base_url = "", sectionLa
347
348
  }
348
349
 
349
350
  const linkCls = cn(
350
- "flex items-center transition-colors border-l-4",
351
+ "relative flex items-center transition-colors border-l-4",
351
352
  isCollapsed ? "justify-center p-2" : "px-2 lg:px-3 py-1.5 lg:py-2 gap-x-3 text-sm",
352
353
  isDisabled
353
354
  ? "opacity-40 cursor-not-allowed text-text-secondary border-transparent"
@@ -365,6 +366,7 @@ function Sidebar({ currentMenu, sidebarMenus = {}, main_base_url = "", sectionLa
365
366
  {!isCollapsed && (
366
367
  <span className="flex-1 truncate">{item.name}</span>
367
368
  )}
369
+ <MenuBadge badge={item.badge} dot={isCollapsed} />
368
370
  </>
369
371
  )
370
372
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orsetra/shared-ui",
3
- "version": "1.12.1",
3
+ "version": "1.13.0",
4
4
  "description": "Shared UI components for Orsetra platform",
5
5
  "main": "./index.ts",
6
6
  "types": "./index.ts",