@djangocfg/ui-core 1.0.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/README.md +135 -0
- package/package.json +111 -0
- package/src/components/accordion.tsx +56 -0
- package/src/components/alert-dialog.tsx +142 -0
- package/src/components/alert.tsx +59 -0
- package/src/components/aspect-ratio.tsx +7 -0
- package/src/components/avatar.tsx +50 -0
- package/src/components/badge.tsx +36 -0
- package/src/components/button-group.tsx +85 -0
- package/src/components/button.tsx +111 -0
- package/src/components/calendar.tsx +213 -0
- package/src/components/card.tsx +76 -0
- package/src/components/carousel.tsx +261 -0
- package/src/components/chart.tsx +369 -0
- package/src/components/checkbox.tsx +29 -0
- package/src/components/collapsible.tsx +11 -0
- package/src/components/combobox.tsx +182 -0
- package/src/components/command.tsx +170 -0
- package/src/components/context-menu.tsx +200 -0
- package/src/components/copy.tsx +144 -0
- package/src/components/dialog.tsx +122 -0
- package/src/components/drawer.tsx +137 -0
- package/src/components/empty.tsx +104 -0
- package/src/components/field.tsx +244 -0
- package/src/components/form.tsx +178 -0
- package/src/components/hover-card.tsx +29 -0
- package/src/components/image-with-fallback.tsx +170 -0
- package/src/components/index.ts +86 -0
- package/src/components/input-group.tsx +170 -0
- package/src/components/input-otp.tsx +81 -0
- package/src/components/input.tsx +22 -0
- package/src/components/item.tsx +195 -0
- package/src/components/kbd.tsx +28 -0
- package/src/components/label.tsx +26 -0
- package/src/components/multi-select.tsx +222 -0
- package/src/components/og-image.tsx +47 -0
- package/src/components/popover.tsx +33 -0
- package/src/components/portal.tsx +106 -0
- package/src/components/preloader.tsx +250 -0
- package/src/components/progress.tsx +28 -0
- package/src/components/radio-group.tsx +43 -0
- package/src/components/resizable.tsx +111 -0
- package/src/components/scroll-area.tsx +102 -0
- package/src/components/section.tsx +58 -0
- package/src/components/select.tsx +158 -0
- package/src/components/separator.tsx +31 -0
- package/src/components/sheet.tsx +140 -0
- package/src/components/skeleton.tsx +15 -0
- package/src/components/slider.tsx +28 -0
- package/src/components/spinner.tsx +16 -0
- package/src/components/sticky.tsx +117 -0
- package/src/components/switch.tsx +29 -0
- package/src/components/table.tsx +120 -0
- package/src/components/tabs.tsx +238 -0
- package/src/components/textarea.tsx +22 -0
- package/src/components/toast.tsx +129 -0
- package/src/components/toaster.tsx +41 -0
- package/src/components/toggle-group.tsx +61 -0
- package/src/components/toggle.tsx +45 -0
- package/src/components/token-icon.tsx +156 -0
- package/src/components/tooltip-provider-safe.tsx +43 -0
- package/src/components/tooltip.tsx +32 -0
- package/src/hooks/index.ts +15 -0
- package/src/hooks/useCopy.ts +41 -0
- package/src/hooks/useCountdown.ts +73 -0
- package/src/hooks/useDebounce.ts +25 -0
- package/src/hooks/useDebouncedCallback.ts +58 -0
- package/src/hooks/useDebugTools.ts +52 -0
- package/src/hooks/useEventsBus.ts +53 -0
- package/src/hooks/useImageLoader.ts +95 -0
- package/src/hooks/useMediaQuery.ts +40 -0
- package/src/hooks/useMobile.tsx +22 -0
- package/src/hooks/useToast.ts +194 -0
- package/src/index.ts +14 -0
- package/src/lib/index.ts +2 -0
- package/src/lib/og-image.ts +151 -0
- package/src/lib/utils.ts +6 -0
- package/src/styles/base.css +20 -0
- package/src/styles/globals.css +12 -0
- package/src/styles/index.css +25 -0
- package/src/styles/sources.css +11 -0
- package/src/styles/theme/animations.css +65 -0
- package/src/styles/theme/dark.css +49 -0
- package/src/styles/theme/light.css +50 -0
- package/src/styles/theme/tokens.css +134 -0
- package/src/styles/theme.css +22 -0
- package/src/styles/utilities.css +187 -0
- package/src/types/index.ts +0 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import * as TabsPrimitive from "@radix-ui/react-tabs"
|
|
5
|
+
import { Menu } from "lucide-react"
|
|
6
|
+
|
|
7
|
+
import { cn } from "../lib/utils"
|
|
8
|
+
import { useIsMobile } from "../hooks"
|
|
9
|
+
import {
|
|
10
|
+
Sheet,
|
|
11
|
+
SheetContent,
|
|
12
|
+
SheetHeader,
|
|
13
|
+
SheetTitle,
|
|
14
|
+
SheetTrigger,
|
|
15
|
+
} from "./sheet"
|
|
16
|
+
import { Button } from "./button"
|
|
17
|
+
import { ScrollArea, ScrollBar } from "./scroll-area"
|
|
18
|
+
|
|
19
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
20
|
+
// Tabs Root with Mobile Sheet Support
|
|
21
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
interface TabsProps extends React.ComponentPropsWithoutRef<typeof TabsPrimitive.Root> {
|
|
24
|
+
/**
|
|
25
|
+
* Enable mobile sheet mode (automatically shows Sheet on mobile devices)
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
mobileSheet?: boolean
|
|
29
|
+
/**
|
|
30
|
+
* Title for mobile sheet header
|
|
31
|
+
* @default "Navigation"
|
|
32
|
+
*/
|
|
33
|
+
mobileSheetTitle?: string
|
|
34
|
+
/**
|
|
35
|
+
* Title to display next to burger menu on mobile
|
|
36
|
+
*/
|
|
37
|
+
mobileTitleText?: string
|
|
38
|
+
/**
|
|
39
|
+
* Enable sticky positioning (stays at top on scroll)
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
sticky?: boolean
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const Tabs = React.forwardRef<
|
|
46
|
+
React.ElementRef<typeof TabsPrimitive.Root>,
|
|
47
|
+
TabsProps
|
|
48
|
+
>(({ mobileSheet = false, mobileSheetTitle = "Navigation", mobileTitleText, sticky = false, children, ...props }, ref) => {
|
|
49
|
+
const isMobile = useIsMobile()
|
|
50
|
+
const [open, setOpen] = React.useState(false)
|
|
51
|
+
|
|
52
|
+
// If mobile sheet mode is disabled, render normal tabs
|
|
53
|
+
if (!mobileSheet || !isMobile) {
|
|
54
|
+
// If sticky is enabled for desktop, wrap TabsList in sticky container
|
|
55
|
+
if (sticky) {
|
|
56
|
+
const childrenArray = React.Children.toArray(children)
|
|
57
|
+
const tabsList = childrenArray.find(
|
|
58
|
+
(child) => React.isValidElement(child) && child.type === TabsList
|
|
59
|
+
)
|
|
60
|
+
const tabsContent = childrenArray.filter(
|
|
61
|
+
(child) => React.isValidElement(child) && child.type === TabsContent
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<TabsPrimitive.Root ref={ref} {...props}>
|
|
66
|
+
<div className="sticky top-0 z-40 w-full border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 mb-4">
|
|
67
|
+
{tabsList}
|
|
68
|
+
</div>
|
|
69
|
+
{tabsContent}
|
|
70
|
+
</TabsPrimitive.Root>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<TabsPrimitive.Root ref={ref} {...props}>
|
|
76
|
+
{children}
|
|
77
|
+
</TabsPrimitive.Root>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Extract TabsList and TabsContent from children
|
|
82
|
+
const childrenArray = React.Children.toArray(children)
|
|
83
|
+
const tabsList = childrenArray.find(
|
|
84
|
+
(child) => React.isValidElement(child) && child.type === TabsList
|
|
85
|
+
)
|
|
86
|
+
const tabsContent = childrenArray.filter(
|
|
87
|
+
(child) => React.isValidElement(child) && child.type === TabsContent
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
// Extract triggers from TabsList children
|
|
91
|
+
const triggers = React.isValidElement(tabsList)
|
|
92
|
+
? React.Children.toArray((tabsList.props as any).children)
|
|
93
|
+
: []
|
|
94
|
+
|
|
95
|
+
// Mobile Sheet Navigation
|
|
96
|
+
return (
|
|
97
|
+
<TabsPrimitive.Root ref={ref} {...props}>
|
|
98
|
+
<div className={cn(
|
|
99
|
+
"w-full border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 mb-4",
|
|
100
|
+
sticky && "sticky top-0 z-40"
|
|
101
|
+
)}>
|
|
102
|
+
<div className="container mx-auto flex items-center justify-between h-14 px-4">
|
|
103
|
+
{/* Title */}
|
|
104
|
+
{mobileTitleText && (
|
|
105
|
+
<h1 className="text-lg font-semibold">{mobileTitleText}</h1>
|
|
106
|
+
)}
|
|
107
|
+
|
|
108
|
+
{/* Menu Button */}
|
|
109
|
+
<Sheet open={open} onOpenChange={setOpen}>
|
|
110
|
+
<SheetTrigger asChild>
|
|
111
|
+
<Button variant="ghost" size="icon" className={mobileTitleText ? "" : "ml-auto"}>
|
|
112
|
+
<Menu className="h-5 w-5" />
|
|
113
|
+
</Button>
|
|
114
|
+
</SheetTrigger>
|
|
115
|
+
<SheetContent side="right" className="w-[280px] sm:w-[350px]">
|
|
116
|
+
<SheetHeader>
|
|
117
|
+
<SheetTitle>{mobileSheetTitle}</SheetTitle>
|
|
118
|
+
</SheetHeader>
|
|
119
|
+
<nav className="flex flex-col gap-2 mt-6">
|
|
120
|
+
<TabsPrimitive.List className="flex flex-col gap-2">
|
|
121
|
+
{triggers.map((trigger, index) => {
|
|
122
|
+
if (!React.isValidElement(trigger)) return null
|
|
123
|
+
|
|
124
|
+
// Clone trigger and wrap in mobile-friendly container
|
|
125
|
+
const triggerProps = (trigger as any).props || {};
|
|
126
|
+
return React.cloneElement(trigger as React.ReactElement, {
|
|
127
|
+
key: index,
|
|
128
|
+
onClick: (e: React.MouseEvent) => {
|
|
129
|
+
setOpen(false)
|
|
130
|
+
triggerProps.onClick?.(e)
|
|
131
|
+
},
|
|
132
|
+
className: cn(
|
|
133
|
+
"flex items-center gap-3 px-3 py-2 rounded-md transition-colors justify-start w-full",
|
|
134
|
+
"data-[state=active]:bg-primary data-[state=active]:text-primary-foreground",
|
|
135
|
+
"hover:bg-muted",
|
|
136
|
+
triggerProps.className
|
|
137
|
+
),
|
|
138
|
+
} as any)
|
|
139
|
+
})}
|
|
140
|
+
</TabsPrimitive.List>
|
|
141
|
+
</nav>
|
|
142
|
+
</SheetContent>
|
|
143
|
+
</Sheet>
|
|
144
|
+
</div>
|
|
145
|
+
</div>
|
|
146
|
+
{tabsContent}
|
|
147
|
+
</TabsPrimitive.Root>
|
|
148
|
+
)
|
|
149
|
+
})
|
|
150
|
+
Tabs.displayName = "Tabs"
|
|
151
|
+
|
|
152
|
+
const TabsList = React.forwardRef<
|
|
153
|
+
React.ElementRef<typeof TabsPrimitive.List>,
|
|
154
|
+
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List> & {
|
|
155
|
+
/**
|
|
156
|
+
* Full width mode - tabs will stretch equally to fill the container
|
|
157
|
+
* @default false
|
|
158
|
+
*/
|
|
159
|
+
fullWidth?: boolean
|
|
160
|
+
/**
|
|
161
|
+
* Enable horizontal scrolling when tabs overflow
|
|
162
|
+
* @default false
|
|
163
|
+
*/
|
|
164
|
+
scrollable?: boolean
|
|
165
|
+
}
|
|
166
|
+
>(({ className, fullWidth = false, scrollable = false, ...props }, ref) => {
|
|
167
|
+
// If scrollable mode is enabled, wrap in ScrollArea
|
|
168
|
+
if (scrollable) {
|
|
169
|
+
return (
|
|
170
|
+
<ScrollArea className="w-full whitespace-nowrap rounded-lg">
|
|
171
|
+
<TabsPrimitive.List
|
|
172
|
+
ref={ref}
|
|
173
|
+
className={cn(
|
|
174
|
+
"inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",
|
|
175
|
+
fullWidth && "w-full flex",
|
|
176
|
+
className
|
|
177
|
+
)}
|
|
178
|
+
{...props}
|
|
179
|
+
/>
|
|
180
|
+
<ScrollBar orientation="horizontal" />
|
|
181
|
+
</ScrollArea>
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Default mode without scrolling
|
|
186
|
+
return (
|
|
187
|
+
<TabsPrimitive.List
|
|
188
|
+
ref={ref}
|
|
189
|
+
className={cn(
|
|
190
|
+
"inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",
|
|
191
|
+
fullWidth && "w-full flex",
|
|
192
|
+
className
|
|
193
|
+
)}
|
|
194
|
+
{...props}
|
|
195
|
+
/>
|
|
196
|
+
)
|
|
197
|
+
})
|
|
198
|
+
TabsList.displayName = TabsPrimitive.List.displayName
|
|
199
|
+
|
|
200
|
+
const TabsTrigger = React.forwardRef<
|
|
201
|
+
React.ElementRef<typeof TabsPrimitive.Trigger>,
|
|
202
|
+
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger> & {
|
|
203
|
+
/**
|
|
204
|
+
* Makes the trigger take equal space (use with fullWidth TabsList)
|
|
205
|
+
* @default false
|
|
206
|
+
*/
|
|
207
|
+
flexEqual?: boolean
|
|
208
|
+
key?: React.Key
|
|
209
|
+
}
|
|
210
|
+
>(({ className, flexEqual = false, ...props }, ref) => (
|
|
211
|
+
<TabsPrimitive.Trigger
|
|
212
|
+
ref={ref}
|
|
213
|
+
className={cn(
|
|
214
|
+
"inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background 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 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow",
|
|
215
|
+
flexEqual && "flex-1",
|
|
216
|
+
className
|
|
217
|
+
)}
|
|
218
|
+
{...props}
|
|
219
|
+
/>
|
|
220
|
+
))
|
|
221
|
+
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName
|
|
222
|
+
|
|
223
|
+
const TabsContent = React.forwardRef<
|
|
224
|
+
React.ElementRef<typeof TabsPrimitive.Content>,
|
|
225
|
+
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content> & { key?: React.Key }
|
|
226
|
+
>(({ className, ...props }, ref) => (
|
|
227
|
+
<TabsPrimitive.Content
|
|
228
|
+
ref={ref}
|
|
229
|
+
className={cn(
|
|
230
|
+
"mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
|
|
231
|
+
className
|
|
232
|
+
)}
|
|
233
|
+
{...props}
|
|
234
|
+
/>
|
|
235
|
+
))
|
|
236
|
+
TabsContent.displayName = TabsPrimitive.Content.displayName
|
|
237
|
+
|
|
238
|
+
export { Tabs, TabsList, TabsTrigger, TabsContent }
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
import { cn } from "../lib/utils"
|
|
4
|
+
|
|
5
|
+
const Textarea = React.forwardRef<
|
|
6
|
+
HTMLTextAreaElement,
|
|
7
|
+
React.ComponentProps<"textarea">
|
|
8
|
+
>(({ className, ...props }, ref) => {
|
|
9
|
+
return (
|
|
10
|
+
<textarea
|
|
11
|
+
className={cn(
|
|
12
|
+
"flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
|
|
13
|
+
className
|
|
14
|
+
)}
|
|
15
|
+
ref={ref}
|
|
16
|
+
{...props}
|
|
17
|
+
/>
|
|
18
|
+
)
|
|
19
|
+
})
|
|
20
|
+
Textarea.displayName = "Textarea"
|
|
21
|
+
|
|
22
|
+
export { Textarea }
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
4
|
+
import { X } from 'lucide-react';
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
|
|
7
|
+
import { cn } from '../lib/utils';
|
|
8
|
+
import * as ToastPrimitives from '@radix-ui/react-toast';
|
|
9
|
+
|
|
10
|
+
const ToastProvider = ToastPrimitives.Provider
|
|
11
|
+
|
|
12
|
+
const ToastViewport = React.forwardRef<
|
|
13
|
+
React.ElementRef<typeof ToastPrimitives.Viewport>,
|
|
14
|
+
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
|
|
15
|
+
>(({ className, ...props }, ref) => (
|
|
16
|
+
<ToastPrimitives.Viewport
|
|
17
|
+
ref={ref}
|
|
18
|
+
className={cn(
|
|
19
|
+
"fixed top-0 z-9999 flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-md",
|
|
20
|
+
className
|
|
21
|
+
)}
|
|
22
|
+
{...props}
|
|
23
|
+
/>
|
|
24
|
+
))
|
|
25
|
+
ToastViewport.displayName = ToastPrimitives.Viewport.displayName
|
|
26
|
+
|
|
27
|
+
const toastVariants = cva(
|
|
28
|
+
"group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",
|
|
29
|
+
{
|
|
30
|
+
variants: {
|
|
31
|
+
variant: {
|
|
32
|
+
default: "border bg-background text-foreground",
|
|
33
|
+
destructive:
|
|
34
|
+
"destructive group border-destructive bg-destructive text-destructive-foreground",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
defaultVariants: {
|
|
38
|
+
variant: "default",
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
const Toast = React.forwardRef<
|
|
44
|
+
React.ElementRef<typeof ToastPrimitives.Root>,
|
|
45
|
+
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
|
|
46
|
+
VariantProps<typeof toastVariants>
|
|
47
|
+
>(({ className, variant, ...props }, ref) => {
|
|
48
|
+
return (
|
|
49
|
+
<ToastPrimitives.Root
|
|
50
|
+
ref={ref}
|
|
51
|
+
className={cn(toastVariants({ variant }), className)}
|
|
52
|
+
{...props}
|
|
53
|
+
/>
|
|
54
|
+
)
|
|
55
|
+
})
|
|
56
|
+
Toast.displayName = ToastPrimitives.Root.displayName
|
|
57
|
+
|
|
58
|
+
const ToastAction = React.forwardRef<
|
|
59
|
+
React.ElementRef<typeof ToastPrimitives.Action>,
|
|
60
|
+
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
|
|
61
|
+
>(({ className, ...props }, ref) => (
|
|
62
|
+
<ToastPrimitives.Action
|
|
63
|
+
ref={ref}
|
|
64
|
+
className={cn(
|
|
65
|
+
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
|
|
66
|
+
className
|
|
67
|
+
)}
|
|
68
|
+
{...props}
|
|
69
|
+
/>
|
|
70
|
+
))
|
|
71
|
+
ToastAction.displayName = ToastPrimitives.Action.displayName
|
|
72
|
+
|
|
73
|
+
const ToastClose = React.forwardRef<
|
|
74
|
+
React.ElementRef<typeof ToastPrimitives.Close>,
|
|
75
|
+
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
|
|
76
|
+
>(({ className, ...props }, ref) => (
|
|
77
|
+
<ToastPrimitives.Close
|
|
78
|
+
ref={ref}
|
|
79
|
+
className={cn(
|
|
80
|
+
"absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",
|
|
81
|
+
className
|
|
82
|
+
)}
|
|
83
|
+
toast-close=""
|
|
84
|
+
{...props}
|
|
85
|
+
>
|
|
86
|
+
<X className="h-4 w-4" />
|
|
87
|
+
</ToastPrimitives.Close>
|
|
88
|
+
))
|
|
89
|
+
ToastClose.displayName = ToastPrimitives.Close.displayName
|
|
90
|
+
|
|
91
|
+
const ToastTitle = React.forwardRef<
|
|
92
|
+
React.ElementRef<typeof ToastPrimitives.Title>,
|
|
93
|
+
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
|
|
94
|
+
>(({ className, ...props }, ref) => (
|
|
95
|
+
<ToastPrimitives.Title
|
|
96
|
+
ref={ref}
|
|
97
|
+
className={cn("text-sm font-semibold", className)}
|
|
98
|
+
{...props}
|
|
99
|
+
/>
|
|
100
|
+
))
|
|
101
|
+
ToastTitle.displayName = ToastPrimitives.Title.displayName
|
|
102
|
+
|
|
103
|
+
const ToastDescription = React.forwardRef<
|
|
104
|
+
React.ElementRef<typeof ToastPrimitives.Description>,
|
|
105
|
+
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
|
|
106
|
+
>(({ className, ...props }, ref) => (
|
|
107
|
+
<ToastPrimitives.Description
|
|
108
|
+
ref={ref}
|
|
109
|
+
className={cn("text-sm opacity-90", className)}
|
|
110
|
+
{...props}
|
|
111
|
+
/>
|
|
112
|
+
))
|
|
113
|
+
ToastDescription.displayName = ToastPrimitives.Description.displayName
|
|
114
|
+
|
|
115
|
+
type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>
|
|
116
|
+
|
|
117
|
+
type ToastActionElement = React.ReactElement<typeof ToastAction>
|
|
118
|
+
|
|
119
|
+
export {
|
|
120
|
+
type ToastProps,
|
|
121
|
+
type ToastActionElement,
|
|
122
|
+
ToastProvider,
|
|
123
|
+
ToastViewport,
|
|
124
|
+
Toast,
|
|
125
|
+
ToastTitle,
|
|
126
|
+
ToastDescription,
|
|
127
|
+
ToastClose,
|
|
128
|
+
ToastAction,
|
|
129
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { useToast } from '../hooks/useToast';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
Toast, ToastClose, ToastDescription, ToastProvider, ToastTitle, ToastViewport
|
|
8
|
+
} from './toast';
|
|
9
|
+
|
|
10
|
+
export function Toaster() {
|
|
11
|
+
const { toasts } = useToast()
|
|
12
|
+
const [isMounted, setIsMounted] = useState(false)
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
setIsMounted(true)
|
|
16
|
+
}, [])
|
|
17
|
+
|
|
18
|
+
if (!isMounted) {
|
|
19
|
+
return null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<ToastProvider>
|
|
24
|
+
{toasts.map(function ({ id, title, description, action, ...props }) {
|
|
25
|
+
return (
|
|
26
|
+
<Toast key={id} {...props}>
|
|
27
|
+
<div className="grid gap-1">
|
|
28
|
+
{title && <ToastTitle>{title}</ToastTitle>}
|
|
29
|
+
{description && (
|
|
30
|
+
<ToastDescription>{description}</ToastDescription>
|
|
31
|
+
)}
|
|
32
|
+
</div>
|
|
33
|
+
{action}
|
|
34
|
+
<ToastClose />
|
|
35
|
+
</Toast>
|
|
36
|
+
)
|
|
37
|
+
})}
|
|
38
|
+
<ToastViewport />
|
|
39
|
+
</ToastProvider>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group"
|
|
5
|
+
import { type VariantProps } from "class-variance-authority"
|
|
6
|
+
|
|
7
|
+
import { cn } from "../lib/utils"
|
|
8
|
+
import { toggleVariants } from "./toggle"
|
|
9
|
+
|
|
10
|
+
const ToggleGroupContext = React.createContext<
|
|
11
|
+
VariantProps<typeof toggleVariants>
|
|
12
|
+
>({
|
|
13
|
+
size: "default",
|
|
14
|
+
variant: "default",
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const ToggleGroup = React.forwardRef<
|
|
18
|
+
React.ElementRef<typeof ToggleGroupPrimitive.Root>,
|
|
19
|
+
React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Root> &
|
|
20
|
+
VariantProps<typeof toggleVariants>
|
|
21
|
+
>(({ className, variant, size, children, ...props }, ref) => (
|
|
22
|
+
<ToggleGroupPrimitive.Root
|
|
23
|
+
ref={ref}
|
|
24
|
+
className={cn("flex items-center justify-center gap-1", className)}
|
|
25
|
+
{...props}
|
|
26
|
+
>
|
|
27
|
+
<ToggleGroupContext.Provider value={{ variant, size }}>
|
|
28
|
+
{children}
|
|
29
|
+
</ToggleGroupContext.Provider>
|
|
30
|
+
</ToggleGroupPrimitive.Root>
|
|
31
|
+
))
|
|
32
|
+
|
|
33
|
+
ToggleGroup.displayName = ToggleGroupPrimitive.Root.displayName
|
|
34
|
+
|
|
35
|
+
const ToggleGroupItem = React.forwardRef<
|
|
36
|
+
React.ElementRef<typeof ToggleGroupPrimitive.Item>,
|
|
37
|
+
React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Item> &
|
|
38
|
+
VariantProps<typeof toggleVariants> & { key?: React.Key }
|
|
39
|
+
>(({ className, children, variant, size, ...props }, ref) => {
|
|
40
|
+
const context = React.useContext(ToggleGroupContext)
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<ToggleGroupPrimitive.Item
|
|
44
|
+
ref={ref}
|
|
45
|
+
className={cn(
|
|
46
|
+
toggleVariants({
|
|
47
|
+
variant: context.variant || variant,
|
|
48
|
+
size: context.size || size,
|
|
49
|
+
}),
|
|
50
|
+
className
|
|
51
|
+
)}
|
|
52
|
+
{...props}
|
|
53
|
+
>
|
|
54
|
+
{children}
|
|
55
|
+
</ToggleGroupPrimitive.Item>
|
|
56
|
+
)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
ToggleGroupItem.displayName = ToggleGroupPrimitive.Item.displayName
|
|
60
|
+
|
|
61
|
+
export { ToggleGroup, ToggleGroupItem }
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import * as TogglePrimitive from "@radix-ui/react-toggle"
|
|
5
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
6
|
+
|
|
7
|
+
import { cn } from "../lib/utils"
|
|
8
|
+
|
|
9
|
+
const toggleVariants = cva(
|
|
10
|
+
"inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
|
|
11
|
+
{
|
|
12
|
+
variants: {
|
|
13
|
+
variant: {
|
|
14
|
+
default: "bg-transparent",
|
|
15
|
+
outline:
|
|
16
|
+
"border border-input bg-transparent shadow-sm hover:bg-accent hover:text-accent-foreground",
|
|
17
|
+
},
|
|
18
|
+
size: {
|
|
19
|
+
default: "h-9 px-2 min-w-9",
|
|
20
|
+
sm: "h-8 px-1.5 min-w-8",
|
|
21
|
+
lg: "h-10 px-2.5 min-w-10",
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
defaultVariants: {
|
|
25
|
+
variant: "default",
|
|
26
|
+
size: "default",
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
const Toggle = React.forwardRef<
|
|
32
|
+
React.ElementRef<typeof TogglePrimitive.Root>,
|
|
33
|
+
React.ComponentPropsWithoutRef<typeof TogglePrimitive.Root> &
|
|
34
|
+
VariantProps<typeof toggleVariants>
|
|
35
|
+
>(({ className, variant, size, ...props }, ref) => (
|
|
36
|
+
<TogglePrimitive.Root
|
|
37
|
+
ref={ref}
|
|
38
|
+
className={cn(toggleVariants({ variant, size, className }))}
|
|
39
|
+
{...props}
|
|
40
|
+
/>
|
|
41
|
+
))
|
|
42
|
+
|
|
43
|
+
Toggle.displayName = TogglePrimitive.Root.displayName
|
|
44
|
+
|
|
45
|
+
export { Toggle, toggleVariants }
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { cn } from "../lib/utils"
|
|
5
|
+
|
|
6
|
+
export interface TokenIconProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
7
|
+
symbol: string
|
|
8
|
+
variant?: 'branded' | 'mono'
|
|
9
|
+
size?: number
|
|
10
|
+
network?: string
|
|
11
|
+
address?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Get all available token symbols from @web3icons/react
|
|
16
|
+
* Uses dynamic import to avoid bundling all icons
|
|
17
|
+
*/
|
|
18
|
+
export async function getAllTokenSymbols(): Promise<string[]> {
|
|
19
|
+
try {
|
|
20
|
+
const { tokenIcons } = await import('@web3icons/react')
|
|
21
|
+
return Object.keys(tokenIcons).map(key =>
|
|
22
|
+
key.replace(/^Token/, '').replace(/_/g, '-')
|
|
23
|
+
).sort()
|
|
24
|
+
} catch {
|
|
25
|
+
return []
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Search tokens by symbol
|
|
31
|
+
*/
|
|
32
|
+
export async function searchTokens(query: string): Promise<string[]> {
|
|
33
|
+
const allTokens = await getAllTokenSymbols()
|
|
34
|
+
const lowerQuery = query.toLowerCase()
|
|
35
|
+
return allTokens.filter(symbol =>
|
|
36
|
+
symbol.toLowerCase().includes(lowerQuery)
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get popular tokens grouped by category
|
|
42
|
+
*/
|
|
43
|
+
export interface TokenCategory {
|
|
44
|
+
name: string
|
|
45
|
+
tokens: string[]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function getTokensByCategory(): Promise<TokenCategory[]> {
|
|
49
|
+
const allTokens = await getAllTokenSymbols()
|
|
50
|
+
|
|
51
|
+
// Top tokens by market cap
|
|
52
|
+
const topTokens = ['BTC', 'ETH', 'USDT', 'BNB', 'SOL', 'USDC', 'XRP', 'DOGE', 'ADA', 'TRX']
|
|
53
|
+
.filter(t => allTokens.includes(t))
|
|
54
|
+
|
|
55
|
+
const stablecoins = ['USDT', 'USDC', 'BUSD', 'DAI', 'TUSD', 'USDP', 'GUSD', 'FRAX']
|
|
56
|
+
.filter(t => allTokens.includes(t))
|
|
57
|
+
|
|
58
|
+
const defi = ['UNI', 'AAVE', 'MKR', 'CRV', 'CAKE', 'SUSHI', 'BAL', 'COMP', 'YFI', 'SNX', 'LINK']
|
|
59
|
+
.filter(t => allTokens.includes(t))
|
|
60
|
+
|
|
61
|
+
const layer1 = ['ETH', 'BNB', 'SOL', 'ADA', 'AVAX', 'DOT', 'ATOM', 'NEAR', 'ALGO', 'FTM']
|
|
62
|
+
.filter(t => allTokens.includes(t))
|
|
63
|
+
|
|
64
|
+
const layer2 = ['MATIC', 'OP', 'ARB', 'IMX', 'LRC', 'METIS']
|
|
65
|
+
.filter(t => allTokens.includes(t))
|
|
66
|
+
|
|
67
|
+
const memeCoins = ['DOGE', 'SHIB', 'PEPE', 'FLOKI', 'ELON', 'BONK']
|
|
68
|
+
.filter(t => allTokens.includes(t))
|
|
69
|
+
|
|
70
|
+
return [
|
|
71
|
+
{ name: 'Top 10', tokens: topTokens },
|
|
72
|
+
{ name: 'Stablecoins', tokens: stablecoins },
|
|
73
|
+
{ name: 'DeFi', tokens: defi },
|
|
74
|
+
{ name: 'Layer 1', tokens: layer1 },
|
|
75
|
+
{ name: 'Layer 2', tokens: layer2 },
|
|
76
|
+
{ name: 'Meme Coins', tokens: memeCoins },
|
|
77
|
+
].filter(cat => cat.tokens.length > 0)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export type TokenSymbol = string
|
|
81
|
+
|
|
82
|
+
// Dynamic import for @web3icons/react tokens
|
|
83
|
+
const tokenIconCache = new Map<string, React.ComponentType<any>>()
|
|
84
|
+
|
|
85
|
+
async function getTokenIcon(symbol: string): Promise<React.ComponentType<any> | null> {
|
|
86
|
+
const normalizedSymbol = symbol.toUpperCase().replace(/[^A-Z0-9]/g, '_')
|
|
87
|
+
const componentName = `Token${normalizedSymbol}`
|
|
88
|
+
|
|
89
|
+
if (tokenIconCache.has(componentName)) {
|
|
90
|
+
return tokenIconCache.get(componentName)!
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
const module = await import('@web3icons/react')
|
|
95
|
+
const Component = (module as any)[componentName]
|
|
96
|
+
if (Component) {
|
|
97
|
+
tokenIconCache.set(componentName, Component)
|
|
98
|
+
return Component
|
|
99
|
+
}
|
|
100
|
+
} catch (e) {
|
|
101
|
+
// Token not found
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return null
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function TokenIcon({
|
|
108
|
+
symbol,
|
|
109
|
+
variant = 'branded',
|
|
110
|
+
size = 24,
|
|
111
|
+
className,
|
|
112
|
+
network,
|
|
113
|
+
address,
|
|
114
|
+
...props
|
|
115
|
+
}: TokenIconProps) {
|
|
116
|
+
const [IconComponent, setIconComponent] = React.useState<React.ComponentType<any> | null>(null)
|
|
117
|
+
const [loading, setLoading] = React.useState(true)
|
|
118
|
+
|
|
119
|
+
React.useEffect(() => {
|
|
120
|
+
let mounted = true
|
|
121
|
+
|
|
122
|
+
getTokenIcon(symbol).then((component) => {
|
|
123
|
+
if (mounted) {
|
|
124
|
+
setIconComponent(() => component)
|
|
125
|
+
setLoading(false)
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
return () => {
|
|
130
|
+
mounted = false
|
|
131
|
+
}
|
|
132
|
+
}, [symbol])
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<div
|
|
136
|
+
className={cn("inline-flex items-center justify-center flex-shrink-0", className)}
|
|
137
|
+
style={{ width: size, height: size }}
|
|
138
|
+
{...props}
|
|
139
|
+
>
|
|
140
|
+
{IconComponent ? (
|
|
141
|
+
<IconComponent
|
|
142
|
+
variant={variant}
|
|
143
|
+
size={size}
|
|
144
|
+
/>
|
|
145
|
+
) : (
|
|
146
|
+
// Fallback: show symbol as text
|
|
147
|
+
<span
|
|
148
|
+
className="text-muted-foreground font-medium uppercase"
|
|
149
|
+
style={{ fontSize: Math.max(8, size * 0.4) }}
|
|
150
|
+
>
|
|
151
|
+
{symbol?.slice(0, 3) || '?'}
|
|
152
|
+
</span>
|
|
153
|
+
)}
|
|
154
|
+
</div>
|
|
155
|
+
)
|
|
156
|
+
}
|