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