@whity/ui 0.0.0-stage → 1.0.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.
- package/README.md +106 -2
- package/package.json +219 -4
- package/src/access-denied.stories.tsx +179 -0
- package/src/access-denied.tsx +305 -0
- package/src/action-proposal.tsx +338 -0
- package/src/actor-chip.tsx +71 -0
- package/src/agent-activity.tsx +163 -0
- package/src/agent-collaboration.stories.tsx +156 -0
- package/src/agent-run-status.tsx +196 -0
- package/src/alert-dialog.stories.tsx +45 -0
- package/src/alert-dialog.tsx +147 -0
- package/src/alert.stories.tsx +91 -0
- package/src/alert.tsx +89 -0
- package/src/app-sidebar.stories.tsx +195 -0
- package/src/app-sidebar.tsx +604 -0
- package/src/approval-queue.tsx +109 -0
- package/src/audience-group-picker.stories.tsx +198 -0
- package/src/audience-group-picker.tsx +362 -0
- package/src/audience-people-picker.stories.tsx +102 -0
- package/src/audience-people-picker.tsx +279 -0
- package/src/avatar-pattern.ts +138 -0
- package/src/avatar.tsx +125 -0
- package/src/badge.stories.tsx +105 -0
- package/src/badge.tsx +68 -0
- package/src/beta-warning.stories.tsx +79 -0
- package/src/beta-warning.tsx +189 -0
- package/src/bilingual-input.stories.tsx +82 -0
- package/src/bilingual-input.tsx +188 -0
- package/src/board.tsx +216 -0
- package/src/breadcrumb.stories.tsx +51 -0
- package/src/breadcrumb.tsx +90 -0
- package/src/built-on-whity.tsx +52 -0
- package/src/button.stories.tsx +87 -0
- package/src/button.tsx +123 -0
- package/src/card.stories.tsx +423 -0
- package/src/card.tsx +180 -0
- package/src/chart.stories.tsx +66 -0
- package/src/chart.tsx +228 -0
- package/src/checkbox.stories.tsx +62 -0
- package/src/checkbox.tsx +54 -0
- package/src/collapsible.stories.tsx +48 -0
- package/src/collapsible.tsx +34 -0
- package/src/color-card.stories.tsx +61 -0
- package/src/color-card.tsx +270 -0
- package/src/color-picker.stories.tsx +65 -0
- package/src/color-picker.tsx +425 -0
- package/src/column-matcher.tsx +84 -0
- package/src/command-palette.tsx +398 -0
- package/src/confirm-action.tsx +98 -0
- package/src/copy-block.stories.tsx +38 -0
- package/src/copy-block.tsx +85 -0
- package/src/data-table.stories.tsx +200 -0
- package/src/data-table.tsx +1686 -0
- package/src/date-picker.stories.tsx +61 -0
- package/src/date-picker.tsx +456 -0
- package/src/design-cards.stories.tsx +551 -0
- package/src/dialog.stories.tsx +48 -0
- package/src/dialog.tsx +179 -0
- package/src/display-preferences.tsx +50 -0
- package/src/documents/barcode-svg.stories.tsx +72 -0
- package/src/documents/barcode-svg.tsx +79 -0
- package/src/dropdown-menu.stories.tsx +77 -0
- package/src/dropdown-menu.tsx +271 -0
- package/src/editor/agent-panel.tsx +222 -0
- package/src/editor/agents.stories.tsx +81 -0
- package/src/editor/agents.ts +55 -0
- package/src/editor/behaviour.ts +279 -0
- package/src/editor/block-ids.ts +44 -0
- package/src/editor/block-list.tsx +104 -0
- package/src/editor/block-toolbar.tsx +490 -0
- package/src/editor/bubble.tsx +119 -0
- package/src/editor/catalogue.ts +169 -0
- package/src/editor/collab-rail.tsx +746 -0
- package/src/editor/collab.stories.tsx +207 -0
- package/src/editor/collab.ts +87 -0
- package/src/editor/contract.ts +476 -0
- package/src/editor/convert.ts +414 -0
- package/src/editor/doc-editor.stories.tsx +98 -0
- package/src/editor/doc-editor.tsx +1492 -0
- package/src/editor/editor.css +636 -0
- package/src/editor/extensions.ts +86 -0
- package/src/editor/field-bar.tsx +154 -0
- package/src/editor/field-picker.tsx +109 -0
- package/src/editor/fields.ts +100 -0
- package/src/editor/gutter.tsx +443 -0
- package/src/editor/index.ts +23 -0
- package/src/editor/label-sheet.tsx +289 -0
- package/src/editor/labels.ts +394 -0
- package/src/editor/link-tools.tsx +141 -0
- package/src/editor/node-views.tsx +461 -0
- package/src/editor/page-view.tsx +372 -0
- package/src/editor/phone.tsx +310 -0
- package/src/editor/plugin-block-view.tsx +230 -0
- package/src/editor/plugin-blocks.stories.tsx +96 -0
- package/src/editor/plugin-blocks.ts +52 -0
- package/src/editor/publish-check.tsx +201 -0
- package/src/editor/rich-blocks.stories.tsx +146 -0
- package/src/editor/sample.ts +40 -0
- package/src/editor/save-block-dialog.tsx +141 -0
- package/src/editor/saved-block-view.tsx +205 -0
- package/src/editor/saved-blocks.stories.tsx +105 -0
- package/src/editor/saved-parts.ts +192 -0
- package/src/editor/schema-rich.ts +156 -0
- package/src/editor/schema.ts +368 -0
- package/src/editor/services.tsx +205 -0
- package/src/editor/slash.ts +64 -0
- package/src/editor/suggesting.ts +372 -0
- package/src/editor/suggestions.ts +763 -0
- package/src/editor/table-keys.ts +66 -0
- package/src/editor/templates.stories.tsx +324 -0
- package/src/editor/toolbar.tsx +364 -0
- package/src/empty-state.stories.tsx +51 -0
- package/src/empty-state.tsx +126 -0
- package/src/empty-state.usage-notes.md +30 -0
- package/src/form.stories.tsx +112 -0
- package/src/form.tsx +176 -0
- package/src/globals.css +20 -0
- package/src/icon-button.tsx +85 -0
- package/src/icon-map.ts +335 -0
- package/src/icon.tsx +41 -0
- package/src/index.ts +90 -0
- package/src/input.stories.tsx +157 -0
- package/src/input.tsx +768 -0
- package/src/kpi-strip.tsx +47 -0
- package/src/localized-text.ts +76 -0
- package/src/locked-screen.stories.tsx +29 -0
- package/src/locked-screen.tsx +75 -0
- package/src/lockup.tsx +42 -0
- package/src/lottie.tsx +441 -0
- package/src/mark.tsx +62 -0
- package/src/math-text.stories.tsx +33 -0
- package/src/math-text.tsx +43 -0
- package/src/menu-bar.stories.tsx +198 -0
- package/src/menu-bar.tsx +373 -0
- package/src/message-thread.tsx +181 -0
- package/src/money/currency.ts +244 -0
- package/src/money/money-input.tsx +131 -0
- package/src/money/money.tsx +33 -0
- package/src/open-on-computer.tsx +150 -0
- package/src/otp-input.tsx +161 -0
- package/src/page-header.stories.tsx +95 -0
- package/src/page-header.tsx +122 -0
- package/src/page-shell.stories.tsx +42 -0
- package/src/page-shell.tsx +32 -0
- package/src/page-states.tsx +277 -0
- package/src/pagination.stories.tsx +45 -0
- package/src/pagination.tsx +98 -0
- package/src/paper-sheet.stories.tsx +88 -0
- package/src/paper-sheet.tsx +85 -0
- package/src/phone-tab-bar.tsx +152 -0
- package/src/plugin-card.stories.tsx +208 -0
- package/src/plugin-card.tsx +931 -0
- package/src/popover.stories.tsx +48 -0
- package/src/popover.tsx +55 -0
- package/src/radio-group.stories.tsx +26 -0
- package/src/radio-group.tsx +44 -0
- package/src/route-flow/editor.tsx +1087 -0
- package/src/route-flow/model.ts +771 -0
- package/src/save-bar.tsx +94 -0
- package/src/scope-grant.tsx +139 -0
- package/src/screen-too-small.stories.tsx +61 -0
- package/src/screen-too-small.tsx +104 -0
- package/src/search-field.tsx +65 -0
- package/src/select.stories.tsx +44 -0
- package/src/select.tsx +197 -0
- package/src/separator.stories.tsx +34 -0
- package/src/separator.tsx +34 -0
- package/src/sheet.stories.tsx +49 -0
- package/src/sheet.tsx +168 -0
- package/src/skeleton.stories.tsx +28 -0
- package/src/skeleton.tsx +19 -0
- package/src/slider.stories.tsx +78 -0
- package/src/slider.tsx +300 -0
- package/src/spinner.stories.tsx +33 -0
- package/src/spinner.tsx +55 -0
- package/src/stepper.tsx +85 -0
- package/src/switch.stories.tsx +42 -0
- package/src/switch.tsx +41 -0
- package/src/switcher.stories.tsx +111 -0
- package/src/switcher.tsx +131 -0
- package/src/system-state.tsx +55 -0
- package/src/table.stories.tsx +48 -0
- package/src/table.tsx +121 -0
- package/src/tabs.stories.tsx +74 -0
- package/src/tabs.tsx +90 -0
- package/src/tag-input.stories.tsx +67 -0
- package/src/tag-input.tsx +117 -0
- package/src/tenant-logo.tsx +63 -0
- package/src/tenant-switcher.stories.tsx +38 -0
- package/src/tenant-switcher.tsx +164 -0
- package/src/textarea.stories.tsx +27 -0
- package/src/textarea.tsx +18 -0
- package/src/theme-mode.ts +52 -0
- package/src/time-grid.tsx +163 -0
- package/src/time-picker.stories.tsx +62 -0
- package/src/time-picker.tsx +615 -0
- package/src/toggle-group.tsx +138 -0
- package/src/tooltip.stories.tsx +43 -0
- package/src/tooltip.tsx +73 -0
- package/src/top-nav.stories.tsx +58 -0
- package/src/top-nav.tsx +324 -0
- package/src/undo-bar.tsx +107 -0
- package/src/utils.ts +45 -0
- package/src/view-toggle.stories.tsx +84 -0
- package/src/view-toggle.tsx +110 -0
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-xs font-semibold text-muted-foreground">
|
|
282
|
+
{renderDisplayVal()}
|
|
283
|
+
</span>
|
|
284
|
+
)}
|
|
285
|
+
</div>
|
|
286
|
+
)}
|
|
287
|
+
{renderCombinedSlider()}
|
|
288
|
+
{errorText ? (
|
|
289
|
+
<p className="text-xs font-medium text-destructive">{errorText}</p>
|
|
290
|
+
) : (
|
|
291
|
+
helperText && <p className="text-xs 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
|
+
}
|
package/src/spinner.tsx
ADDED
|
@@ -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 }
|
package/src/stepper.tsx
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Icon } from "./icon"
|
|
2
|
+
import { cn } from "./utils"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Where a person is in a flow of 3 to 6 steps (docs/design/components/Stepper).
|
|
6
|
+
* Steps aren't links: people move with the form's own Back and Continue.
|
|
7
|
+
*/
|
|
8
|
+
export interface StepperProps {
|
|
9
|
+
steps: { label: string; hint?: string }[]
|
|
10
|
+
/** Index of the current step. */
|
|
11
|
+
current: number
|
|
12
|
+
orientation?: "horizontal" | "vertical"
|
|
13
|
+
/** Names the stepper for assistive technology. */
|
|
14
|
+
label: string
|
|
15
|
+
/** "Step {n} of {total}", shown above the dots on a phone. */
|
|
16
|
+
stepOfLabel?: (n: number, total: number) => string
|
|
17
|
+
className?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function Stepper({ steps, current, orientation = "horizontal", label, stepOfLabel, className }: StepperProps) {
|
|
21
|
+
const vertical = orientation === "vertical"
|
|
22
|
+
return (
|
|
23
|
+
<nav aria-label={label} data-slot="stepper" className={cn("grid gap-2", className)}>
|
|
24
|
+
{!vertical && (
|
|
25
|
+
<p className="text-sm text-muted-foreground sm:hidden">
|
|
26
|
+
{stepOfLabel?.(current + 1, steps.length) ?? `Step ${current + 1} of ${steps.length}`}
|
|
27
|
+
{steps[current] && <span className="font-medium text-foreground"> · {steps[current].label}</span>}
|
|
28
|
+
</p>
|
|
29
|
+
)}
|
|
30
|
+
<ol className={cn("flex", vertical ? "flex-col gap-4" : "gap-0")}>
|
|
31
|
+
{steps.map((step, index) => {
|
|
32
|
+
const done = index < current
|
|
33
|
+
const isCurrent = index === current
|
|
34
|
+
const last = index === steps.length - 1
|
|
35
|
+
return (
|
|
36
|
+
<li
|
|
37
|
+
key={step.label}
|
|
38
|
+
aria-current={isCurrent ? "step" : undefined}
|
|
39
|
+
className={cn("relative flex min-w-0 items-start gap-2.5", !vertical && !last && "flex-1")}
|
|
40
|
+
>
|
|
41
|
+
<span
|
|
42
|
+
className={cn(
|
|
43
|
+
"grid size-7 flex-none place-items-center rounded-full border-[1.5px] border-input text-sm font-medium tabular-nums text-muted-foreground",
|
|
44
|
+
done && "border-primary bg-primary text-primary-foreground",
|
|
45
|
+
isCurrent && "border-primary bg-primary-tint text-primary-tint-foreground outline-[1.5px] outline-offset-2 outline-primary"
|
|
46
|
+
)}
|
|
47
|
+
>
|
|
48
|
+
{done ? <Icon name="check" size={16} /> : index + 1}
|
|
49
|
+
</span>
|
|
50
|
+
<span className={cn("grid flex-none gap-0.5 pt-1", !vertical && "max-sm:hidden")}>
|
|
51
|
+
<span
|
|
52
|
+
className={cn(
|
|
53
|
+
"text-sm font-medium whitespace-nowrap text-muted-foreground",
|
|
54
|
+
(done || isCurrent) && "text-foreground",
|
|
55
|
+
isCurrent && "font-semibold"
|
|
56
|
+
)}
|
|
57
|
+
>
|
|
58
|
+
{step.label}
|
|
59
|
+
</span>
|
|
60
|
+
{step.hint && <span className="text-xs text-muted-foreground">{step.hint}</span>}
|
|
61
|
+
</span>
|
|
62
|
+
{!last && !vertical && (
|
|
63
|
+
<span
|
|
64
|
+
aria-hidden
|
|
65
|
+
className={cn("mt-[13px] me-3 h-0.5 min-w-4 flex-1 rounded-[1px] bg-border", done && "bg-primary")}
|
|
66
|
+
/>
|
|
67
|
+
)}
|
|
68
|
+
{!last && vertical && (
|
|
69
|
+
<span
|
|
70
|
+
aria-hidden
|
|
71
|
+
className={cn(
|
|
72
|
+
"absolute start-[13px] top-[34px] -bottom-2.5 w-0.5 rounded-[1px] bg-border",
|
|
73
|
+
done && "bg-primary"
|
|
74
|
+
)}
|
|
75
|
+
/>
|
|
76
|
+
)}
|
|
77
|
+
</li>
|
|
78
|
+
)
|
|
79
|
+
})}
|
|
80
|
+
</ol>
|
|
81
|
+
</nav>
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { Stepper }
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite"
|
|
2
|
+
import * as React from "react"
|
|
3
|
+
|
|
4
|
+
import { Switch } from "./switch"
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: "Primitives/Switch",
|
|
8
|
+
component: Switch,
|
|
9
|
+
tags: ["autodocs"],
|
|
10
|
+
args: { disabled: false },
|
|
11
|
+
} satisfies Meta<typeof Switch>
|
|
12
|
+
|
|
13
|
+
export default meta
|
|
14
|
+
type Story = StoryObj<typeof meta>
|
|
15
|
+
|
|
16
|
+
export const Playground: Story = {}
|
|
17
|
+
|
|
18
|
+
export const Checked: Story = {
|
|
19
|
+
args: { defaultChecked: true },
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const Disabled: Story = {
|
|
23
|
+
render: () => (
|
|
24
|
+
<div className="flex items-center gap-4">
|
|
25
|
+
<Switch disabled />
|
|
26
|
+
<Switch disabled defaultChecked />
|
|
27
|
+
</div>
|
|
28
|
+
),
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const WithLabel: Story = {
|
|
32
|
+
render: () => {
|
|
33
|
+
const id = "sb-switch-self-registration"
|
|
34
|
+
const [checked, setChecked] = React.useState(false)
|
|
35
|
+
return (
|
|
36
|
+
<label htmlFor={id} className="flex items-center gap-3 text-sm">
|
|
37
|
+
<Switch id={id} checked={checked} onCheckedChange={setChecked} />
|
|
38
|
+
<span>Allow public sign-up</span>
|
|
39
|
+
</label>
|
|
40
|
+
)
|
|
41
|
+
},
|
|
42
|
+
}
|
package/src/switch.tsx
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { Switch as SwitchPrimitive } from "radix-ui"
|
|
5
|
+
|
|
6
|
+
import { cn } from "./utils"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A binary on/off toggle built on Radix Switch. Use it for boolean settings
|
|
10
|
+
* where the change takes effect on toggle (governance flags, feature switches)
|
|
11
|
+
* — prefer a Checkbox for multi-select lists inside a form.
|
|
12
|
+
*
|
|
13
|
+
* All colours/sizing come from design tokens (primary/input/background), so the
|
|
14
|
+
* control themes automatically in light and dark. Forwards every Radix prop
|
|
15
|
+
* (`checked`, `defaultChecked`, `onCheckedChange`, `disabled`, `required`,
|
|
16
|
+
* `name`, `value`, …) plus `aria-*` for labelling.
|
|
17
|
+
*/
|
|
18
|
+
function Switch({
|
|
19
|
+
className,
|
|
20
|
+
...props
|
|
21
|
+
}: React.ComponentProps<typeof SwitchPrimitive.Root>) {
|
|
22
|
+
return (
|
|
23
|
+
<SwitchPrimitive.Root
|
|
24
|
+
data-slot="switch"
|
|
25
|
+
className={cn(
|
|
26
|
+
"peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border border-transparent shadow-xs transition-colors outline-none focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input dark:data-[state=unchecked]:bg-input/60",
|
|
27
|
+
className
|
|
28
|
+
)}
|
|
29
|
+
{...props}
|
|
30
|
+
>
|
|
31
|
+
<SwitchPrimitive.Thumb
|
|
32
|
+
data-slot="switch-thumb"
|
|
33
|
+
className={cn(
|
|
34
|
+
"pointer-events-none block size-4 rounded-full bg-background shadow-sm ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0.5 rtl:data-[state=checked]:-translate-x-4 rtl:data-[state=unchecked]:-translate-x-0.5"
|
|
35
|
+
)}
|
|
36
|
+
/>
|
|
37
|
+
</SwitchPrimitive.Root>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { Switch }
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite"
|
|
2
|
+
import { fn } from "storybook/test"
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { IconBuilding, IconUsersGroup } from "@tabler/icons-react"
|
|
5
|
+
|
|
6
|
+
import { Switcher, type SwitcherItem } from "./switcher"
|
|
7
|
+
|
|
8
|
+
const TENANTS: SwitcherItem[] = [
|
|
9
|
+
{ id: "1", label: "Acme Inc." },
|
|
10
|
+
{ id: "2", label: "Globex Corp." },
|
|
11
|
+
{ id: "3", label: "Initech" },
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
const TEAMS: SwitcherItem[] = [
|
|
15
|
+
{ id: "eng", label: "Engineering" },
|
|
16
|
+
{ id: "sales", label: "Sales" },
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
const meta = {
|
|
20
|
+
title: "Layout/Switcher",
|
|
21
|
+
component: Switcher,
|
|
22
|
+
tags: ["autodocs"],
|
|
23
|
+
args: {
|
|
24
|
+
items: TENANTS,
|
|
25
|
+
icon: <IconBuilding />,
|
|
26
|
+
switchLabel: "Tenant",
|
|
27
|
+
onChange: fn(),
|
|
28
|
+
},
|
|
29
|
+
} satisfies Meta<typeof Switcher>
|
|
30
|
+
|
|
31
|
+
export default meta
|
|
32
|
+
type Story = StoryObj<typeof meta>
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* `Switcher` is controlled, so the stories drive it through this wrapper: the
|
|
36
|
+
* active item is held locally (starting at the first of the `items` arg) and
|
|
37
|
+
* the `onChange` arg still fires, so the Actions panel logs every switch.
|
|
38
|
+
*/
|
|
39
|
+
function Controlled({ items, onChange, ...props }: React.ComponentProps<typeof Switcher>) {
|
|
40
|
+
const [activeId, setActiveId] = React.useState(items[0]?.id)
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<Switcher
|
|
44
|
+
{...props}
|
|
45
|
+
items={items}
|
|
46
|
+
activeId={activeId}
|
|
47
|
+
onChange={(id) => {
|
|
48
|
+
setActiveId(id)
|
|
49
|
+
onChange(id)
|
|
50
|
+
}}
|
|
51
|
+
/>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const TenantSwitcherManyTenants: Story = {
|
|
56
|
+
name: "Tenant switcher — many tenants",
|
|
57
|
+
render: (args) => (
|
|
58
|
+
<div className="w-64">
|
|
59
|
+
<Controlled {...args} />
|
|
60
|
+
</div>
|
|
61
|
+
),
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const TeamSwitcherManyTeams: Story = {
|
|
65
|
+
name: "Team switcher — many teams",
|
|
66
|
+
args: { items: TEAMS, icon: <IconUsersGroup />, switchLabel: "Team" },
|
|
67
|
+
render: (args) => (
|
|
68
|
+
<div className="w-64">
|
|
69
|
+
<Controlled {...args} />
|
|
70
|
+
</div>
|
|
71
|
+
),
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const SingleItem: Story = {
|
|
75
|
+
name: "Single item — static label, no dropdown",
|
|
76
|
+
args: { items: [TENANTS[0]] },
|
|
77
|
+
render: (args) => (
|
|
78
|
+
<div className="w-64">
|
|
79
|
+
<Controlled {...args} />
|
|
80
|
+
</div>
|
|
81
|
+
),
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const NoItems: Story = {
|
|
85
|
+
name: "No items — static empty label",
|
|
86
|
+
args: { items: [], icon: <IconUsersGroup />, switchLabel: "Team" },
|
|
87
|
+
render: (args) => (
|
|
88
|
+
<div className="w-64">
|
|
89
|
+
<Controlled {...args} />
|
|
90
|
+
</div>
|
|
91
|
+
),
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const Collapsed: Story = {
|
|
95
|
+
args: { collapsed: true },
|
|
96
|
+
render: (args) => (
|
|
97
|
+
<div className="w-16">
|
|
98
|
+
<Controlled {...args} />
|
|
99
|
+
</div>
|
|
100
|
+
),
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const BothStacked: Story = {
|
|
104
|
+
name: "Tenant + team stacked (as used in AppSidebar)",
|
|
105
|
+
render: (args) => (
|
|
106
|
+
<div className="w-64 space-y-1.5">
|
|
107
|
+
<Controlled {...args} />
|
|
108
|
+
<Controlled {...args} items={TEAMS} icon={<IconUsersGroup />} switchLabel="Team" />
|
|
109
|
+
</div>
|
|
110
|
+
),
|
|
111
|
+
}
|