@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,215 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import { ChevronDown } from 'lucide-react';
|
|
4
|
+
import { cn } from '@surreal-ui/core';
|
|
5
|
+
|
|
6
|
+
type AccordionType = 'single' | 'multiple';
|
|
7
|
+
|
|
8
|
+
interface AccordionContextValue {
|
|
9
|
+
type: AccordionType;
|
|
10
|
+
openValues: string[];
|
|
11
|
+
toggleItem: (value: string, disabled?: boolean) => void;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const AccordionContext = React.createContext<AccordionContextValue | null>(null);
|
|
16
|
+
|
|
17
|
+
function useAccordionContext() {
|
|
18
|
+
const context = React.useContext(AccordionContext);
|
|
19
|
+
if (!context) {
|
|
20
|
+
throw new Error('Accordion subcomponents must be used within an Accordion component.');
|
|
21
|
+
}
|
|
22
|
+
return context;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface AccordionItemContextValue {
|
|
26
|
+
value: string;
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const AccordionItemContext = React.createContext<AccordionItemContextValue | null>(null);
|
|
31
|
+
|
|
32
|
+
function useAccordionItemContext() {
|
|
33
|
+
const context = React.useContext(AccordionItemContext);
|
|
34
|
+
if (!context) {
|
|
35
|
+
throw new Error('AccordionTrigger and AccordionContent must be used within an AccordionItem.');
|
|
36
|
+
}
|
|
37
|
+
return context;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ShadcnAccordionProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
41
|
+
type?: AccordionType;
|
|
42
|
+
value?: string | string[];
|
|
43
|
+
defaultValue?: string | string[];
|
|
44
|
+
collapsible?: boolean;
|
|
45
|
+
disabled?: boolean;
|
|
46
|
+
onValueChange?: (value: string | string[]) => void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const Root = React.forwardRef<HTMLDivElement, AccordionProps>(
|
|
50
|
+
(
|
|
51
|
+
{
|
|
52
|
+
type = 'single',
|
|
53
|
+
value: controlledValue,
|
|
54
|
+
defaultValue,
|
|
55
|
+
collapsible = true,
|
|
56
|
+
disabled = false,
|
|
57
|
+
onValueChange,
|
|
58
|
+
className,
|
|
59
|
+
children,
|
|
60
|
+
...props
|
|
61
|
+
},
|
|
62
|
+
ref,
|
|
63
|
+
) => {
|
|
64
|
+
const [uncontrolledValue, setUncontrolledValue] = React.useState<string[]>(() => {
|
|
65
|
+
if (defaultValue !== undefined) {
|
|
66
|
+
return Array.isArray(defaultValue) ? defaultValue : [defaultValue];
|
|
67
|
+
}
|
|
68
|
+
return [];
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const isControlled = controlledValue !== undefined;
|
|
72
|
+
const openValues = isControlled
|
|
73
|
+
? Array.isArray(controlledValue)
|
|
74
|
+
? controlledValue
|
|
75
|
+
: controlledValue
|
|
76
|
+
? [controlledValue]
|
|
77
|
+
: []
|
|
78
|
+
: uncontrolledValue;
|
|
79
|
+
|
|
80
|
+
const toggleItem = React.useCallback(
|
|
81
|
+
(itemValue: string, itemDisabled?: boolean) => {
|
|
82
|
+
if (disabled || itemDisabled) return;
|
|
83
|
+
|
|
84
|
+
let nextValues: string[];
|
|
85
|
+
const isOpen = openValues.includes(itemValue);
|
|
86
|
+
|
|
87
|
+
if (type === 'single') {
|
|
88
|
+
if (isOpen) {
|
|
89
|
+
nextValues = collapsible ? [] : [itemValue];
|
|
90
|
+
} else {
|
|
91
|
+
nextValues = [itemValue];
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
if (isOpen) {
|
|
95
|
+
nextValues = openValues.filter((v) => v !== itemValue);
|
|
96
|
+
} else {
|
|
97
|
+
nextValues = [...openValues, itemValue];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!isControlled) {
|
|
102
|
+
setUncontrolledValue(nextValues);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const emitted = type === 'single' ? (nextValues[0] ?? '') : nextValues;
|
|
106
|
+
onValueChange?.(emitted);
|
|
107
|
+
},
|
|
108
|
+
[disabled, openValues, type, collapsible, isControlled, onValueChange],
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<AccordionContext.Provider value={{ type, openValues, toggleItem, disabled }}>
|
|
113
|
+
<div ref={ref} className={cn('w-full divide-y divide-border', className)} {...props}>
|
|
114
|
+
{children}
|
|
115
|
+
</div>
|
|
116
|
+
</AccordionContext.Provider>
|
|
117
|
+
);
|
|
118
|
+
},
|
|
119
|
+
);
|
|
120
|
+
Root.displayName = 'Accordion';
|
|
121
|
+
|
|
122
|
+
export interface ShadcnAccordionItemProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
123
|
+
value: string;
|
|
124
|
+
disabled?: boolean;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const Item = React.forwardRef<HTMLDivElement, AccordionItemProps>(
|
|
128
|
+
({ className, value, disabled = false, children, ...props }, ref) => {
|
|
129
|
+
const { openValues } = useAccordionContext();
|
|
130
|
+
const isOpen = openValues.includes(value);
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<AccordionItemContext.Provider value={{ value, disabled }}>
|
|
134
|
+
<div
|
|
135
|
+
ref={ref}
|
|
136
|
+
data-state={isOpen ? 'open' : 'closed'}
|
|
137
|
+
data-disabled={disabled ? '' : undefined}
|
|
138
|
+
className={cn('border-b border-border last:border-b-0', className)}
|
|
139
|
+
{...props}
|
|
140
|
+
>
|
|
141
|
+
{children}
|
|
142
|
+
</div>
|
|
143
|
+
</AccordionItemContext.Provider>
|
|
144
|
+
);
|
|
145
|
+
},
|
|
146
|
+
);
|
|
147
|
+
Item.displayName = 'AccordionItem';
|
|
148
|
+
|
|
149
|
+
export interface ShadcnAccordionTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {}
|
|
150
|
+
|
|
151
|
+
export const Trigger = React.forwardRef<HTMLButtonElement, AccordionTriggerProps>(
|
|
152
|
+
({ className, children, ...props }, ref) => {
|
|
153
|
+
const { openValues, toggleItem, disabled: rootDisabled } = useAccordionContext();
|
|
154
|
+
const { value, disabled: itemDisabled } = useAccordionItemContext();
|
|
155
|
+
const isOpen = openValues.includes(value);
|
|
156
|
+
const isDisabled = rootDisabled || itemDisabled;
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<h3 className="flex">
|
|
160
|
+
<button
|
|
161
|
+
ref={ref}
|
|
162
|
+
type="button"
|
|
163
|
+
aria-expanded={isOpen}
|
|
164
|
+
data-state={isOpen ? 'open' : 'closed'}
|
|
165
|
+
disabled={isDisabled}
|
|
166
|
+
onClick={() => toggleItem(value, itemDisabled)}
|
|
167
|
+
className={cn(
|
|
168
|
+
'flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all hover:underline text-left text-foreground [&[data-state=open]>svg]:rotate-180 disabled:pointer-events-none disabled:opacity-50',
|
|
169
|
+
className,
|
|
170
|
+
)}
|
|
171
|
+
{...props}
|
|
172
|
+
>
|
|
173
|
+
{children}
|
|
174
|
+
<ChevronDown className="size-4 shrink-0 text-muted-foreground transition-transform duration-200" />
|
|
175
|
+
</button>
|
|
176
|
+
</h3>
|
|
177
|
+
);
|
|
178
|
+
},
|
|
179
|
+
);
|
|
180
|
+
Trigger.displayName = 'AccordionTrigger';
|
|
181
|
+
|
|
182
|
+
export interface ShadcnAccordionContentProps extends React.HTMLAttributes<HTMLDivElement> {}
|
|
183
|
+
|
|
184
|
+
export const Content = React.forwardRef<HTMLDivElement, AccordionContentProps>(
|
|
185
|
+
({ className, children, ...props }, ref) => {
|
|
186
|
+
const { openValues } = useAccordionContext();
|
|
187
|
+
const { value } = useAccordionItemContext();
|
|
188
|
+
const isOpen = openValues.includes(value);
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
<div
|
|
192
|
+
ref={ref}
|
|
193
|
+
data-state={isOpen ? 'open' : 'closed'}
|
|
194
|
+
className={cn(
|
|
195
|
+
'grid transition-all duration-200 ease-out text-sm text-muted-foreground',
|
|
196
|
+
isOpen ? 'grid-rows-[1fr] opacity-100' : 'grid-rows-[0fr] opacity-0 invisible h-0',
|
|
197
|
+
className,
|
|
198
|
+
)}
|
|
199
|
+
{...props}
|
|
200
|
+
>
|
|
201
|
+
<div className="overflow-hidden pb-4 pt-0">{children}</div>
|
|
202
|
+
</div>
|
|
203
|
+
);
|
|
204
|
+
},
|
|
205
|
+
);
|
|
206
|
+
Content.displayName = 'AccordionContent';
|
|
207
|
+
|
|
208
|
+
export {
|
|
209
|
+
Root as ShadcnAccordion,
|
|
210
|
+
Item as AccordionItem,
|
|
211
|
+
Trigger as AccordionTrigger,
|
|
212
|
+
Content as AccordionContent,
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export default MinimalistAccordion;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CheckCircle2, ArrowRight } from 'lucide-react';
|
|
3
|
+
|
|
4
|
+
interface CreatedComponent {
|
|
5
|
+
id: string;
|
|
6
|
+
title: string;
|
|
7
|
+
currentVersion: string | number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface ModernAlertProps {
|
|
11
|
+
successMessage?: string;
|
|
12
|
+
createdComponent?: CreatedComponent | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const ModernAlert: React.FC<ModernAlertProps> = ({ successMessage = '', createdComponent = null }) => {
|
|
16
|
+
if (!successMessage || !createdComponent) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div className="p-6 bg-emerald-500/10 border border-emerald-500/30 rounded-2xl space-y-4">
|
|
22
|
+
<div className="flex items-center gap-3 text-emerald-300 font-bold text-lg">
|
|
23
|
+
<CheckCircle2 className="w-6 h-6" />
|
|
24
|
+
<span>{successMessage}</span>
|
|
25
|
+
</div>
|
|
26
|
+
<p className="text-slate-300 text-sm">
|
|
27
|
+
View your new component v{createdComponent.currentVersion} in the Surreal UI catalog:
|
|
28
|
+
</p>
|
|
29
|
+
<a
|
|
30
|
+
href={`/components/${createdComponent.id}`}
|
|
31
|
+
className="inline-flex items-center gap-2 px-5 py-2.5 bg-emerald-600 hover:bg-emerald-700 text-white font-semibold text-sm rounded-xl transition-colors shadow-lg shadow-emerald-500/20"
|
|
32
|
+
>
|
|
33
|
+
<span>Open {createdComponent.title} in Playground</span>
|
|
34
|
+
<ArrowRight className="w-4 h-4" />
|
|
35
|
+
</a>
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default MinimalistAlert;
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { cn, cva, type VariantProps } from '@surreal-ui/core';
|
|
3
|
+
|
|
4
|
+
interface AlertDialogContextType {
|
|
5
|
+
open: boolean;
|
|
6
|
+
setOpen: (open: boolean) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const AlertDialogContext = React.createContext<AlertDialogContextType | undefined>(undefined);
|
|
10
|
+
|
|
11
|
+
function useAlertDialog() {
|
|
12
|
+
const context = React.useContext(AlertDialogContext);
|
|
13
|
+
if (!context) {
|
|
14
|
+
throw new Error('AlertDialog compound components must be used within an <AlertDialog />');
|
|
15
|
+
}
|
|
16
|
+
return context;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ShadcnAlertDialogProps {
|
|
20
|
+
open?: boolean;
|
|
21
|
+
defaultOpen?: boolean;
|
|
22
|
+
onOpenChange?: (open: boolean) => void;
|
|
23
|
+
children?: React.ReactNode;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function ShadcnAlertDialog({
|
|
27
|
+
open: controlledOpen,
|
|
28
|
+
defaultOpen = false,
|
|
29
|
+
onOpenChange,
|
|
30
|
+
children,
|
|
31
|
+
}: AlertDialogProps) {
|
|
32
|
+
const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen);
|
|
33
|
+
const isControlled = controlledOpen !== undefined;
|
|
34
|
+
const open = isControlled ? controlledOpen : uncontrolledOpen;
|
|
35
|
+
|
|
36
|
+
const setOpen = React.useCallback(
|
|
37
|
+
(nextOpen: boolean) => {
|
|
38
|
+
if (!isControlled) {
|
|
39
|
+
setUncontrolledOpen(nextOpen);
|
|
40
|
+
}
|
|
41
|
+
onOpenChange?.(nextOpen);
|
|
42
|
+
},
|
|
43
|
+
[isControlled, onOpenChange],
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<AlertDialogContext.Provider value={{ open, setOpen }}>{children}</AlertDialogContext.Provider>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ShadcnAlertDialogTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
52
|
+
asChild?: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const ShadcnAlertDialogTrigger = React.forwardRef<HTMLButtonElement, AlertDialogTriggerProps>(
|
|
56
|
+
({ onClick, children, ...props }, ref) => {
|
|
57
|
+
const { setOpen } = useAlertDialog();
|
|
58
|
+
return (
|
|
59
|
+
<button
|
|
60
|
+
ref={ref}
|
|
61
|
+
type="button"
|
|
62
|
+
data-slot="alert-dialog-trigger"
|
|
63
|
+
onClick={(e) => {
|
|
64
|
+
onClick?.(e);
|
|
65
|
+
setOpen(true);
|
|
66
|
+
}}
|
|
67
|
+
{...props}
|
|
68
|
+
>
|
|
69
|
+
{children}
|
|
70
|
+
</button>
|
|
71
|
+
);
|
|
72
|
+
},
|
|
73
|
+
);
|
|
74
|
+
AlertDialogTrigger.displayName = 'AlertDialogTrigger';
|
|
75
|
+
|
|
76
|
+
export const ShadcnAlertDialogPortal = ({ children }: { children: React.ReactNode }) => {
|
|
77
|
+
return <>{children}</>;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export interface ShadcnAlertDialogOverlayProps extends React.HTMLAttributes<HTMLDivElement> {}
|
|
81
|
+
|
|
82
|
+
export const ShadcnAlertDialogOverlay = React.forwardRef<HTMLDivElement, AlertDialogOverlayProps>(
|
|
83
|
+
({ className, ...props }, ref) => {
|
|
84
|
+
return (
|
|
85
|
+
<div
|
|
86
|
+
ref={ref}
|
|
87
|
+
data-slot="alert-dialog-overlay"
|
|
88
|
+
className={cn(
|
|
89
|
+
'fixed inset-0 z-50 bg-black/60 backdrop-blur-xs transition-opacity animate-in fade-in-0',
|
|
90
|
+
className,
|
|
91
|
+
)}
|
|
92
|
+
{...props}
|
|
93
|
+
/>
|
|
94
|
+
);
|
|
95
|
+
},
|
|
96
|
+
);
|
|
97
|
+
AlertDialogOverlay.displayName = 'AlertDialogOverlay';
|
|
98
|
+
|
|
99
|
+
export interface ShadcnAlertDialogContentProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
100
|
+
size?: 'default' | 'sm';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const ShadcnAlertDialogContent = React.forwardRef<HTMLDivElement, AlertDialogContentProps>(
|
|
104
|
+
({ className, size = 'default', children, ...props }, ref) => {
|
|
105
|
+
const { open, setOpen } = useAlertDialog();
|
|
106
|
+
|
|
107
|
+
React.useEffect(() => {
|
|
108
|
+
const handleKeyDown = (e: KeyboardEvent) => {
|
|
109
|
+
if (e.key === 'Escape' && open) {
|
|
110
|
+
setOpen(false);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
114
|
+
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
115
|
+
}, [open, setOpen]);
|
|
116
|
+
|
|
117
|
+
if (!open) return null;
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<AlertDialogPortal>
|
|
121
|
+
<AlertDialogOverlay onClick={() => setOpen(false)} />
|
|
122
|
+
<div
|
|
123
|
+
ref={ref}
|
|
124
|
+
role="alertdialog"
|
|
125
|
+
aria-modal="true"
|
|
126
|
+
data-slot="alert-dialog-content"
|
|
127
|
+
data-size={size}
|
|
128
|
+
className={cn(
|
|
129
|
+
'fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-popover-foreground ring-1 ring-foreground/10 shadow-2xl duration-150 animate-in fade-in-0 zoom-in-95 outline-none',
|
|
130
|
+
size === 'default' ? 'max-w-xs sm:max-w-sm' : 'max-w-xs',
|
|
131
|
+
className,
|
|
132
|
+
)}
|
|
133
|
+
{...props}
|
|
134
|
+
>
|
|
135
|
+
{children}
|
|
136
|
+
</div>
|
|
137
|
+
</AlertDialogPortal>
|
|
138
|
+
);
|
|
139
|
+
},
|
|
140
|
+
);
|
|
141
|
+
AlertDialogContent.displayName = 'AlertDialogContent';
|
|
142
|
+
|
|
143
|
+
export interface ShadcnAlertDialogHeaderProps extends React.HTMLAttributes<HTMLDivElement> {}
|
|
144
|
+
|
|
145
|
+
export const ShadcnAlertDialogHeader = React.forwardRef<HTMLDivElement, AlertDialogHeaderProps>(
|
|
146
|
+
({ className, ...props }, ref) => (
|
|
147
|
+
<div
|
|
148
|
+
ref={ref}
|
|
149
|
+
data-slot="alert-dialog-header"
|
|
150
|
+
className={cn(
|
|
151
|
+
'grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-4 sm:place-items-start sm:text-left sm:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]',
|
|
152
|
+
className,
|
|
153
|
+
)}
|
|
154
|
+
{...props}
|
|
155
|
+
/>
|
|
156
|
+
),
|
|
157
|
+
);
|
|
158
|
+
AlertDialogHeader.displayName = 'AlertDialogHeader';
|
|
159
|
+
|
|
160
|
+
export interface ShadcnAlertDialogMediaProps extends React.HTMLAttributes<HTMLDivElement> {}
|
|
161
|
+
|
|
162
|
+
export const ShadcnAlertDialogMedia = React.forwardRef<HTMLDivElement, AlertDialogMediaProps>(
|
|
163
|
+
({ className, ...props }, ref) => (
|
|
164
|
+
<div
|
|
165
|
+
ref={ref}
|
|
166
|
+
data-slot="alert-dialog-media"
|
|
167
|
+
className={cn(
|
|
168
|
+
"mb-2 inline-flex size-10 items-center justify-center rounded-md bg-muted sm:row-span-2 *:[svg:not([class*='size-'])]:size-6",
|
|
169
|
+
className,
|
|
170
|
+
)}
|
|
171
|
+
{...props}
|
|
172
|
+
/>
|
|
173
|
+
),
|
|
174
|
+
);
|
|
175
|
+
AlertDialogMedia.displayName = 'AlertDialogMedia';
|
|
176
|
+
|
|
177
|
+
export interface ShadcnAlertDialogTitleProps extends React.HTMLAttributes<HTMLHeadingElement> {}
|
|
178
|
+
|
|
179
|
+
export const ShadcnAlertDialogTitle = React.forwardRef<HTMLHeadingElement, AlertDialogTitleProps>(
|
|
180
|
+
({ className, ...props }, ref) => (
|
|
181
|
+
<h2
|
|
182
|
+
ref={ref}
|
|
183
|
+
data-slot="alert-dialog-title"
|
|
184
|
+
className={cn(
|
|
185
|
+
'text-base font-semibold tracking-tight text-foreground sm:col-start-2',
|
|
186
|
+
className,
|
|
187
|
+
)}
|
|
188
|
+
{...props}
|
|
189
|
+
/>
|
|
190
|
+
),
|
|
191
|
+
);
|
|
192
|
+
AlertDialogTitle.displayName = 'AlertDialogTitle';
|
|
193
|
+
|
|
194
|
+
export interface ShadcnAlertDialogDescriptionProps extends React.HTMLAttributes<HTMLParagraphElement> {}
|
|
195
|
+
|
|
196
|
+
export const ShadcnAlertDialogDescription = React.forwardRef<
|
|
197
|
+
HTMLParagraphElement,
|
|
198
|
+
AlertDialogDescriptionProps
|
|
199
|
+
>(({ className, ...props }, ref) => (
|
|
200
|
+
<p
|
|
201
|
+
ref={ref}
|
|
202
|
+
data-slot="alert-dialog-description"
|
|
203
|
+
className={cn(
|
|
204
|
+
'text-sm text-balance text-muted-foreground leading-relaxed md:text-pretty *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground',
|
|
205
|
+
className,
|
|
206
|
+
)}
|
|
207
|
+
{...props}
|
|
208
|
+
/>
|
|
209
|
+
));
|
|
210
|
+
AlertDialogDescription.displayName = 'AlertDialogDescription';
|
|
211
|
+
|
|
212
|
+
export interface ShadcnAlertDialogFooterProps extends React.HTMLAttributes<HTMLDivElement> {}
|
|
213
|
+
|
|
214
|
+
export const ShadcnAlertDialogFooter = React.forwardRef<HTMLDivElement, AlertDialogFooterProps>(
|
|
215
|
+
({ className, ...props }, ref) => (
|
|
216
|
+
<div
|
|
217
|
+
ref={ref}
|
|
218
|
+
data-slot="alert-dialog-footer"
|
|
219
|
+
className={cn(
|
|
220
|
+
'-mx-4 -mb-4 flex flex-col-reverse gap-2 rounded-b-xl border-t border-border bg-muted/50 p-4 sm:flex-row sm:justify-end',
|
|
221
|
+
className,
|
|
222
|
+
)}
|
|
223
|
+
{...props}
|
|
224
|
+
/>
|
|
225
|
+
),
|
|
226
|
+
);
|
|
227
|
+
AlertDialogFooter.displayName = 'AlertDialogFooter';
|
|
228
|
+
|
|
229
|
+
const buttonVariants = cva(
|
|
230
|
+
'inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
|
|
231
|
+
{
|
|
232
|
+
variants: {
|
|
233
|
+
variant: {
|
|
234
|
+
default: 'bg-primary text-primary-foreground shadow hover:bg-primary/90',
|
|
235
|
+
destructive: 'bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90',
|
|
236
|
+
outline:
|
|
237
|
+
'border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground',
|
|
238
|
+
secondary: 'bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80',
|
|
239
|
+
ghost: 'hover:bg-accent hover:text-accent-foreground',
|
|
240
|
+
link: 'text-primary underline-offset-4 hover:underline',
|
|
241
|
+
},
|
|
242
|
+
size: {
|
|
243
|
+
default: 'h-9 px-4 py-2',
|
|
244
|
+
sm: 'h-8 rounded-md px-3 text-xs',
|
|
245
|
+
lg: 'h-10 rounded-md px-8',
|
|
246
|
+
icon: 'h-9 w-9',
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
defaultVariants: {
|
|
250
|
+
variant: 'default',
|
|
251
|
+
size: 'default',
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
export interface ShadcnAlertDialogActionProps
|
|
257
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {}
|
|
258
|
+
|
|
259
|
+
export const ShadcnAlertDialogAction = React.forwardRef<HTMLButtonElement, AlertDialogActionProps>(
|
|
260
|
+
({ className, variant = 'default', size = 'default', onClick, ...props }, ref) => {
|
|
261
|
+
const { setOpen } = useAlertDialog();
|
|
262
|
+
return (
|
|
263
|
+
<button
|
|
264
|
+
ref={ref}
|
|
265
|
+
type="button"
|
|
266
|
+
data-slot="alert-dialog-action"
|
|
267
|
+
className={cn(buttonVariants({ variant, size }), className)}
|
|
268
|
+
onClick={(e) => {
|
|
269
|
+
onClick?.(e);
|
|
270
|
+
setOpen(false);
|
|
271
|
+
}}
|
|
272
|
+
{...props}
|
|
273
|
+
/>
|
|
274
|
+
);
|
|
275
|
+
},
|
|
276
|
+
);
|
|
277
|
+
AlertDialogAction.displayName = 'AlertDialogAction';
|
|
278
|
+
|
|
279
|
+
export interface ShadcnAlertDialogCancelProps
|
|
280
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {}
|
|
281
|
+
|
|
282
|
+
export const ShadcnAlertDialogCancel = React.forwardRef<HTMLButtonElement, AlertDialogCancelProps>(
|
|
283
|
+
({ className, variant = 'outline', size = 'default', onClick, ...props }, ref) => {
|
|
284
|
+
const { setOpen } = useAlertDialog();
|
|
285
|
+
return (
|
|
286
|
+
<button
|
|
287
|
+
ref={ref}
|
|
288
|
+
type="button"
|
|
289
|
+
data-slot="alert-dialog-cancel"
|
|
290
|
+
className={cn(buttonVariants({ variant, size }), className)}
|
|
291
|
+
onClick={(e) => {
|
|
292
|
+
onClick?.(e);
|
|
293
|
+
setOpen(false);
|
|
294
|
+
}}
|
|
295
|
+
{...props}
|
|
296
|
+
/>
|
|
297
|
+
);
|
|
298
|
+
},
|
|
299
|
+
);
|
|
300
|
+
AlertDialogCancel.displayName = 'AlertDialogCancel';
|
|
301
|
+
|
|
302
|
+
export {
|
|
303
|
+
ShadcnAlertDialog as Root,
|
|
304
|
+
AlertDialogTrigger as Trigger,
|
|
305
|
+
AlertDialogContent as Content,
|
|
306
|
+
AlertDialogHeader as Header,
|
|
307
|
+
AlertDialogFooter as Footer,
|
|
308
|
+
AlertDialogTitle as Title,
|
|
309
|
+
AlertDialogDescription as Description,
|
|
310
|
+
AlertDialogAction as Action,
|
|
311
|
+
AlertDialogCancel as Cancel,
|
|
312
|
+
AlertDialogMedia as Media,
|
|
313
|
+
AlertDialogOverlay as Overlay,
|
|
314
|
+
AlertDialogPortal as Portal,
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
export default MinimalistAlertDialog;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { cn } from '@surreal-ui/core';
|
|
3
|
+
|
|
4
|
+
export interface ShadcnAspectRatioProps extends React.ComponentProps<'div'> {
|
|
5
|
+
ratio?: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const ShadcnAspectRatio = React.forwardRef<HTMLDivElement, AspectRatioProps>(
|
|
9
|
+
({ ratio = 16 / 9, style, className, children, ...props }, ref) => {
|
|
10
|
+
return (
|
|
11
|
+
<div
|
|
12
|
+
ref={ref}
|
|
13
|
+
data-slot="aspect-ratio"
|
|
14
|
+
style={{
|
|
15
|
+
position: 'relative',
|
|
16
|
+
width: '100%',
|
|
17
|
+
aspectRatio: ratio,
|
|
18
|
+
...style,
|
|
19
|
+
}}
|
|
20
|
+
className={cn(className)}
|
|
21
|
+
{...props}
|
|
22
|
+
>
|
|
23
|
+
{children}
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
},
|
|
27
|
+
);
|
|
28
|
+
AspectRatio.displayName = 'AspectRatio';
|
|
29
|
+
|
|
30
|
+
export default MinimalistAspectRatio;
|