@surreal-ui/react 0.8.1 → 0.9.1
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/LICENSE +21 -0
- package/dist/index.js +955 -7227
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +14 -0
- package/package.json +21 -4
- package/CHANGELOG.md +0 -149
- package/src/components/GlassmorphismAlert.tsx +0 -43
- package/src/components/GlassmorphismButton.tsx +0 -20
- package/src/components/GlassmorphismCard.tsx +0 -43
- package/src/components/GlassmorphismEmptyState.tsx +0 -20
- package/src/components/GlassmorphismInputGroup.tsx +0 -148
- package/src/components/GlassmorphismMenubar.tsx +0 -96
- package/src/components/GlassmorphismScrollArea.tsx +0 -67
- package/src/components/GlassmorphismTable.tsx +0 -61
- package/src/components/GlassmorphismTypography.tsx +0 -31
- package/src/components/MinimalistAccordion.tsx +0 -215
- package/src/components/MinimalistAlert.tsx +0 -43
- package/src/components/MinimalistAlertDialog.tsx +0 -318
- package/src/components/MinimalistAspectRatio.tsx +0 -30
- package/src/components/MinimalistAvatar.tsx +0 -149
- package/src/components/MinimalistBadge.tsx +0 -49
- package/src/components/MinimalistBreadcrumb.tsx +0 -109
- package/src/components/MinimalistButton.tsx +0 -86
- package/src/components/MinimalistButtonGroup.tsx +0 -86
- package/src/components/MinimalistCalendar.tsx +0 -355
- package/src/components/MinimalistCard.tsx +0 -89
- package/src/components/MinimalistCarousel.tsx +0 -266
- package/src/components/MinimalistChart.tsx +0 -296
- package/src/components/MinimalistCheckbox.tsx +0 -117
- package/src/components/MinimalistCodeBlock.tsx +0 -203
- package/src/components/MinimalistCollapsible.tsx +0 -134
- package/src/components/MinimalistCommand.tsx +0 -344
- package/src/components/MinimalistContextMenu.tsx +0 -408
- package/src/components/MinimalistDialog.tsx +0 -273
- package/src/components/MinimalistDrawer.tsx +0 -220
- package/src/components/MinimalistDropdownMenu.tsx +0 -431
- package/src/components/MinimalistEmpty.tsx +0 -105
- package/src/components/MinimalistEmptyState.tsx +0 -34
- package/src/components/MinimalistField.tsx +0 -275
- package/src/components/MinimalistForm.tsx +0 -205
- package/src/components/MinimalistHoverCard.tsx +0 -48
- package/src/components/MinimalistInput.tsx +0 -24
- package/src/components/MinimalistInputGroup.tsx +0 -180
- package/src/components/MinimalistInputOtp.tsx +0 -189
- package/src/components/MinimalistItem.tsx +0 -182
- package/src/components/MinimalistKbd.tsx +0 -46
- package/src/components/MinimalistLabel.tsx +0 -19
- package/src/components/MinimalistMenubar.tsx +0 -491
- package/src/components/MinimalistNativeSelect.tsx +0 -77
- package/src/components/MinimalistNavigationMenu.tsx +0 -198
- package/src/components/MinimalistPagination.tsx +0 -152
- package/src/components/MinimalistPopover.tsx +0 -229
- package/src/components/MinimalistProgress.tsx +0 -39
- package/src/components/MinimalistRadioGroup.tsx +0 -115
- package/src/components/MinimalistRangeCalendar.tsx +0 -396
- package/src/components/MinimalistResizable.tsx +0 -54
- package/src/components/MinimalistScrollArea.tsx +0 -41
- package/src/components/MinimalistSelect.tsx +0 -262
- package/src/components/MinimalistSeparator.tsx +0 -45
- package/src/components/MinimalistSheet.tsx +0 -247
- package/src/components/MinimalistSidebar.tsx +0 -638
- package/src/components/MinimalistSkeleton.tsx +0 -16
- package/src/components/MinimalistSlider.tsx +0 -213
- package/src/components/MinimalistSonner.tsx +0 -41
- package/src/components/MinimalistSpinner.tsx +0 -39
- package/src/components/MinimalistSwitch.tsx +0 -92
- package/src/components/MinimalistTable.tsx +0 -65
- package/src/components/MinimalistTabs.tsx +0 -171
- package/src/components/MinimalistTextarea.tsx +0 -24
- package/src/components/MinimalistToggle.tsx +0 -74
- package/src/components/MinimalistToggleGroup.tsx +0 -197
- package/src/components/MinimalistTooltip.tsx +0 -172
- package/src/components/MinimalistTypography.tsx +0 -33
- package/src/components/NeubrutalismCard.tsx +0 -84
- package/src/components/NeubrutalismItem.tsx +0 -48
- package/src/components/ShadcnAccordion.tsx +0 -215
- package/src/components/ShadcnAlertDialog.tsx +0 -318
- package/src/components/ShadcnAspectRatio.tsx +0 -30
- package/src/components/ShadcnAvatar.tsx +0 -149
- package/src/components/ShadcnBadge.tsx +0 -49
- package/src/components/ShadcnBreadcrumb.tsx +0 -109
- package/src/components/ShadcnButton.tsx +0 -86
- package/src/components/ShadcnButtonGroup.tsx +0 -86
- package/src/components/ShadcnCalendar.tsx +0 -355
- package/src/components/ShadcnCarousel.tsx +0 -266
- package/src/components/ShadcnChart.tsx +0 -296
- package/src/components/ShadcnCheckbox.tsx +0 -117
- package/src/components/ShadcnCodeBlock.tsx +0 -203
- package/src/components/ShadcnCollapsible.tsx +0 -134
- package/src/components/ShadcnCommand.tsx +0 -344
- package/src/components/ShadcnContextMenu.tsx +0 -408
- package/src/components/ShadcnDialog.tsx +0 -273
- package/src/components/ShadcnDrawer.tsx +0 -220
- package/src/components/ShadcnDropdownMenu.tsx +0 -431
- package/src/components/ShadcnEmpty.tsx +0 -105
- package/src/components/ShadcnField.tsx +0 -275
- package/src/components/ShadcnForm.tsx +0 -205
- package/src/components/ShadcnHoverCard.tsx +0 -48
- package/src/components/ShadcnInput.tsx +0 -24
- package/src/components/ShadcnInputGroup.tsx +0 -180
- package/src/components/ShadcnInputOtp.tsx +0 -189
- package/src/components/ShadcnItem.tsx +0 -182
- package/src/components/ShadcnKbd.tsx +0 -46
- package/src/components/ShadcnLabel.tsx +0 -19
- package/src/components/ShadcnMenubar.tsx +0 -491
- package/src/components/ShadcnNativeSelect.tsx +0 -77
- package/src/components/ShadcnNavigationMenu.tsx +0 -198
- package/src/components/ShadcnPagination.tsx +0 -152
- package/src/components/ShadcnPopover.tsx +0 -229
- package/src/components/ShadcnProgress.tsx +0 -39
- package/src/components/ShadcnRadioGroup.tsx +0 -115
- package/src/components/ShadcnRangeCalendar.tsx +0 -396
- package/src/components/ShadcnSelect.tsx +0 -262
- package/src/components/ShadcnSeparator.tsx +0 -45
- package/src/components/ShadcnSheet.tsx +0 -247
- package/src/components/ShadcnSidebar.tsx +0 -638
- package/src/components/ShadcnSkeleton.tsx +0 -16
- package/src/components/ShadcnSlider.tsx +0 -213
- package/src/components/ShadcnSonner.tsx +0 -41
- package/src/components/ShadcnSpinner.tsx +0 -39
- package/src/components/ShadcnSwitch.tsx +0 -92
- package/src/components/ShadcnTabs.tsx +0 -171
- package/src/components/ShadcnTextarea.tsx +0 -24
- package/src/components/ShadcnToggle.tsx +0 -74
- package/src/components/ShadcnToggleGroup.tsx +0 -197
- package/src/components/ShadcnTooltip.tsx +0 -172
- package/src/index.ts +0 -124
- package/tsconfig.json +0 -10
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
import { Check, Copy } from 'lucide-react';
|
|
4
|
-
import { cn } from '@surreal-ui/core';
|
|
5
|
-
|
|
6
|
-
interface CodeBlockContextValue {
|
|
7
|
-
code: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const CodeBlockContext = React.createContext<CodeBlockContextValue | null>(null);
|
|
11
|
-
|
|
12
|
-
export function useCodeBlock() {
|
|
13
|
-
const context = React.useContext(CodeBlockContext);
|
|
14
|
-
if (!context) {
|
|
15
|
-
throw new Error('CodeBlock subcomponents must be used within a CodeBlock provider');
|
|
16
|
-
}
|
|
17
|
-
return context;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface ShadcnCodeBlockProps extends React.ComponentProps<'div'> {
|
|
21
|
-
code: string;
|
|
22
|
-
language?: string;
|
|
23
|
-
showLineNumbers?: boolean;
|
|
24
|
-
wrap?: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const ShadcnCodeBlock = React.forwardRef<HTMLDivElement, CodeBlockProps>(
|
|
28
|
-
(
|
|
29
|
-
{
|
|
30
|
-
code,
|
|
31
|
-
language = 'plaintext',
|
|
32
|
-
showLineNumbers = false,
|
|
33
|
-
wrap = false,
|
|
34
|
-
className,
|
|
35
|
-
children,
|
|
36
|
-
...props
|
|
37
|
-
},
|
|
38
|
-
ref
|
|
39
|
-
) => {
|
|
40
|
-
const [highlightedLight, setHighlightedLight] = React.useState<string>('');
|
|
41
|
-
const [highlightedDark, setHighlightedDark] = React.useState<string>('');
|
|
42
|
-
|
|
43
|
-
React.useEffect(() => {
|
|
44
|
-
let isMounted = true;
|
|
45
|
-
|
|
46
|
-
async function highlight() {
|
|
47
|
-
try {
|
|
48
|
-
const { codeToHtml } = await import('shiki');
|
|
49
|
-
const lineNumberTransformer = {
|
|
50
|
-
name: 'line-numbers',
|
|
51
|
-
line(node: any, line: number) {
|
|
52
|
-
node.children.unshift({
|
|
53
|
-
type: 'element',
|
|
54
|
-
tagName: 'span',
|
|
55
|
-
properties: {
|
|
56
|
-
className: [
|
|
57
|
-
'inline-block',
|
|
58
|
-
'min-w-10',
|
|
59
|
-
'mr-4',
|
|
60
|
-
'text-right',
|
|
61
|
-
'select-none',
|
|
62
|
-
'text-muted-foreground'
|
|
63
|
-
]
|
|
64
|
-
},
|
|
65
|
-
children: [{ type: 'text', value: String(line) }]
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const transformers = showLineNumbers ? [lineNumberTransformer] : [];
|
|
71
|
-
|
|
72
|
-
const [light, dark] = await Promise.all([
|
|
73
|
-
codeToHtml(code, {
|
|
74
|
-
lang: language,
|
|
75
|
-
theme: 'one-light',
|
|
76
|
-
transformers
|
|
77
|
-
}),
|
|
78
|
-
codeToHtml(code, {
|
|
79
|
-
lang: language,
|
|
80
|
-
theme: 'one-dark-pro',
|
|
81
|
-
transformers
|
|
82
|
-
})
|
|
83
|
-
]);
|
|
84
|
-
|
|
85
|
-
if (isMounted) {
|
|
86
|
-
setHighlightedLight(light);
|
|
87
|
-
setHighlightedDark(dark);
|
|
88
|
-
}
|
|
89
|
-
} catch (err) {
|
|
90
|
-
if (isMounted) {
|
|
91
|
-
const escaped = code.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
92
|
-
const fallback = `<pre class="p-4 text-sm font-mono"><code>${escaped}</code></pre>`;
|
|
93
|
-
setHighlightedLight(fallback);
|
|
94
|
-
setHighlightedDark(fallback);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
highlight();
|
|
100
|
-
return () => {
|
|
101
|
-
isMounted = false;
|
|
102
|
-
};
|
|
103
|
-
}, [code, language, showLineNumbers]);
|
|
104
|
-
|
|
105
|
-
const contextValue = React.useMemo(() => ({ code }), [code]);
|
|
106
|
-
|
|
107
|
-
return (
|
|
108
|
-
<CodeBlockContext.Provider value={contextValue}>
|
|
109
|
-
<div
|
|
110
|
-
ref={ref}
|
|
111
|
-
className={cn(
|
|
112
|
-
'group relative w-full overflow-hidden rounded-md border bg-background dark:bg-neutral-950 text-foreground font-mono text-sm',
|
|
113
|
-
className
|
|
114
|
-
)}
|
|
115
|
-
{...props}
|
|
116
|
-
>
|
|
117
|
-
<div className="relative">
|
|
118
|
-
<div
|
|
119
|
-
className={cn(
|
|
120
|
-
'overflow-auto dark:hidden [&>pre]:m-0 [&>pre]:bg-background dark:[&>pre]:bg-neutral-950! [&>pre]:p-4 [&>pre]:text-foreground! [&>pre]:text-sm [&_code]:font-mono [&_code]:text-sm',
|
|
121
|
-
wrap && '[&>pre]:whitespace-pre-wrap [&>pre]:break-words'
|
|
122
|
-
)}
|
|
123
|
-
dangerouslySetInnerHTML={{
|
|
124
|
-
__html: highlightedLight || `<pre class="p-4"><code>${code}</code></pre>`
|
|
125
|
-
}}
|
|
126
|
-
/>
|
|
127
|
-
<div
|
|
128
|
-
className={cn(
|
|
129
|
-
'hidden overflow-auto dark:block [&>pre]:m-0 [&>pre]:bg-background dark:[&>pre]:bg-neutral-950! [&>pre]:p-4 [&>pre]:text-foreground! [&>pre]:text-sm [&_code]:font-mono [&_code]:text-sm',
|
|
130
|
-
wrap && '[&>pre]:whitespace-pre-wrap [&>pre]:break-words'
|
|
131
|
-
)}
|
|
132
|
-
dangerouslySetInnerHTML={{
|
|
133
|
-
__html: highlightedDark || `<pre class="p-4"><code>${code}</code></pre>`
|
|
134
|
-
}}
|
|
135
|
-
/>
|
|
136
|
-
{children && (
|
|
137
|
-
<div className="absolute top-2 right-2 flex items-center gap-2 z-10">{children}</div>
|
|
138
|
-
)}
|
|
139
|
-
</div>
|
|
140
|
-
</div>
|
|
141
|
-
</CodeBlockContext.Provider>
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
);
|
|
145
|
-
CodeBlock.displayName = 'CodeBlock';
|
|
146
|
-
|
|
147
|
-
export interface CodeBlockCopyButtonProps extends React.ComponentProps<'button'> {
|
|
148
|
-
onCopy?: () => void;
|
|
149
|
-
onError?: (error: unknown) => void;
|
|
150
|
-
timeout?: number;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export const CodeBlockCopyButton = React.forwardRef<HTMLButtonElement, CodeBlockCopyButtonProps>(
|
|
154
|
-
({ onCopy, onError, timeout = 2000, className, children, onClick, ...props }, ref) => {
|
|
155
|
-
const { code } = useCodeBlock();
|
|
156
|
-
const [isCopied, setIsCopied] = React.useState(false);
|
|
157
|
-
|
|
158
|
-
const handleCopy = async (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
159
|
-
onClick?.(event);
|
|
160
|
-
if (event.defaultPrevented) return;
|
|
161
|
-
|
|
162
|
-
if (typeof window === 'undefined' || !navigator?.clipboard?.writeText) {
|
|
163
|
-
onError?.(new Error('Clipboard API not available'));
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
try {
|
|
168
|
-
await navigator.clipboard.writeText(code);
|
|
169
|
-
setIsCopied(true);
|
|
170
|
-
onCopy?.();
|
|
171
|
-
setTimeout(() => {
|
|
172
|
-
setIsCopied(false);
|
|
173
|
-
}, timeout);
|
|
174
|
-
} catch (err) {
|
|
175
|
-
onError?.(err);
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
return (
|
|
180
|
-
<button
|
|
181
|
-
ref={ref}
|
|
182
|
-
type="button"
|
|
183
|
-
onClick={handleCopy}
|
|
184
|
-
className={cn(
|
|
185
|
-
'inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 hover:bg-accent hover:text-accent-foreground h-8 w-8 shrink-0 text-muted-foreground hover:text-foreground',
|
|
186
|
-
className
|
|
187
|
-
)}
|
|
188
|
-
{...props}
|
|
189
|
-
>
|
|
190
|
-
{children ? (
|
|
191
|
-
children
|
|
192
|
-
) : isCopied ? (
|
|
193
|
-
<Check className="h-4 w-4 text-emerald-500" />
|
|
194
|
-
) : (
|
|
195
|
-
<Copy className="h-4 w-4" />
|
|
196
|
-
)}
|
|
197
|
-
</button>
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
);
|
|
201
|
-
CodeBlockCopyButton.displayName = 'CodeBlockCopyButton';
|
|
202
|
-
|
|
203
|
-
export default ShadcnCodeBlock;
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { cn } from '@surreal-ui/core';
|
|
3
|
-
|
|
4
|
-
interface CollapsibleContextValue {
|
|
5
|
-
open: boolean;
|
|
6
|
-
onOpenChange: (open: boolean) => void;
|
|
7
|
-
disabled?: boolean;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const CollapsibleContext = React.createContext<CollapsibleContextValue | null>(null);
|
|
11
|
-
|
|
12
|
-
function useCollapsible() {
|
|
13
|
-
const context = React.useContext(CollapsibleContext);
|
|
14
|
-
if (!context) {
|
|
15
|
-
throw new Error('Collapsible compound components must be used within a Collapsible');
|
|
16
|
-
}
|
|
17
|
-
return context;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface ShadcnCollapsibleProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
21
|
-
open?: boolean;
|
|
22
|
-
defaultOpen?: boolean;
|
|
23
|
-
onOpenChange?: (open: boolean) => void;
|
|
24
|
-
disabled?: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function ShadcnCollapsible({
|
|
28
|
-
open: controlledOpen,
|
|
29
|
-
defaultOpen = false,
|
|
30
|
-
onOpenChange,
|
|
31
|
-
disabled = false,
|
|
32
|
-
className,
|
|
33
|
-
children,
|
|
34
|
-
...props
|
|
35
|
-
}: CollapsibleProps) {
|
|
36
|
-
const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen);
|
|
37
|
-
const isControlled = controlledOpen !== undefined;
|
|
38
|
-
const open = isControlled ? controlledOpen : uncontrolledOpen;
|
|
39
|
-
|
|
40
|
-
const handleOpenChange = React.useCallback(
|
|
41
|
-
(nextOpen: boolean) => {
|
|
42
|
-
if (!isControlled) {
|
|
43
|
-
setUncontrolledOpen(nextOpen);
|
|
44
|
-
}
|
|
45
|
-
onOpenChange?.(nextOpen);
|
|
46
|
-
},
|
|
47
|
-
[isControlled, onOpenChange]
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
return (
|
|
51
|
-
<CollapsibleContext.Provider value={{ open, onOpenChange: handleOpenChange, disabled }}>
|
|
52
|
-
<div
|
|
53
|
-
data-slot="collapsible"
|
|
54
|
-
data-state={open ? 'open' : 'closed'}
|
|
55
|
-
data-disabled={disabled ? '' : undefined}
|
|
56
|
-
className={cn(className)}
|
|
57
|
-
{...props}
|
|
58
|
-
>
|
|
59
|
-
{children}
|
|
60
|
-
</div>
|
|
61
|
-
</CollapsibleContext.Provider>
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface ShadcnCollapsibleTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
66
|
-
asChild?: boolean;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function ShadcnCollapsibleTrigger({
|
|
70
|
-
className,
|
|
71
|
-
onClick,
|
|
72
|
-
children,
|
|
73
|
-
...props
|
|
74
|
-
}: CollapsibleTriggerProps) {
|
|
75
|
-
const { open, onOpenChange, disabled } = useCollapsible();
|
|
76
|
-
|
|
77
|
-
return (
|
|
78
|
-
<button
|
|
79
|
-
type="button"
|
|
80
|
-
data-slot="collapsible-trigger"
|
|
81
|
-
data-state={open ? 'open' : 'closed'}
|
|
82
|
-
data-disabled={disabled ? '' : undefined}
|
|
83
|
-
aria-expanded={open}
|
|
84
|
-
disabled={disabled}
|
|
85
|
-
onClick={(e) => {
|
|
86
|
-
onClick?.(e);
|
|
87
|
-
if (!e.defaultPrevented && !disabled) {
|
|
88
|
-
onOpenChange(!open);
|
|
89
|
-
}
|
|
90
|
-
}}
|
|
91
|
-
className={cn(
|
|
92
|
-
'flex items-center justify-between font-medium transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
|
|
93
|
-
className
|
|
94
|
-
)}
|
|
95
|
-
{...props}
|
|
96
|
-
>
|
|
97
|
-
{children}
|
|
98
|
-
</button>
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export interface ShadcnCollapsibleContentProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
103
|
-
forceMount?: boolean;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function ShadcnCollapsibleContent({
|
|
107
|
-
className,
|
|
108
|
-
children,
|
|
109
|
-
forceMount = false,
|
|
110
|
-
...props
|
|
111
|
-
}: CollapsibleContentProps) {
|
|
112
|
-
const { open, disabled } = useCollapsible();
|
|
113
|
-
|
|
114
|
-
if (!open && !forceMount) {
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return (
|
|
119
|
-
<div
|
|
120
|
-
data-slot="collapsible-content"
|
|
121
|
-
data-state={open ? 'open' : 'closed'}
|
|
122
|
-
data-disabled={disabled ? '' : undefined}
|
|
123
|
-
hidden={!open && forceMount}
|
|
124
|
-
className={cn('overflow-hidden transition-all', className)}
|
|
125
|
-
{...props}
|
|
126
|
-
>
|
|
127
|
-
{children}
|
|
128
|
-
</div>
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export { ShadcnCollapsible as Root, CollapsibleTrigger as Trigger, CollapsibleContent as Content };
|
|
133
|
-
|
|
134
|
-
export default ShadcnCollapsible;
|
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
import { Search, Check } from 'lucide-react';
|
|
4
|
-
import { cn } from '@surreal-ui/core';
|
|
5
|
-
|
|
6
|
-
interface CommandContextValue {
|
|
7
|
-
search: string;
|
|
8
|
-
setSearch: (query: string) => void;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const CommandContext = React.createContext<CommandContextValue | null>(null);
|
|
12
|
-
|
|
13
|
-
export function useCommand() {
|
|
14
|
-
const context = React.useContext(CommandContext);
|
|
15
|
-
if (!context) {
|
|
16
|
-
throw new Error('Command subcomponents must be used within a <Command /> root');
|
|
17
|
-
}
|
|
18
|
-
return context;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface ShadcnCommandProps extends React.ComponentProps<'div'> {
|
|
22
|
-
value?: string;
|
|
23
|
-
onValueChange?: (value: string) => void;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const ShadcnCommand = React.forwardRef<HTMLDivElement, CommandProps>(
|
|
27
|
-
({ className, children, value, onValueChange, ...props }, ref) => {
|
|
28
|
-
const [search, setSearch] = React.useState(value ?? '');
|
|
29
|
-
|
|
30
|
-
const handleSearch = React.useCallback(
|
|
31
|
-
(val: string) => {
|
|
32
|
-
setSearch(val);
|
|
33
|
-
onValueChange?.(val);
|
|
34
|
-
},
|
|
35
|
-
[onValueChange]
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
<CommandContext.Provider value={{ search, setSearch: handleSearch }}>
|
|
40
|
-
<div
|
|
41
|
-
ref={ref}
|
|
42
|
-
data-slot="command"
|
|
43
|
-
className={cn(
|
|
44
|
-
'rounded-xl bg-popover p-1 text-popover-foreground flex size-full flex-col overflow-hidden border border-border shadow-md',
|
|
45
|
-
className
|
|
46
|
-
)}
|
|
47
|
-
{...props}
|
|
48
|
-
>
|
|
49
|
-
{children}
|
|
50
|
-
</div>
|
|
51
|
-
</CommandContext.Provider>
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
);
|
|
55
|
-
Command.displayName = 'Command';
|
|
56
|
-
|
|
57
|
-
export interface CommandDialogProps extends React.ComponentProps<'div'> {
|
|
58
|
-
open?: boolean;
|
|
59
|
-
onOpenChange?: (open: boolean) => void;
|
|
60
|
-
title?: string;
|
|
61
|
-
description?: string;
|
|
62
|
-
showCloseButton?: boolean;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export const CommandDialog = React.forwardRef<HTMLDivElement, CommandDialogProps>(
|
|
66
|
-
(
|
|
67
|
-
{
|
|
68
|
-
open = false,
|
|
69
|
-
onOpenChange,
|
|
70
|
-
title = 'Command Palette',
|
|
71
|
-
description = 'Search for a command to run...',
|
|
72
|
-
showCloseButton = false,
|
|
73
|
-
className,
|
|
74
|
-
children,
|
|
75
|
-
...props
|
|
76
|
-
},
|
|
77
|
-
ref
|
|
78
|
-
) => {
|
|
79
|
-
if (!open) return null;
|
|
80
|
-
|
|
81
|
-
return (
|
|
82
|
-
<div
|
|
83
|
-
className="fixed inset-0 z-50 bg-black/80 backdrop-blur-xs flex items-center justify-center p-4"
|
|
84
|
-
onClick={() => onOpenChange?.(false)}
|
|
85
|
-
>
|
|
86
|
-
<div
|
|
87
|
-
ref={ref}
|
|
88
|
-
role="dialog"
|
|
89
|
-
aria-modal="true"
|
|
90
|
-
aria-label={title}
|
|
91
|
-
aria-description={description}
|
|
92
|
-
onClick={(e) => e.stopPropagation()}
|
|
93
|
-
className={cn(
|
|
94
|
-
'bg-popover text-popover-foreground rounded-xl border border-border shadow-2xl w-full max-w-lg overflow-hidden animate-in fade-in-0 zoom-in-95',
|
|
95
|
-
className
|
|
96
|
-
)}
|
|
97
|
-
{...props}
|
|
98
|
-
>
|
|
99
|
-
<div className="sr-only">
|
|
100
|
-
<h2>{title}</h2>
|
|
101
|
-
<p>{description}</p>
|
|
102
|
-
</div>
|
|
103
|
-
<Command>{children}</Command>
|
|
104
|
-
</div>
|
|
105
|
-
</div>
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
);
|
|
109
|
-
CommandDialog.displayName = 'CommandDialog';
|
|
110
|
-
|
|
111
|
-
export interface ShadcnCommandInputProps extends React.ComponentProps<'input'> {}
|
|
112
|
-
|
|
113
|
-
export const ShadcnCommandInput = React.forwardRef<HTMLInputElement, CommandInputProps>(
|
|
114
|
-
({ className, value, onChange, placeholder = 'Type a command or search...', ...props }, ref) => {
|
|
115
|
-
const { search, setSearch } = useCommand();
|
|
116
|
-
|
|
117
|
-
return (
|
|
118
|
-
<div data-slot="command-input-wrapper" className="p-2 pb-1 border-b border-border">
|
|
119
|
-
<div className="flex h-9 items-center gap-2 rounded-lg border border-input/30 bg-input/20 px-3 shadow-none text-sm ring-offset-background focus-within:ring-1 focus-within:ring-ring">
|
|
120
|
-
<Search className="size-4 shrink-0 opacity-50" />
|
|
121
|
-
<input
|
|
122
|
-
ref={ref}
|
|
123
|
-
data-slot="command-input"
|
|
124
|
-
value={value !== undefined ? value : search}
|
|
125
|
-
onChange={(e) => {
|
|
126
|
-
setSearch(e.target.value);
|
|
127
|
-
onChange?.(e);
|
|
128
|
-
}}
|
|
129
|
-
placeholder={placeholder}
|
|
130
|
-
className={cn(
|
|
131
|
-
'flex h-full w-full bg-transparent text-sm outline-hidden placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50',
|
|
132
|
-
className
|
|
133
|
-
)}
|
|
134
|
-
{...props}
|
|
135
|
-
/>
|
|
136
|
-
</div>
|
|
137
|
-
</div>
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
);
|
|
141
|
-
CommandInput.displayName = 'CommandInput';
|
|
142
|
-
|
|
143
|
-
export interface ShadcnCommandListProps extends React.ComponentProps<'div'> {}
|
|
144
|
-
|
|
145
|
-
export const ShadcnCommandList = React.forwardRef<HTMLDivElement, CommandListProps>(
|
|
146
|
-
({ className, children, ...props }, ref) => {
|
|
147
|
-
return (
|
|
148
|
-
<div
|
|
149
|
-
ref={ref}
|
|
150
|
-
data-slot="command-list"
|
|
151
|
-
className={cn(
|
|
152
|
-
'max-h-72 scroll-py-1 overflow-x-hidden overflow-y-auto p-1 outline-none',
|
|
153
|
-
className
|
|
154
|
-
)}
|
|
155
|
-
{...props}
|
|
156
|
-
>
|
|
157
|
-
{children}
|
|
158
|
-
</div>
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
);
|
|
162
|
-
CommandList.displayName = 'CommandList';
|
|
163
|
-
|
|
164
|
-
export interface CommandEmptyProps extends React.ComponentProps<'div'> {}
|
|
165
|
-
|
|
166
|
-
export const CommandEmpty = React.forwardRef<HTMLDivElement, CommandEmptyProps>(
|
|
167
|
-
({ className, children, ...props }, ref) => {
|
|
168
|
-
return (
|
|
169
|
-
<div
|
|
170
|
-
ref={ref}
|
|
171
|
-
data-slot="command-empty"
|
|
172
|
-
className={cn('py-6 text-center text-sm text-muted-foreground', className)}
|
|
173
|
-
{...props}
|
|
174
|
-
>
|
|
175
|
-
{children}
|
|
176
|
-
</div>
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
);
|
|
180
|
-
CommandEmpty.displayName = 'CommandEmpty';
|
|
181
|
-
|
|
182
|
-
export interface ShadcnCommandGroupProps extends React.ComponentProps<'div'> {
|
|
183
|
-
heading?: React.ReactNode;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export const ShadcnCommandGroup = React.forwardRef<HTMLDivElement, CommandGroupProps>(
|
|
187
|
-
({ className, heading, children, ...props }, ref) => {
|
|
188
|
-
return (
|
|
189
|
-
<div
|
|
190
|
-
ref={ref}
|
|
191
|
-
data-slot="command-group"
|
|
192
|
-
role="group"
|
|
193
|
-
className={cn('overflow-hidden p-1 text-foreground', className)}
|
|
194
|
-
{...props}
|
|
195
|
-
>
|
|
196
|
-
{heading && (
|
|
197
|
-
<div
|
|
198
|
-
data-slot="command-group-heading"
|
|
199
|
-
className="px-2 py-1.5 text-xs font-medium text-muted-foreground"
|
|
200
|
-
>
|
|
201
|
-
{heading}
|
|
202
|
-
</div>
|
|
203
|
-
)}
|
|
204
|
-
{children}
|
|
205
|
-
</div>
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
);
|
|
209
|
-
CommandGroup.displayName = 'CommandGroup';
|
|
210
|
-
|
|
211
|
-
export interface ShadcnCommandItemProps extends React.ComponentProps<'div'> {
|
|
212
|
-
value?: string;
|
|
213
|
-
selected?: boolean;
|
|
214
|
-
checked?: boolean;
|
|
215
|
-
disabled?: boolean;
|
|
216
|
-
onSelect?: (value: string) => void;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export const ShadcnCommandItem = React.forwardRef<HTMLDivElement, CommandItemProps>(
|
|
220
|
-
(
|
|
221
|
-
{
|
|
222
|
-
className,
|
|
223
|
-
value = '',
|
|
224
|
-
selected = false,
|
|
225
|
-
checked = false,
|
|
226
|
-
disabled = false,
|
|
227
|
-
onSelect,
|
|
228
|
-
children,
|
|
229
|
-
onClick,
|
|
230
|
-
...props
|
|
231
|
-
},
|
|
232
|
-
ref
|
|
233
|
-
) => {
|
|
234
|
-
return (
|
|
235
|
-
<div
|
|
236
|
-
ref={ref}
|
|
237
|
-
role="option"
|
|
238
|
-
aria-selected={selected}
|
|
239
|
-
aria-disabled={disabled}
|
|
240
|
-
data-slot="command-item"
|
|
241
|
-
data-selected={selected ? 'true' : undefined}
|
|
242
|
-
data-checked={checked ? 'true' : undefined}
|
|
243
|
-
data-disabled={disabled ? 'true' : undefined}
|
|
244
|
-
onClick={(e) => {
|
|
245
|
-
if (disabled) return;
|
|
246
|
-
onSelect?.(value);
|
|
247
|
-
onClick?.(e);
|
|
248
|
-
}}
|
|
249
|
-
className={cn(
|
|
250
|
-
"group/command-item relative flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 data-[selected=true]:bg-muted data-[selected=true]:text-foreground hover:bg-muted hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
251
|
-
className
|
|
252
|
-
)}
|
|
253
|
-
{...props}
|
|
254
|
-
>
|
|
255
|
-
{children}
|
|
256
|
-
{checked && <Check className="ml-auto size-4 shrink-0 text-foreground" />}
|
|
257
|
-
</div>
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
);
|
|
261
|
-
CommandItem.displayName = 'CommandItem';
|
|
262
|
-
|
|
263
|
-
export interface CommandLinkItemProps extends React.ComponentProps<'a'> {
|
|
264
|
-
disabled?: boolean;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
export const CommandLinkItem = React.forwardRef<HTMLAnchorElement, CommandLinkItemProps>(
|
|
268
|
-
({ className, disabled = false, children, ...props }, ref) => {
|
|
269
|
-
return (
|
|
270
|
-
<a
|
|
271
|
-
ref={ref}
|
|
272
|
-
data-slot="command-link-item"
|
|
273
|
-
aria-disabled={disabled}
|
|
274
|
-
data-disabled={disabled ? 'true' : undefined}
|
|
275
|
-
className={cn(
|
|
276
|
-
"relative flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 hover:bg-accent hover:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",
|
|
277
|
-
className
|
|
278
|
-
)}
|
|
279
|
-
{...props}
|
|
280
|
-
>
|
|
281
|
-
{children}
|
|
282
|
-
</a>
|
|
283
|
-
);
|
|
284
|
-
}
|
|
285
|
-
);
|
|
286
|
-
CommandLinkItem.displayName = 'CommandLinkItem';
|
|
287
|
-
|
|
288
|
-
export interface ShadcnCommandSeparatorProps extends React.ComponentProps<'div'> {}
|
|
289
|
-
|
|
290
|
-
export const ShadcnCommandSeparator = React.forwardRef<HTMLDivElement, CommandSeparatorProps>(
|
|
291
|
-
({ className, ...props }, ref) => {
|
|
292
|
-
return (
|
|
293
|
-
<div
|
|
294
|
-
ref={ref}
|
|
295
|
-
data-slot="command-separator"
|
|
296
|
-
role="separator"
|
|
297
|
-
className={cn('-mx-1 my-1 h-px bg-border', className)}
|
|
298
|
-
{...props}
|
|
299
|
-
/>
|
|
300
|
-
);
|
|
301
|
-
}
|
|
302
|
-
);
|
|
303
|
-
CommandSeparator.displayName = 'CommandSeparator';
|
|
304
|
-
|
|
305
|
-
export interface ShadcnCommandShortcutProps extends React.ComponentProps<'span'> {}
|
|
306
|
-
|
|
307
|
-
export const ShadcnCommandShortcut = React.forwardRef<HTMLSpanElement, CommandShortcutProps>(
|
|
308
|
-
({ className, children, ...props }, ref) => {
|
|
309
|
-
return (
|
|
310
|
-
<span
|
|
311
|
-
ref={ref}
|
|
312
|
-
data-slot="command-shortcut"
|
|
313
|
-
className={cn(
|
|
314
|
-
'ml-auto text-xs tracking-widest text-muted-foreground group-data-[selected=true]/command-item:text-foreground',
|
|
315
|
-
className
|
|
316
|
-
)}
|
|
317
|
-
{...props}
|
|
318
|
-
>
|
|
319
|
-
{children}
|
|
320
|
-
</span>
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
);
|
|
324
|
-
CommandShortcut.displayName = 'CommandShortcut';
|
|
325
|
-
|
|
326
|
-
export interface CommandLoadingProps extends React.ComponentProps<'div'> {}
|
|
327
|
-
|
|
328
|
-
export const CommandLoading = React.forwardRef<HTMLDivElement, CommandLoadingProps>(
|
|
329
|
-
({ className, children, ...props }, ref) => {
|
|
330
|
-
return (
|
|
331
|
-
<div
|
|
332
|
-
ref={ref}
|
|
333
|
-
data-slot="command-loading"
|
|
334
|
-
className={cn('py-6 text-center text-sm text-muted-foreground', className)}
|
|
335
|
-
{...props}
|
|
336
|
-
>
|
|
337
|
-
{children}
|
|
338
|
-
</div>
|
|
339
|
-
);
|
|
340
|
-
}
|
|
341
|
-
);
|
|
342
|
-
CommandLoading.displayName = 'CommandLoading';
|
|
343
|
-
|
|
344
|
-
export default ShadcnCommand;
|