@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.
Files changed (155) hide show
  1. package/dist/data/data.tsx +29 -29
  2. package/dist/data/tailwind.config.js +3821 -261
  3. package/dist/data.tsx +29 -29
  4. package/package.json +4 -3
  5. package/components/catalyst-ui/buttons/burger.tsx +0 -207
  6. package/components/catalyst-ui/core/data-display/timeline.tsx +0 -210
  7. package/components/catalyst-ui/core/feedback/alert.tsx +0 -491
  8. package/components/catalyst-ui/core/feedback/spinner-1.tsx +0 -65
  9. package/components/catalyst-ui/core/feedback/toast.tsx +0 -1857
  10. package/components/catalyst-ui/core/navigation/menu.tsx +0 -164
  11. package/components/catalyst-ui/forms/toggle-class.tsx +0 -176
  12. package/components/catalyst-ui/hooks/use-copy-to-clipboard.tsx +0 -419
  13. package/components/catalyst-ui/hooks/use-counter.tsx +0 -13
  14. package/components/catalyst-ui/hooks/use-event-listener.tsx +0 -23
  15. package/components/catalyst-ui/hooks/use-export-markdown.tsx +0 -47
  16. package/components/catalyst-ui/hooks/use-focus.tsx +0 -17
  17. package/components/catalyst-ui/hooks/use-interval.tsx +0 -23
  18. package/components/catalyst-ui/hooks/use-is-client.tsx +0 -16
  19. package/components/catalyst-ui/hooks/use-media-query.tsx +0 -19
  20. package/components/catalyst-ui/hooks/use-mobile.tsx +0 -19
  21. package/components/catalyst-ui/hooks/use-resize-observer.tsx +0 -81
  22. package/components/catalyst-ui/hooks/use-timeout.tsx +0 -21
  23. package/components/catalyst-ui/hooks/use-timer.tsx +0 -209
  24. package/components/catalyst-ui/hooks/use-toggle.tsx +0 -12
  25. package/components/catalyst-ui/media/image.tsx +0 -13
  26. package/components/catalyst-ui/overlays/dual-sidebar.tsx +0 -4142
  27. package/components/catalyst-ui/overlays/sidebar-original.tsx +0 -726
  28. package/components/catalyst-ui/primitives/accordion.tsx +0 -250
  29. package/components/catalyst-ui/primitives/alert-dialog.tsx +0 -126
  30. package/components/catalyst-ui/primitives/aspect-ratio.tsx +0 -9
  31. package/components/catalyst-ui/primitives/avatar.tsx +0 -296
  32. package/components/catalyst-ui/primitives/badge.tsx +0 -57
  33. package/components/catalyst-ui/primitives/breadcrumb.tsx +0 -101
  34. package/components/catalyst-ui/primitives/button.tsx +0 -265
  35. package/components/catalyst-ui/primitives/calendar-v4.tsx +0 -208
  36. package/components/catalyst-ui/primitives/calendar.tsx +0 -295
  37. package/components/catalyst-ui/primitives/card.tsx +0 -618
  38. package/components/catalyst-ui/primitives/carousel.tsx +0 -238
  39. package/components/catalyst-ui/primitives/chart.tsx +0 -347
  40. package/components/catalyst-ui/primitives/checkbox.tsx +0 -225
  41. package/components/catalyst-ui/primitives/collapsible.tsx +0 -212
  42. package/components/catalyst-ui/primitives/command.tsx +0 -393
  43. package/components/catalyst-ui/primitives/context-menu.tsx +0 -236
  44. package/components/catalyst-ui/primitives/dialog.tsx +0 -471
  45. package/components/catalyst-ui/primitives/drawer.tsx +0 -761
  46. package/components/catalyst-ui/primitives/dropdown-menu.tsx +0 -290
  47. package/components/catalyst-ui/primitives/empty.tsx +0 -104
  48. package/components/catalyst-ui/primitives/field.tsx +0 -244
  49. package/components/catalyst-ui/primitives/hover-card.tsx +0 -124
  50. package/components/catalyst-ui/primitives/input-otp.tsx +0 -76
  51. package/components/catalyst-ui/primitives/input.tsx +0 -64
  52. package/components/catalyst-ui/primitives/item.tsx +0 -196
  53. package/components/catalyst-ui/primitives/kbd.tsx +0 -75
  54. package/components/catalyst-ui/primitives/label.tsx +0 -24
  55. package/components/catalyst-ui/primitives/navigation-menu.tsx +0 -150
  56. package/components/catalyst-ui/primitives/pagination.tsx +0 -198
  57. package/components/catalyst-ui/primitives/popover.tsx +0 -232
  58. package/components/catalyst-ui/primitives/progress.tsx +0 -34
  59. package/components/catalyst-ui/primitives/radio-group.tsx +0 -43
  60. package/components/catalyst-ui/primitives/resizable.tsx +0 -56
  61. package/components/catalyst-ui/primitives/select.tsx +0 -155
  62. package/components/catalyst-ui/primitives/separator.tsx +0 -74
  63. package/components/catalyst-ui/primitives/sheet.tsx +0 -126
  64. package/components/catalyst-ui/primitives/skeleton.tsx +0 -15
  65. package/components/catalyst-ui/primitives/slider.tsx +0 -27
  66. package/components/catalyst-ui/primitives/switch.tsx +0 -187
  67. package/components/catalyst-ui/primitives/tabs.tsx +0 -335
  68. package/components/catalyst-ui/primitives/textarea.tsx +0 -24
  69. package/components/catalyst-ui/primitives/toggle-group.tsx +0 -55
  70. package/components/catalyst-ui/primitives/toggle.tsx +0 -42
  71. package/components/catalyst-ui/primitives/tooltip.tsx +0 -116
  72. package/components/catalyst-ui/utils/basic-auth.tsx +0 -40
  73. package/components/catalyst-ui/utils/context-storage.tsx +0 -19
  74. package/components/catalyst-ui/utils/cors-middleware.tsx +0 -71
  75. package/components/catalyst-ui/utils/deferred-content.tsx +0 -595
  76. package/components/catalyst-ui/utils/honeypot-middleware.tsx +0 -38
  77. package/components/catalyst-ui/utils/incId.tsx +0 -75
  78. package/components/catalyst-ui/utils/jwk-auth.tsx +0 -36
  79. package/components/catalyst-ui/utils/request-id.tsx +0 -14
  80. package/components/catalyst-ui/utils/secure-headers.tsx +0 -37
  81. package/components/catalyst-ui/utils/server-timing.tsx +0 -23
  82. package/components/catalyst-ui/utils/utils.ts +0 -43
  83. package/components/catalyst-ui/utils/with-cookie.tsx +0 -43
  84. package/components/catalyst-ui/x/accordian-x.tsx +0 -428
  85. package/components/catalyst-ui/x/alert-x.tsx +0 -413
  86. package/components/catalyst-ui/x/animated-text-x.tsx +0 -2242
  87. package/components/catalyst-ui/x/avatar-x.tsx +0 -515
  88. package/components/catalyst-ui/x/badge-x.tsx +0 -670
  89. package/components/catalyst-ui/x/button-X.tsx +0 -2857
  90. package/components/catalyst-ui/x/button-group-x.tsx +0 -847
  91. package/components/catalyst-ui/x/calendar-x.tsx +0 -1910
  92. package/components/catalyst-ui/x/card-x.tsx +0 -2597
  93. package/components/catalyst-ui/x/checkbox-x.tsx +0 -656
  94. package/components/catalyst-ui/x/collapsible-x.tsx +0 -1360
  95. package/components/catalyst-ui/x/combobox-x.tsx +0 -911
  96. package/components/catalyst-ui/x/data-table-x.tsx +0 -1753
  97. package/components/catalyst-ui/x/date-picker-x.tsx +0 -648
  98. package/components/catalyst-ui/x/dialog-x.tsx +0 -659
  99. package/components/catalyst-ui/x/dropdown-menu-x.tsx +0 -612
  100. package/components/catalyst-ui/x/hover-card-x.tsx +0 -375
  101. package/components/catalyst-ui/x/icon-x.tsx +0 -840
  102. package/components/catalyst-ui/x/input-mask-x.tsx +0 -981
  103. package/components/catalyst-ui/x/input-otp-x.tsx +0 -659
  104. package/components/catalyst-ui/x/loader-x.tsx +0 -1757
  105. package/components/catalyst-ui/x/pagination-x.tsx +0 -622
  106. package/components/catalyst-ui/x/popover-x.tsx +0 -744
  107. package/components/catalyst-ui/x/radio-group-x.tsx +0 -499
  108. package/components/catalyst-ui/x/select-x.tsx +0 -1127
  109. package/components/catalyst-ui/x/sheet-x.tsx +0 -668
  110. package/components/catalyst-ui/x/switch-x.tsx +0 -681
  111. package/components/catalyst-ui/x/table-x.tsx +0 -574
  112. package/components/catalyst-ui/x/tabs-x.tsx +0 -839
  113. package/components/catalyst-ui/x/textarea-x.tsx +0 -1263
  114. package/components/catalyst-ui/x/tooltip-x.tsx +0 -396
  115. package/components/catalyst-ui/x/tracker-x.tsx +0 -560
  116. package/data/bg-data.tsx +0 -901
  117. package/data/buttons-data.tsx +0 -2327
  118. package/data/charts-data.tsx +0 -102
  119. package/data/chat-data.tsx +0 -83
  120. package/data/code-data.tsx +0 -1040
  121. package/data/comboboxes-data.tsx +0 -1843
  122. package/data/command-data.tsx +0 -1381
  123. package/data/core-data.tsx +0 -15953
  124. package/data/crm-data.tsx +0 -47
  125. package/data/data.tsx +0 -159
  126. package/data/date-and-time-data.tsx +0 -554
  127. package/data/dependencies.tsx +0 -7
  128. package/data/ecommerce-data.tsx +0 -1387
  129. package/data/forms-data.tsx +0 -7890
  130. package/data/hooks-data.tsx +0 -5487
  131. package/data/index.ts +0 -34
  132. package/data/inputs-data.tsx +0 -557
  133. package/data/interactive-data.tsx +0 -5394
  134. package/data/lofi-data.tsx +0 -18295
  135. package/data/marketing-data.tsx +0 -2546
  136. package/data/media-data.tsx +0 -1510
  137. package/data/motion-data.tsx +0 -5801
  138. package/data/overlay-data.tsx +0 -4136
  139. package/data/pdf-data.tsx +0 -124
  140. package/data/pos-data.tsx +0 -213
  141. package/data/postcss.config.js +0 -6
  142. package/data/primitive-data.tsx +0 -5170
  143. package/data/prompt-data.tsx +0 -1226
  144. package/data/requiredLibs.ts +0 -4
  145. package/data/sandbox-data.tsx +0 -1
  146. package/data/sidebars-data.tsx +0 -5421
  147. package/data/stacks-data.tsx +0 -32
  148. package/data/table-data.tsx +0 -706
  149. package/data/tailwind.config.js +0 -270
  150. package/data/tailwind.config.ngin.js +0 -3830
  151. package/data/tailwind.css +0 -431
  152. package/data/tools-data.tsx +0 -6910
  153. package/data/typography-data.tsx +0 -2050
  154. package/data/utils-data.tsx +0 -6500
  155. package/data/x-data.tsx +0 -1171
@@ -1,71 +0,0 @@
1
- import { useState, useEffect, useCallback, useRef } from "react";
2
-
3
- export function CORSMiddleware() {
4
- const handleCORS = useCallback((
5
- request: Request,
6
- options: CORSOptions
7
- ): Response | null => {
8
- const origin = request.headers.get('Origin');
9
- const method = request.method;
10
-
11
- if (method === 'OPTIONS') {
12
- const headers = new Headers();
13
-
14
- if (typeof options.origin === 'boolean') {
15
- headers.set('Access-Control-Allow-Origin', options.origin ? '*' : 'null');
16
- } else if (typeof options.origin === 'string') {
17
- headers.set('Access-Control-Allow-Origin', options.origin);
18
- } else if (Array.isArray(options.origin) && origin) {
19
- if (options.origin.includes(origin)) {
20
- headers.set('Access-Control-Allow-Origin', origin);
21
- }
22
- }
23
-
24
- if (options.credentials) {
25
- headers.set('Access-Control-Allow-Credentials', 'true');
26
- }
27
-
28
- if (options.methods) {
29
- headers.set('Access-Control-Allow-Methods', options.methods.join(', '));
30
- }
31
-
32
- if (options.headers) {
33
- headers.set('Access-Control-Allow-Headers', options.headers.join(', '));
34
- }
35
-
36
- return new Response(null, { status: 204, headers });
37
- }
38
-
39
- return null;
40
- }, []);
41
-
42
- const addCORSHeaders = useCallback((
43
- response: Response,
44
- options: CORSOptions,
45
- requestOrigin?: string
46
- ): Response => {
47
- const headers = new Headers(response.headers);
48
-
49
- if (typeof options.origin === 'boolean') {
50
- headers.set('Access-Control-Allow-Origin', options.origin ? '*' : 'null');
51
- } else if (typeof options.origin === 'string') {
52
- headers.set('Access-Control-Allow-Origin', options.origin);
53
- } else if (Array.isArray(options.origin) && requestOrigin) {
54
- if (options.origin.includes(requestOrigin)) {
55
- headers.set('Access-Control-Allow-Origin', requestOrigin);
56
- }
57
- }
58
-
59
- if (options.credentials) {
60
- headers.set('Access-Control-Allow-Credentials', 'true');
61
- }
62
-
63
- return new Response(response.body, {
64
- status: response.status,
65
- statusText: response.statusText,
66
- headers,
67
- });
68
- }, []);
69
-
70
- return { handleCORS, addCORSHeaders };
71
- }
@@ -1,595 +0,0 @@
1
- import React, { useState, useRef, useEffect, ReactNode } from 'react';
2
- import { cn } from '~/components/catalyst-ui';
3
- import { Loader2 } from 'lucide-react';
4
-
5
- export interface DeferredContentProps {
6
- children: ReactNode;
7
- className?: string;
8
- onLoad?: () => void;
9
- loading?: boolean;
10
- loadingTemplate?: ReactNode;
11
- threshold?: number;
12
- rootMargin?: string;
13
- root?: Element | null;
14
- }
15
-
16
- export function DeferredContent({
17
- children,
18
- className,
19
- onLoad,
20
- loading = false,
21
- loadingTemplate,
22
- threshold = 0,
23
- rootMargin = '0px',
24
- root = null,
25
- }: DeferredContentProps) {
26
- const [isVisible, setIsVisible] = useState(false);
27
- const [hasLoaded, setHasLoaded] = useState(false);
28
- const elementRef = useRef<HTMLDivElement>(null);
29
-
30
- useEffect(() => {
31
- const element = elementRef.current;
32
- if (!element) return;
33
-
34
- const observer = new IntersectionObserver(
35
- (entries) => {
36
- const [entry] = entries;
37
- if (entry.isIntersecting && !hasLoaded) {
38
- setIsVisible(true);
39
- setHasLoaded(true);
40
- onLoad?.();
41
- observer.unobserve(element);
42
- }
43
- },
44
- {
45
- threshold,
46
- rootMargin,
47
- root,
48
- }
49
- );
50
-
51
- observer.observe(element);
52
-
53
- return () => {
54
- if (element) {
55
- observer.unobserve(element);
56
- }
57
- };
58
- }, [threshold, rootMargin, root, hasLoaded, onLoad]);
59
-
60
- const defaultLoadingTemplate = (
61
- <div className="flex items-center justify-center p-8">
62
- <Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
63
- </div>
64
- );
65
-
66
- return (
67
- <div
68
- ref={elementRef}
69
- className={cn('min-h-[1px]', className)}
70
- >
71
- {hasLoaded && !loading ? (
72
- children
73
- ) : (
74
- loadingTemplate || defaultLoadingTemplate
75
- )}
76
- </div>
77
- );
78
- }
79
-
80
- export interface DeferredImageProps {
81
- src: string;
82
- alt?: string;
83
- className?: string;
84
- loadingClassName?: string;
85
- threshold?: number;
86
- rootMargin?: string;
87
- onLoad?: () => void;
88
- }
89
-
90
- export function DeferredImage({
91
- src,
92
- alt = '',
93
- className,
94
- loadingClassName,
95
- threshold = 0,
96
- rootMargin = '0px',
97
- onLoad,
98
- }: DeferredImageProps) {
99
- const [imageLoaded, setImageLoaded] = useState(false);
100
- const [imageError, setImageError] = useState(false);
101
-
102
- const handleImageLoad = () => {
103
- setImageLoaded(true);
104
- onLoad?.();
105
- };
106
-
107
- const handleImageError = () => {
108
- setImageError(true);
109
- };
110
-
111
- const loadingTemplate = (
112
- <div className={cn(
113
- 'bg-muted animate-pulse rounded-md flex items-center justify-center',
114
- 'min-h-[200px] w-full',
115
- loadingClassName
116
- )}>
117
- <div className="text-muted-foreground text-sm">Loading...</div>
118
- </div>
119
- );
120
-
121
- return (
122
- <DeferredContent
123
- threshold={threshold}
124
- rootMargin={rootMargin}
125
- loadingTemplate={loadingTemplate}
126
- >
127
- {imageError ? (
128
- <div className={cn(
129
- 'bg-muted rounded-md flex items-center justify-center',
130
- 'min-h-[200px] w-full text-muted-foreground',
131
- className
132
- )}>
133
- Failed to load image
134
- </div>
135
- ) : (
136
- <img
137
- src={src}
138
- alt={alt}
139
- className={cn(
140
- 'transition-opacity duration-300',
141
- imageLoaded ? 'opacity-100' : 'opacity-0',
142
- className
143
- )}
144
- onLoad={handleImageLoad}
145
- onError={handleImageError}
146
- />
147
- )}
148
- </DeferredContent>
149
- );
150
- }
151
-
152
- export interface DeferredTableProps {
153
- data: any[];
154
- columns: Array<{
155
- field: string;
156
- header: string;
157
- className?: string;
158
- }>;
159
- className?: string;
160
- threshold?: number;
161
- rootMargin?: string;
162
- onLoad?: () => void;
163
- }
164
-
165
- export function DeferredTable({
166
- data,
167
- columns,
168
- className,
169
- threshold = 0,
170
- rootMargin = '0px',
171
- onLoad,
172
- }: DeferredTableProps) {
173
- const loadingTemplate = (
174
- <div className="space-y-4">
175
- <div className="h-8 bg-muted animate-pulse rounded" />
176
- {Array.from({ length: 5 }).map((_, i) => (
177
- <div key={i} className="h-12 bg-muted animate-pulse rounded" />
178
- ))}
179
- </div>
180
- );
181
-
182
- return (
183
- <DeferredContent
184
- threshold={threshold}
185
- rootMargin={rootMargin}
186
- loadingTemplate={loadingTemplate}
187
- onLoad={onLoad}
188
- >
189
- <div className={cn('overflow-x-auto', className)}>
190
- <table className="w-full border-collapse">
191
- <thead>
192
- <tr className="border-b border-border">
193
- {columns.map((column) => (
194
- <th
195
- key={column.field}
196
- className={cn(
197
- 'text-left p-4 font-medium text-foreground',
198
- column.className
199
- )}
200
- >
201
- {column.header}
202
- </th>
203
- ))}
204
- </tr>
205
- </thead>
206
- <tbody>
207
- {data.map((row, index) => (
208
- <tr
209
- key={index}
210
- className="border-b border-border hover:bg-muted/50"
211
- >
212
- {columns.map((column) => (
213
- <td
214
- key={column.field}
215
- className={cn('p-4 text-foreground', column.className)}
216
- >
217
- {row[column.field]}
218
- </td>
219
- ))}
220
- </tr>
221
- ))}
222
- </tbody>
223
- </table>
224
- </div>
225
- </DeferredContent>
226
- );
227
- }
228
-
229
- export interface DeferredCardProps {
230
- title: string;
231
- description?: string;
232
- imageUrl?: string;
233
- buttonText?: string;
234
- secondaryButtonText?: string;
235
- onButtonClick?: () => void;
236
- onSecondaryButtonClick?: () => void;
237
- className?: string;
238
- threshold?: number;
239
- rootMargin?: string;
240
- onLoad?: () => void;
241
- }
242
-
243
- export function DeferredCard({
244
- title,
245
- description,
246
- imageUrl,
247
- buttonText,
248
- secondaryButtonText,
249
- onButtonClick,
250
- onSecondaryButtonClick,
251
- className,
252
- threshold = 0,
253
- rootMargin = '0px',
254
- onLoad,
255
- }: DeferredCardProps) {
256
- const loadingTemplate = (
257
- <div className="bg-background border border-border rounded-lg p-6 space-y-4">
258
- <div className="h-6 bg-muted animate-pulse rounded" />
259
- <div className="h-4 bg-muted animate-pulse rounded" />
260
- <div className="h-4 bg-muted animate-pulse rounded w-2/3" />
261
- {imageUrl && <div className="h-48 bg-muted animate-pulse rounded" />}
262
- <div className="flex gap-2">
263
- <div className="h-10 bg-muted animate-pulse rounded w-24" />
264
- {secondaryButtonText && (
265
- <div className="h-10 bg-muted animate-pulse rounded w-24" />
266
- )}
267
- </div>
268
- </div>
269
- );
270
-
271
- return (
272
- <DeferredContent
273
- threshold={threshold}
274
- rootMargin={rootMargin}
275
- loadingTemplate={loadingTemplate}
276
- onLoad={onLoad}
277
- >
278
- <div className={cn(
279
- 'bg-background border border-border rounded-lg p-6 space-y-4',
280
- className
281
- )}>
282
- <h3 className="text-lg font-semibold text-foreground">{title}</h3>
283
- {description && (
284
- <p className="text-muted-foreground">{description}</p>
285
- )}
286
- {imageUrl && (
287
- <DeferredImage
288
- src={imageUrl}
289
- alt={title}
290
- className="w-full h-48 object-cover rounded-md"
291
- />
292
- )}
293
- {(buttonText || secondaryButtonText) && (
294
- <div className="flex gap-2">
295
- {buttonText && (
296
- <button
297
- onClick={onButtonClick}
298
- className="px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90 transition-colors"
299
- >
300
- {buttonText}
301
- </button>
302
- )}
303
- {secondaryButtonText && (
304
- <button
305
- onClick={onSecondaryButtonClick}
306
- className="px-4 py-2 border border-border text-foreground rounded-md hover:bg-muted transition-colors"
307
- >
308
- {secondaryButtonText}
309
- </button>
310
- )}
311
- </div>
312
- )}
313
- </div>
314
- </DeferredContent>
315
- );
316
- }
317
-
318
-
319
- export default function DeferredContentDemo() {
320
- const tableData = [
321
- { id: 1, name: 'John Doe', email: 'john@example.com', role: 'Developer' },
322
- { id: 2, name: 'Jane Smith', email: 'jane@example.com', role: 'Designer' },
323
- { id: 3, name: 'Bob Johnson', email: 'bob@example.com', role: 'Manager' },
324
- { id: 4, name: 'Alice Brown', email: 'alice@example.com', role: 'Developer' },
325
- { id: 5, name: 'Charlie Wilson', email: 'charlie@example.com', role: 'Designer' },
326
- ];
327
-
328
- const tableColumns = [
329
- { field: 'id', header: 'ID', className: 'w-16' },
330
- { field: 'name', header: 'Name' },
331
- { field: 'email', header: 'Email' },
332
- { field: 'role', header: 'Role' },
333
- ];
334
-
335
- const handleLoad = (section: string) => {
336
- console.log(`${section} loaded!`);
337
- };
338
-
339
- return (
340
- <div className="min-h-screen bg-background">
341
- <div className="container mx-auto px-4 py-8 space-y-12">
342
- <div className="text-center space-y-4">
343
- <h1 className="text-4xl font-bold text-foreground">
344
- DeferredContent Demo
345
- </h1>
346
- <p className="text-lg text-muted-foreground max-w-2xl mx-auto">
347
- Scroll down to see different deferred content components load as they come into view.
348
- This technique improves page performance by only loading content when needed.
349
- </p>
350
- </div>
351
-
352
- <div className="h-screen flex items-center justify-center bg-muted/20 rounded-lg">
353
- <div className="text-center space-y-4">
354
- <h2 className="text-2xl font-semibold text-foreground">
355
- Scroll Down to See Deferred Content
356
- </h2>
357
- <p className="text-muted-foreground">
358
- The components below will load when they become visible
359
- </p>
360
- </div>
361
- </div>
362
-
363
- <section className="space-y-6">
364
- <h2 className="text-2xl font-bold text-foreground">Basic Deferred Content</h2>
365
- <DeferredContent
366
- onLoad={() => handleLoad('Basic Content')}
367
- className="bg-card border border-border rounded-lg p-8"
368
- >
369
- <div className="text-center space-y-4">
370
- <h3 className="text-xl font-semibold text-foreground">
371
- This content was loaded lazily!
372
- </h3>
373
- <p className="text-muted-foreground">
374
- This content only loaded when it became visible in the viewport.
375
- This helps improve initial page load performance.
376
- </p>
377
- </div>
378
- </DeferredContent>
379
- </section>
380
-
381
- <section className="space-y-6">
382
- <h2 className="text-2xl font-bold text-foreground">Deferred Images</h2>
383
- <div className="grid md:grid-cols-2 gap-6">
384
- <DeferredImage
385
- src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=500&h=300&fit=crop"
386
- alt="Mountain landscape"
387
- className="w-full h-64 object-cover rounded-lg"
388
- onLoad={() => handleLoad('Mountain Image')}
389
- />
390
- <DeferredImage
391
- src="https://images.unsplash.com/photo-1441974231531-c6227db76b6e?w=500&h=300&fit=crop"
392
- alt="Forest landscape"
393
- className="w-full h-64 object-cover rounded-lg"
394
- onLoad={() => handleLoad('Forest Image')}
395
- />
396
- </div>
397
- </section>
398
-
399
- <section className="space-y-6">
400
- <h2 className="text-2xl font-bold text-foreground">Deferred Table</h2>
401
- <DeferredTable
402
- data={tableData}
403
- columns={tableColumns}
404
- className="bg-card border border-border rounded-lg overflow-hidden"
405
- onLoad={() => handleLoad('User Table')}
406
- />
407
- </section>
408
-
409
- <section className="space-y-6">
410
- <h2 className="text-2xl font-bold text-foreground">Deferred Cards</h2>
411
- <div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
412
- <DeferredCard
413
- title="Product Demo"
414
- description="Experience our latest product features with this interactive demonstration."
415
- imageUrl="https://images.unsplash.com/photo-1460925895917-afdab827c52f?w=400&h=200&fit=crop"
416
- buttonText="Try Demo"
417
- secondaryButtonText="Learn More"
418
- onButtonClick={() => console.log('Demo clicked')}
419
- onSecondaryButtonClick={() => console.log('Learn more clicked')}
420
- onLoad={() => handleLoad('Product Card')}
421
- />
422
-
423
- <DeferredCard
424
- title="Get Started"
425
- description="Ready to begin your journey? Follow our comprehensive getting started guide."
426
- buttonText="Start Now"
427
- onButtonClick={() => console.log('Start clicked')}
428
- onLoad={() => handleLoad('Getting Started Card')}
429
- />
430
-
431
- <DeferredCard
432
- title="Documentation"
433
- description="Explore our complete documentation with examples, API references, and best practices."
434
- imageUrl="https://images.unsplash.com/photo-1481627834876-b7833e8f5570?w=400&h=200&fit=crop"
435
- buttonText="Read Docs"
436
- secondaryButtonText="API Reference"
437
- onButtonClick={() => console.log('Docs clicked')}
438
- onSecondaryButtonClick={() => console.log('API clicked')}
439
- onLoad={() => handleLoad('Documentation Card')}
440
- />
441
- </div>
442
- </section>
443
-
444
- <section className="space-y-6">
445
- <h2 className="text-2xl font-bold text-foreground">Custom Loading Template</h2>
446
- <DeferredContent
447
- onLoad={() => handleLoad('Custom Loading')}
448
- loadingTemplate={
449
- <div className="bg-card border border-border rounded-lg p-8">
450
- <div className="flex items-center justify-center space-x-2">
451
- <div className="w-3 h-3 bg-primary rounded-full animate-bounce"></div>
452
- <div className="w-3 h-3 bg-primary rounded-full animate-bounce" style={{ animationDelay: '0.1s' }}></div>
453
- <div className="w-3 h-3 bg-primary rounded-full animate-bounce" style={{ animationDelay: '0.2s' }}></div>
454
- </div>
455
- <p className="text-center text-muted-foreground mt-4">
456
- Custom loading animation...
457
- </p>
458
- </div>
459
- }
460
- >
461
- <div className="bg-card border border-border rounded-lg p-8 text-center space-y-4">
462
- <h3 className="text-xl font-semibold text-foreground">
463
- Content with Custom Loading
464
- </h3>
465
- <p className="text-muted-foreground">
466
- This section used a custom loading template with bouncing dots animation.
467
- </p>
468
- </div>
469
- </DeferredContent>
470
- </section>
471
-
472
- <section className="space-y-6">
473
- <h2 className="text-2xl font-bold text-foreground">Advanced Configuration</h2>
474
- <div className="grid gap-6">
475
- <DeferredContent
476
- threshold={0.5}
477
- rootMargin="50px"
478
- onLoad={() => handleLoad('Advanced Config 1')}
479
- className="bg-card border border-border rounded-lg p-6"
480
- >
481
- <div className="space-y-2">
482
- <h3 className="text-lg font-semibold text-foreground">
483
- 50% Visible + 50px Margin
484
- </h3>
485
- <p className="text-sm text-muted-foreground">
486
- threshold: 0.5, rootMargin: "50px"
487
- </p>
488
- <p className="text-muted-foreground">
489
- This content loads when 50% is visible, with 50px extra margin for early triggering.
490
- </p>
491
- </div>
492
- </DeferredContent>
493
-
494
- <DeferredContent
495
- threshold={1.0}
496
- onLoad={() => handleLoad('Advanced Config 2')}
497
- className="bg-card border border-border rounded-lg p-6"
498
- >
499
- <div className="space-y-2">
500
- <h3 className="text-lg font-semibold text-foreground">
501
- Fully Visible Required
502
- </h3>
503
- <p className="text-sm text-muted-foreground">
504
- threshold: 1.0
505
- </p>
506
- <p className="text-muted-foreground">
507
- This content only loads when the entire element is visible in the viewport.
508
- </p>
509
- </div>
510
- </DeferredContent>
511
- </div>
512
- </section>
513
-
514
- <div className="h-32 flex items-center justify-center bg-muted/20 rounded-lg">
515
- <p className="text-muted-foreground text-center">
516
- End of demo - Check your console for load events!
517
- </p>
518
- </div>
519
- </div>
520
- </div>
521
- );
522
- }
523
-
524
- function DeferredContentDemo1() {
525
- return (
526
- <div className="space-y-8 p-6">
527
- <h1>Deferred Content Demo</h1>
528
-
529
- {/* Basic Deferred Content */}
530
- <DeferredContent
531
- threshold={0.1}
532
- rootMargin="100px"
533
- onLoad={() => console.log('Content loaded!')}
534
- loadingTemplate={<div>Custom loading...</div>}
535
- >
536
- <div className="p-6 bg-blue-100 rounded-lg">
537
- <h2>This content loads when visible</h2>
538
- <p>It uses Intersection Observer to defer loading until needed.</p>
539
- </div>
540
- </DeferredContent>
541
-
542
- {/* Deferred Image */}
543
- <DeferredImage
544
- src="https://example.com/large-image.jpg"
545
- alt="Large image"
546
- className="rounded-lg shadow-lg"
547
- loadingClassName="rounded-lg"
548
- threshold={0.2}
549
- onLoad={() => console.log('Image loaded!')}
550
- />
551
-
552
- {/* Deferred Table */}
553
- <DeferredTable
554
- data={[
555
- { id: 1, name: 'John', age: 30 },
556
- { id: 2, name: 'Jane', age: 25 }
557
- ]}
558
- columns={[
559
- { field: 'id', header: 'ID', className: 'w-20' },
560
- { field: 'name', header: 'Name' },
561
- { field: 'age', header: 'Age', className: 'w-20' }
562
- ]}
563
- threshold={0.3}
564
- onLoad={() => console.log('Table loaded!')}
565
- />
566
-
567
- {/* Deferred Card */}
568
- <DeferredCard
569
- title="Product Card"
570
- description="This card loads when it enters the viewport"
571
- imageUrl="https://example.com/product.jpg"
572
- buttonText="Buy Now"
573
- secondaryButtonText="Learn More"
574
- onButtonClick={() => console.log('Buy clicked')}
575
- onSecondaryButtonClick={() => console.log('Learn more clicked')}
576
- threshold={0.5}
577
- rootMargin="200px"
578
- onLoad={() => console.log('Card loaded!')}
579
- />
580
-
581
- {/* Multiple deferred items in a grid */}
582
- <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
583
- {[1, 2, 3, 4].map((item) => (
584
- <DeferredCard
585
- key={item}
586
- title={`Card ${item}`}
587
- description={`This is card number ${item}`}
588
- threshold={0.1}
589
- rootMargin="50px"
590
- />
591
- ))}
592
- </div>
593
- </div>
594
- );
595
- }
@@ -1,38 +0,0 @@
1
-
2
- import { useState, useEffect, useCallback, useRef } from "react";
3
-
4
- export function HoneypotMiddleware() {
5
- const createHoneypot = useCallback((config: HoneypotConfig) => {
6
- const timestamp = Date.now().toString();
7
- const hash = btoa(`${timestamp}-${config.encryptionSeed}`);
8
-
9
- return {
10
- nameField: config.nameFieldName,
11
- validFromField: config.validFromFieldName,
12
- encryptedValidFrom: hash,
13
- };
14
- }, []);
15
-
16
- const validateHoneypot = useCallback((
17
- formData: FormData,
18
- config: HoneypotConfig
19
- ): boolean => {
20
- const nameFieldValue = formData.get(config.nameFieldName);
21
- const validFromValue = formData.get(config.validFromFieldName);
22
-
23
- if (nameFieldValue) return false;
24
-
25
- try {
26
- const decrypted = atob(validFromValue as string);
27
- const [timestamp] = decrypted.split('-');
28
- const submissionTime = Date.now();
29
- const honeypotTime = parseInt(timestamp);
30
-
31
- return submissionTime - honeypotTime > 1000;
32
- } catch {
33
- return false;
34
- }
35
- }, []);
36
-
37
- return { createHoneypot, validateHoneypot };
38
- }