@thangnqdev/ui 0.2.0 → 0.2.2
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 -21
- package/README.md +144 -142
- package/bin/cli.js +125 -0
- package/dist/bento/index.cjs.map +1 -1
- package/dist/bento/index.js +2 -2
- package/dist/buttons/index.cjs.map +1 -1
- package/dist/buttons/index.js +3 -3
- package/dist/{chunk-77KTYOMQ.js → chunk-2OXZK6IP.js} +3 -3
- package/dist/chunk-2OXZK6IP.js.map +1 -0
- package/dist/{chunk-4CRFNALF.js → chunk-4GNFT2ZJ.js} +7 -7
- package/dist/chunk-4GNFT2ZJ.js.map +1 -0
- package/dist/{chunk-2YJBW4E2.js → chunk-4S6L5V7X.js} +2 -2
- package/dist/chunk-4S6L5V7X.js.map +1 -0
- package/dist/{chunk-I2FQBMVW.js → chunk-66VWUJEI.js} +3 -3
- package/dist/chunk-66VWUJEI.js.map +1 -0
- package/dist/{chunk-YOCGBORV.js → chunk-7NMB2Y64.js} +4 -4
- package/dist/chunk-7NMB2Y64.js.map +1 -0
- package/dist/{chunk-V52JOSDF.js → chunk-A7P3O5Z5.js} +3 -3
- package/dist/chunk-A7P3O5Z5.js.map +1 -0
- package/dist/{chunk-ME4XILG5.js → chunk-ATYGDTMK.js} +5 -5
- package/dist/chunk-ATYGDTMK.js.map +1 -0
- package/dist/{chunk-S6XJMYME.js → chunk-C4SUXMI3.js} +3 -3
- package/dist/chunk-C4SUXMI3.js.map +1 -0
- package/dist/{chunk-EXFR2BFJ.js → chunk-DUPPPGXY.js} +7 -7
- package/dist/chunk-DUPPPGXY.js.map +1 -0
- package/dist/{chunk-I5O2WCGF.js → chunk-EU2LPUYP.js} +3 -3
- package/dist/chunk-EU2LPUYP.js.map +1 -0
- package/dist/{chunk-D7FB3TCA.js → chunk-GXI2H5XA.js} +3 -3
- package/dist/chunk-GXI2H5XA.js.map +1 -0
- package/dist/{chunk-ADO3SVUA.js → chunk-IABPUCAQ.js} +2 -2
- package/dist/chunk-IABPUCAQ.js.map +1 -0
- package/dist/{chunk-PC5SZFZC.js → chunk-JOKEKOP3.js} +8 -8
- package/dist/chunk-JOKEKOP3.js.map +1 -0
- package/dist/{chunk-GXWB6BSY.js → chunk-KUQWUTZA.js} +4 -4
- package/dist/chunk-KUQWUTZA.js.map +1 -0
- package/dist/{chunk-ZEDXARXW.js → chunk-U3J4UPV3.js} +2 -2
- package/dist/chunk-U3J4UPV3.js.map +1 -0
- package/dist/{chunk-DSEL7ELZ.js → chunk-VE2PNSDQ.js} +4 -4
- package/dist/chunk-VE2PNSDQ.js.map +1 -0
- package/dist/{chunk-YJ64RI7J.js → chunk-WAFHC4DQ.js} +3 -3
- package/dist/chunk-WAFHC4DQ.js.map +1 -0
- package/dist/{chunk-W5WNWTQC.js → chunk-YJ67WYVW.js} +5 -5
- package/dist/chunk-YJ67WYVW.js.map +1 -0
- package/dist/{chunk-4MS6ZHFQ.js → chunk-Z427NPMU.js} +7 -7
- package/dist/chunk-Z427NPMU.js.map +1 -0
- package/dist/core/index.cjs +4 -4
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +2 -2
- package/dist/data-display/index.cjs.map +1 -1
- package/dist/data-display/index.js +5 -5
- package/dist/feedback/index.cjs.map +1 -1
- package/dist/feedback/index.js +2 -2
- package/dist/forms/index.cjs.map +1 -1
- package/dist/forms/index.js +8 -8
- package/dist/glass/index.cjs.map +1 -1
- package/dist/glass/index.js +2 -2
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -19
- package/dist/layout/index.cjs.map +1 -1
- package/dist/layout/index.js +2 -2
- package/dist/navigation/index.cjs.map +1 -1
- package/dist/navigation/index.js +6 -6
- package/dist/overlays/index.cjs.map +1 -1
- package/dist/overlays/index.js +7 -7
- package/dist/reset.css +45 -45
- package/dist/tokens.css +11 -11
- package/dist/typography/index.cjs.map +1 -1
- package/dist/typography/index.js +4 -4
- package/llms.txt +3 -3
- package/package.json +166 -159
- package/scripts/postinstall.js +125 -0
- package/src/bento/BentoCard.tsx +140 -140
- package/src/bento/BentoGrid.tsx +50 -50
- package/src/bento/index.ts +2 -2
- package/src/bento/tokens.css +46 -46
- package/src/buttons/Button.tsx +104 -104
- package/src/buttons/ButtonGroup.tsx +43 -43
- package/src/buttons/IconButton.tsx +79 -79
- package/src/buttons/SplitButton.tsx +186 -186
- package/src/buttons/ToggleButton.tsx +157 -157
- package/src/buttons/index.ts +5 -5
- package/src/buttons/tokens.css +6 -6
- package/src/core/ThemeProvider.tsx +133 -133
- package/src/core/index.ts +2 -2
- package/src/core/tokens.css +134 -134
- package/src/data-display/Accordion.tsx +147 -147
- package/src/data-display/Avatar.tsx +134 -134
- package/src/data-display/Card.tsx +112 -112
- package/src/data-display/Chip.tsx +74 -74
- package/src/data-display/DataTablePro.tsx +534 -534
- package/src/data-display/StatCard.tsx +60 -60
- package/src/data-display/Table.tsx +74 -74
- package/src/data-display/Timeline.tsx +62 -62
- package/src/data-display/TreeView.tsx +279 -279
- package/src/data-display/tokens.css +4 -4
- package/src/feedback/Alert.tsx +80 -80
- package/src/feedback/EmptyState.tsx +45 -45
- package/src/feedback/Skeleton.tsx +66 -66
- package/src/feedback/Spinner.tsx +65 -65
- package/src/feedback/index.ts +5 -5
- package/src/feedback/tokens.css +4 -4
- package/src/forms/Checkbox.tsx +149 -149
- package/src/forms/CheckboxGroup.tsx +76 -76
- package/src/forms/Combobox.tsx +512 -512
- package/src/forms/DatePicker.tsx +784 -784
- package/src/forms/FileUpload.tsx +266 -266
- package/src/forms/FormField.tsx +115 -115
- package/src/forms/Input.tsx +151 -151
- package/src/forms/NumberInput.tsx +262 -262
- package/src/forms/PasswordInput.tsx +35 -35
- package/src/forms/PinInput.tsx +139 -139
- package/src/forms/Radio.tsx +142 -142
- package/src/forms/RangeSlider.tsx +237 -237
- package/src/forms/SearchInput.tsx +34 -34
- package/src/forms/Select.tsx +103 -103
- package/src/forms/Slider.tsx +85 -85
- package/src/forms/Textarea.tsx +114 -114
- package/src/forms/tokens.css +6 -6
- package/src/glass/GlassButton.tsx +59 -59
- package/src/glass/GlassCard.tsx +71 -71
- package/src/glass/index.ts +3 -3
- package/src/glass/tokens.css +81 -81
- package/src/index.ts +26 -26
- package/src/layout/AspectRatio.tsx +39 -39
- package/src/layout/Container.tsx +53 -53
- package/src/layout/Divider.tsx +61 -61
- package/src/layout/Flex.tsx +79 -79
- package/src/layout/Grid.tsx +124 -124
- package/src/layout/PageLayout.tsx +59 -59
- package/src/layout/Section.tsx +47 -47
- package/src/layout/Spacer.tsx +30 -30
- package/src/layout/Stack.tsx +88 -88
- package/src/layout/tokens.css +8 -8
- package/src/navigation/Breadcrumb.tsx +73 -73
- package/src/navigation/CommandPalette.tsx +142 -142
- package/src/navigation/DropdownMenu.tsx +244 -244
- package/src/navigation/Pagination.tsx +114 -114
- package/src/navigation/Stepper.tsx +93 -93
- package/src/navigation/Tabs.tsx +265 -265
- package/src/navigation/index.ts +6 -6
- package/src/navigation/tokens.css +4 -4
- package/src/overlays/AlertDialog.tsx +63 -63
- package/src/overlays/BottomSheet.tsx +143 -143
- package/src/overlays/ContextMenu.tsx +161 -161
- package/src/overlays/Drawer.tsx +160 -160
- package/src/overlays/FocusTrap.tsx +122 -122
- package/src/overlays/Modal.tsx +296 -296
- package/src/overlays/Popover.tsx +156 -156
- package/src/overlays/Portal.tsx +23 -23
- package/src/overlays/Toast.tsx +175 -175
- package/src/overlays/Tooltip.tsx +125 -125
- package/src/overlays/tokens.css +8 -8
- package/src/registry/components.ts +1368 -1368
- package/src/styles/components.css +39 -39
- package/src/styles/index.css +5 -5
- package/src/styles/reset.css +45 -45
- package/src/styles/tokens.css +11 -11
- package/src/typography/Blockquote.tsx +32 -32
- package/src/typography/Code.tsx +89 -89
- package/src/typography/Heading.tsx +56 -56
- package/src/typography/Kbd.tsx +25 -25
- package/src/typography/Label.tsx +47 -47
- package/src/typography/Link.tsx +56 -56
- package/src/typography/Text.tsx +62 -62
- package/src/typography/index.ts +7 -7
- package/src/typography/tokens.css +5 -5
- package/src/utils/cn.ts +6 -6
- package/src/utils/scroll-lock.ts +19 -19
- package/src/utils/useControllableState.ts +54 -54
- package/ui-contract.json +1 -1
- package/dist/chunk-2YJBW4E2.js.map +0 -1
- package/dist/chunk-4CRFNALF.js.map +0 -1
- package/dist/chunk-4MS6ZHFQ.js.map +0 -1
- package/dist/chunk-77KTYOMQ.js.map +0 -1
- package/dist/chunk-ADO3SVUA.js.map +0 -1
- package/dist/chunk-D7FB3TCA.js.map +0 -1
- package/dist/chunk-DSEL7ELZ.js.map +0 -1
- package/dist/chunk-EXFR2BFJ.js.map +0 -1
- package/dist/chunk-GXWB6BSY.js.map +0 -1
- package/dist/chunk-I2FQBMVW.js.map +0 -1
- package/dist/chunk-I5O2WCGF.js.map +0 -1
- package/dist/chunk-ME4XILG5.js.map +0 -1
- package/dist/chunk-PC5SZFZC.js.map +0 -1
- package/dist/chunk-S6XJMYME.js.map +0 -1
- package/dist/chunk-V52JOSDF.js.map +0 -1
- package/dist/chunk-W5WNWTQC.js.map +0 -1
- package/dist/chunk-YJ64RI7J.js.map +0 -1
- package/dist/chunk-YOCGBORV.js.map +0 -1
- package/dist/chunk-ZEDXARXW.js.map +0 -1
package/src/overlays/Toast.tsx
CHANGED
|
@@ -1,175 +1,175 @@
|
|
|
1
|
-
import React, { createContext, useContext, useState, useCallback } from 'react';
|
|
2
|
-
import { cva } from 'class-variance-authority';
|
|
3
|
-
import { CheckCircle2, AlertTriangle, AlertCircle, Info, X } from 'lucide-react';
|
|
4
|
-
import { Portal } from './Portal';
|
|
5
|
-
import { cn } from '../utils/cn';
|
|
6
|
-
|
|
7
|
-
export type ToastType = 'info' | 'success' | 'warning' | 'error';
|
|
8
|
-
|
|
9
|
-
export interface ToastOptions {
|
|
10
|
-
id?: string;
|
|
11
|
-
title: string;
|
|
12
|
-
description?: string;
|
|
13
|
-
type?: ToastType;
|
|
14
|
-
duration?: number;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface ToastItem extends ToastOptions {
|
|
18
|
-
id: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
interface ToastContextType {
|
|
22
|
-
toast: (options: ToastOptions) => string;
|
|
23
|
-
dismiss: (id: string) => void;
|
|
24
|
-
toasts: ToastItem[];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const ToastContext = createContext<ToastContextType | null>(null);
|
|
28
|
-
|
|
29
|
-
export function useToast() {
|
|
30
|
-
const context = useContext(ToastContext);
|
|
31
|
-
if (!context) {
|
|
32
|
-
throw new Error('useToast must be used within a ToasterProvider');
|
|
33
|
-
}
|
|
34
|
-
return context;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const toastVariants = cva(
|
|
38
|
-
'pointer-events-auto flex w-full max-w-md items-start gap-3 rounded-[var(--ui-radius-lg)] border p-4 shadow-lg transition-all animate-in slide-in-from-bottom-5 duration-300',
|
|
39
|
-
{
|
|
40
|
-
variants: {
|
|
41
|
-
type: {
|
|
42
|
-
info: 'bg-[var(--ui-bg-surface)] border-[var(--ui-info)]/30 text-[var(--ui-text-primary)]',
|
|
43
|
-
success: 'bg-[var(--ui-bg-surface)] border-[var(--ui-success)]/30 text-[var(--ui-text-primary)]',
|
|
44
|
-
warning: 'bg-[var(--ui-bg-surface)] border-[var(--ui-warning)]/30 text-[var(--ui-text-primary)]',
|
|
45
|
-
error: 'bg-[var(--ui-bg-surface)] border-[var(--ui-error)]/30 text-[var(--ui-text-primary)]',
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
defaultVariants: {
|
|
49
|
-
type: 'info',
|
|
50
|
-
},
|
|
51
|
-
}
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
const toastIcons: Record<ToastType, React.ReactNode> = {
|
|
55
|
-
info: <Info className="w-5 h-5 text-[var(--ui-info)] flex-shrink-0" />,
|
|
56
|
-
success: <CheckCircle2 className="w-5 h-5 text-[var(--ui-success)] flex-shrink-0" />,
|
|
57
|
-
warning: <AlertTriangle className="w-5 h-5 text-[var(--ui-warning)] flex-shrink-0" />,
|
|
58
|
-
error: <AlertCircle className="w-5 h-5 text-[var(--ui-error)] flex-shrink-0" />,
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export interface ToastProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
62
|
-
title: React.ReactNode;
|
|
63
|
-
description?: React.ReactNode;
|
|
64
|
-
type?: ToastType;
|
|
65
|
-
onDismiss?: () => void;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export const Toast = React.forwardRef<HTMLDivElement, ToastProps>(
|
|
69
|
-
({ className, title, description, type = 'info', onDismiss, ...props }, ref) => {
|
|
70
|
-
return (
|
|
71
|
-
<div
|
|
72
|
-
ref={ref}
|
|
73
|
-
role="status"
|
|
74
|
-
aria-live="polite"
|
|
75
|
-
className={cn(toastVariants({ type }), className)}
|
|
76
|
-
{...props}
|
|
77
|
-
>
|
|
78
|
-
{toastIcons[type || 'info']}
|
|
79
|
-
<div className="flex-1 space-y-1">
|
|
80
|
-
<h4 className="text-sm font-semibold text-[var(--ui-text-primary)]">{title}</h4>
|
|
81
|
-
{description && <p className="text-xs text-[var(--ui-text-muted)]">{description}</p>}
|
|
82
|
-
</div>
|
|
83
|
-
{onDismiss && (
|
|
84
|
-
<button
|
|
85
|
-
type="button"
|
|
86
|
-
onClick={onDismiss}
|
|
87
|
-
aria-label="Dismiss toast"
|
|
88
|
-
className="p-1 rounded text-[var(--ui-text-muted)] hover:text-[var(--ui-text-primary)] hover:bg-[var(--ui-bg-tertiary)] transition-colors cursor-pointer"
|
|
89
|
-
>
|
|
90
|
-
<X className="w-3.5 h-3.5" />
|
|
91
|
-
</button>
|
|
92
|
-
)}
|
|
93
|
-
</div>
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
);
|
|
97
|
-
Toast.displayName = 'Toast';
|
|
98
|
-
|
|
99
|
-
export interface ToasterProviderProps {
|
|
100
|
-
children: React.ReactNode;
|
|
101
|
-
position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-center' | 'bottom-center';
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function ToasterProvider({ children, position = 'bottom-right' }: ToasterProviderProps) {
|
|
105
|
-
const [toasts, setToasts] = useState<ToastItem[]>([]);
|
|
106
|
-
|
|
107
|
-
const dismiss = useCallback((id: string) => {
|
|
108
|
-
setToasts((prev) => prev.filter((t) => t.id !== id));
|
|
109
|
-
}, []);
|
|
110
|
-
|
|
111
|
-
const toast = useCallback(
|
|
112
|
-
({ id = Math.random().toString(36).slice(2, 9), title, description, type = 'info', duration = 4000 }: ToastOptions) => {
|
|
113
|
-
const item: ToastItem = { id, title, description, type, duration };
|
|
114
|
-
|
|
115
|
-
setToasts((prev) => [...prev, item]);
|
|
116
|
-
|
|
117
|
-
if (duration > 0) {
|
|
118
|
-
setTimeout(() => {
|
|
119
|
-
dismiss(id);
|
|
120
|
-
}, duration);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return id;
|
|
124
|
-
},
|
|
125
|
-
[dismiss]
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
const getPositionClasses = () => {
|
|
129
|
-
switch (position) {
|
|
130
|
-
case 'top-left':
|
|
131
|
-
return 'top-4 left-4 items-start';
|
|
132
|
-
case 'top-center':
|
|
133
|
-
return 'top-4 left-1/2 -translate-x-1/2 items-center';
|
|
134
|
-
case 'top-right':
|
|
135
|
-
return 'top-4 right-4 items-end';
|
|
136
|
-
case 'bottom-left':
|
|
137
|
-
return 'bottom-4 left-4 items-start';
|
|
138
|
-
case 'bottom-center':
|
|
139
|
-
return 'bottom-4 left-1/2 -translate-x-1/2 items-center';
|
|
140
|
-
case 'bottom-right':
|
|
141
|
-
default:
|
|
142
|
-
return 'bottom-4 right-4 items-end';
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
return (
|
|
147
|
-
<ToastContext.Provider value={{ toast, dismiss, toasts }}>
|
|
148
|
-
{children}
|
|
149
|
-
<Portal>
|
|
150
|
-
<div
|
|
151
|
-
aria-live="polite"
|
|
152
|
-
className={cn('fixed z-[100] flex flex-col gap-2 pointer-events-none p-4 w-full max-w-sm sm:max-w-md', getPositionClasses())}
|
|
153
|
-
>
|
|
154
|
-
{toasts.map((t) => (
|
|
155
|
-
<div key={t.id} className={cn(toastVariants({ type: t.type }))}>
|
|
156
|
-
{toastIcons[t.type || 'info']}
|
|
157
|
-
<div className="flex-1 space-y-1">
|
|
158
|
-
<h4 className="text-sm font-semibold text-[var(--ui-text-primary)]">{t.title}</h4>
|
|
159
|
-
{t.description && <p className="text-xs text-[var(--ui-text-muted)]">{t.description}</p>}
|
|
160
|
-
</div>
|
|
161
|
-
<button
|
|
162
|
-
type="button"
|
|
163
|
-
onClick={() => dismiss(t.id)}
|
|
164
|
-
aria-label="Dismiss toast"
|
|
165
|
-
className="p-1 rounded text-[var(--ui-text-muted)] hover:text-[var(--ui-text-primary)] hover:bg-[var(--ui-bg-tertiary)] transition-colors"
|
|
166
|
-
>
|
|
167
|
-
<X className="w-3.5 h-3.5" />
|
|
168
|
-
</button>
|
|
169
|
-
</div>
|
|
170
|
-
))}
|
|
171
|
-
</div>
|
|
172
|
-
</Portal>
|
|
173
|
-
</ToastContext.Provider>
|
|
174
|
-
);
|
|
175
|
-
}
|
|
1
|
+
import React, { createContext, useContext, useState, useCallback } from 'react';
|
|
2
|
+
import { cva } from 'class-variance-authority';
|
|
3
|
+
import { CheckCircle2, AlertTriangle, AlertCircle, Info, X } from 'lucide-react';
|
|
4
|
+
import { Portal } from './Portal';
|
|
5
|
+
import { cn } from '../utils/cn';
|
|
6
|
+
|
|
7
|
+
export type ToastType = 'info' | 'success' | 'warning' | 'error';
|
|
8
|
+
|
|
9
|
+
export interface ToastOptions {
|
|
10
|
+
id?: string;
|
|
11
|
+
title: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
type?: ToastType;
|
|
14
|
+
duration?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ToastItem extends ToastOptions {
|
|
18
|
+
id: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface ToastContextType {
|
|
22
|
+
toast: (options: ToastOptions) => string;
|
|
23
|
+
dismiss: (id: string) => void;
|
|
24
|
+
toasts: ToastItem[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const ToastContext = createContext<ToastContextType | null>(null);
|
|
28
|
+
|
|
29
|
+
export function useToast() {
|
|
30
|
+
const context = useContext(ToastContext);
|
|
31
|
+
if (!context) {
|
|
32
|
+
throw new Error('useToast must be used within a ToasterProvider');
|
|
33
|
+
}
|
|
34
|
+
return context;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const toastVariants = cva(
|
|
38
|
+
'pointer-events-auto flex w-full max-w-md items-start gap-3 rounded-[var(--ui-radius-lg)] border p-4 shadow-lg transition-all animate-in slide-in-from-bottom-5 duration-300',
|
|
39
|
+
{
|
|
40
|
+
variants: {
|
|
41
|
+
type: {
|
|
42
|
+
info: 'bg-[var(--ui-bg-surface)] border-[var(--ui-info)]/30 text-[var(--ui-text-primary)]',
|
|
43
|
+
success: 'bg-[var(--ui-bg-surface)] border-[var(--ui-success)]/30 text-[var(--ui-text-primary)]',
|
|
44
|
+
warning: 'bg-[var(--ui-bg-surface)] border-[var(--ui-warning)]/30 text-[var(--ui-text-primary)]',
|
|
45
|
+
error: 'bg-[var(--ui-bg-surface)] border-[var(--ui-error)]/30 text-[var(--ui-text-primary)]',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
defaultVariants: {
|
|
49
|
+
type: 'info',
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const toastIcons: Record<ToastType, React.ReactNode> = {
|
|
55
|
+
info: <Info className="w-5 h-5 text-[var(--ui-info)] flex-shrink-0" />,
|
|
56
|
+
success: <CheckCircle2 className="w-5 h-5 text-[var(--ui-success)] flex-shrink-0" />,
|
|
57
|
+
warning: <AlertTriangle className="w-5 h-5 text-[var(--ui-warning)] flex-shrink-0" />,
|
|
58
|
+
error: <AlertCircle className="w-5 h-5 text-[var(--ui-error)] flex-shrink-0" />,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export interface ToastProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
62
|
+
title: React.ReactNode;
|
|
63
|
+
description?: React.ReactNode;
|
|
64
|
+
type?: ToastType;
|
|
65
|
+
onDismiss?: () => void;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const Toast = React.forwardRef<HTMLDivElement, ToastProps>(
|
|
69
|
+
({ className, title, description, type = 'info', onDismiss, ...props }, ref) => {
|
|
70
|
+
return (
|
|
71
|
+
<div
|
|
72
|
+
ref={ref}
|
|
73
|
+
role="status"
|
|
74
|
+
aria-live="polite"
|
|
75
|
+
className={cn(toastVariants({ type }), className)}
|
|
76
|
+
{...props}
|
|
77
|
+
>
|
|
78
|
+
{toastIcons[type || 'info']}
|
|
79
|
+
<div className="flex-1 space-y-1">
|
|
80
|
+
<h4 className="text-sm font-semibold text-[var(--ui-text-primary)]">{title}</h4>
|
|
81
|
+
{description && <p className="text-xs text-[var(--ui-text-muted)]">{description}</p>}
|
|
82
|
+
</div>
|
|
83
|
+
{onDismiss && (
|
|
84
|
+
<button
|
|
85
|
+
type="button"
|
|
86
|
+
onClick={onDismiss}
|
|
87
|
+
aria-label="Dismiss toast"
|
|
88
|
+
className="p-1 rounded text-[var(--ui-text-muted)] hover:text-[var(--ui-text-primary)] hover:bg-[var(--ui-bg-tertiary)] transition-colors cursor-pointer"
|
|
89
|
+
>
|
|
90
|
+
<X className="w-3.5 h-3.5" />
|
|
91
|
+
</button>
|
|
92
|
+
)}
|
|
93
|
+
</div>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
Toast.displayName = 'Toast';
|
|
98
|
+
|
|
99
|
+
export interface ToasterProviderProps {
|
|
100
|
+
children: React.ReactNode;
|
|
101
|
+
position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-center' | 'bottom-center';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function ToasterProvider({ children, position = 'bottom-right' }: ToasterProviderProps) {
|
|
105
|
+
const [toasts, setToasts] = useState<ToastItem[]>([]);
|
|
106
|
+
|
|
107
|
+
const dismiss = useCallback((id: string) => {
|
|
108
|
+
setToasts((prev) => prev.filter((t) => t.id !== id));
|
|
109
|
+
}, []);
|
|
110
|
+
|
|
111
|
+
const toast = useCallback(
|
|
112
|
+
({ id = Math.random().toString(36).slice(2, 9), title, description, type = 'info', duration = 4000 }: ToastOptions) => {
|
|
113
|
+
const item: ToastItem = { id, title, description, type, duration };
|
|
114
|
+
|
|
115
|
+
setToasts((prev) => [...prev, item]);
|
|
116
|
+
|
|
117
|
+
if (duration > 0) {
|
|
118
|
+
setTimeout(() => {
|
|
119
|
+
dismiss(id);
|
|
120
|
+
}, duration);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return id;
|
|
124
|
+
},
|
|
125
|
+
[dismiss]
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const getPositionClasses = () => {
|
|
129
|
+
switch (position) {
|
|
130
|
+
case 'top-left':
|
|
131
|
+
return 'top-4 left-4 items-start';
|
|
132
|
+
case 'top-center':
|
|
133
|
+
return 'top-4 left-1/2 -translate-x-1/2 items-center';
|
|
134
|
+
case 'top-right':
|
|
135
|
+
return 'top-4 right-4 items-end';
|
|
136
|
+
case 'bottom-left':
|
|
137
|
+
return 'bottom-4 left-4 items-start';
|
|
138
|
+
case 'bottom-center':
|
|
139
|
+
return 'bottom-4 left-1/2 -translate-x-1/2 items-center';
|
|
140
|
+
case 'bottom-right':
|
|
141
|
+
default:
|
|
142
|
+
return 'bottom-4 right-4 items-end';
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<ToastContext.Provider value={{ toast, dismiss, toasts }}>
|
|
148
|
+
{children}
|
|
149
|
+
<Portal>
|
|
150
|
+
<div
|
|
151
|
+
aria-live="polite"
|
|
152
|
+
className={cn('fixed z-[100] flex flex-col gap-2 pointer-events-none p-4 w-full max-w-sm sm:max-w-md', getPositionClasses())}
|
|
153
|
+
>
|
|
154
|
+
{toasts.map((t) => (
|
|
155
|
+
<div key={t.id} className={cn(toastVariants({ type: t.type }))}>
|
|
156
|
+
{toastIcons[t.type || 'info']}
|
|
157
|
+
<div className="flex-1 space-y-1">
|
|
158
|
+
<h4 className="text-sm font-semibold text-[var(--ui-text-primary)]">{t.title}</h4>
|
|
159
|
+
{t.description && <p className="text-xs text-[var(--ui-text-muted)]">{t.description}</p>}
|
|
160
|
+
</div>
|
|
161
|
+
<button
|
|
162
|
+
type="button"
|
|
163
|
+
onClick={() => dismiss(t.id)}
|
|
164
|
+
aria-label="Dismiss toast"
|
|
165
|
+
className="p-1 rounded text-[var(--ui-text-muted)] hover:text-[var(--ui-text-primary)] hover:bg-[var(--ui-bg-tertiary)] transition-colors"
|
|
166
|
+
>
|
|
167
|
+
<X className="w-3.5 h-3.5" />
|
|
168
|
+
</button>
|
|
169
|
+
</div>
|
|
170
|
+
))}
|
|
171
|
+
</div>
|
|
172
|
+
</Portal>
|
|
173
|
+
</ToastContext.Provider>
|
|
174
|
+
);
|
|
175
|
+
}
|
package/src/overlays/Tooltip.tsx
CHANGED
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
import React, { useState, useRef, useId, useEffect } from 'react';
|
|
2
|
-
import { cva, type VariantProps } from 'class-variance-authority';
|
|
3
|
-
import { Portal } from './Portal';
|
|
4
|
-
import { cn } from '../utils/cn';
|
|
5
|
-
|
|
6
|
-
export const tooltipVariants = cva(
|
|
7
|
-
'z-50 overflow-hidden rounded-[var(--ui-radius-sm)] bg-[var(--ui-bg-primary)] border border-[var(--ui-border-default)] px-2.5 py-1 text-xs font-medium text-[var(--ui-text-primary)] shadow-md animate-in fade-in zoom-in-95 pointer-events-none select-none',
|
|
8
|
-
{
|
|
9
|
-
variants: {
|
|
10
|
-
placement: {
|
|
11
|
-
top: '-translate-x-1/2 -translate-y-full mb-1.5',
|
|
12
|
-
bottom: '-translate-x-1/2 mt-1.5',
|
|
13
|
-
left: '-translate-x-full -translate-y-1/2 mr-1.5',
|
|
14
|
-
right: 'translate-y-[-50%] ml-1.5',
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
defaultVariants: {
|
|
18
|
-
placement: 'top',
|
|
19
|
-
},
|
|
20
|
-
}
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
export interface TooltipProps extends VariantProps<typeof tooltipVariants> {
|
|
24
|
-
content: React.ReactNode;
|
|
25
|
-
children: React.ReactNode;
|
|
26
|
-
delayDuration?: number;
|
|
27
|
-
className?: string;
|
|
28
|
-
id?: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function Tooltip({
|
|
32
|
-
content,
|
|
33
|
-
children,
|
|
34
|
-
placement = 'top',
|
|
35
|
-
delayDuration = 200,
|
|
36
|
-
className,
|
|
37
|
-
id: customId,
|
|
38
|
-
}: TooltipProps) {
|
|
39
|
-
const generatedId = useId();
|
|
40
|
-
const tooltipId = customId || `tooltip-${generatedId}`;
|
|
41
|
-
|
|
42
|
-
const [isVisible, setIsVisible] = useState(false);
|
|
43
|
-
const [coords, setCoords] = useState<{ top: number; left: number }>({ top: 0, left: 0 });
|
|
44
|
-
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
45
|
-
const triggerRef = useRef<HTMLDivElement | null>(null);
|
|
46
|
-
|
|
47
|
-
const calculatePosition = () => {
|
|
48
|
-
if (triggerRef.current) {
|
|
49
|
-
const rect = triggerRef.current.getBoundingClientRect();
|
|
50
|
-
let top = 0;
|
|
51
|
-
let left = 0;
|
|
52
|
-
|
|
53
|
-
if (placement === 'top') {
|
|
54
|
-
top = rect.top + window.scrollY;
|
|
55
|
-
left = rect.left + rect.width / 2 + window.scrollX;
|
|
56
|
-
} else if (placement === 'bottom') {
|
|
57
|
-
top = rect.bottom + window.scrollY;
|
|
58
|
-
left = rect.left + rect.width / 2 + window.scrollX;
|
|
59
|
-
} else if (placement === 'left') {
|
|
60
|
-
top = rect.top + rect.height / 2 + window.scrollY;
|
|
61
|
-
left = rect.left + window.scrollX;
|
|
62
|
-
} else if (placement === 'right') {
|
|
63
|
-
top = rect.top + rect.height / 2 + window.scrollY;
|
|
64
|
-
left = rect.right + window.scrollX;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
setCoords({ top, left });
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const handleMouseEnter = () => {
|
|
72
|
-
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
73
|
-
timeoutRef.current = setTimeout(() => {
|
|
74
|
-
calculatePosition();
|
|
75
|
-
setIsVisible(true);
|
|
76
|
-
}, delayDuration);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const handleMouseLeave = () => {
|
|
80
|
-
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
81
|
-
setIsVisible(false);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
useEffect(() => {
|
|
85
|
-
if (!isVisible) return;
|
|
86
|
-
|
|
87
|
-
const handleKeyDown = (e: KeyboardEvent) => {
|
|
88
|
-
if (e.key === 'Escape') {
|
|
89
|
-
setIsVisible(false);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
window.addEventListener('keydown', handleKeyDown);
|
|
94
|
-
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
95
|
-
}, [isVisible]);
|
|
96
|
-
|
|
97
|
-
return (
|
|
98
|
-
<>
|
|
99
|
-
<div
|
|
100
|
-
ref={triggerRef}
|
|
101
|
-
onMouseEnter={handleMouseEnter}
|
|
102
|
-
onMouseLeave={handleMouseLeave}
|
|
103
|
-
onFocus={handleMouseEnter}
|
|
104
|
-
onBlur={handleMouseLeave}
|
|
105
|
-
aria-describedby={isVisible ? tooltipId : undefined}
|
|
106
|
-
className="inline-flex cursor-pointer"
|
|
107
|
-
>
|
|
108
|
-
{children}
|
|
109
|
-
</div>
|
|
110
|
-
|
|
111
|
-
{isVisible && (
|
|
112
|
-
<Portal>
|
|
113
|
-
<div
|
|
114
|
-
id={tooltipId}
|
|
115
|
-
role="tooltip"
|
|
116
|
-
style={{ top: `${coords.top}px`, left: `${coords.left}px`, position: 'absolute' }}
|
|
117
|
-
className={cn(tooltipVariants({ placement }), className)}
|
|
118
|
-
>
|
|
119
|
-
{content}
|
|
120
|
-
</div>
|
|
121
|
-
</Portal>
|
|
122
|
-
)}
|
|
123
|
-
</>
|
|
124
|
-
);
|
|
125
|
-
}
|
|
1
|
+
import React, { useState, useRef, useId, useEffect } from 'react';
|
|
2
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
3
|
+
import { Portal } from './Portal';
|
|
4
|
+
import { cn } from '../utils/cn';
|
|
5
|
+
|
|
6
|
+
export const tooltipVariants = cva(
|
|
7
|
+
'z-50 overflow-hidden rounded-[var(--ui-radius-sm)] bg-[var(--ui-bg-primary)] border border-[var(--ui-border-default)] px-2.5 py-1 text-xs font-medium text-[var(--ui-text-primary)] shadow-md animate-in fade-in zoom-in-95 pointer-events-none select-none',
|
|
8
|
+
{
|
|
9
|
+
variants: {
|
|
10
|
+
placement: {
|
|
11
|
+
top: '-translate-x-1/2 -translate-y-full mb-1.5',
|
|
12
|
+
bottom: '-translate-x-1/2 mt-1.5',
|
|
13
|
+
left: '-translate-x-full -translate-y-1/2 mr-1.5',
|
|
14
|
+
right: 'translate-y-[-50%] ml-1.5',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
defaultVariants: {
|
|
18
|
+
placement: 'top',
|
|
19
|
+
},
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export interface TooltipProps extends VariantProps<typeof tooltipVariants> {
|
|
24
|
+
content: React.ReactNode;
|
|
25
|
+
children: React.ReactNode;
|
|
26
|
+
delayDuration?: number;
|
|
27
|
+
className?: string;
|
|
28
|
+
id?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function Tooltip({
|
|
32
|
+
content,
|
|
33
|
+
children,
|
|
34
|
+
placement = 'top',
|
|
35
|
+
delayDuration = 200,
|
|
36
|
+
className,
|
|
37
|
+
id: customId,
|
|
38
|
+
}: TooltipProps) {
|
|
39
|
+
const generatedId = useId();
|
|
40
|
+
const tooltipId = customId || `tooltip-${generatedId}`;
|
|
41
|
+
|
|
42
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
43
|
+
const [coords, setCoords] = useState<{ top: number; left: number }>({ top: 0, left: 0 });
|
|
44
|
+
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
45
|
+
const triggerRef = useRef<HTMLDivElement | null>(null);
|
|
46
|
+
|
|
47
|
+
const calculatePosition = () => {
|
|
48
|
+
if (triggerRef.current) {
|
|
49
|
+
const rect = triggerRef.current.getBoundingClientRect();
|
|
50
|
+
let top = 0;
|
|
51
|
+
let left = 0;
|
|
52
|
+
|
|
53
|
+
if (placement === 'top') {
|
|
54
|
+
top = rect.top + window.scrollY;
|
|
55
|
+
left = rect.left + rect.width / 2 + window.scrollX;
|
|
56
|
+
} else if (placement === 'bottom') {
|
|
57
|
+
top = rect.bottom + window.scrollY;
|
|
58
|
+
left = rect.left + rect.width / 2 + window.scrollX;
|
|
59
|
+
} else if (placement === 'left') {
|
|
60
|
+
top = rect.top + rect.height / 2 + window.scrollY;
|
|
61
|
+
left = rect.left + window.scrollX;
|
|
62
|
+
} else if (placement === 'right') {
|
|
63
|
+
top = rect.top + rect.height / 2 + window.scrollY;
|
|
64
|
+
left = rect.right + window.scrollX;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
setCoords({ top, left });
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const handleMouseEnter = () => {
|
|
72
|
+
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
73
|
+
timeoutRef.current = setTimeout(() => {
|
|
74
|
+
calculatePosition();
|
|
75
|
+
setIsVisible(true);
|
|
76
|
+
}, delayDuration);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const handleMouseLeave = () => {
|
|
80
|
+
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
81
|
+
setIsVisible(false);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (!isVisible) return;
|
|
86
|
+
|
|
87
|
+
const handleKeyDown = (e: KeyboardEvent) => {
|
|
88
|
+
if (e.key === 'Escape') {
|
|
89
|
+
setIsVisible(false);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
94
|
+
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
95
|
+
}, [isVisible]);
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<>
|
|
99
|
+
<div
|
|
100
|
+
ref={triggerRef}
|
|
101
|
+
onMouseEnter={handleMouseEnter}
|
|
102
|
+
onMouseLeave={handleMouseLeave}
|
|
103
|
+
onFocus={handleMouseEnter}
|
|
104
|
+
onBlur={handleMouseLeave}
|
|
105
|
+
aria-describedby={isVisible ? tooltipId : undefined}
|
|
106
|
+
className="inline-flex cursor-pointer"
|
|
107
|
+
>
|
|
108
|
+
{children}
|
|
109
|
+
</div>
|
|
110
|
+
|
|
111
|
+
{isVisible && (
|
|
112
|
+
<Portal>
|
|
113
|
+
<div
|
|
114
|
+
id={tooltipId}
|
|
115
|
+
role="tooltip"
|
|
116
|
+
style={{ top: `${coords.top}px`, left: `${coords.left}px`, position: 'absolute' }}
|
|
117
|
+
className={cn(tooltipVariants({ placement }), className)}
|
|
118
|
+
>
|
|
119
|
+
{content}
|
|
120
|
+
</div>
|
|
121
|
+
</Portal>
|
|
122
|
+
)}
|
|
123
|
+
</>
|
|
124
|
+
);
|
|
125
|
+
}
|
package/src/overlays/tokens.css
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/* Overlay Tokens */
|
|
2
|
-
:root {
|
|
3
|
-
--ui-z-drawer: 40;
|
|
4
|
-
--ui-z-modal: 50;
|
|
5
|
-
--ui-z-popover: 60;
|
|
6
|
-
--ui-z-tooltip: 70;
|
|
7
|
-
--ui-z-toast: 100;
|
|
8
|
-
}
|
|
1
|
+
/* Overlay Tokens */
|
|
2
|
+
:root {
|
|
3
|
+
--ui-z-drawer: 40;
|
|
4
|
+
--ui-z-modal: 50;
|
|
5
|
+
--ui-z-popover: 60;
|
|
6
|
+
--ui-z-tooltip: 70;
|
|
7
|
+
--ui-z-toast: 100;
|
|
8
|
+
}
|