@surreal-ui/react 0.8.1 → 0.9.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 (128) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.js +955 -7227
  3. package/dist/utils.d.ts +9 -0
  4. package/dist/utils.js +14 -0
  5. package/package.json +21 -4
  6. package/CHANGELOG.md +0 -149
  7. package/src/components/GlassmorphismAlert.tsx +0 -43
  8. package/src/components/GlassmorphismButton.tsx +0 -20
  9. package/src/components/GlassmorphismCard.tsx +0 -43
  10. package/src/components/GlassmorphismEmptyState.tsx +0 -20
  11. package/src/components/GlassmorphismInputGroup.tsx +0 -148
  12. package/src/components/GlassmorphismMenubar.tsx +0 -96
  13. package/src/components/GlassmorphismScrollArea.tsx +0 -67
  14. package/src/components/GlassmorphismTable.tsx +0 -61
  15. package/src/components/GlassmorphismTypography.tsx +0 -31
  16. package/src/components/MinimalistAccordion.tsx +0 -215
  17. package/src/components/MinimalistAlert.tsx +0 -43
  18. package/src/components/MinimalistAlertDialog.tsx +0 -318
  19. package/src/components/MinimalistAspectRatio.tsx +0 -30
  20. package/src/components/MinimalistAvatar.tsx +0 -149
  21. package/src/components/MinimalistBadge.tsx +0 -49
  22. package/src/components/MinimalistBreadcrumb.tsx +0 -109
  23. package/src/components/MinimalistButton.tsx +0 -86
  24. package/src/components/MinimalistButtonGroup.tsx +0 -86
  25. package/src/components/MinimalistCalendar.tsx +0 -355
  26. package/src/components/MinimalistCard.tsx +0 -89
  27. package/src/components/MinimalistCarousel.tsx +0 -266
  28. package/src/components/MinimalistChart.tsx +0 -296
  29. package/src/components/MinimalistCheckbox.tsx +0 -117
  30. package/src/components/MinimalistCodeBlock.tsx +0 -203
  31. package/src/components/MinimalistCollapsible.tsx +0 -134
  32. package/src/components/MinimalistCommand.tsx +0 -344
  33. package/src/components/MinimalistContextMenu.tsx +0 -408
  34. package/src/components/MinimalistDialog.tsx +0 -273
  35. package/src/components/MinimalistDrawer.tsx +0 -220
  36. package/src/components/MinimalistDropdownMenu.tsx +0 -431
  37. package/src/components/MinimalistEmpty.tsx +0 -105
  38. package/src/components/MinimalistEmptyState.tsx +0 -34
  39. package/src/components/MinimalistField.tsx +0 -275
  40. package/src/components/MinimalistForm.tsx +0 -205
  41. package/src/components/MinimalistHoverCard.tsx +0 -48
  42. package/src/components/MinimalistInput.tsx +0 -24
  43. package/src/components/MinimalistInputGroup.tsx +0 -180
  44. package/src/components/MinimalistInputOtp.tsx +0 -189
  45. package/src/components/MinimalistItem.tsx +0 -182
  46. package/src/components/MinimalistKbd.tsx +0 -46
  47. package/src/components/MinimalistLabel.tsx +0 -19
  48. package/src/components/MinimalistMenubar.tsx +0 -491
  49. package/src/components/MinimalistNativeSelect.tsx +0 -77
  50. package/src/components/MinimalistNavigationMenu.tsx +0 -198
  51. package/src/components/MinimalistPagination.tsx +0 -152
  52. package/src/components/MinimalistPopover.tsx +0 -229
  53. package/src/components/MinimalistProgress.tsx +0 -39
  54. package/src/components/MinimalistRadioGroup.tsx +0 -115
  55. package/src/components/MinimalistRangeCalendar.tsx +0 -396
  56. package/src/components/MinimalistResizable.tsx +0 -54
  57. package/src/components/MinimalistScrollArea.tsx +0 -41
  58. package/src/components/MinimalistSelect.tsx +0 -262
  59. package/src/components/MinimalistSeparator.tsx +0 -45
  60. package/src/components/MinimalistSheet.tsx +0 -247
  61. package/src/components/MinimalistSidebar.tsx +0 -638
  62. package/src/components/MinimalistSkeleton.tsx +0 -16
  63. package/src/components/MinimalistSlider.tsx +0 -213
  64. package/src/components/MinimalistSonner.tsx +0 -41
  65. package/src/components/MinimalistSpinner.tsx +0 -39
  66. package/src/components/MinimalistSwitch.tsx +0 -92
  67. package/src/components/MinimalistTable.tsx +0 -65
  68. package/src/components/MinimalistTabs.tsx +0 -171
  69. package/src/components/MinimalistTextarea.tsx +0 -24
  70. package/src/components/MinimalistToggle.tsx +0 -74
  71. package/src/components/MinimalistToggleGroup.tsx +0 -197
  72. package/src/components/MinimalistTooltip.tsx +0 -172
  73. package/src/components/MinimalistTypography.tsx +0 -33
  74. package/src/components/NeubrutalismCard.tsx +0 -84
  75. package/src/components/NeubrutalismItem.tsx +0 -48
  76. package/src/components/ShadcnAccordion.tsx +0 -215
  77. package/src/components/ShadcnAlertDialog.tsx +0 -318
  78. package/src/components/ShadcnAspectRatio.tsx +0 -30
  79. package/src/components/ShadcnAvatar.tsx +0 -149
  80. package/src/components/ShadcnBadge.tsx +0 -49
  81. package/src/components/ShadcnBreadcrumb.tsx +0 -109
  82. package/src/components/ShadcnButton.tsx +0 -86
  83. package/src/components/ShadcnButtonGroup.tsx +0 -86
  84. package/src/components/ShadcnCalendar.tsx +0 -355
  85. package/src/components/ShadcnCarousel.tsx +0 -266
  86. package/src/components/ShadcnChart.tsx +0 -296
  87. package/src/components/ShadcnCheckbox.tsx +0 -117
  88. package/src/components/ShadcnCodeBlock.tsx +0 -203
  89. package/src/components/ShadcnCollapsible.tsx +0 -134
  90. package/src/components/ShadcnCommand.tsx +0 -344
  91. package/src/components/ShadcnContextMenu.tsx +0 -408
  92. package/src/components/ShadcnDialog.tsx +0 -273
  93. package/src/components/ShadcnDrawer.tsx +0 -220
  94. package/src/components/ShadcnDropdownMenu.tsx +0 -431
  95. package/src/components/ShadcnEmpty.tsx +0 -105
  96. package/src/components/ShadcnField.tsx +0 -275
  97. package/src/components/ShadcnForm.tsx +0 -205
  98. package/src/components/ShadcnHoverCard.tsx +0 -48
  99. package/src/components/ShadcnInput.tsx +0 -24
  100. package/src/components/ShadcnInputGroup.tsx +0 -180
  101. package/src/components/ShadcnInputOtp.tsx +0 -189
  102. package/src/components/ShadcnItem.tsx +0 -182
  103. package/src/components/ShadcnKbd.tsx +0 -46
  104. package/src/components/ShadcnLabel.tsx +0 -19
  105. package/src/components/ShadcnMenubar.tsx +0 -491
  106. package/src/components/ShadcnNativeSelect.tsx +0 -77
  107. package/src/components/ShadcnNavigationMenu.tsx +0 -198
  108. package/src/components/ShadcnPagination.tsx +0 -152
  109. package/src/components/ShadcnPopover.tsx +0 -229
  110. package/src/components/ShadcnProgress.tsx +0 -39
  111. package/src/components/ShadcnRadioGroup.tsx +0 -115
  112. package/src/components/ShadcnRangeCalendar.tsx +0 -396
  113. package/src/components/ShadcnSelect.tsx +0 -262
  114. package/src/components/ShadcnSeparator.tsx +0 -45
  115. package/src/components/ShadcnSheet.tsx +0 -247
  116. package/src/components/ShadcnSidebar.tsx +0 -638
  117. package/src/components/ShadcnSkeleton.tsx +0 -16
  118. package/src/components/ShadcnSlider.tsx +0 -213
  119. package/src/components/ShadcnSonner.tsx +0 -41
  120. package/src/components/ShadcnSpinner.tsx +0 -39
  121. package/src/components/ShadcnSwitch.tsx +0 -92
  122. package/src/components/ShadcnTabs.tsx +0 -171
  123. package/src/components/ShadcnTextarea.tsx +0 -24
  124. package/src/components/ShadcnToggle.tsx +0 -74
  125. package/src/components/ShadcnToggleGroup.tsx +0 -197
  126. package/src/components/ShadcnTooltip.tsx +0 -172
  127. package/src/index.ts +0 -124
  128. package/tsconfig.json +0 -10
@@ -1,408 +0,0 @@
1
- import * as React from 'react';
2
- import { Check, ChevronRight } from 'lucide-react';
3
- import { cn } from '@surreal-ui/core';
4
-
5
- interface ContextMenuContextValue {
6
- isOpen: boolean;
7
- position: { x: number; y: number };
8
- setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;
9
- setPosition: React.Dispatch<React.SetStateAction<{ x: number; y: number }>>;
10
- }
11
-
12
- const ContextMenuContext = React.createContext<ContextMenuContextValue | null>(null);
13
-
14
- export interface ShadcnContextMenuProps {
15
- children?: React.ReactNode;
16
- open?: boolean;
17
- onOpenChange?: (open: boolean) => void;
18
- }
19
-
20
- export function ShadcnContextMenu({
21
- children,
22
- open: controlledOpen,
23
- onOpenChange
24
- }: ContextMenuProps) {
25
- const [uncontrolledOpen, setUncontrolledOpen] = React.useState(false);
26
- const [position, setPosition] = React.useState({ x: 0, y: 0 });
27
-
28
- const isControlled = controlledOpen !== undefined;
29
- const isOpen = isControlled ? controlledOpen : uncontrolledOpen;
30
-
31
- const setIsOpen = React.useCallback(
32
- (updater: boolean | ((prev: boolean) => boolean)) => {
33
- const nextValue = typeof updater === 'function' ? updater(isOpen) : updater;
34
- if (!isControlled) {
35
- setUncontrolledOpen(nextValue);
36
- }
37
- onOpenChange?.(nextValue);
38
- },
39
- [isControlled, isOpen, onOpenChange]
40
- );
41
-
42
- return (
43
- <ContextMenuContext.Provider value={{ isOpen, position, setIsOpen, setPosition }}>
44
- {children}
45
- </ContextMenuContext.Provider>
46
- );
47
- }
48
-
49
- export interface ShadcnContextMenuTriggerProps extends React.HTMLAttributes<HTMLDivElement> {}
50
-
51
- export const ShadcnContextMenuTrigger = React.forwardRef<HTMLDivElement, ContextMenuTriggerProps>(
52
- ({ className, onContextMenu, children, ...props }, ref) => {
53
- const ctx = React.useContext(ContextMenuContext);
54
-
55
- const handleContextMenu = (e: React.MouseEvent<HTMLDivElement>) => {
56
- e.preventDefault();
57
- ctx?.setPosition({ x: e.clientX, y: e.clientY });
58
- ctx?.setIsOpen(true);
59
- onContextMenu?.(e);
60
- };
61
-
62
- return (
63
- <div
64
- ref={ref}
65
- data-slot="context-menu-trigger"
66
- className={cn('cn-context-menu-trigger select-none', className)}
67
- onContextMenu={handleContextMenu}
68
- {...props}
69
- >
70
- {children}
71
- </div>
72
- );
73
- }
74
- );
75
- ContextMenuTrigger.displayName = 'ContextMenuTrigger';
76
-
77
- export interface ShadcnContextMenuContentProps extends React.HTMLAttributes<HTMLDivElement> {}
78
-
79
- export const ShadcnContextMenuContent = React.forwardRef<HTMLDivElement, ContextMenuContentProps>(
80
- ({ className, style, children, ...props }, ref) => {
81
- const ctx = React.useContext(ContextMenuContext);
82
- const menuRef = React.useRef<HTMLDivElement | null>(null);
83
-
84
- React.useEffect(() => {
85
- if (!ctx?.isOpen) return;
86
- const handleClickOutside = (e: MouseEvent) => {
87
- if (menuRef.current && !menuRef.current.contains(e.target as Node)) {
88
- ctx.setIsOpen(false);
89
- }
90
- };
91
- const handleKeyDown = (e: KeyboardEvent) => {
92
- if (e.key === 'Escape') {
93
- ctx.setIsOpen(false);
94
- }
95
- };
96
- document.addEventListener('pointerdown', handleClickOutside);
97
- document.addEventListener('keydown', handleKeyDown);
98
- return () => {
99
- document.removeEventListener('pointerdown', handleClickOutside);
100
- document.removeEventListener('keydown', handleKeyDown);
101
- };
102
- }, [ctx]);
103
-
104
- if (!ctx?.isOpen) return null;
105
-
106
- return (
107
- <div
108
- ref={(node) => {
109
- menuRef.current = node;
110
- if (typeof ref === 'function') ref(node);
111
- else if (ref) ref.current = node;
112
- }}
113
- data-slot="context-menu-content"
114
- data-open
115
- style={{
116
- position: 'fixed',
117
- left: ctx.position.x,
118
- top: ctx.position.y,
119
- ...style
120
- }}
121
- className={cn(
122
- 'min-w-36 rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 z-50 overflow-x-hidden overflow-y-auto outline-none animate-in fade-in-0 zoom-in-95',
123
- className
124
- )}
125
- {...props}
126
- >
127
- {children}
128
- </div>
129
- );
130
- }
131
- );
132
- ContextMenuContent.displayName = 'ContextMenuContent';
133
-
134
- export interface ShadcnContextMenuGroupProps extends React.HTMLAttributes<HTMLDivElement> {}
135
-
136
- export const ShadcnContextMenuGroup = React.forwardRef<HTMLDivElement, ContextMenuGroupProps>(
137
- ({ className, ...props }, ref) => (
138
- <div ref={ref} data-slot="context-menu-group" className={cn(className)} {...props} />
139
- )
140
- );
141
- ContextMenuGroup.displayName = 'ContextMenuGroup';
142
-
143
- export interface ContextMenuGroupHeadingProps extends React.HTMLAttributes<HTMLDivElement> {
144
- inset?: boolean;
145
- }
146
-
147
- export const ContextMenuGroupHeading = React.forwardRef<
148
- HTMLDivElement,
149
- ContextMenuGroupHeadingProps
150
- >(({ className, inset, ...props }, ref) => (
151
- <div
152
- ref={ref}
153
- data-slot="context-menu-group-heading"
154
- data-inset={inset}
155
- className={cn('px-2 py-1.5 text-sm font-medium text-foreground', inset && 'ps-8', className)}
156
- {...props}
157
- />
158
- ));
159
- ContextMenuGroupHeading.displayName = 'ContextMenuGroupHeading';
160
-
161
- export interface ShadcnContextMenuItemProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
162
- inset?: boolean;
163
- variant?: 'default' | 'destructive';
164
- }
165
-
166
- export const ShadcnContextMenuItem = React.forwardRef<HTMLButtonElement, ContextMenuItemProps>(
167
- ({ className, inset, variant = 'default', onClick, children, ...props }, ref) => {
168
- const ctx = React.useContext(ContextMenuContext);
169
- return (
170
- <button
171
- ref={ref}
172
- type="button"
173
- role="menuitem"
174
- data-slot="context-menu-item"
175
- data-inset={inset}
176
- data-variant={variant}
177
- onClick={(e) => {
178
- onClick?.(e);
179
- ctx?.setIsOpen(false);
180
- }}
181
- className={cn(
182
- "gap-1.5 rounded-md px-1.5 py-1 text-sm focus:bg-accent focus:text-accent-foreground w-full text-left [&_svg:not([class*='size-'])]:size-4 focus:*:[svg]:text-accent-foreground group/context-menu-item relative flex cursor-default items-center outline-hidden select-none disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
183
- inset && 'pl-7',
184
- variant === 'destructive' &&
185
- 'text-destructive focus:bg-destructive/10 focus:text-destructive dark:focus:bg-destructive/20 *:[svg]:text-destructive',
186
- className
187
- )}
188
- {...props}
189
- >
190
- {children}
191
- </button>
192
- );
193
- }
194
- );
195
- ContextMenuItem.displayName = 'ContextMenuItem';
196
-
197
- export interface ContextMenuCheckboxItemProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
198
- checked?: boolean;
199
- inset?: boolean;
200
- onCheckedChange?: (checked: boolean) => void;
201
- }
202
-
203
- export const ContextMenuCheckboxItem = React.forwardRef<
204
- HTMLButtonElement,
205
- ContextMenuCheckboxItemProps
206
- >(({ className, checked, inset, onCheckedChange, onClick, children, ...props }, ref) => {
207
- const ctx = React.useContext(ContextMenuContext);
208
- return (
209
- <button
210
- ref={ref}
211
- type="button"
212
- role="menuitemcheckbox"
213
- aria-checked={checked}
214
- data-slot="context-menu-checkbox-item"
215
- data-inset={inset}
216
- onClick={(e) => {
217
- onCheckedChange?.(!checked);
218
- onClick?.(e);
219
- ctx?.setIsOpen(false);
220
- }}
221
- className={cn(
222
- "gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm focus:bg-accent focus:text-accent-foreground w-full text-left [&_svg:not([class*='size-'])]:size-4 relative flex cursor-default items-center outline-hidden select-none disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
223
- inset && 'pl-7',
224
- className
225
- )}
226
- {...props}
227
- >
228
- <span className="absolute right-2 flex size-3.5 items-center justify-center pointer-events-none">
229
- {checked && <Check className="size-4" />}
230
- </span>
231
- {children}
232
- </button>
233
- );
234
- });
235
- ContextMenuCheckboxItem.displayName = 'ContextMenuCheckboxItem';
236
-
237
- export interface ContextMenuRadioGroupContextValue {
238
- value?: string;
239
- onValueChange?: (value: string) => void;
240
- }
241
-
242
- const RadioGroupContext = React.createContext<ContextMenuRadioGroupContextValue>({});
243
-
244
- export interface ContextMenuRadioGroupProps extends React.HTMLAttributes<HTMLDivElement> {
245
- value?: string;
246
- onValueChange?: (value: string) => void;
247
- }
248
-
249
- export const ContextMenuRadioGroup = React.forwardRef<HTMLDivElement, ContextMenuRadioGroupProps>(
250
- ({ value, onValueChange, className, ...props }, ref) => (
251
- <RadioGroupContext.Provider value={{ value, onValueChange }}>
252
- <div ref={ref} data-slot="context-menu-radio-group" className={cn(className)} {...props} />
253
- </RadioGroupContext.Provider>
254
- )
255
- );
256
- ContextMenuRadioGroup.displayName = 'ContextMenuRadioGroup';
257
-
258
- export interface ContextMenuRadioItemProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
259
- value: string;
260
- inset?: boolean;
261
- }
262
-
263
- export const ContextMenuRadioItem = React.forwardRef<HTMLButtonElement, ContextMenuRadioItemProps>(
264
- ({ className, value, inset, onClick, children, ...props }, ref) => {
265
- const menuCtx = React.useContext(ContextMenuContext);
266
- const radioCtx = React.useContext(RadioGroupContext);
267
- const isChecked = radioCtx.value === value;
268
-
269
- return (
270
- <button
271
- ref={ref}
272
- type="button"
273
- role="menuitemradio"
274
- aria-checked={isChecked}
275
- data-slot="context-menu-radio-item"
276
- data-inset={inset}
277
- onClick={(e) => {
278
- radioCtx.onValueChange?.(value);
279
- onClick?.(e);
280
- menuCtx?.setIsOpen(false);
281
- }}
282
- className={cn(
283
- "gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm focus:bg-accent focus:text-accent-foreground w-full text-left [&_svg:not([class*='size-'])]:size-4 relative flex cursor-default items-center outline-hidden select-none disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
284
- inset && 'pl-7',
285
- className
286
- )}
287
- {...props}
288
- >
289
- <span className="absolute right-2 flex size-3.5 items-center justify-center pointer-events-none">
290
- {isChecked && <Check className="size-4" />}
291
- </span>
292
- {children}
293
- </button>
294
- );
295
- }
296
- );
297
- ContextMenuRadioItem.displayName = 'ContextMenuRadioItem';
298
-
299
- export interface ShadcnContextMenuLabelProps extends React.HTMLAttributes<HTMLDivElement> {
300
- inset?: boolean;
301
- }
302
-
303
- export const ShadcnContextMenuLabel = React.forwardRef<HTMLDivElement, ContextMenuLabelProps>(
304
- ({ className, inset, ...props }, ref) => (
305
- <div
306
- ref={ref}
307
- data-slot="context-menu-label"
308
- data-inset={inset}
309
- className={cn(
310
- 'px-1.5 py-1 text-xs font-medium text-muted-foreground',
311
- inset && 'pl-8',
312
- className
313
- )}
314
- {...props}
315
- />
316
- )
317
- );
318
- ContextMenuLabel.displayName = 'ContextMenuLabel';
319
-
320
- export interface ShadcnContextMenuSeparatorProps extends React.HTMLAttributes<HTMLDivElement> {}
321
-
322
- export const ShadcnContextMenuSeparator = React.forwardRef<
323
- HTMLDivElement,
324
- ContextMenuSeparatorProps
325
- >(({ className, ...props }, ref) => (
326
- <div
327
- ref={ref}
328
- data-slot="context-menu-separator"
329
- className={cn('-mx-1 my-1 h-px bg-border', className)}
330
- {...props}
331
- />
332
- ));
333
- ContextMenuSeparator.displayName = 'ContextMenuSeparator';
334
-
335
- export interface ShadcnContextMenuShortcutProps extends React.HTMLAttributes<HTMLSpanElement> {}
336
-
337
- export const ShadcnContextMenuShortcut = React.forwardRef<
338
- HTMLSpanElement,
339
- ContextMenuShortcutProps
340
- >(({ className, ...props }, ref) => (
341
- <span
342
- ref={ref}
343
- data-slot="context-menu-shortcut"
344
- className={cn(
345
- 'ml-auto text-xs tracking-widest text-muted-foreground group-focus/context-menu-item:text-accent-foreground',
346
- className
347
- )}
348
- {...props}
349
- />
350
- ));
351
- ContextMenuShortcut.displayName = 'ContextMenuShortcut';
352
-
353
- export interface ContextMenuSubProps {
354
- children?: React.ReactNode;
355
- }
356
-
357
- export function ContextMenuSub({ children }: ContextMenuSubProps) {
358
- return <div className="relative group/sub">{children}</div>;
359
- }
360
-
361
- export interface ContextMenuSubTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
362
- inset?: boolean;
363
- }
364
-
365
- export const ContextMenuSubTrigger = React.forwardRef<
366
- HTMLButtonElement,
367
- ContextMenuSubTriggerProps
368
- >(({ className, inset, children, ...props }, ref) => (
369
- <button
370
- ref={ref}
371
- type="button"
372
- data-slot="context-menu-sub-trigger"
373
- data-inset={inset}
374
- className={cn(
375
- "gap-1.5 rounded-md px-1.5 py-1 text-sm focus:bg-accent focus:text-accent-foreground group-hover/sub:bg-accent group-hover/sub:text-accent-foreground w-full text-left [&_svg:not([class*='size-'])]:size-4 flex cursor-default items-center outline-hidden select-none [&_svg]:pointer-events-none [&_svg]:shrink-0",
376
- inset && 'ps-8',
377
- className
378
- )}
379
- {...props}
380
- >
381
- {children}
382
- <ChevronRight className="ml-auto size-4" />
383
- </button>
384
- ));
385
- ContextMenuSubTrigger.displayName = 'ContextMenuSubTrigger';
386
-
387
- export interface ContextMenuSubContentProps extends React.HTMLAttributes<HTMLDivElement> {}
388
-
389
- export const ContextMenuSubContent = React.forwardRef<HTMLDivElement, ContextMenuSubContentProps>(
390
- ({ className, ...props }, ref) => (
391
- <div
392
- ref={ref}
393
- data-slot="context-menu-sub-content"
394
- className={cn(
395
- 'hidden group-hover/sub:block absolute left-full top-0 ml-1 min-w-32 rounded-lg border bg-popover p-1 text-popover-foreground shadow-lg duration-100 z-50 animate-in fade-in-0 zoom-in-95',
396
- className
397
- )}
398
- {...props}
399
- />
400
- )
401
- );
402
- ContextMenuSubContent.displayName = 'ContextMenuSubContent';
403
-
404
- export const ShadcnContextMenuPortal = ({ children }: { children?: React.ReactNode }) => (
405
- <>{children}</>
406
- );
407
-
408
- export default MinimalistContextMenu;
@@ -1,273 +0,0 @@
1
- import * as React from 'react';
2
- import { createPortal } from 'react-dom';
3
- import { X } from 'lucide-react';
4
- import { cn } from '@surreal-ui/core';
5
-
6
- interface DialogContextValue {
7
- open: boolean;
8
- setOpen: (open: boolean) => void;
9
- }
10
-
11
- const DialogContext = React.createContext<DialogContextValue | null>(null);
12
-
13
- export interface ShadcnDialogProps {
14
- open?: boolean;
15
- defaultOpen?: boolean;
16
- onOpenChange?: (open: boolean) => void;
17
- children?: React.ReactNode;
18
- }
19
-
20
- export function ShadcnDialog({
21
- open: controlledOpen,
22
- defaultOpen = false,
23
- onOpenChange,
24
- children
25
- }: DialogProps) {
26
- const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen);
27
- const isControlled = controlledOpen !== undefined;
28
- const open = isControlled ? controlledOpen : uncontrolledOpen;
29
-
30
- const setOpen = React.useCallback(
31
- (nextOpen: boolean) => {
32
- if (!isControlled) {
33
- setUncontrolledOpen(nextOpen);
34
- }
35
- onOpenChange?.(nextOpen);
36
- },
37
- [isControlled, onOpenChange]
38
- );
39
-
40
- return <DialogContext.Provider value={{ open, setOpen }}>{children}</DialogContext.Provider>;
41
- }
42
-
43
- function useDialogContext() {
44
- const context = React.useContext(DialogContext);
45
- if (!context) {
46
- throw new Error('Dialog subcomponents must be used within a Dialog provider');
47
- }
48
- return context;
49
- }
50
-
51
- export function ShadcnDialogTrigger({
52
- className,
53
- children,
54
- onClick,
55
- ...props
56
- }: React.ComponentProps<'button'>) {
57
- const { setOpen } = useDialogContext();
58
-
59
- return (
60
- <button
61
- type="button"
62
- data-slot="dialog-trigger"
63
- className={cn('inline-flex items-center justify-center', className)}
64
- onClick={(e) => {
65
- setOpen(true);
66
- onClick?.(e);
67
- }}
68
- {...props}
69
- >
70
- {children}
71
- </button>
72
- );
73
- }
74
-
75
- export function ShadcnDialogPortal({ children }: { children?: React.ReactNode }) {
76
- const [mounted, setMounted] = React.useState(false);
77
- React.useEffect(() => {
78
- setMounted(true);
79
- }, []);
80
-
81
- if (!mounted) return null;
82
- return createPortal(children, document.body);
83
- }
84
-
85
- export function ShadcnDialogOverlay({ className, onClick, ...props }: React.ComponentProps<'div'>) {
86
- const { setOpen } = useDialogContext();
87
-
88
- return (
89
- <div
90
- role="presentation"
91
- data-slot="dialog-overlay"
92
- className={cn(
93
- 'bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0 fixed inset-0 isolate z-50',
94
- className
95
- )}
96
- onClick={(e) => {
97
- setOpen(false);
98
- onClick?.(e);
99
- }}
100
- {...props}
101
- />
102
- );
103
- }
104
-
105
- export interface ShadcnDialogContentProps extends React.ComponentProps<'div'> {
106
- showCloseButton?: boolean;
107
- }
108
-
109
- export function ShadcnDialogContent({
110
- className,
111
- children,
112
- showCloseButton = true,
113
- ...props
114
- }: DialogContentProps) {
115
- const { open, setOpen } = useDialogContext();
116
-
117
- React.useEffect(() => {
118
- const onKeyDown = (e: KeyboardEvent) => {
119
- if (e.key === 'Escape') {
120
- setOpen(false);
121
- }
122
- };
123
- if (open) {
124
- window.addEventListener('keydown', onKeyDown);
125
- return () => window.removeEventListener('keydown', onKeyDown);
126
- }
127
- }, [open, setOpen]);
128
-
129
- if (!open) return null;
130
-
131
- return (
132
- <DialogPortal>
133
- <DialogOverlay />
134
- <div
135
- role="dialog"
136
- aria-modal="true"
137
- data-slot="dialog-content"
138
- className={cn(
139
- 'grid max-w-[calc(100%-2rem)] gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 sm:max-w-sm fixed top-1/2 left-1/2 z-50 w-full -translate-x-1/2 -translate-y-1/2 outline-none shadow-lg',
140
- className
141
- )}
142
- {...props}
143
- >
144
- {children}
145
- {showCloseButton && (
146
- <button
147
- type="button"
148
- data-slot="dialog-close"
149
- aria-label="Close"
150
- className="absolute top-2 right-2 inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring outline-none transition-colors"
151
- onClick={() => setOpen(false)}
152
- >
153
- <X className="h-4 w-4" />
154
- <span className="sr-only">Close</span>
155
- </button>
156
- )}
157
- </div>
158
- </DialogPortal>
159
- );
160
- }
161
-
162
- export function ShadcnDialogHeader({ className, children, ...props }: React.ComponentProps<'div'>) {
163
- return (
164
- <div data-slot="dialog-header" className={cn('gap-2 flex flex-col', className)} {...props}>
165
- {children}
166
- </div>
167
- );
168
- }
169
-
170
- export function ShadcnDialogTitle({ className, children, ...props }: React.ComponentProps<'h2'>) {
171
- return (
172
- <h2
173
- data-slot="dialog-title"
174
- className={cn('text-base leading-none font-medium', className)}
175
- {...props}
176
- >
177
- {children}
178
- </h2>
179
- );
180
- }
181
-
182
- export function ShadcnDialogDescription({
183
- className,
184
- children,
185
- ...props
186
- }: React.ComponentProps<'p'>) {
187
- return (
188
- <p
189
- data-slot="dialog-description"
190
- className={cn(
191
- 'text-sm text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground',
192
- className
193
- )}
194
- {...props}
195
- >
196
- {children}
197
- </p>
198
- );
199
- }
200
-
201
- export interface ShadcnDialogFooterProps extends React.ComponentProps<'div'> {
202
- showCloseButton?: boolean;
203
- }
204
-
205
- export function ShadcnDialogFooter({
206
- className,
207
- children,
208
- showCloseButton = false,
209
- ...props
210
- }: DialogFooterProps) {
211
- const { setOpen } = useDialogContext();
212
-
213
- return (
214
- <div
215
- data-slot="dialog-footer"
216
- className={cn(
217
- '-mx-4 -mb-4 rounded-b-xl border-t bg-muted/50 p-4 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end',
218
- className
219
- )}
220
- {...props}
221
- >
222
- {children}
223
- {showCloseButton && (
224
- <button
225
- type="button"
226
- className="inline-flex items-center justify-center rounded-md border border-input bg-background px-3 py-1.5 text-sm font-medium shadow-xs hover:bg-accent hover:text-accent-foreground"
227
- onClick={() => setOpen(false)}
228
- >
229
- Close
230
- </button>
231
- )}
232
- </div>
233
- );
234
- }
235
-
236
- export function ShadcnDialogClose({
237
- className,
238
- children,
239
- onClick,
240
- ...props
241
- }: React.ComponentProps<'button'>) {
242
- const { setOpen } = useDialogContext();
243
-
244
- return (
245
- <button
246
- type="button"
247
- data-slot="dialog-close"
248
- className={cn('inline-flex items-center justify-center', className)}
249
- onClick={(e) => {
250
- setOpen(false);
251
- onClick?.(e);
252
- }}
253
- {...props}
254
- >
255
- {children}
256
- </button>
257
- );
258
- }
259
-
260
- export {
261
- ShadcnDialog as Root,
262
- DialogTitle as Title,
263
- DialogPortal as Portal,
264
- DialogFooter as Footer,
265
- DialogHeader as Header,
266
- DialogTrigger as Trigger,
267
- DialogOverlay as Overlay,
268
- DialogContent as Content,
269
- DialogDescription as Description,
270
- DialogClose as Close
271
- };
272
-
273
- export default MinimalistDialog;