@catalystsoftware/ui 1.0.4 → 1.0.5
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/data/tailwind.config.js +261 -3821
- package/dist/components/catalyst-ui/buttons/burger.tsx +207 -0
- package/dist/components/catalyst-ui/core/data-display/timeline.tsx +210 -0
- package/dist/components/catalyst-ui/core/feedback/alert.tsx +491 -0
- package/dist/components/catalyst-ui/core/feedback/spinner-1.tsx +65 -0
- package/dist/components/catalyst-ui/core/feedback/toast.tsx +1857 -0
- package/dist/components/catalyst-ui/core/navigation/menu.tsx +164 -0
- package/dist/components/catalyst-ui/forms/toggle-class.tsx +176 -0
- package/dist/components/catalyst-ui/hooks/use-copy-to-clipboard.tsx +419 -0
- package/dist/components/catalyst-ui/hooks/use-counter.tsx +13 -0
- package/dist/components/catalyst-ui/hooks/use-event-listener.tsx +23 -0
- package/dist/components/catalyst-ui/hooks/use-export-markdown.tsx +47 -0
- package/dist/components/catalyst-ui/hooks/use-focus.tsx +17 -0
- package/dist/components/catalyst-ui/hooks/use-interval.tsx +23 -0
- package/dist/components/catalyst-ui/hooks/use-is-client.tsx +16 -0
- package/dist/components/catalyst-ui/hooks/use-media-query.tsx +19 -0
- package/dist/components/catalyst-ui/hooks/use-mobile.tsx +19 -0
- package/dist/components/catalyst-ui/hooks/use-resize-observer.tsx +81 -0
- package/dist/components/catalyst-ui/hooks/use-timeout.tsx +21 -0
- package/dist/components/catalyst-ui/hooks/use-timer.tsx +209 -0
- package/dist/components/catalyst-ui/hooks/use-toggle.tsx +12 -0
- package/dist/components/catalyst-ui/media/image.tsx +13 -0
- package/dist/components/catalyst-ui/overlays/dual-sidebar.tsx +4142 -0
- package/dist/components/catalyst-ui/overlays/sidebar-original.tsx +726 -0
- package/dist/components/catalyst-ui/primitives/accordion.tsx +250 -0
- package/dist/components/catalyst-ui/primitives/alert-dialog.tsx +126 -0
- package/dist/components/catalyst-ui/primitives/aspect-ratio.tsx +9 -0
- package/dist/components/catalyst-ui/primitives/avatar.tsx +296 -0
- package/dist/components/catalyst-ui/primitives/badge.tsx +57 -0
- package/dist/components/catalyst-ui/primitives/breadcrumb.tsx +101 -0
- package/dist/components/catalyst-ui/primitives/button.tsx +265 -0
- package/dist/components/catalyst-ui/primitives/calendar-v4.tsx +208 -0
- package/dist/components/catalyst-ui/primitives/calendar.tsx +295 -0
- package/dist/components/catalyst-ui/primitives/card.tsx +618 -0
- package/dist/components/catalyst-ui/primitives/carousel.tsx +238 -0
- package/dist/components/catalyst-ui/primitives/chart.tsx +347 -0
- package/dist/components/catalyst-ui/primitives/checkbox.tsx +225 -0
- package/dist/components/catalyst-ui/primitives/collapsible.tsx +212 -0
- package/dist/components/catalyst-ui/primitives/command.tsx +393 -0
- package/dist/components/catalyst-ui/primitives/context-menu.tsx +236 -0
- package/dist/components/catalyst-ui/primitives/dialog.tsx +471 -0
- package/dist/components/catalyst-ui/primitives/drawer.tsx +761 -0
- package/dist/components/catalyst-ui/primitives/dropdown-menu.tsx +290 -0
- package/dist/components/catalyst-ui/primitives/empty.tsx +104 -0
- package/dist/components/catalyst-ui/primitives/field.tsx +244 -0
- package/dist/components/catalyst-ui/primitives/hover-card.tsx +124 -0
- package/dist/components/catalyst-ui/primitives/input-otp.tsx +76 -0
- package/dist/components/catalyst-ui/primitives/input.tsx +64 -0
- package/dist/components/catalyst-ui/primitives/item.tsx +196 -0
- package/dist/components/catalyst-ui/primitives/kbd.tsx +75 -0
- package/dist/components/catalyst-ui/primitives/label.tsx +24 -0
- package/dist/components/catalyst-ui/primitives/navigation-menu.tsx +150 -0
- package/dist/components/catalyst-ui/primitives/pagination.tsx +198 -0
- package/dist/components/catalyst-ui/primitives/popover.tsx +232 -0
- package/dist/components/catalyst-ui/primitives/progress.tsx +34 -0
- package/dist/components/catalyst-ui/primitives/radio-group.tsx +43 -0
- package/dist/components/catalyst-ui/primitives/resizable.tsx +56 -0
- package/dist/components/catalyst-ui/primitives/select.tsx +155 -0
- package/dist/components/catalyst-ui/primitives/separator.tsx +74 -0
- package/dist/components/catalyst-ui/primitives/sheet.tsx +126 -0
- package/dist/components/catalyst-ui/primitives/skeleton.tsx +15 -0
- package/dist/components/catalyst-ui/primitives/slider.tsx +27 -0
- package/dist/components/catalyst-ui/primitives/switch.tsx +187 -0
- package/dist/components/catalyst-ui/primitives/tabs.tsx +335 -0
- package/dist/components/catalyst-ui/primitives/textarea.tsx +24 -0
- package/dist/components/catalyst-ui/primitives/toggle-group.tsx +55 -0
- package/dist/components/catalyst-ui/primitives/toggle.tsx +42 -0
- package/dist/components/catalyst-ui/primitives/tooltip.tsx +116 -0
- package/dist/components/catalyst-ui/utils/basic-auth.tsx +40 -0
- package/dist/components/catalyst-ui/utils/context-storage.tsx +19 -0
- package/dist/components/catalyst-ui/utils/cors-middleware.tsx +71 -0
- package/dist/components/catalyst-ui/utils/deferred-content.tsx +595 -0
- package/dist/components/catalyst-ui/utils/honeypot-middleware.tsx +38 -0
- package/dist/components/catalyst-ui/utils/incId.tsx +75 -0
- package/dist/components/catalyst-ui/utils/jwk-auth.tsx +36 -0
- package/dist/components/catalyst-ui/utils/request-id.tsx +14 -0
- package/dist/components/catalyst-ui/utils/secure-headers.tsx +37 -0
- package/dist/components/catalyst-ui/utils/server-timing.tsx +23 -0
- package/dist/components/catalyst-ui/utils/utils.ts +43 -0
- package/dist/components/catalyst-ui/utils/with-cookie.tsx +43 -0
- package/dist/components/catalyst-ui/x/accordian-x.tsx +428 -0
- package/dist/components/catalyst-ui/x/alert-x.tsx +413 -0
- package/dist/components/catalyst-ui/x/animated-text-x.tsx +2242 -0
- package/dist/components/catalyst-ui/x/avatar-x.tsx +515 -0
- package/dist/components/catalyst-ui/x/badge-x.tsx +670 -0
- package/dist/components/catalyst-ui/x/button-X.tsx +2857 -0
- package/dist/components/catalyst-ui/x/button-group-x.tsx +847 -0
- package/dist/components/catalyst-ui/x/calendar-x.tsx +1910 -0
- package/dist/components/catalyst-ui/x/card-x.tsx +2597 -0
- package/dist/components/catalyst-ui/x/checkbox-x.tsx +656 -0
- package/dist/components/catalyst-ui/x/collapsible-x.tsx +1360 -0
- package/dist/components/catalyst-ui/x/combobox-x.tsx +911 -0
- package/dist/components/catalyst-ui/x/data-table-x.tsx +1753 -0
- package/dist/components/catalyst-ui/x/date-picker-x.tsx +648 -0
- package/dist/components/catalyst-ui/x/dialog-x.tsx +659 -0
- package/dist/components/catalyst-ui/x/dropdown-menu-x.tsx +612 -0
- package/dist/components/catalyst-ui/x/hover-card-x.tsx +375 -0
- package/dist/components/catalyst-ui/x/icon-x.tsx +840 -0
- package/dist/components/catalyst-ui/x/input-mask-x.tsx +981 -0
- package/dist/components/catalyst-ui/x/input-otp-x.tsx +659 -0
- package/dist/components/catalyst-ui/x/loader-x.tsx +1757 -0
- package/dist/components/catalyst-ui/x/pagination-x.tsx +622 -0
- package/dist/components/catalyst-ui/x/popover-x.tsx +744 -0
- package/dist/components/catalyst-ui/x/radio-group-x.tsx +499 -0
- package/dist/components/catalyst-ui/x/select-x.tsx +1127 -0
- package/dist/components/catalyst-ui/x/sheet-x.tsx +668 -0
- package/dist/components/catalyst-ui/x/switch-x.tsx +681 -0
- package/dist/components/catalyst-ui/x/table-x.tsx +574 -0
- package/dist/components/catalyst-ui/x/tabs-x.tsx +839 -0
- package/dist/components/catalyst-ui/x/textarea-x.tsx +1263 -0
- package/dist/components/catalyst-ui/x/tooltip-x.tsx +396 -0
- package/dist/components/catalyst-ui/x/tracker-x.tsx +560 -0
- package/dist/data/bg-data.tsx +901 -0
- package/dist/data/buttons-data.tsx +2327 -0
- package/dist/data/charts-data.tsx +102 -0
- package/dist/data/chat-data.tsx +83 -0
- package/dist/data/code-data.tsx +1040 -0
- package/dist/data/comboboxes-data.tsx +1843 -0
- package/dist/data/command-data.tsx +1381 -0
- package/dist/data/core-data.tsx +15953 -0
- package/dist/data/crm-data.tsx +47 -0
- package/dist/data/data.tsx +159 -0
- package/dist/data/date-and-time-data.tsx +554 -0
- package/dist/data/dependencies.tsx +7 -0
- package/dist/data/ecommerce-data.tsx +1387 -0
- package/dist/data/forms-data.tsx +7890 -0
- package/dist/data/hooks-data.tsx +5487 -0
- package/dist/data/index.ts +34 -0
- package/dist/data/inputs-data.tsx +557 -0
- package/dist/data/interactive-data.tsx +5394 -0
- package/dist/data/lofi-data.tsx +18295 -0
- package/dist/data/marketing-data.tsx +2546 -0
- package/dist/data/media-data.tsx +1510 -0
- package/dist/data/motion-data.tsx +5801 -0
- package/dist/data/overlay-data.tsx +4136 -0
- package/dist/data/pdf-data.tsx +124 -0
- package/dist/data/pos-data.tsx +213 -0
- package/dist/data/postcss.config.js +6 -0
- package/dist/data/primitive-data.tsx +5170 -0
- package/dist/data/prompt-data.tsx +1226 -0
- package/dist/data/requiredLibs.ts +4 -0
- package/dist/data/sandbox-data.tsx +1 -0
- package/dist/data/sidebars-data.tsx +5421 -0
- package/dist/data/stacks-data.tsx +32 -0
- package/dist/data/table-data.tsx +706 -0
- package/dist/data/tailwind.config.js +270 -0
- package/dist/data/tailwind.config.ngin.js +3830 -0
- package/dist/data/tailwind.css +431 -0
- package/dist/data/tools-data.tsx +6910 -0
- package/dist/data/typography-data.tsx +2050 -0
- package/dist/data/utils-data.tsx +6500 -0
- package/dist/data/x-data.tsx +1171 -0
- package/dist/data.tsx +159 -0
- package/package.json +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -362
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Info, Mail, HelpCircle, CreditCard, Home, Settings, User, FileText, Calendar, ShoppingCart, BarChart3, Shield } from 'lucide-react';
|
|
3
|
+
import { cn } from '~/components/catalyst-ui';
|
|
4
|
+
|
|
5
|
+
interface MenuItem {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
icon: React.ReactNode;
|
|
9
|
+
href?: string;
|
|
10
|
+
onClick?: () => void;
|
|
11
|
+
active?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface CategoryMenuProps {
|
|
15
|
+
title?: string;
|
|
16
|
+
items: MenuItem[];
|
|
17
|
+
activeItemId?: string;
|
|
18
|
+
onItemClick?: (item: MenuItem) => void;
|
|
19
|
+
className?: string;
|
|
20
|
+
width?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function Menu({
|
|
24
|
+
title = "Categories",
|
|
25
|
+
items,
|
|
26
|
+
activeItemId,
|
|
27
|
+
onItemClick,
|
|
28
|
+
className = "",
|
|
29
|
+
width = "md:w-80"
|
|
30
|
+
}: CategoryMenuProps) {
|
|
31
|
+
const [selectedItemId, setSelectedItemId] = useState(activeItemId || items.find(item => item.active)?.id || '');
|
|
32
|
+
|
|
33
|
+
const handleItemClick = (item, index) => {
|
|
34
|
+
setSelectedItemId(index);
|
|
35
|
+
onItemClick?.(item);
|
|
36
|
+
if (item.onClick) {
|
|
37
|
+
item.onClick();
|
|
38
|
+
} else if (item.href) {
|
|
39
|
+
window.location.href = item.href;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div className={cn("bg-card border-0 mb-0", width, className)}>
|
|
45
|
+
<div className="text-foreground block font-bold mb-3 text-lg">
|
|
46
|
+
{title}
|
|
47
|
+
</div>
|
|
48
|
+
<ul className="list-none m-0 p-0">
|
|
49
|
+
{items.map((item,index) => (
|
|
50
|
+
<li key={index} className="mb-2">
|
|
51
|
+
<button
|
|
52
|
+
onClick={() => handleItemClick(item, index)}
|
|
53
|
+
className={cn(
|
|
54
|
+
"w-full flex items-center cursor-pointer select-none p-3 transition-colors duration-150 rounded-md text-left",
|
|
55
|
+
selectedItemId === index
|
|
56
|
+
? "bg-muted text-foreground"
|
|
57
|
+
: "hover:bg-accent hover:text-accent-foreground text-muted-foreground"
|
|
58
|
+
)}
|
|
59
|
+
>
|
|
60
|
+
{item.icon && (
|
|
61
|
+
<span className="mr-2 text-lg flex-shrink-0">
|
|
62
|
+
{item.icon}
|
|
63
|
+
</span>
|
|
64
|
+
)}
|
|
65
|
+
<span className="font-medium">
|
|
66
|
+
{item.label}
|
|
67
|
+
</span>
|
|
68
|
+
</button>
|
|
69
|
+
</li>
|
|
70
|
+
))}
|
|
71
|
+
</ul>
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function CategoryMenuDemo() {
|
|
77
|
+
const [selectedCategory, setSelectedCategory] = useState('');
|
|
78
|
+
|
|
79
|
+
const menuItems: MenuItem[] = [
|
|
80
|
+
{
|
|
81
|
+
id: 'general',
|
|
82
|
+
label: 'General',
|
|
83
|
+
icon: <Info className="w-5 h-5" />,
|
|
84
|
+
href: '#general'
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
id: 'mailing',
|
|
88
|
+
label: 'Mailing',
|
|
89
|
+
icon: <Mail className="w-5 h-5" />,
|
|
90
|
+
href: '#mailing'
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
id: 'support',
|
|
94
|
+
label: 'Support',
|
|
95
|
+
icon: <HelpCircle className="w-5 h-5" />,
|
|
96
|
+
href: '#support'
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
id: 'billing',
|
|
100
|
+
label: 'Billing',
|
|
101
|
+
icon: <CreditCard className="w-5 h-5" />,
|
|
102
|
+
href: '#billing',
|
|
103
|
+
active: true
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: 'dashboard',
|
|
107
|
+
label: 'Dashboard',
|
|
108
|
+
icon: <BarChart3 className="w-5 h-5" />,
|
|
109
|
+
href: '#dashboard'
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: 'profile',
|
|
113
|
+
label: 'Profile',
|
|
114
|
+
icon: <User className="w-5 h-5" />,
|
|
115
|
+
href: '#profile'
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
id: 'documents',
|
|
119
|
+
label: 'Documents',
|
|
120
|
+
icon: <FileText className="w-5 h-5" />,
|
|
121
|
+
href: '#documents'
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
id: 'calendar',
|
|
125
|
+
label: 'Calendar',
|
|
126
|
+
icon: <Calendar className="w-5 h-5" />,
|
|
127
|
+
href: '#calendar'
|
|
128
|
+
}
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
const handleCategorySelect = (item: MenuItem) => {
|
|
132
|
+
setSelectedCategory(item.label);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<div className="min-h-screen bg-background p-8">
|
|
137
|
+
<div className="max-w-6xl mx-auto">
|
|
138
|
+
<h2 className="text-2xl font-bold text-foreground mb-8">Category Menu Demo</h2>
|
|
139
|
+
|
|
140
|
+
<div className="grid grid-cols-1 lg:grid-cols-3 gap-8">
|
|
141
|
+
<Menu
|
|
142
|
+
items={menuItems}
|
|
143
|
+
onItemClick={handleCategorySelect}
|
|
144
|
+
title="Main Categories"
|
|
145
|
+
/>
|
|
146
|
+
|
|
147
|
+
<Menu
|
|
148
|
+
items={menuItems.slice(0, 4)}
|
|
149
|
+
onItemClick={handleCategorySelect}
|
|
150
|
+
title="Quick Access"
|
|
151
|
+
width="w-full"
|
|
152
|
+
/>
|
|
153
|
+
|
|
154
|
+
<div className="bg-card border border-border rounded-lg p-6">
|
|
155
|
+
<h3 className="font-semibold text-foreground mb-4">Selected Category</h3>
|
|
156
|
+
<p className="text-muted-foreground">
|
|
157
|
+
{selectedCategory ? `You selected: ${selectedCategory}` : 'Click on a category to see it here'}
|
|
158
|
+
</p>
|
|
159
|
+
</div>
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
162
|
+
</div>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import React, { useRef, useEffect, useCallback } from 'react'
|
|
2
|
+
import { Button } from "~/components/catalyst-ui"
|
|
3
|
+
import { Input } from "~/components/catalyst-ui"
|
|
4
|
+
import { Card, CardContent } from "~/components/catalyst-ui"
|
|
5
|
+
import { cn } from "~/components/catalyst-ui"
|
|
6
|
+
|
|
7
|
+
interface ToggleClassProps {
|
|
8
|
+
nodeRef?: React.RefObject<HTMLElement>
|
|
9
|
+
selector?: string
|
|
10
|
+
toggleClassName?: string
|
|
11
|
+
enterClassName?: string
|
|
12
|
+
enterActiveClassName?: string
|
|
13
|
+
enterToClassName?: string
|
|
14
|
+
leaveClassName?: string
|
|
15
|
+
leaveActiveClassName?: string
|
|
16
|
+
leaveToClassName?: string
|
|
17
|
+
hideOnOutsideClick?: boolean
|
|
18
|
+
animationDuration?: number
|
|
19
|
+
children?: React.ReactNode
|
|
20
|
+
variant?: "toggle" | "enter-leave"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
function ToggleClass({
|
|
25
|
+
nodeRef,
|
|
26
|
+
selector = "@next",
|
|
27
|
+
toggleClassName,
|
|
28
|
+
enterClassName,
|
|
29
|
+
enterActiveClassName,
|
|
30
|
+
enterToClassName,
|
|
31
|
+
leaveClassName,
|
|
32
|
+
leaveActiveClassName,
|
|
33
|
+
leaveToClassName,
|
|
34
|
+
hideOnOutsideClick = false,
|
|
35
|
+
animationDuration = 300,
|
|
36
|
+
children,
|
|
37
|
+
variant = "toggle"
|
|
38
|
+
}) {
|
|
39
|
+
const internalRef = useRef(null);
|
|
40
|
+
const targetRef = nodeRef || internalRef;
|
|
41
|
+
const isAnimating = useRef(false);
|
|
42
|
+
|
|
43
|
+
const findTarget = useCallback((element, selector) => {
|
|
44
|
+
switch (selector) {
|
|
45
|
+
case "@next":
|
|
46
|
+
return element.nextElementSibling;
|
|
47
|
+
case "@prev":
|
|
48
|
+
return element.previousElementSibling;
|
|
49
|
+
case "@parent":
|
|
50
|
+
return element.parentElement;
|
|
51
|
+
case "@grandparent":
|
|
52
|
+
return element.parentElement?.parentElement;
|
|
53
|
+
default:
|
|
54
|
+
return document.querySelector(selector);
|
|
55
|
+
}
|
|
56
|
+
}, []);
|
|
57
|
+
|
|
58
|
+
const handleToggleClass = useCallback(() => {
|
|
59
|
+
const triggerElement = targetRef.current;
|
|
60
|
+
if (!triggerElement) return;
|
|
61
|
+
|
|
62
|
+
const target = findTarget(triggerElement, selector);
|
|
63
|
+
if (!target || !toggleClassName) return;
|
|
64
|
+
|
|
65
|
+
toggleClassName.split(' ').forEach(cls => {
|
|
66
|
+
target.classList.toggle(cls);
|
|
67
|
+
});
|
|
68
|
+
}, [targetRef, selector, toggleClassName, findTarget]);
|
|
69
|
+
|
|
70
|
+
const handleEnterLeave = useCallback((isEntering) => {
|
|
71
|
+
const triggerElement = targetRef.current;
|
|
72
|
+
if (!triggerElement || isAnimating.current) return;
|
|
73
|
+
|
|
74
|
+
const target = findTarget(triggerElement, selector);
|
|
75
|
+
if (!target) return;
|
|
76
|
+
|
|
77
|
+
isAnimating.current = true;
|
|
78
|
+
|
|
79
|
+
if (isEntering) {
|
|
80
|
+
if (enterClassName) enterClassName.split(' ').forEach(cls => target.classList.add(cls));
|
|
81
|
+
if (enterActiveClassName) {
|
|
82
|
+
enterActiveClassName.split(' ').forEach(cls => target.classList.add(cls));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
requestAnimationFrame(() => {
|
|
86
|
+
if (enterToClassName) enterToClassName.split(' ').forEach(cls => target.classList.add(cls));
|
|
87
|
+
if (enterClassName) enterClassName.split(' ').forEach(cls => target.classList.remove(cls));
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
setTimeout(() => {
|
|
91
|
+
if (enterActiveClassName) enterActiveClassName.split(' ').forEach(cls => target.classList.remove(cls));
|
|
92
|
+
if (enterToClassName) enterToClassName.split(' ').forEach(cls => target.classList.remove(cls));
|
|
93
|
+
isAnimating.current = false;
|
|
94
|
+
}, animationDuration);
|
|
95
|
+
} else {
|
|
96
|
+
if (leaveClassName) leaveClassName.split(' ').forEach(cls => target.classList.add(cls));
|
|
97
|
+
if (leaveActiveClassName) {
|
|
98
|
+
leaveActiveClassName.split(' ').forEach(cls => target.classList.add(cls));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
requestAnimationFrame(() => {
|
|
102
|
+
if (leaveToClassName) leaveToClassName.split(' ').forEach(cls => target.classList.add(cls));
|
|
103
|
+
if (leaveClassName) leaveClassName.split(' ').forEach(cls => target.classList.remove(cls));
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
setTimeout(() => {
|
|
107
|
+
if (leaveActiveClassName) leaveActiveClassName.split(' ').forEach(cls => target.classList.remove(cls));
|
|
108
|
+
if (leaveToClassName) leaveToClassName.split(' ').forEach(cls => target.classList.remove(cls));
|
|
109
|
+
isAnimating.current = false;
|
|
110
|
+
}, animationDuration);
|
|
111
|
+
}
|
|
112
|
+
}, [targetRef, selector, enterClassName, enterActiveClassName, enterToClassName, leaveClassName, leaveActiveClassName, leaveToClassName, animationDuration, findTarget]);
|
|
113
|
+
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
const triggerElement = targetRef.current;
|
|
116
|
+
if (!triggerElement) return;
|
|
117
|
+
|
|
118
|
+
const handleClick = () => {
|
|
119
|
+
if (variant === "toggle" && toggleClassName) {
|
|
120
|
+
handleToggleClass();
|
|
121
|
+
} else if (variant === "enter-leave") {
|
|
122
|
+
const target = findTarget(triggerElement, selector);
|
|
123
|
+
if (target) {
|
|
124
|
+
const isHidden = target.classList.contains("hidden") ||
|
|
125
|
+
target.style.display === "none" ||
|
|
126
|
+
target.offsetParent === null;
|
|
127
|
+
handleEnterLeave(isHidden);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const handleOutsideClick = (event) => {
|
|
133
|
+
if (!hideOnOutsideClick) return;
|
|
134
|
+
|
|
135
|
+
const target = findTarget(triggerElement, selector);
|
|
136
|
+
if (!target) return;
|
|
137
|
+
|
|
138
|
+
const clickedElement = event.target;
|
|
139
|
+
if (!target.contains(clickedElement) && !triggerElement.contains(clickedElement)) {
|
|
140
|
+
if (variant === "enter-leave") {
|
|
141
|
+
handleEnterLeave(false);
|
|
142
|
+
} else if (variant === "toggle" && toggleClassName) {
|
|
143
|
+
toggleClassName.split(' ').forEach(cls => {
|
|
144
|
+
if (target.classList.contains(cls)) {
|
|
145
|
+
target.classList.remove(cls);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
triggerElement.addEventListener('click', handleClick);
|
|
153
|
+
|
|
154
|
+
if (hideOnOutsideClick) {
|
|
155
|
+
document.addEventListener('click', handleOutsideClick);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return () => {
|
|
159
|
+
triggerElement.removeEventListener('click', handleClick);
|
|
160
|
+
if (hideOnOutsideClick) {
|
|
161
|
+
document.removeEventListener('click', handleOutsideClick);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}, [variant, toggleClassName, hideOnOutsideClick, handleToggleClass, handleEnterLeave, targetRef, selector, findTarget]);
|
|
165
|
+
|
|
166
|
+
if (!children) {
|
|
167
|
+
return <div ref={internalRef} />;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return React.cloneElement(children, {
|
|
171
|
+
ref: targetRef
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
export { ToggleClass }
|