@nikala-ui/core 0.10.1 → 0.11.0-nightly.b01fa01

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 (106) hide show
  1. package/package.json +1 -1
  2. package/registry/banner.json +1 -1
  3. package/registry/bubble.json +18 -0
  4. package/registry/button-group.json +20 -0
  5. package/registry/button.json +1 -1
  6. package/registry/checkbox.json +4 -1
  7. package/registry/combobox.json +1 -1
  8. package/registry/command.json +3 -2
  9. package/registry/context-menu.json +1 -1
  10. package/registry/create-app-updater.json +13 -0
  11. package/registry/create-chat-scroll.json +13 -0
  12. package/registry/create-document-tabs.json +13 -0
  13. package/registry/create-drop-zone.json +13 -0
  14. package/registry/create-global-shortcut.json +13 -0
  15. package/registry/create-pagination.json +13 -0
  16. package/registry/create-tauri-window.json +13 -0
  17. package/registry/dialog.json +1 -1
  18. package/registry/dropdown-menu.json +3 -2
  19. package/registry/dropzone.json +21 -0
  20. package/registry/field.json +1 -1
  21. package/registry/footer.json +18 -0
  22. package/registry/forgot-password-01.json +28 -0
  23. package/registry/form-message.json +3 -2
  24. package/registry/hero-01.json +22 -0
  25. package/registry/icon-button.json +1 -1
  26. package/registry/index.json +432 -5
  27. package/registry/login-01.json +28 -0
  28. package/registry/marker.json +17 -0
  29. package/registry/marquee.json +17 -0
  30. package/registry/message.json +17 -0
  31. package/registry/navbar.json +19 -0
  32. package/registry/navigation-menu.json +22 -0
  33. package/registry/number-input.json +1 -1
  34. package/registry/otp-verification-01.json +26 -0
  35. package/registry/pagination.json +22 -0
  36. package/registry/popover.json +4 -1
  37. package/registry/rating.json +19 -0
  38. package/registry/register-01.json +31 -0
  39. package/registry/resizable.json +1 -1
  40. package/registry/review-card.json +23 -0
  41. package/registry/scroll-area.json +1 -1
  42. package/registry/select.json +3 -2
  43. package/registry/sheet.json +1 -1
  44. package/registry/sidebar.json +24 -0
  45. package/registry/spinner.json +1 -1
  46. package/registry/stat.json +19 -0
  47. package/registry/status.json +1 -1
  48. package/registry/switch.json +4 -1
  49. package/registry/table.json +17 -0
  50. package/registry/tabs.json +4 -1
  51. package/registry/theme-manager.json +4 -3
  52. package/registry/timeline.json +18 -0
  53. package/registry/titlebar-tabs.json +24 -0
  54. package/registry/titlebar.json +26 -0
  55. package/registry/toggle-group.json +21 -0
  56. package/registry/updater-modal.json +26 -0
  57. package/src/registry/blocks/forgot-password-01.tsx +141 -0
  58. package/src/registry/blocks/hero-01.tsx +28 -0
  59. package/src/registry/blocks/login-01.tsx +231 -0
  60. package/src/registry/blocks/otp-verification-01.tsx +170 -0
  61. package/src/registry/blocks/register-01.tsx +318 -0
  62. package/src/registry/components/ui/banner.tsx +0 -2
  63. package/src/registry/components/ui/bubble.tsx +142 -0
  64. package/src/registry/components/ui/button-group.tsx +42 -0
  65. package/src/registry/components/ui/button.tsx +1 -1
  66. package/src/registry/components/ui/checkbox.tsx +1 -1
  67. package/src/registry/components/ui/combobox.tsx +83 -18
  68. package/src/registry/components/ui/command.tsx +101 -105
  69. package/src/registry/components/ui/context-menu.tsx +67 -22
  70. package/src/registry/components/ui/dialog.tsx +42 -32
  71. package/src/registry/components/ui/dropdown-menu.tsx +69 -31
  72. package/src/registry/components/ui/dropzone.tsx +189 -0
  73. package/src/registry/components/ui/field.tsx +7 -3
  74. package/src/registry/components/ui/footer.tsx +247 -0
  75. package/src/registry/components/ui/form-message.tsx +2 -2
  76. package/src/registry/components/ui/icon-button.tsx +1 -1
  77. package/src/registry/components/ui/marker.tsx +102 -0
  78. package/src/registry/components/ui/marquee.tsx +118 -0
  79. package/src/registry/components/ui/message.tsx +168 -0
  80. package/src/registry/components/ui/navbar.tsx +375 -0
  81. package/src/registry/components/ui/navigation-menu.tsx +358 -0
  82. package/src/registry/components/ui/number-input.tsx +3 -3
  83. package/src/registry/components/ui/pagination.tsx +258 -0
  84. package/src/registry/components/ui/popover.tsx +1 -1
  85. package/src/registry/components/ui/rating.tsx +185 -0
  86. package/src/registry/components/ui/resizable.tsx +3 -1
  87. package/src/registry/components/ui/review-card.tsx +195 -0
  88. package/src/registry/components/ui/scroll-area.tsx +13 -3
  89. package/src/registry/components/ui/select.tsx +16 -19
  90. package/src/registry/components/ui/sheet.tsx +58 -53
  91. package/src/registry/components/ui/sidebar.tsx +692 -0
  92. package/src/registry/components/ui/spinner.tsx +1 -1
  93. package/src/registry/components/ui/stat.tsx +245 -0
  94. package/src/registry/components/ui/status.tsx +7 -5
  95. package/src/registry/components/ui/switch.tsx +1 -1
  96. package/src/registry/components/ui/table.tsx +160 -0
  97. package/src/registry/components/ui/tabs.tsx +1 -1
  98. package/src/registry/components/ui/theme-toggle.tsx +80 -79
  99. package/src/registry/components/ui/timeline.tsx +350 -0
  100. package/src/registry/components/ui/titlebar-tabs.tsx +412 -0
  101. package/src/registry/components/ui/titlebar.tsx +399 -0
  102. package/src/registry/components/ui/toggle-group.tsx +203 -0
  103. package/src/registry/components/ui/updater-modal.tsx +254 -0
  104. package/src/registry/index.ts +3 -3
  105. package/src/registry/metadata.ts +184 -5
  106. package/src/registry/providers/theme-transitions.ts +81 -50
@@ -0,0 +1,399 @@
1
+ import {
2
+ createContext,
3
+ useContext,
4
+ splitProps,
5
+ createMemo,
6
+ Show,
7
+ type Component,
8
+ type JSX,
9
+ type ParentComponent,
10
+ type Accessor,
11
+ } from "solid-js";
12
+ import { cva, type VariantProps } from "class-variance-authority";
13
+ import { createTauriWindow, type TauriPlatform, detectPlatform } from "@/hooks/create-tauri-window";
14
+ import { cn } from "@/lib/cn";
15
+
16
+ /* --- 1. Context & Types --- */
17
+ export type TitlebarPlatform = "macos" | "windows" | "auto";
18
+
19
+ interface TitlebarContextValue {
20
+ platform: Accessor<"macos" | "windows">;
21
+ isMaximized: Accessor<boolean>;
22
+ minimize: () => Promise<void> | void;
23
+ toggleMaximize: () => Promise<void> | void;
24
+ close: () => Promise<void> | void;
25
+ }
26
+
27
+ const TitlebarContext = createContext<TitlebarContextValue>();
28
+
29
+ export function useTitlebar() {
30
+ const context = useContext(TitlebarContext);
31
+ if (!context) {
32
+ throw new Error("useTitlebar must be used within a <Titlebar />");
33
+ }
34
+ return context;
35
+ }
36
+
37
+ /* --- 2. Titlebar Variants --- */
38
+ export const titlebarVariants = cva(
39
+ "relative flex w-full select-none items-center justify-between border-b transition-colors shrink-0 sticky top-0 z-50",
40
+ {
41
+ variants: {
42
+ variant: {
43
+ default: "border-border/50 bg-background text-foreground",
44
+ translucent: "border-border/40 bg-background/80 backdrop-blur-md text-foreground",
45
+ floating: "m-2 rounded-lg border border-border bg-card shadow-sm text-card-foreground",
46
+ transparent: "border-transparent bg-transparent text-foreground",
47
+ },
48
+ size: {
49
+ sm: "h-8 text-xs px-2.5",
50
+ default: "h-9 text-xs px-3",
51
+ lg: "h-11 text-sm px-4",
52
+ },
53
+ },
54
+ defaultVariants: {
55
+ variant: "default",
56
+ size: "default",
57
+ },
58
+ }
59
+ );
60
+
61
+ /* --- 3. Root Titlebar Component --- */
62
+ export interface TitlebarProps
63
+ extends JSX.HTMLAttributes<HTMLElement>,
64
+ VariantProps<typeof titlebarVariants> {
65
+ /** Explicit platform style, or 'auto' to detect host OS. */
66
+ platform?: TitlebarPlatform;
67
+ /** Optional controlled maximize state override. */
68
+ isMaximized?: boolean;
69
+ /** Optional minimize callback override. */
70
+ onMinimize?: () => void | Promise<void>;
71
+ /** Optional maximize callback override. */
72
+ onToggleMaximize?: () => void | Promise<void>;
73
+ /** Optional close callback override. */
74
+ onClose?: () => void | Promise<void>;
75
+ /** Whether double-clicking the titlebar toggles window maximize state. Defaults to true. */
76
+ doubleClickToMaximize?: boolean;
77
+ }
78
+
79
+ export const Titlebar: ParentComponent<TitlebarProps> = (props) => {
80
+ const [local, rest] = splitProps(props, [
81
+ "platform",
82
+ "isMaximized",
83
+ "onMinimize",
84
+ "onToggleMaximize",
85
+ "onClose",
86
+ "variant",
87
+ "size",
88
+ "class",
89
+ "children",
90
+ "doubleClickToMaximize",
91
+ "onDblClick",
92
+ ]);
93
+
94
+ const windowCtrl = createTauriWindow();
95
+
96
+ const resolvedPlatform = createMemo<"macos" | "windows">(() => {
97
+ if (local.platform && local.platform !== "auto") {
98
+ return local.platform;
99
+ }
100
+ const detected = detectPlatform();
101
+ return detected === "macos" ? "macos" : "windows";
102
+ });
103
+
104
+ const isMaximized = () =>
105
+ local.isMaximized !== undefined ? local.isMaximized : windowCtrl.isMaximized();
106
+
107
+ const minimize = () => (local.onMinimize ? local.onMinimize() : windowCtrl.minimize());
108
+ const toggleMaximize = () =>
109
+ local.onToggleMaximize ? local.onToggleMaximize() : windowCtrl.toggleMaximize();
110
+ const close = () => (local.onClose ? local.onClose() : windowCtrl.close());
111
+
112
+ const handleMouseDown: JSX.EventHandlerUnion<HTMLElement, MouseEvent> = (e) => {
113
+ if (e.button === 0) {
114
+ const target = e.target as HTMLElement;
115
+ if (!target.closest("button, a, input, select, textarea, [data-no-drag], [data-tauri-drag-region='false']")) {
116
+ windowCtrl.startDragging(e);
117
+ }
118
+ }
119
+ if (typeof (local as any).onMouseDown === "function") {
120
+ ((local as any).onMouseDown)(e);
121
+ }
122
+ };
123
+
124
+ const handleDoubleClick: JSX.EventHandlerUnion<HTMLElement, MouseEvent> = (e) => {
125
+ if (local.doubleClickToMaximize !== false) {
126
+ // Don't maximize if user double-clicked an interactive button
127
+ const target = e.target as HTMLElement;
128
+ if (!target.closest("button, [data-no-drag], [data-tauri-drag-region='false']")) {
129
+ toggleMaximize();
130
+ }
131
+ }
132
+ if (typeof local.onDblClick === "function") {
133
+ (local.onDblClick as any)(e);
134
+ }
135
+ };
136
+
137
+ const contextValue: TitlebarContextValue = {
138
+ platform: resolvedPlatform,
139
+ isMaximized,
140
+ minimize,
141
+ toggleMaximize,
142
+ close,
143
+ };
144
+
145
+ return (
146
+ <TitlebarContext.Provider value={contextValue}>
147
+ <header
148
+ data-tauri-drag-region
149
+ onMouseDown={handleMouseDown}
150
+ onDblClick={handleDoubleClick}
151
+ class={cn(
152
+ titlebarVariants({ variant: local.variant, size: local.size }),
153
+ "select-none cursor-default",
154
+ local.class
155
+ )}
156
+ {...rest}
157
+ >
158
+ {local.children}
159
+ </header>
160
+ </TitlebarContext.Provider>
161
+ );
162
+ };
163
+
164
+ /* --- 4. Subcomponents --- */
165
+
166
+ /**
167
+ * Traffic light buttons for macOS or Fluent control buttons for Windows.
168
+ */
169
+ export interface TitlebarControlsProps extends JSX.HTMLAttributes<HTMLDivElement> {
170
+ /** Optional override platform style. Defaults to Titlebar context. */
171
+ platform?: "macos" | "windows";
172
+ }
173
+
174
+ export const TitlebarControls: Component<TitlebarControlsProps> = (props) => {
175
+ const [local, rest] = splitProps(props, ["platform", "class", "style"]);
176
+ const ctx = useTitlebar();
177
+ const activePlatform = () => local.platform || ctx.platform();
178
+
179
+ return (
180
+ <div
181
+ data-no-drag
182
+ data-tauri-drag-region="false"
183
+ style={("-webkit-app-region: no-drag; app-region: no-drag;" + (typeof local.style === "string" ? ` ${local.style}` : "")) as any}
184
+ class={cn(
185
+ "flex items-center z-10 self-stretch shrink-0 pointer-events-auto [app-region:no-drag] [-webkit-app-region:no-drag]",
186
+ activePlatform() === "macos"
187
+ ? "gap-2 px-1 order-first"
188
+ : "gap-0 -mr-3 h-full order-last ml-auto",
189
+ local.class
190
+ )}
191
+ {...rest}
192
+ >
193
+ <Show
194
+ when={activePlatform() === "macos"}
195
+ fallback={
196
+ /* Windows 11 Fluent Window Controls */
197
+ <div class="flex items-center h-full self-stretch">
198
+ {/* Minimize */}
199
+ <button
200
+ type="button"
201
+ onClick={() => ctx.minimize()}
202
+ class="inline-flex h-full w-11 items-center justify-center text-muted-foreground hover:bg-muted hover:text-foreground transition-colors cursor-pointer"
203
+ aria-label="Minimize Window"
204
+ >
205
+ <svg class="h-3 w-3" fill="none" viewBox="0 0 12 12">
206
+ <path stroke="currentColor" stroke-width="1" d="M1.5 6h9" />
207
+ </svg>
208
+ </button>
209
+
210
+ {/* Maximize / Restore */}
211
+ <button
212
+ type="button"
213
+ onClick={() => ctx.toggleMaximize()}
214
+ class="inline-flex h-full w-11 items-center justify-center text-muted-foreground hover:bg-muted hover:text-foreground transition-colors cursor-pointer"
215
+ aria-label={ctx.isMaximized() ? "Restore Window" : "Maximize Window"}
216
+ >
217
+ <Show
218
+ when={ctx.isMaximized()}
219
+ fallback={
220
+ <svg class="h-3 w-3" fill="none" viewBox="0 0 12 12">
221
+ <rect width="8" height="8" x="2" y="2" stroke="currentColor" stroke-width="1" rx="0.5" />
222
+ </svg>
223
+ }
224
+ >
225
+ <svg class="h-3 w-3" fill="none" viewBox="0 0 12 12">
226
+ <path stroke="currentColor" stroke-width="1" d="M3.5 3.5v-1.5h6v6h-1.5M2 4.5h6v6h-6z" />
227
+ </svg>
228
+ </Show>
229
+ </button>
230
+
231
+ {/* Close */}
232
+ <button
233
+ type="button"
234
+ onClick={() => ctx.close()}
235
+ class="inline-flex h-full w-11 items-center justify-center text-muted-foreground hover:bg-destructive hover:text-destructive-foreground transition-colors cursor-pointer"
236
+ aria-label="Close Window"
237
+ >
238
+ <svg class="h-3 w-3" fill="none" viewBox="0 0 12 12">
239
+ <path stroke="currentColor" stroke-width="1" d="M2.5 2.5l7 7M9.5 2.5l-7 7" />
240
+ </svg>
241
+ </button>
242
+ </div>
243
+ }
244
+ >
245
+ {/* macOS Traffic Lights */}
246
+ <div class="group/traffic flex items-center gap-2">
247
+ {/* Close */}
248
+ <button
249
+ type="button"
250
+ onClick={() => ctx.close()}
251
+ class="flex size-3 items-center justify-center rounded-full bg-[#ff5f57] border border-[#e0443e] cursor-pointer"
252
+ aria-label="Close Window"
253
+ >
254
+ <svg
255
+ class="size-1.5 text-[#4c0000] opacity-0 group-hover/traffic:opacity-100 transition-opacity"
256
+ viewBox="0 0 6 6"
257
+ fill="none"
258
+ stroke="currentColor"
259
+ stroke-width="1.2"
260
+ >
261
+ <path d="M1 1l4 4M5 1L1 5" />
262
+ </svg>
263
+ </button>
264
+
265
+ {/* Minimize */}
266
+ <button
267
+ type="button"
268
+ onClick={() => ctx.minimize()}
269
+ class="flex size-3 items-center justify-center rounded-full bg-[#febc2e] border border-[#d89e24] cursor-pointer"
270
+ aria-label="Minimize Window"
271
+ >
272
+ <svg
273
+ class="size-1.5 text-[#5c3e00] opacity-0 group-hover/traffic:opacity-100 transition-opacity"
274
+ viewBox="0 0 6 6"
275
+ fill="none"
276
+ stroke="currentColor"
277
+ stroke-width="1.2"
278
+ >
279
+ <path d="M1 3h4" />
280
+ </svg>
281
+ </button>
282
+
283
+ {/* Maximize */}
284
+ <button
285
+ type="button"
286
+ onClick={() => ctx.toggleMaximize()}
287
+ class="flex size-3 items-center justify-center rounded-full bg-[#28c840] border border-[#1aab29] cursor-pointer"
288
+ aria-label="Maximize Window"
289
+ >
290
+ <svg
291
+ class="size-1.5 text-[#003d07] opacity-0 group-hover/traffic:opacity-100 transition-opacity"
292
+ viewBox="0 0 6 6"
293
+ fill="none"
294
+ stroke="currentColor"
295
+ stroke-width="1"
296
+ >
297
+ <path d="M1 4.5l3.5-3.5M4.5 1h-3M4.5 1v3" />
298
+ </svg>
299
+ </button>
300
+ </div>
301
+ </Show>
302
+ </div>
303
+ );
304
+ };
305
+
306
+ /**
307
+ * Title text container. Placed naturally in JSX flow by default, or centered with align="center".
308
+ */
309
+ export interface TitlebarTitleProps extends JSX.HTMLAttributes<HTMLDivElement> {
310
+ align?: "center" | "start";
311
+ }
312
+
313
+ export const TitlebarTitle: ParentComponent<TitlebarTitleProps> = (props) => {
314
+ const [local, rest] = splitProps(props, ["align", "class", "children"]);
315
+
316
+ const isCentered = () => local.align === "center";
317
+
318
+ return (
319
+ <div
320
+ data-tauri-drag-region
321
+ class={cn(
322
+ "flex items-center gap-2 font-medium truncate text-xs text-foreground",
323
+ isCentered()
324
+ ? "absolute left-1/2 -translate-x-1/2 pointer-events-none text-center justify-center max-w-[calc(100%-160px)]"
325
+ : "shrink-0",
326
+ local.class
327
+ )}
328
+ {...rest}
329
+ >
330
+ {local.children}
331
+ </div>
332
+ );
333
+ };
334
+
335
+ /**
336
+ * App icon slot within Titlebar.
337
+ */
338
+ export const TitlebarIcon: ParentComponent<JSX.HTMLAttributes<HTMLDivElement>> = (props) => {
339
+ const [local, rest] = splitProps(props, ["class", "children"]);
340
+ return (
341
+ <div
342
+ data-no-drag
343
+ data-tauri-drag-region="false"
344
+ class={cn(
345
+ "flex shrink-0 items-center justify-center size-4 text-muted-foreground pointer-events-auto [app-region:no-drag] [-webkit-app-region:no-drag]",
346
+ local.class
347
+ )}
348
+ {...rest}
349
+ >
350
+ {local.children}
351
+ </div>
352
+ );
353
+ };
354
+
355
+ /**
356
+ * Action buttons container (Search, Settings, ThemeToggle, Navigation) placed in the titlebar.
357
+ * Supports start, end, center, or natural flow alignment.
358
+ */
359
+ export interface TitlebarActionsProps extends JSX.HTMLAttributes<HTMLDivElement> {
360
+ /** Alignment of the actions container within the titlebar. Defaults to 'end'. */
361
+ align?: "start" | "end" | "center" | "none";
362
+ }
363
+
364
+ export const TitlebarActions: ParentComponent<TitlebarActionsProps> = (props) => {
365
+ const [local, rest] = splitProps(props, ["align", "class", "children", "style"]);
366
+
367
+ const alignClass = () => {
368
+ switch (local.align) {
369
+ case "start":
370
+ return "mr-auto";
371
+ case "center":
372
+ return "mx-auto";
373
+ case "none":
374
+ return "";
375
+ case "end":
376
+ default:
377
+ return "ml-auto";
378
+ }
379
+ };
380
+
381
+ return (
382
+ <div
383
+ data-no-drag
384
+ data-tauri-drag-region="false"
385
+ style={("-webkit-app-region: no-drag; app-region: no-drag;" + (typeof local.style === "string" ? ` ${local.style}` : "")) as any}
386
+ class={cn(
387
+ "flex items-center gap-1 shrink-0 z-10 px-1 pointer-events-auto [app-region:no-drag] [-webkit-app-region:no-drag]",
388
+ alignClass(),
389
+ local.class
390
+ )}
391
+ {...rest}
392
+ >
393
+ {local.children}
394
+ </div>
395
+ );
396
+ };
397
+
398
+ /* --- 6. Re-export TitlebarTabs Suite --- */
399
+ export * from "./titlebar-tabs";
@@ -0,0 +1,203 @@
1
+ import {
2
+ createContext,
3
+ useContext,
4
+ splitProps,
5
+ type Component,
6
+ type JSX,
7
+ type Accessor,
8
+ } from "solid-js";
9
+ import { cva, type VariantProps } from "class-variance-authority";
10
+ import { createControllableSignal } from "@/hooks/create-controllable-signal";
11
+ import { cn } from "@/lib/cn";
12
+
13
+ export const toggleGroupItemVariants = cva(
14
+ "inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 cursor-pointer",
15
+ {
16
+ variants: {
17
+ variant: {
18
+ default: "bg-transparent",
19
+ outline:
20
+ "border border-border bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground data-[state=on]:bg-accent data-[state=on]:text-accent-foreground",
21
+ },
22
+ size: {
23
+ default: "h-9 px-3 min-w-9",
24
+ sm: "h-8 px-2 text-xs min-w-8",
25
+ lg: "h-10 px-3 min-w-10",
26
+ },
27
+ },
28
+ defaultVariants: {
29
+ variant: "default",
30
+ size: "default",
31
+ },
32
+ }
33
+ );
34
+
35
+ interface ToggleGroupContextValue {
36
+ type: "single" | "multiple";
37
+ value: Accessor<any>;
38
+ onItemSelect: (itemValue: string) => void;
39
+ variant: Accessor<"default" | "outline">;
40
+ size: Accessor<"default" | "sm" | "lg">;
41
+ disabled: Accessor<boolean>;
42
+ }
43
+
44
+ const ToggleGroupContext = createContext<ToggleGroupContextValue>();
45
+
46
+ export interface ToggleGroupProps<T extends "single" | "multiple" = "single">
47
+ extends Omit<JSX.HTMLAttributes<HTMLDivElement>, "onChange">,
48
+ VariantProps<typeof toggleGroupItemVariants> {
49
+ /** Mode of selection: single choice or multiple choices */
50
+ type?: T;
51
+ /** Controlled value: string for 'single', string[] for 'multiple' */
52
+ value?: T extends "multiple" ? string[] : string;
53
+ /** Uncontrolled default value */
54
+ defaultValue?: T extends "multiple" ? string[] : string;
55
+ /** Callback fired when selection changes */
56
+ onChange?: (value: T extends "multiple" ? string[] : string) => void;
57
+ /** Layout orientation */
58
+ orientation?: "horizontal" | "vertical";
59
+ /** Disables all buttons in the group */
60
+ disabled?: boolean;
61
+ class?: string;
62
+ children?: JSX.Element;
63
+ }
64
+
65
+ /**
66
+ * Root container for grouping connected toggle items with shared single/multiple selection state.
67
+ */
68
+ export const ToggleGroup = <T extends "single" | "multiple" = "single">(
69
+ props: ToggleGroupProps<T>
70
+ ) => {
71
+ const [local, rest] = splitProps(props, [
72
+ "type",
73
+ "value",
74
+ "defaultValue",
75
+ "onChange",
76
+ "orientation",
77
+ "variant",
78
+ "size",
79
+ "disabled",
80
+ "class",
81
+ "children",
82
+ ]);
83
+
84
+ const type = () => local.type ?? ("single" as T);
85
+ const variant = () => local.variant ?? "default";
86
+ const size = () => local.size ?? "default";
87
+ const disabled = () => local.disabled ?? false;
88
+ const orientation = () => local.orientation ?? "horizontal";
89
+
90
+ const [currentValue, setCurrentValue] = createControllableSignal<any>({
91
+ value: () => local.value,
92
+ defaultValue: local.defaultValue ?? (type() === "multiple" ? [] : undefined),
93
+ onChange: (val) => local.onChange?.(val),
94
+ });
95
+
96
+ const onItemSelect = (itemValue: string) => {
97
+ if (disabled()) return;
98
+
99
+ if (type() === "multiple") {
100
+ const currentList = Array.isArray(currentValue()) ? currentValue() : [];
101
+ if (currentList.includes(itemValue)) {
102
+ setCurrentValue(currentList.filter((v: string) => v !== itemValue));
103
+ } else {
104
+ setCurrentValue([...currentList, itemValue]);
105
+ }
106
+ } else {
107
+ const current = currentValue();
108
+ if (current === itemValue) {
109
+ setCurrentValue(undefined);
110
+ } else {
111
+ setCurrentValue(itemValue);
112
+ }
113
+ }
114
+ };
115
+
116
+ const contextValue: ToggleGroupContextValue = {
117
+ type: type(),
118
+ value: currentValue,
119
+ onItemSelect,
120
+ variant,
121
+ size,
122
+ disabled,
123
+ };
124
+
125
+ return (
126
+ <ToggleGroupContext.Provider value={contextValue}>
127
+ <div
128
+ role="group"
129
+ data-orientation={orientation()}
130
+ class={cn(
131
+ "flex items-center justify-center gap-1 rounded-lg",
132
+ orientation() === "vertical" ? "flex-col" : "flex-row",
133
+ local.class
134
+ )}
135
+ {...rest}
136
+ >
137
+ {local.children}
138
+ </div>
139
+ </ToggleGroupContext.Provider>
140
+ );
141
+ };
142
+
143
+ export interface ToggleGroupItemProps
144
+ extends JSX.ButtonHTMLAttributes<HTMLButtonElement>,
145
+ VariantProps<typeof toggleGroupItemVariants> {
146
+ /** Unique value representing this toggle item within the group */
147
+ value: string;
148
+ class?: string;
149
+ children?: JSX.Element;
150
+ }
151
+
152
+ /**
153
+ * Individual toggle button item within a ToggleGroup.
154
+ */
155
+ export const ToggleGroupItem: Component<ToggleGroupItemProps> = (props) => {
156
+ const context = useContext(ToggleGroupContext);
157
+
158
+ if (!context) {
159
+ throw new Error("ToggleGroupItem must be used within a ToggleGroup");
160
+ }
161
+
162
+ const [local, rest] = splitProps(props, [
163
+ "value",
164
+ "variant",
165
+ "size",
166
+ "disabled",
167
+ "class",
168
+ "children",
169
+ ]);
170
+
171
+ const isSelected = () => {
172
+ const groupValue = context.value();
173
+ if (context.type === "multiple") {
174
+ return Array.isArray(groupValue) && groupValue.includes(local.value);
175
+ }
176
+ return groupValue === local.value;
177
+ };
178
+
179
+ const isDisabled = () => local.disabled || context.disabled();
180
+ const itemVariant = () => local.variant || context.variant();
181
+ const itemSize = () => local.size || context.size();
182
+
183
+ return (
184
+ <button
185
+ type="button"
186
+ role={context.type === "single" ? "radio" : "checkbox"}
187
+ aria-checked={isSelected()}
188
+ data-state={isSelected() ? "on" : "off"}
189
+ disabled={isDisabled()}
190
+ onClick={() => context.onItemSelect(local.value)}
191
+ class={cn(
192
+ toggleGroupItemVariants({
193
+ variant: itemVariant(),
194
+ size: itemSize(),
195
+ }),
196
+ local.class
197
+ )}
198
+ {...rest}
199
+ >
200
+ {local.children}
201
+ </button>
202
+ );
203
+ };