@whity/ui 0.0.0-stage → 0.5.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.
Files changed (169) hide show
  1. package/README.md +107 -3
  2. package/package.json +192 -6
  3. package/src/access-denied.stories.tsx +179 -0
  4. package/src/access-denied.tsx +305 -0
  5. package/src/action-proposal.tsx +302 -0
  6. package/src/actor-chip.tsx +71 -0
  7. package/src/agent-activity.tsx +163 -0
  8. package/src/agent-collaboration.stories.tsx +156 -0
  9. package/src/agent-run-status.tsx +196 -0
  10. package/src/alert-dialog.stories.tsx +45 -0
  11. package/src/alert-dialog.tsx +147 -0
  12. package/src/alert.stories.tsx +91 -0
  13. package/src/alert.tsx +89 -0
  14. package/src/app-sidebar.stories.tsx +195 -0
  15. package/src/app-sidebar.tsx +500 -0
  16. package/src/approval-queue.tsx +108 -0
  17. package/src/audience-group-picker.stories.tsx +198 -0
  18. package/src/audience-group-picker.tsx +362 -0
  19. package/src/audience-people-picker.stories.tsx +102 -0
  20. package/src/audience-people-picker.tsx +279 -0
  21. package/src/avatar.tsx +83 -0
  22. package/src/badge.stories.tsx +105 -0
  23. package/src/badge.tsx +68 -0
  24. package/src/beta-warning.stories.tsx +79 -0
  25. package/src/beta-warning.tsx +189 -0
  26. package/src/bilingual-input.stories.tsx +82 -0
  27. package/src/bilingual-input.tsx +183 -0
  28. package/src/breadcrumb.stories.tsx +51 -0
  29. package/src/breadcrumb.tsx +90 -0
  30. package/src/button.stories.tsx +87 -0
  31. package/src/button.tsx +118 -0
  32. package/src/card.stories.tsx +423 -0
  33. package/src/card.tsx +180 -0
  34. package/src/chart.stories.tsx +66 -0
  35. package/src/chart.tsx +228 -0
  36. package/src/checkbox.stories.tsx +62 -0
  37. package/src/checkbox.tsx +54 -0
  38. package/src/collapsible.stories.tsx +48 -0
  39. package/src/collapsible.tsx +34 -0
  40. package/src/color-card.stories.tsx +61 -0
  41. package/src/color-card.tsx +270 -0
  42. package/src/color-picker.stories.tsx +65 -0
  43. package/src/color-picker.tsx +425 -0
  44. package/src/command-palette.tsx +306 -0
  45. package/src/copy-block.stories.tsx +38 -0
  46. package/src/copy-block.tsx +85 -0
  47. package/src/data-table.stories.tsx +200 -0
  48. package/src/data-table.tsx +1106 -0
  49. package/src/date-picker.stories.tsx +61 -0
  50. package/src/date-picker.tsx +422 -0
  51. package/src/design-cards.stories.tsx +458 -0
  52. package/src/dialog.stories.tsx +48 -0
  53. package/src/dialog.tsx +166 -0
  54. package/src/documents/barcode-svg.stories.tsx +72 -0
  55. package/src/documents/barcode-svg.tsx +79 -0
  56. package/src/dropdown-menu.stories.tsx +77 -0
  57. package/src/dropdown-menu.tsx +271 -0
  58. package/src/editor/behaviour.ts +279 -0
  59. package/src/editor/block-ids.ts +44 -0
  60. package/src/editor/block-list.tsx +101 -0
  61. package/src/editor/block-toolbar.tsx +477 -0
  62. package/src/editor/bubble.tsx +93 -0
  63. package/src/editor/catalogue.ts +103 -0
  64. package/src/editor/collab-rail.tsx +746 -0
  65. package/src/editor/collab.stories.tsx +207 -0
  66. package/src/editor/collab.ts +87 -0
  67. package/src/editor/contract.ts +408 -0
  68. package/src/editor/convert.ts +362 -0
  69. package/src/editor/doc-editor.stories.tsx +98 -0
  70. package/src/editor/doc-editor.tsx +1287 -0
  71. package/src/editor/editor.css +536 -0
  72. package/src/editor/extensions.ts +86 -0
  73. package/src/editor/field-picker.tsx +107 -0
  74. package/src/editor/fields.ts +100 -0
  75. package/src/editor/gutter.tsx +367 -0
  76. package/src/editor/index.ts +22 -0
  77. package/src/editor/label-sheet.tsx +289 -0
  78. package/src/editor/labels.ts +310 -0
  79. package/src/editor/link-tools.tsx +141 -0
  80. package/src/editor/node-views.tsx +450 -0
  81. package/src/editor/page-view.tsx +353 -0
  82. package/src/editor/publish-check.tsx +182 -0
  83. package/src/editor/rich-blocks.stories.tsx +146 -0
  84. package/src/editor/sample.ts +40 -0
  85. package/src/editor/schema-rich.ts +150 -0
  86. package/src/editor/schema.ts +315 -0
  87. package/src/editor/services.tsx +127 -0
  88. package/src/editor/slash.ts +64 -0
  89. package/src/editor/suggesting.ts +372 -0
  90. package/src/editor/suggestions.ts +763 -0
  91. package/src/editor/table-keys.ts +66 -0
  92. package/src/editor/templates.stories.tsx +324 -0
  93. package/src/editor/toolbar.tsx +358 -0
  94. package/src/empty-state.stories.tsx +51 -0
  95. package/src/empty-state.tsx +100 -0
  96. package/src/empty-state.usage-notes.md +30 -0
  97. package/src/form.stories.tsx +112 -0
  98. package/src/form.tsx +176 -0
  99. package/src/globals.css +20 -0
  100. package/src/icon-button.tsx +85 -0
  101. package/src/icon-map.ts +244 -0
  102. package/src/icon.tsx +41 -0
  103. package/src/index.ts +67 -0
  104. package/src/input.stories.tsx +157 -0
  105. package/src/input.tsx +759 -0
  106. package/src/locked-screen.stories.tsx +29 -0
  107. package/src/locked-screen.tsx +61 -0
  108. package/src/mark.tsx +62 -0
  109. package/src/math-text.stories.tsx +33 -0
  110. package/src/math-text.tsx +43 -0
  111. package/src/menu-bar.stories.tsx +198 -0
  112. package/src/menu-bar.tsx +373 -0
  113. package/src/money/currency.ts +230 -0
  114. package/src/page-header.stories.tsx +95 -0
  115. package/src/page-header.tsx +122 -0
  116. package/src/page-shell.stories.tsx +42 -0
  117. package/src/page-shell.tsx +32 -0
  118. package/src/pagination.stories.tsx +45 -0
  119. package/src/pagination.tsx +98 -0
  120. package/src/plugin-card.stories.tsx +180 -0
  121. package/src/plugin-card.tsx +848 -0
  122. package/src/popover.stories.tsx +48 -0
  123. package/src/popover.tsx +55 -0
  124. package/src/radio-group.stories.tsx +26 -0
  125. package/src/radio-group.tsx +44 -0
  126. package/src/route-flow/editor.tsx +1014 -0
  127. package/src/route-flow/model.ts +716 -0
  128. package/src/scope-grant.tsx +139 -0
  129. package/src/screen-too-small.stories.tsx +61 -0
  130. package/src/screen-too-small.tsx +104 -0
  131. package/src/select.stories.tsx +44 -0
  132. package/src/select.tsx +197 -0
  133. package/src/separator.stories.tsx +34 -0
  134. package/src/separator.tsx +34 -0
  135. package/src/sheet.stories.tsx +49 -0
  136. package/src/sheet.tsx +168 -0
  137. package/src/skeleton.stories.tsx +28 -0
  138. package/src/skeleton.tsx +19 -0
  139. package/src/slider.stories.tsx +78 -0
  140. package/src/slider.tsx +300 -0
  141. package/src/spinner.stories.tsx +33 -0
  142. package/src/spinner.tsx +55 -0
  143. package/src/switch.stories.tsx +42 -0
  144. package/src/switch.tsx +41 -0
  145. package/src/switcher.stories.tsx +111 -0
  146. package/src/switcher.tsx +131 -0
  147. package/src/table.stories.tsx +48 -0
  148. package/src/table.tsx +121 -0
  149. package/src/tabs.stories.tsx +74 -0
  150. package/src/tabs.tsx +90 -0
  151. package/src/tag-input.stories.tsx +67 -0
  152. package/src/tag-input.tsx +117 -0
  153. package/src/tenant-logo.tsx +63 -0
  154. package/src/tenant-switcher.stories.tsx +38 -0
  155. package/src/tenant-switcher.tsx +164 -0
  156. package/src/textarea.stories.tsx +27 -0
  157. package/src/textarea.tsx +18 -0
  158. package/src/theme-mode.ts +52 -0
  159. package/src/time-picker.stories.tsx +62 -0
  160. package/src/time-picker.tsx +615 -0
  161. package/src/toggle-group.tsx +138 -0
  162. package/src/tooltip.stories.tsx +43 -0
  163. package/src/tooltip.tsx +73 -0
  164. package/src/top-nav.stories.tsx +58 -0
  165. package/src/top-nav.tsx +324 -0
  166. package/src/undo-bar.tsx +107 -0
  167. package/src/utils.ts +45 -0
  168. package/src/view-toggle.stories.tsx +84 -0
  169. package/src/view-toggle.tsx +110 -0
package/src/sheet.tsx ADDED
@@ -0,0 +1,168 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { Dialog as SheetPrimitive } from "radix-ui"
5
+
6
+ import { cn, useIsDarkMode } from "./utils"
7
+ import { Button } from "./button"
8
+ import { IconX } from "@tabler/icons-react"
9
+
10
+ /**
11
+ * A side drawer ("sheet") built on the Radix Dialog primitive — the same
12
+ * accessibility model as {@link ./dialog} (focus trap, Esc to close, scroll
13
+ * lock, labelled by title) but anchored to an edge of the viewport. Used by the
14
+ * OU Management Hub'header detail drawer.
15
+ */
16
+ function Sheet({
17
+ ...props
18
+ }: React.ComponentProps<typeof SheetPrimitive.Root>) {
19
+ return <SheetPrimitive.Root data-slot="sheet" {...props} />
20
+ }
21
+
22
+ function SheetTrigger({
23
+ ...props
24
+ }: React.ComponentProps<typeof SheetPrimitive.Trigger>) {
25
+ return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />
26
+ }
27
+
28
+ function SheetClose({
29
+ ...props
30
+ }: React.ComponentProps<typeof SheetPrimitive.Close>) {
31
+ return <SheetPrimitive.Close data-slot="sheet-close" {...props} />
32
+ }
33
+
34
+ function SheetOverlay({
35
+ className,
36
+ ...props
37
+ }: React.ComponentProps<typeof SheetPrimitive.Overlay>) {
38
+ return (
39
+ <SheetPrimitive.Overlay
40
+ data-slot="sheet-overlay"
41
+ className={cn(
42
+ "fixed inset-0 z-50 bg-overlay duration-100 data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
43
+ className
44
+ )}
45
+ {...props}
46
+ />
47
+ )
48
+ }
49
+
50
+ /**
51
+ * "left"/"right" are logical (start/end), not fixed screen sides — the
52
+ * implementation below maps them to `start-`/`end-` + `border-e`/`border-s`,
53
+ * so `side="right"` renders on the inline-end edge and flips with `dir="rtl"`
54
+ * like every other directional value in this kit, not a fixed physical side.
55
+ */
56
+ type SheetSide = "top" | "right" | "bottom" | "left"
57
+
58
+ function SheetContent({
59
+ className,
60
+ children,
61
+ side = "right",
62
+ showCloseButton = true,
63
+ closeLabel = "Close",
64
+ ...props
65
+ }: React.ComponentProps<typeof SheetPrimitive.Content> & {
66
+ side?: SheetSide
67
+ showCloseButton?: boolean
68
+ /** Accessible name for the close button (visually hidden). */
69
+ closeLabel?: string
70
+ }) {
71
+ const isDark = useIsDarkMode()
72
+
73
+ return (
74
+ <SheetPrimitive.Portal>
75
+ <SheetOverlay />
76
+ <SheetPrimitive.Content
77
+ data-slot="sheet-content"
78
+ className={cn(
79
+ isDark && "dark",
80
+ "fixed z-50 flex flex-col gap-4 overflow-y-auto bg-popover p-5 text-xs/relaxed text-popover-foreground shadow-lg duration-150 outline-none data-open:animate-in data-closed:animate-out",
81
+ side === "right" &&
82
+ "inset-y-0 end-0 h-full w-full max-w-md border-s border-border data-open:slide-in-from-right data-closed:slide-out-to-right",
83
+ side === "left" &&
84
+ "inset-y-0 start-0 h-full w-full max-w-md border-e border-border data-open:slide-in-from-left data-closed:slide-out-to-left",
85
+ side === "top" &&
86
+ "inset-x-0 top-0 h-auto max-h-[80%] w-full border-b border-border data-open:slide-in-from-top data-closed:slide-out-to-top",
87
+ side === "bottom" &&
88
+ "inset-x-0 bottom-0 h-auto max-h-[80%] w-full border-t border-border data-open:slide-in-from-bottom data-closed:slide-out-to-bottom",
89
+ className
90
+ )}
91
+ {...props}
92
+ >
93
+ {children}
94
+ {showCloseButton && (
95
+ <SheetPrimitive.Close data-slot="sheet-close" asChild>
96
+ <Button variant="ghost" className="absolute top-3 end-3" size="icon-sm">
97
+ <IconX />
98
+ <span className="sr-only">{closeLabel}</span>
99
+ </Button>
100
+ </SheetPrimitive.Close>
101
+ )}
102
+ </SheetPrimitive.Content>
103
+ </SheetPrimitive.Portal>
104
+ )
105
+ }
106
+
107
+ function SheetHeader({
108
+ className,
109
+ ...props
110
+ }: React.ComponentProps<"div">) {
111
+ return (
112
+ <div
113
+ data-slot="sheet-header"
114
+ className={cn("flex flex-col gap-1 text-start", className)}
115
+ {...props}
116
+ />
117
+ )
118
+ }
119
+
120
+ function SheetFooter({
121
+ className,
122
+ ...props
123
+ }: React.ComponentProps<"div">) {
124
+ return (
125
+ <div
126
+ data-slot="sheet-footer"
127
+ className={cn("mt-auto flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", className)}
128
+ {...props}
129
+ />
130
+ )
131
+ }
132
+
133
+ function SheetTitle({
134
+ className,
135
+ ...props
136
+ }: React.ComponentProps<typeof SheetPrimitive.Title>) {
137
+ return (
138
+ <SheetPrimitive.Title
139
+ data-slot="sheet-title"
140
+ className={cn("font-heading text-sm font-medium text-foreground", className)}
141
+ {...props}
142
+ />
143
+ )
144
+ }
145
+
146
+ function SheetDescription({
147
+ className,
148
+ ...props
149
+ }: React.ComponentProps<typeof SheetPrimitive.Description>) {
150
+ return (
151
+ <SheetPrimitive.Description
152
+ data-slot="sheet-description"
153
+ className={cn("text-xs text-muted-foreground", className)}
154
+ {...props}
155
+ />
156
+ )
157
+ }
158
+
159
+ export {
160
+ Sheet,
161
+ SheetTrigger,
162
+ SheetClose,
163
+ SheetContent,
164
+ SheetHeader,
165
+ SheetFooter,
166
+ SheetTitle,
167
+ SheetDescription,
168
+ }
@@ -0,0 +1,28 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite"
2
+
3
+ import { Skeleton } from "./skeleton"
4
+
5
+ const meta = {
6
+ title: "Primitives/Skeleton",
7
+ component: Skeleton,
8
+ tags: ["autodocs"],
9
+ } satisfies Meta<typeof Skeleton>
10
+
11
+ export default meta
12
+ type Story = StoryObj<typeof meta>
13
+
14
+ export const Default: Story = {
15
+ render: () => <Skeleton className="h-6 w-48" />,
16
+ }
17
+
18
+ export const CardPlaceholder: Story = {
19
+ render: () => (
20
+ <div className="flex w-72 items-center gap-3">
21
+ <Skeleton className="size-10 rounded-full" />
22
+ <div className="flex flex-1 flex-col gap-2">
23
+ <Skeleton className="h-4 w-3/4" />
24
+ <Skeleton className="h-4 w-1/2" />
25
+ </div>
26
+ </div>
27
+ ),
28
+ }
@@ -0,0 +1,19 @@
1
+ import { cn } from "./utils"
2
+
3
+ /**
4
+ * Loading placeholder for structured content. Preserves layout while data is
5
+ * in flight (preferred over a bare spinner for known shapes — see UI-Patterns).
6
+ * Token-driven: fill is `muted`, animated with `animate-pulse`.
7
+ */
8
+ function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
9
+ return (
10
+ <div
11
+ data-slot="skeleton"
12
+ aria-hidden="true"
13
+ className={cn("animate-pulse rounded-md bg-muted", className)}
14
+ {...props}
15
+ />
16
+ )
17
+ }
18
+
19
+ export { Skeleton }
@@ -0,0 +1,78 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite"
2
+
3
+ import { Slider } from "./slider"
4
+
5
+ const meta = {
6
+ title: "Primitives/Slider",
7
+ component: Slider,
8
+ tags: ["autodocs"],
9
+ args: { defaultValue: [50], max: 100, step: 1 },
10
+ } satisfies Meta<typeof Slider>
11
+
12
+ export default meta
13
+ type Story = StoryObj<typeof meta>
14
+
15
+ export const Default: Story = {
16
+ render: () => (
17
+ <div className="w-80">
18
+ <Slider defaultValue={[50]} />
19
+ </div>
20
+ ),
21
+ }
22
+
23
+ export const WithLabelAndTooltip: Story = {
24
+ render: () => (
25
+ <div className="flex w-80 flex-col gap-6">
26
+ <Slider
27
+ label="Volume Level"
28
+ defaultValue={[75]}
29
+ required
30
+ tooltip="Adjust audio output volume level."
31
+ formatValue={(val) => `${val}%`}
32
+ helperText="Drag thumb or use arrow keys to adjust."
33
+ />
34
+ <Slider
35
+ label="System Opacity"
36
+ defaultValue={[40]}
37
+ min={0}
38
+ max={100}
39
+ step={5}
40
+ formatValue={(val) => `${val}%`}
41
+ helperText="Adjust background opacity overlay."
42
+ />
43
+ </div>
44
+ ),
45
+ }
46
+
47
+ export const RangeSlider: Story = {
48
+ render: () => (
49
+ <div className="flex w-80 flex-col gap-6">
50
+ <Slider
51
+ label="Price Range ($)"
52
+ defaultValue={[20, 80]}
53
+ min={0}
54
+ max={100}
55
+ step={5}
56
+ formatValue={(val) => `$${val}`}
57
+ helperText="Dual thumb range selector."
58
+ />
59
+ </div>
60
+ ),
61
+ }
62
+
63
+ export const States: Story = {
64
+ render: () => (
65
+ <div className="flex w-80 flex-col gap-6">
66
+ <Slider
67
+ label="Active Slider"
68
+ defaultValue={[60]}
69
+ />
70
+ <Slider
71
+ label="Disabled Slider"
72
+ defaultValue={[30]}
73
+ disabled
74
+ helperText="Disabled state."
75
+ />
76
+ </div>
77
+ ),
78
+ }
package/src/slider.tsx ADDED
@@ -0,0 +1,300 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { Slider as SliderPrimitive } from "radix-ui"
5
+ import { IconInfoCircle } from "@tabler/icons-react"
6
+
7
+ import { cn } from "./utils"
8
+ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./tooltip"
9
+
10
+ export interface SliderProps extends React.ComponentPropsWithoutRef<typeof SliderPrimitive.Root> {
11
+ /**
12
+ * Field label text displayed above the slider.
13
+ */
14
+ label?: React.ReactNode
15
+ /**
16
+ * Displays a required asterisk (*) next to the label.
17
+ */
18
+ required?: boolean
19
+ /**
20
+ * Tooltip message displayed in an interactive info icon next to the label.
21
+ */
22
+ tooltip?: React.ReactNode
23
+ /** Accessible name for the tooltip's trigger button. Defaults to "More information". */
24
+ tooltipTriggerLabel?: string
25
+ /**
26
+ * Small informational note rendered below the slider.
27
+ */
28
+ helperText?: React.ReactNode
29
+ /**
30
+ * Error text rendered below the slider in destructive red.
31
+ */
32
+ errorText?: React.ReactNode
33
+ /**
34
+ * Displays the current value badge next to the label. Defaults to true.
35
+ */
36
+ showValueBadge?: boolean
37
+ /**
38
+ * Renders direct numeric entry input field(s) alongside the slider track. Defaults to true.
39
+ */
40
+ showInput?: boolean
41
+ /**
42
+ * Optional formatter function for the value badge e.g. (val) => `${val}%`.
43
+ */
44
+ formatValue?: (value: number) => React.ReactNode
45
+ }
46
+
47
+ const Slider = React.forwardRef<
48
+ React.ElementRef<typeof SliderPrimitive.Root>,
49
+ SliderProps
50
+ >(
51
+ (
52
+ {
53
+ className,
54
+ label,
55
+ required,
56
+ tooltip,
57
+ tooltipTriggerLabel = "More information",
58
+ helperText,
59
+ errorText,
60
+ showValueBadge = true,
61
+ showInput = true,
62
+ formatValue,
63
+ defaultValue,
64
+ value,
65
+ min = 0,
66
+ max = 100,
67
+ step = 1,
68
+ disabled,
69
+ onValueChange,
70
+ ...props
71
+ },
72
+ ref
73
+ ) => {
74
+ const initialVals = Array.isArray(value)
75
+ ? value
76
+ : Array.isArray(defaultValue)
77
+ ? defaultValue
78
+ : [min]
79
+
80
+ const [internalValues, setInternalValues] = React.useState<number[]>(initialVals)
81
+ const [inputStrings, setInputStrings] = React.useState<string[]>(
82
+ initialVals.map((v) => String(v))
83
+ )
84
+
85
+ React.useEffect(() => {
86
+ let nextVals = initialVals
87
+ if (Array.isArray(value)) {
88
+ nextVals = value
89
+ } else if (Array.isArray(defaultValue)) {
90
+ nextVals = defaultValue
91
+ }
92
+ setInternalValues(nextVals)
93
+ setInputStrings(nextVals.map((v) => String(v)))
94
+ }, [value, defaultValue])
95
+
96
+ const handleValueChange = (vals: number[]) => {
97
+ setInternalValues(vals)
98
+ setInputStrings(vals.map((v) => String(v)))
99
+ onValueChange?.(vals)
100
+ }
101
+
102
+ const handleDirectInputChange = (index: number, rawVal: string) => {
103
+ setInputStrings((prev) => {
104
+ const next = [...prev]
105
+ next[index] = rawVal
106
+ return next
107
+ })
108
+
109
+ const parsed = parseFloat(rawVal)
110
+ if (isNaN(parsed)) return
111
+
112
+ const newVals = [...internalValues]
113
+ if (newVals.length === 1) {
114
+ const clamped = Math.min(Math.max(parsed, min), max)
115
+ newVals[0] = clamped
116
+ setInternalValues(newVals)
117
+ onValueChange?.(newVals)
118
+ } else if (newVals.length === 2) {
119
+ if (index === 0) {
120
+ const clamped = Math.min(Math.max(parsed, min), newVals[1])
121
+ newVals[0] = clamped
122
+ } else {
123
+ const clamped = Math.min(Math.max(parsed, newVals[0]), max)
124
+ newVals[1] = clamped
125
+ }
126
+ setInternalValues(newVals)
127
+ onValueChange?.(newVals)
128
+ }
129
+ }
130
+
131
+ const handleInputBlur = (index: number) => {
132
+ let parsed = parseFloat(inputStrings[index])
133
+ if (isNaN(parsed)) {
134
+ parsed = internalValues[index] ?? min
135
+ }
136
+ const newVals = [...internalValues]
137
+ if (newVals.length === 1) {
138
+ const clamped = Math.min(Math.max(parsed, min), max)
139
+ newVals[0] = clamped
140
+ } else if (newVals.length === 2) {
141
+ if (index === 0) {
142
+ const clamped = Math.min(Math.max(parsed, min), newVals[1])
143
+ newVals[0] = clamped
144
+ } else {
145
+ const clamped = Math.min(Math.max(parsed, newVals[0]), max)
146
+ newVals[1] = clamped
147
+ }
148
+ }
149
+ setInternalValues(newVals)
150
+ setInputStrings(newVals.map((v) => String(v)))
151
+ onValueChange?.(newVals)
152
+ }
153
+
154
+ const renderDisplayVal = () => {
155
+ if (!internalValues || internalValues.length === 0) return null
156
+ if (internalValues.length === 1) {
157
+ const val = internalValues[0]
158
+ return formatValue ? formatValue(val) : val
159
+ }
160
+ const val1 = formatValue ? formatValue(internalValues[0]) : internalValues[0]
161
+ const val2 = formatValue ? formatValue(internalValues[1]) : internalValues[1]
162
+ return `${val1} – ${val2}`
163
+ }
164
+
165
+ const hasHeader = label || tooltip || required || (showValueBadge && (!showInput || !!formatValue))
166
+ const hasFooter = helperText || errorText
167
+
168
+ const isRange = internalValues.length > 1
169
+
170
+ const sliderPrimitive = (
171
+ <SliderPrimitive.Root
172
+ ref={ref}
173
+ data-slot="slider"
174
+ disabled={disabled}
175
+ defaultValue={defaultValue}
176
+ value={value}
177
+ min={min}
178
+ max={max}
179
+ step={step}
180
+ onValueChange={handleValueChange}
181
+ className={cn(
182
+ "relative flex w-full touch-none select-none items-center py-1.5",
183
+ disabled && "pointer-events-none opacity-50",
184
+ className
185
+ )}
186
+ {...props}
187
+ >
188
+ <SliderPrimitive.Track className="relative h-1.5 w-full grow overflow-hidden rounded-full bg-muted">
189
+ <SliderPrimitive.Range className="absolute h-full bg-primary" />
190
+ </SliderPrimitive.Track>
191
+ <SliderPrimitive.Thumb className="block size-4 rounded-full border-2 border-primary bg-card shadow-2xs transition-colors hover:scale-110 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 cursor-grab active:cursor-grabbing" />
192
+ {isRange && (
193
+ <SliderPrimitive.Thumb className="block size-4 rounded-full border-2 border-primary bg-card shadow-2xs transition-colors hover:scale-110 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 cursor-grab active:cursor-grabbing" />
194
+ )}
195
+ </SliderPrimitive.Root>
196
+ )
197
+
198
+ const renderCombinedSlider = () => {
199
+ if (!showInput) return sliderPrimitive
200
+
201
+ if (!isRange) {
202
+ return (
203
+ <div className="flex items-center gap-3 w-full">
204
+ <div className="flex-1 min-w-0">{sliderPrimitive}</div>
205
+ <input
206
+ type="number"
207
+ min={min}
208
+ max={max}
209
+ step={step}
210
+ disabled={disabled}
211
+ value={inputStrings[0] ?? ""}
212
+ onChange={(e) => handleDirectInputChange(0, e.target.value)}
213
+ onBlur={() => handleInputBlur(0)}
214
+ onKeyDown={(e) => e.key === "Enter" && handleInputBlur(0)}
215
+ className="h-7 w-14 shrink-0 rounded-md border border-input bg-card px-1.5 py-0.5 text-center text-xs font-medium text-foreground transition-colors outline-none focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
216
+ />
217
+ </div>
218
+ )
219
+ }
220
+
221
+ return (
222
+ <div className="flex items-center gap-2.5 w-full">
223
+ <input
224
+ type="number"
225
+ min={min}
226
+ max={internalValues[1]}
227
+ step={step}
228
+ disabled={disabled}
229
+ value={inputStrings[0] ?? ""}
230
+ onChange={(e) => handleDirectInputChange(0, e.target.value)}
231
+ onBlur={() => handleInputBlur(0)}
232
+ onKeyDown={(e) => e.key === "Enter" && handleInputBlur(0)}
233
+ className="h-7 w-14 shrink-0 rounded-md border border-input bg-card px-1.5 py-0.5 text-center text-xs font-medium text-foreground transition-colors outline-none focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
234
+ />
235
+ <div className="flex-1 min-w-0">{sliderPrimitive}</div>
236
+ <input
237
+ type="number"
238
+ min={internalValues[0]}
239
+ max={max}
240
+ step={step}
241
+ disabled={disabled}
242
+ value={inputStrings[1] ?? ""}
243
+ onChange={(e) => handleDirectInputChange(1, e.target.value)}
244
+ onBlur={() => handleInputBlur(1)}
245
+ onKeyDown={(e) => e.key === "Enter" && handleInputBlur(1)}
246
+ className="h-7 w-14 shrink-0 rounded-md border border-input bg-card px-1.5 py-0.5 text-center text-xs font-medium text-foreground transition-colors outline-none focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
247
+ />
248
+ </div>
249
+ )
250
+ }
251
+
252
+ if (!hasHeader && !hasFooter) {
253
+ return renderCombinedSlider()
254
+ }
255
+
256
+ return (
257
+ <div className="flex flex-col gap-1.5 w-full text-start">
258
+ {hasHeader && (
259
+ <div className="flex items-center justify-between gap-2 text-xs font-semibold text-foreground">
260
+ <div className="flex items-center gap-1">
261
+ {label && <span>{label}</span>}
262
+ {required && <span className="text-destructive font-semibold ms-0.5">*</span>}
263
+ {tooltip && (
264
+ <TooltipProvider>
265
+ <Tooltip>
266
+ <TooltipTrigger asChild>
267
+ <button
268
+ type="button"
269
+ aria-label={tooltipTriggerLabel}
270
+ className="inline-flex items-center text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring rounded p-0.5"
271
+ >
272
+ <IconInfoCircle className="size-3.5 shrink-0" aria-hidden="true" />
273
+ </button>
274
+ </TooltipTrigger>
275
+ <TooltipContent>{tooltip}</TooltipContent>
276
+ </Tooltip>
277
+ </TooltipProvider>
278
+ )}
279
+ </div>
280
+ {showValueBadge && (!showInput || !!formatValue) && (
281
+ <span className="rounded bg-muted px-1.5 py-0.5 font-mono text-[0.6875rem] font-semibold text-muted-foreground">
282
+ {renderDisplayVal()}
283
+ </span>
284
+ )}
285
+ </div>
286
+ )}
287
+ {renderCombinedSlider()}
288
+ {errorText ? (
289
+ <p className="text-[0.6875rem] font-medium text-destructive">{errorText}</p>
290
+ ) : (
291
+ helperText && <p className="text-[0.6875rem] text-muted-foreground">{helperText}</p>
292
+ )}
293
+ </div>
294
+ )
295
+ }
296
+ )
297
+
298
+ Slider.displayName = "Slider"
299
+
300
+ export { Slider }
@@ -0,0 +1,33 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite"
2
+
3
+ import { Spinner } from "./spinner"
4
+
5
+ const meta = {
6
+ title: "Primitives/Spinner",
7
+ component: Spinner,
8
+ tags: ["autodocs"],
9
+ argTypes: {
10
+ size: { control: "select", options: ["sm", "default", "lg"] },
11
+ },
12
+ } satisfies Meta<typeof Spinner>
13
+
14
+ export default meta
15
+ type Story = StoryObj<typeof meta>
16
+
17
+ export const Default: Story = {
18
+ args: {},
19
+ }
20
+
21
+ export const Sizes: Story = {
22
+ render: () => (
23
+ <div className="flex items-center gap-4">
24
+ <Spinner size="sm" />
25
+ <Spinner size="default" />
26
+ <Spinner size="lg" />
27
+ </div>
28
+ ),
29
+ }
30
+
31
+ export const CustomLabel: Story = {
32
+ args: { label: "Fetching audit logs…" },
33
+ }
@@ -0,0 +1,55 @@
1
+ import * as React from "react"
2
+ import { cva, type VariantProps } from "class-variance-authority"
3
+ import { IconLoader2 } from "@tabler/icons-react"
4
+
5
+ import { cn } from "./utils"
6
+
7
+ /**
8
+ * A dedicated loading indicator — replaces the ad-hoc `animate-spin
9
+ * rounded-full border-b-2 border-primary` divs scattered across admin pages
10
+ * (audit-logs, mcp-tools, plugins, registrations, …). Reuses the same
11
+ * IconLoader2 + animate-spin pairing Button already uses for its own
12
+ * `loading` state, so a standalone spinner and a button's inline spinner
13
+ * always look identical.
14
+ *
15
+ * PLATFORM NOTE: `size` and `label` are plain enum/string props — directly
16
+ * mirrorable by a future Flutter CircularProgressIndicator wrapper.
17
+ */
18
+ const spinnerVariants = cva("animate-spin text-muted-foreground", {
19
+ variants: {
20
+ size: {
21
+ sm: "size-4",
22
+ default: "size-6",
23
+ lg: "size-8",
24
+ },
25
+ },
26
+ defaultVariants: {
27
+ size: "default",
28
+ },
29
+ })
30
+
31
+ export interface SpinnerProps
32
+ extends Omit<React.ComponentProps<"span">, "children">,
33
+ VariantProps<typeof spinnerVariants> {
34
+ /** Visually-hidden text announced to assistive tech. Defaults to "Loading". */
35
+ label?: string
36
+ }
37
+
38
+ function Spinner({ className, size, label = "Loading", ...props }: SpinnerProps) {
39
+ return (
40
+ <span
41
+ data-slot="spinner"
42
+ role="status"
43
+ // A generic status/region role gets no "name from content" in the
44
+ // accessible-name computation — aria-label is required, a visually-
45
+ // hidden text child alone would be silently ignored by assistive tech.
46
+ aria-label={label}
47
+ className={cn("inline-flex", className)}
48
+ {...props}
49
+ >
50
+ <IconLoader2 aria-hidden="true" className={cn(spinnerVariants({ size }))} />
51
+ </span>
52
+ )
53
+ }
54
+
55
+ export { Spinner, spinnerVariants }