@orsetra/shared-ui 1.10.4 → 1.10.5

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.
@@ -47,6 +47,7 @@ export { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, Pagi
47
47
  export { Popover, PopoverTrigger, PopoverContent } from './popover'
48
48
  export { Progress } from './progress'
49
49
  export { RadioGroup, RadioGroupItem } from './radio-group'
50
+ export { RelativeTimeRangePicker, type RelativeTimeRangeOption, type RelativeTimeRangePickerProps } from './relative-time-range-picker'
50
51
  export { ResizablePanelGroup, ResizablePanel, ResizableHandle } from './resizable'
51
52
  export { ScrollArea, ScrollBar } from './scroll-area'
52
53
  export { Select, SelectGroup, SelectValue, SelectTrigger, SelectContent, SelectLabel, SelectItem, SelectSeparator } from './select'
@@ -0,0 +1,93 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { Check, ChevronDown, Clock } from "lucide-react"
5
+ import { cn } from "../../lib/utils"
6
+ import { Button } from "./button"
7
+ import { Popover, PopoverContent, PopoverTrigger } from "./popover"
8
+
9
+ export interface RelativeTimeRangeOption {
10
+ label: string
11
+ /** Length of the window, in seconds (e.g. 3600 for "1h"). Used as the option's identity. */
12
+ seconds: number
13
+ }
14
+
15
+ export interface RelativeTimeRangePickerProps {
16
+ id?: string
17
+ value: number
18
+ onChange: (seconds: number) => void
19
+ options: RelativeTimeRangeOption[]
20
+ disabled?: boolean
21
+ className?: string
22
+ /** Popover alignment relative to the trigger. Defaults to "end" (picker anchored right — the
23
+ * common placement next to a panel's close button). */
24
+ align?: "start" | "center" | "end"
25
+ /** Accessible name and popover heading. Defaults to "Time range". */
26
+ triggerLabel?: string
27
+ }
28
+
29
+ /**
30
+ * Flyout picker for a small set of relative time ranges (20m, 1h, 3h, ...), styled as a gallery
31
+ * of choices rather than a dropdown list — the current selection is highlighted with both a
32
+ * filled background and a check mark (not color alone), mirroring how Calendar marks the
33
+ * selected day and Combobox marks the selected item in this same component set.
34
+ */
35
+ export function RelativeTimeRangePicker({
36
+ id,
37
+ value,
38
+ onChange,
39
+ options,
40
+ disabled = false,
41
+ className,
42
+ align = "end",
43
+ triggerLabel = "Time range",
44
+ }: RelativeTimeRangePickerProps) {
45
+ const [open, setOpen] = React.useState(false)
46
+ const selected = options.find(o => o.seconds === value)
47
+
48
+ return (
49
+ <Popover open={open} onOpenChange={setOpen}>
50
+ <PopoverTrigger asChild>
51
+ <Button
52
+ id={id}
53
+ type="button"
54
+ variant="secondary"
55
+ size="sm"
56
+ disabled={disabled}
57
+ aria-label={triggerLabel}
58
+ className={cn("rounded-none", className)}
59
+ leftIcon={<Clock className="h-3.5 w-3.5" />}
60
+ rightIcon={<ChevronDown className="h-3.5 w-3.5 opacity-60" />}
61
+ >
62
+ {selected?.label ?? "Select…"}
63
+ </Button>
64
+ </PopoverTrigger>
65
+ <PopoverContent align={align} sideOffset={6} className="w-auto rounded-none p-2">
66
+ <p className="px-1 pb-2 text-xs font-medium text-ibm-gray-50">{triggerLabel}</p>
67
+ <div role="listbox" aria-label={triggerLabel} className="grid grid-cols-3 gap-1.5">
68
+ {options.map(opt => {
69
+ const isSelected = opt.seconds === value
70
+ return (
71
+ <button
72
+ key={opt.seconds}
73
+ type="button"
74
+ role="option"
75
+ aria-selected={isSelected}
76
+ onClick={() => { onChange(opt.seconds); setOpen(false) }}
77
+ className={cn(
78
+ "flex items-center justify-center gap-1 h-9 px-2 text-sm font-medium border transition-colors whitespace-nowrap",
79
+ isSelected
80
+ ? "bg-ibm-blue-60 text-white border-ibm-blue-60"
81
+ : "bg-white text-ibm-gray-100 border-ibm-gray-20 hover:bg-ibm-blue-10 hover:border-ibm-blue-40"
82
+ )}
83
+ >
84
+ {isSelected && <Check className="h-3 w-3 flex-shrink-0" />}
85
+ {opt.label}
86
+ </button>
87
+ )
88
+ })}
89
+ </div>
90
+ </PopoverContent>
91
+ </Popover>
92
+ )
93
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orsetra/shared-ui",
3
- "version": "1.10.4",
3
+ "version": "1.10.5",
4
4
  "description": "Shared UI components for Orsetra platform",
5
5
  "main": "./index.ts",
6
6
  "types": "./index.ts",