@catalystsoftware/ui 1.0.5 → 1.0.7
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/dist/data/data.tsx +29 -29
- package/dist/data/tailwind.config.js +3821 -261
- package/dist/data.tsx +29 -29
- package/package.json +4 -3
- package/components/catalyst-ui/buttons/burger.tsx +0 -207
- package/components/catalyst-ui/core/data-display/timeline.tsx +0 -210
- package/components/catalyst-ui/core/feedback/alert.tsx +0 -491
- package/components/catalyst-ui/core/feedback/spinner-1.tsx +0 -65
- package/components/catalyst-ui/core/feedback/toast.tsx +0 -1857
- package/components/catalyst-ui/core/navigation/menu.tsx +0 -164
- package/components/catalyst-ui/forms/toggle-class.tsx +0 -176
- package/components/catalyst-ui/hooks/use-copy-to-clipboard.tsx +0 -419
- package/components/catalyst-ui/hooks/use-counter.tsx +0 -13
- package/components/catalyst-ui/hooks/use-event-listener.tsx +0 -23
- package/components/catalyst-ui/hooks/use-export-markdown.tsx +0 -47
- package/components/catalyst-ui/hooks/use-focus.tsx +0 -17
- package/components/catalyst-ui/hooks/use-interval.tsx +0 -23
- package/components/catalyst-ui/hooks/use-is-client.tsx +0 -16
- package/components/catalyst-ui/hooks/use-media-query.tsx +0 -19
- package/components/catalyst-ui/hooks/use-mobile.tsx +0 -19
- package/components/catalyst-ui/hooks/use-resize-observer.tsx +0 -81
- package/components/catalyst-ui/hooks/use-timeout.tsx +0 -21
- package/components/catalyst-ui/hooks/use-timer.tsx +0 -209
- package/components/catalyst-ui/hooks/use-toggle.tsx +0 -12
- package/components/catalyst-ui/media/image.tsx +0 -13
- package/components/catalyst-ui/overlays/dual-sidebar.tsx +0 -4142
- package/components/catalyst-ui/overlays/sidebar-original.tsx +0 -726
- package/components/catalyst-ui/primitives/accordion.tsx +0 -250
- package/components/catalyst-ui/primitives/alert-dialog.tsx +0 -126
- package/components/catalyst-ui/primitives/aspect-ratio.tsx +0 -9
- package/components/catalyst-ui/primitives/avatar.tsx +0 -296
- package/components/catalyst-ui/primitives/badge.tsx +0 -57
- package/components/catalyst-ui/primitives/breadcrumb.tsx +0 -101
- package/components/catalyst-ui/primitives/button.tsx +0 -265
- package/components/catalyst-ui/primitives/calendar-v4.tsx +0 -208
- package/components/catalyst-ui/primitives/calendar.tsx +0 -295
- package/components/catalyst-ui/primitives/card.tsx +0 -618
- package/components/catalyst-ui/primitives/carousel.tsx +0 -238
- package/components/catalyst-ui/primitives/chart.tsx +0 -347
- package/components/catalyst-ui/primitives/checkbox.tsx +0 -225
- package/components/catalyst-ui/primitives/collapsible.tsx +0 -212
- package/components/catalyst-ui/primitives/command.tsx +0 -393
- package/components/catalyst-ui/primitives/context-menu.tsx +0 -236
- package/components/catalyst-ui/primitives/dialog.tsx +0 -471
- package/components/catalyst-ui/primitives/drawer.tsx +0 -761
- package/components/catalyst-ui/primitives/dropdown-menu.tsx +0 -290
- package/components/catalyst-ui/primitives/empty.tsx +0 -104
- package/components/catalyst-ui/primitives/field.tsx +0 -244
- package/components/catalyst-ui/primitives/hover-card.tsx +0 -124
- package/components/catalyst-ui/primitives/input-otp.tsx +0 -76
- package/components/catalyst-ui/primitives/input.tsx +0 -64
- package/components/catalyst-ui/primitives/item.tsx +0 -196
- package/components/catalyst-ui/primitives/kbd.tsx +0 -75
- package/components/catalyst-ui/primitives/label.tsx +0 -24
- package/components/catalyst-ui/primitives/navigation-menu.tsx +0 -150
- package/components/catalyst-ui/primitives/pagination.tsx +0 -198
- package/components/catalyst-ui/primitives/popover.tsx +0 -232
- package/components/catalyst-ui/primitives/progress.tsx +0 -34
- package/components/catalyst-ui/primitives/radio-group.tsx +0 -43
- package/components/catalyst-ui/primitives/resizable.tsx +0 -56
- package/components/catalyst-ui/primitives/select.tsx +0 -155
- package/components/catalyst-ui/primitives/separator.tsx +0 -74
- package/components/catalyst-ui/primitives/sheet.tsx +0 -126
- package/components/catalyst-ui/primitives/skeleton.tsx +0 -15
- package/components/catalyst-ui/primitives/slider.tsx +0 -27
- package/components/catalyst-ui/primitives/switch.tsx +0 -187
- package/components/catalyst-ui/primitives/tabs.tsx +0 -335
- package/components/catalyst-ui/primitives/textarea.tsx +0 -24
- package/components/catalyst-ui/primitives/toggle-group.tsx +0 -55
- package/components/catalyst-ui/primitives/toggle.tsx +0 -42
- package/components/catalyst-ui/primitives/tooltip.tsx +0 -116
- package/components/catalyst-ui/utils/basic-auth.tsx +0 -40
- package/components/catalyst-ui/utils/context-storage.tsx +0 -19
- package/components/catalyst-ui/utils/cors-middleware.tsx +0 -71
- package/components/catalyst-ui/utils/deferred-content.tsx +0 -595
- package/components/catalyst-ui/utils/honeypot-middleware.tsx +0 -38
- package/components/catalyst-ui/utils/incId.tsx +0 -75
- package/components/catalyst-ui/utils/jwk-auth.tsx +0 -36
- package/components/catalyst-ui/utils/request-id.tsx +0 -14
- package/components/catalyst-ui/utils/secure-headers.tsx +0 -37
- package/components/catalyst-ui/utils/server-timing.tsx +0 -23
- package/components/catalyst-ui/utils/utils.ts +0 -43
- package/components/catalyst-ui/utils/with-cookie.tsx +0 -43
- package/components/catalyst-ui/x/accordian-x.tsx +0 -428
- package/components/catalyst-ui/x/alert-x.tsx +0 -413
- package/components/catalyst-ui/x/animated-text-x.tsx +0 -2242
- package/components/catalyst-ui/x/avatar-x.tsx +0 -515
- package/components/catalyst-ui/x/badge-x.tsx +0 -670
- package/components/catalyst-ui/x/button-X.tsx +0 -2857
- package/components/catalyst-ui/x/button-group-x.tsx +0 -847
- package/components/catalyst-ui/x/calendar-x.tsx +0 -1910
- package/components/catalyst-ui/x/card-x.tsx +0 -2597
- package/components/catalyst-ui/x/checkbox-x.tsx +0 -656
- package/components/catalyst-ui/x/collapsible-x.tsx +0 -1360
- package/components/catalyst-ui/x/combobox-x.tsx +0 -911
- package/components/catalyst-ui/x/data-table-x.tsx +0 -1753
- package/components/catalyst-ui/x/date-picker-x.tsx +0 -648
- package/components/catalyst-ui/x/dialog-x.tsx +0 -659
- package/components/catalyst-ui/x/dropdown-menu-x.tsx +0 -612
- package/components/catalyst-ui/x/hover-card-x.tsx +0 -375
- package/components/catalyst-ui/x/icon-x.tsx +0 -840
- package/components/catalyst-ui/x/input-mask-x.tsx +0 -981
- package/components/catalyst-ui/x/input-otp-x.tsx +0 -659
- package/components/catalyst-ui/x/loader-x.tsx +0 -1757
- package/components/catalyst-ui/x/pagination-x.tsx +0 -622
- package/components/catalyst-ui/x/popover-x.tsx +0 -744
- package/components/catalyst-ui/x/radio-group-x.tsx +0 -499
- package/components/catalyst-ui/x/select-x.tsx +0 -1127
- package/components/catalyst-ui/x/sheet-x.tsx +0 -668
- package/components/catalyst-ui/x/switch-x.tsx +0 -681
- package/components/catalyst-ui/x/table-x.tsx +0 -574
- package/components/catalyst-ui/x/tabs-x.tsx +0 -839
- package/components/catalyst-ui/x/textarea-x.tsx +0 -1263
- package/components/catalyst-ui/x/tooltip-x.tsx +0 -396
- package/components/catalyst-ui/x/tracker-x.tsx +0 -560
- package/data/bg-data.tsx +0 -901
- package/data/buttons-data.tsx +0 -2327
- package/data/charts-data.tsx +0 -102
- package/data/chat-data.tsx +0 -83
- package/data/code-data.tsx +0 -1040
- package/data/comboboxes-data.tsx +0 -1843
- package/data/command-data.tsx +0 -1381
- package/data/core-data.tsx +0 -15953
- package/data/crm-data.tsx +0 -47
- package/data/data.tsx +0 -159
- package/data/date-and-time-data.tsx +0 -554
- package/data/dependencies.tsx +0 -7
- package/data/ecommerce-data.tsx +0 -1387
- package/data/forms-data.tsx +0 -7890
- package/data/hooks-data.tsx +0 -5487
- package/data/index.ts +0 -34
- package/data/inputs-data.tsx +0 -557
- package/data/interactive-data.tsx +0 -5394
- package/data/lofi-data.tsx +0 -18295
- package/data/marketing-data.tsx +0 -2546
- package/data/media-data.tsx +0 -1510
- package/data/motion-data.tsx +0 -5801
- package/data/overlay-data.tsx +0 -4136
- package/data/pdf-data.tsx +0 -124
- package/data/pos-data.tsx +0 -213
- package/data/postcss.config.js +0 -6
- package/data/primitive-data.tsx +0 -5170
- package/data/prompt-data.tsx +0 -1226
- package/data/requiredLibs.ts +0 -4
- package/data/sandbox-data.tsx +0 -1
- package/data/sidebars-data.tsx +0 -5421
- package/data/stacks-data.tsx +0 -32
- package/data/table-data.tsx +0 -706
- package/data/tailwind.config.js +0 -270
- package/data/tailwind.config.ngin.js +0 -3830
- package/data/tailwind.css +0 -431
- package/data/tools-data.tsx +0 -6910
- package/data/typography-data.tsx +0 -2050
- package/data/utils-data.tsx +0 -6500
- package/data/x-data.tsx +0 -1171
|
@@ -1,164 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,176 +0,0 @@
|
|
|
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 }
|