@codepom/react 0.1.0

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/index.js ADDED
@@ -0,0 +1,943 @@
1
+ "use client"
2
+
3
+ // src/components/Button.tsx
4
+ import React from "react";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ var Button = React.forwardRef(
7
+ ({
8
+ variant = "primary",
9
+ size = "md",
10
+ loading = false,
11
+ icon,
12
+ iconPosition = "left",
13
+ fullWidth = false,
14
+ disabled,
15
+ children,
16
+ className = "",
17
+ ...props
18
+ }, ref) => {
19
+ const classes = [
20
+ "cp-btn",
21
+ `cp-btn--${variant}`,
22
+ `cp-btn--${size}`,
23
+ fullWidth ? "cp-btn--full" : "",
24
+ loading ? "cp-btn--loading" : "",
25
+ className
26
+ ].filter(Boolean).join(" ");
27
+ return /* @__PURE__ */ jsxs(
28
+ "button",
29
+ {
30
+ ref,
31
+ className: classes,
32
+ disabled: disabled || loading,
33
+ "aria-busy": loading || void 0,
34
+ ...props,
35
+ children: [
36
+ loading && /* @__PURE__ */ jsx("span", { className: "cp-btn__spinner", "aria-hidden": "true" }),
37
+ icon && iconPosition === "left" && !loading && /* @__PURE__ */ jsx("span", { className: "cp-btn__icon", "aria-hidden": "true", children: icon }),
38
+ children && /* @__PURE__ */ jsx("span", { children }),
39
+ icon && iconPosition === "right" && !loading && /* @__PURE__ */ jsx("span", { className: "cp-btn__icon", "aria-hidden": "true", children: icon })
40
+ ]
41
+ }
42
+ );
43
+ }
44
+ );
45
+ Button.displayName = "Button";
46
+
47
+ // src/components/Badge.tsx
48
+ import { jsx as jsx2 } from "react/jsx-runtime";
49
+ var Badge = ({
50
+ variant = "default",
51
+ size = "md",
52
+ dot = false,
53
+ children,
54
+ className = ""
55
+ }) => {
56
+ const classes = [
57
+ "cp-badge",
58
+ `cp-badge--${variant}`,
59
+ size === "sm" ? "cp-badge--sm" : "",
60
+ dot ? "cp-badge--dot" : "",
61
+ className
62
+ ].filter(Boolean).join(" ");
63
+ return /* @__PURE__ */ jsx2("span", { className: classes, children });
64
+ };
65
+
66
+ // src/components/Alert.tsx
67
+ import React2 from "react";
68
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
69
+ var icons = {
70
+ info: "\u2605",
71
+ success: "\u2713",
72
+ warning: "\u26A0",
73
+ error: "\u2715"
74
+ };
75
+ var Alert = ({
76
+ variant = "info",
77
+ title,
78
+ dismissible = false,
79
+ onDismiss,
80
+ children,
81
+ className = ""
82
+ }) => {
83
+ const [dismissed, setDismissed] = React2.useState(false);
84
+ const handleDismiss = () => {
85
+ setDismissed(true);
86
+ onDismiss?.();
87
+ };
88
+ if (dismissed) return null;
89
+ const classes = ["cp-alert", `cp-alert--${variant}`, className].filter(Boolean).join(" ");
90
+ return /* @__PURE__ */ jsxs2(
91
+ "div",
92
+ {
93
+ role: "alert",
94
+ className: classes,
95
+ children: [
96
+ /* @__PURE__ */ jsx3("span", { className: "cp-alert__icon", "aria-hidden": "true", children: icons[variant] }),
97
+ /* @__PURE__ */ jsxs2("div", { className: "cp-alert__body", children: [
98
+ title && /* @__PURE__ */ jsx3("p", { className: "cp-alert__title", children: title }),
99
+ /* @__PURE__ */ jsx3("div", { className: "cp-alert__content", children })
100
+ ] }),
101
+ dismissible && /* @__PURE__ */ jsx3(
102
+ "button",
103
+ {
104
+ className: "cp-alert__close",
105
+ onClick: handleDismiss,
106
+ "aria-label": "Dismiss alert",
107
+ children: "\u2715"
108
+ }
109
+ )
110
+ ]
111
+ }
112
+ );
113
+ };
114
+
115
+ // src/components/Card.tsx
116
+ import { jsx as jsx4 } from "react/jsx-runtime";
117
+ var Card = ({
118
+ elevation = 1,
119
+ padding = "md",
120
+ interactive = false,
121
+ children,
122
+ className = "",
123
+ as: Component = "div"
124
+ }) => {
125
+ const classes = [
126
+ "cp-card",
127
+ `cp-card--elevation-${elevation}`,
128
+ padding !== "none" ? `cp-card--pad-${padding}` : "",
129
+ interactive ? "cp-card--interactive" : "",
130
+ className
131
+ ].filter(Boolean).join(" ");
132
+ return /* @__PURE__ */ jsx4(Component, { className: classes, children });
133
+ };
134
+ var CardHeader = ({ children, className = "" }) => /* @__PURE__ */ jsx4("div", { className: `cp-card__header ${className}`.trim(), children });
135
+ var CardBody = ({ children, className = "" }) => /* @__PURE__ */ jsx4("div", { className: `cp-card__body ${className}`.trim(), children });
136
+ var CardFooter = ({ children, className = "" }) => /* @__PURE__ */ jsx4("div", { className: `cp-card__footer ${className}`.trim(), children });
137
+
138
+ // src/components/Avatar.tsx
139
+ import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
140
+ function getInitials(name) {
141
+ return name.split(" ").slice(0, 2).map((w) => w[0]).join("").toUpperCase();
142
+ }
143
+ var Avatar = ({
144
+ src,
145
+ alt,
146
+ initials,
147
+ name,
148
+ size = "md",
149
+ status = "none",
150
+ className = ""
151
+ }) => {
152
+ const displayInitials = initials ?? (name ? getInitials(name) : "?");
153
+ const label = alt ?? name ?? "Avatar";
154
+ const classes = [
155
+ "cp-avatar",
156
+ `cp-avatar--${size}`,
157
+ className
158
+ ].filter(Boolean).join(" ");
159
+ return /* @__PURE__ */ jsxs3("span", { className: classes, role: "img", "aria-label": label, children: [
160
+ src ? /* @__PURE__ */ jsx5("img", { src, alt: label, className: "cp-avatar__img" }) : /* @__PURE__ */ jsx5("span", { className: "cp-avatar__initials", "aria-hidden": "true", children: displayInitials }),
161
+ status !== "none" && /* @__PURE__ */ jsx5(
162
+ "span",
163
+ {
164
+ className: `cp-avatar__status cp-avatar__status--${status}`,
165
+ "aria-label": status
166
+ }
167
+ )
168
+ ] });
169
+ };
170
+
171
+ // src/components/Input.tsx
172
+ import React3 from "react";
173
+ import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
174
+ var Label = ({ required, children, className = "", ...props }) => /* @__PURE__ */ jsxs4("label", { className: `cp-label ${className}`.trim(), ...props, children: [
175
+ children,
176
+ required && /* @__PURE__ */ jsx6("span", { className: "cp-label__required", "aria-hidden": "true", children: " *" })
177
+ ] });
178
+ var Input = React3.forwardRef(
179
+ ({ inputSize = "md", error = false, leadingIcon, trailingIcon, className = "", ...props }, ref) => {
180
+ const classes = [
181
+ "cp-input",
182
+ `cp-input--${inputSize}`,
183
+ error ? "cp-input--error" : "",
184
+ leadingIcon ? "cp-input--has-leading" : "",
185
+ trailingIcon ? "cp-input--has-trailing" : "",
186
+ className
187
+ ].filter(Boolean).join(" ");
188
+ if (leadingIcon || trailingIcon) {
189
+ return /* @__PURE__ */ jsxs4("div", { className: "cp-input-wrapper", children: [
190
+ leadingIcon && /* @__PURE__ */ jsx6("span", { className: "cp-input__icon cp-input__icon--leading", "aria-hidden": "true", children: leadingIcon }),
191
+ /* @__PURE__ */ jsx6("input", { ref, className: classes, "aria-invalid": error || void 0, ...props }),
192
+ trailingIcon && /* @__PURE__ */ jsx6("span", { className: "cp-input__icon cp-input__icon--trailing", "aria-hidden": "true", children: trailingIcon })
193
+ ] });
194
+ }
195
+ return /* @__PURE__ */ jsx6("input", { ref, className: classes, "aria-invalid": error || void 0, ...props });
196
+ }
197
+ );
198
+ Input.displayName = "Input";
199
+ var Textarea = React3.forwardRef(
200
+ ({ error = false, resize = "vertical", className = "", style, ...props }, ref) => /* @__PURE__ */ jsx6(
201
+ "textarea",
202
+ {
203
+ ref,
204
+ className: ["cp-textarea", error ? "cp-textarea--error" : "", className].filter(Boolean).join(" "),
205
+ "aria-invalid": error || void 0,
206
+ style: { resize, ...style },
207
+ ...props
208
+ }
209
+ )
210
+ );
211
+ Textarea.displayName = "Textarea";
212
+ var Select = React3.forwardRef(
213
+ ({ error = false, className = "", children, ...props }, ref) => /* @__PURE__ */ jsxs4("div", { className: "cp-select-wrapper", children: [
214
+ /* @__PURE__ */ jsx6(
215
+ "select",
216
+ {
217
+ ref,
218
+ className: ["cp-select", error ? "cp-select--error" : "", className].filter(Boolean).join(" "),
219
+ "aria-invalid": error || void 0,
220
+ ...props,
221
+ children
222
+ }
223
+ ),
224
+ /* @__PURE__ */ jsx6("span", { className: "cp-select__chevron", "aria-hidden": "true", children: "\u25BE" })
225
+ ] })
226
+ );
227
+ Select.displayName = "Select";
228
+ var Field = ({
229
+ label,
230
+ htmlFor,
231
+ hint,
232
+ error,
233
+ required,
234
+ children,
235
+ className = ""
236
+ }) => /* @__PURE__ */ jsxs4("div", { className: `cp-field ${className}`.trim(), children: [
237
+ /* @__PURE__ */ jsx6(Label, { htmlFor, required, children: label }),
238
+ children,
239
+ hint && !error && /* @__PURE__ */ jsx6("p", { className: "cp-field__hint", children: hint }),
240
+ error && /* @__PURE__ */ jsx6("p", { className: "cp-field__error", role: "alert", children: error })
241
+ ] });
242
+
243
+ // src/components/Modal.tsx
244
+ import React4 from "react";
245
+ import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
246
+ var Modal = ({
247
+ open,
248
+ onClose,
249
+ title,
250
+ size = "md",
251
+ children,
252
+ footer,
253
+ closeOnBackdrop = true,
254
+ className = ""
255
+ }) => {
256
+ const dialogRef = React4.useRef(null);
257
+ React4.useEffect(() => {
258
+ const dialog = dialogRef.current;
259
+ if (!dialog) return;
260
+ if (open) {
261
+ if (!dialog.open) dialog.showModal();
262
+ } else {
263
+ if (dialog.open) dialog.close();
264
+ }
265
+ }, [open]);
266
+ React4.useEffect(() => {
267
+ const dialog = dialogRef.current;
268
+ if (!dialog) return;
269
+ const handleClose = () => onClose();
270
+ dialog.addEventListener("close", handleClose);
271
+ return () => dialog.removeEventListener("close", handleClose);
272
+ }, [onClose]);
273
+ const handleBackdropClick = (e) => {
274
+ if (!closeOnBackdrop) return;
275
+ if (e.target === dialogRef.current) onClose();
276
+ };
277
+ return /* @__PURE__ */ jsx7(
278
+ "dialog",
279
+ {
280
+ ref: dialogRef,
281
+ className: ["cp-modal-backdrop", className].filter(Boolean).join(" "),
282
+ onClick: handleBackdropClick,
283
+ "aria-labelledby": title ? "cp-modal-title" : void 0,
284
+ "aria-modal": "true",
285
+ children: /* @__PURE__ */ jsxs5("div", { className: `cp-modal cp-modal--${size}`, children: [
286
+ /* @__PURE__ */ jsxs5("div", { className: "cp-modal__header", children: [
287
+ title && /* @__PURE__ */ jsx7("h2", { id: "cp-modal-title", className: "cp-modal__title", children: title }),
288
+ /* @__PURE__ */ jsx7(
289
+ "button",
290
+ {
291
+ className: "cp-modal__close",
292
+ onClick: onClose,
293
+ "aria-label": "Close modal",
294
+ children: "\u2715"
295
+ }
296
+ )
297
+ ] }),
298
+ /* @__PURE__ */ jsx7("div", { className: "cp-modal__body", children }),
299
+ footer && /* @__PURE__ */ jsx7("div", { className: "cp-modal__footer", children: footer })
300
+ ] })
301
+ }
302
+ );
303
+ };
304
+
305
+ // src/components/Toast.tsx
306
+ import React5 from "react";
307
+ import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
308
+ var ToastContext = React5.createContext(null);
309
+ var ToastProvider = ({
310
+ position = "top-right",
311
+ children
312
+ }) => {
313
+ const [toasts, setToasts] = React5.useState([]);
314
+ const dismiss = React5.useCallback((id) => {
315
+ setToasts((prev) => prev.filter((t) => t.id !== id));
316
+ }, []);
317
+ const show = React5.useCallback(
318
+ (toast) => {
319
+ const id = Math.random().toString(36).slice(2);
320
+ setToasts((prev) => [...prev, { ...toast, id }]);
321
+ const duration = toast.duration ?? 4e3;
322
+ if (duration > 0) {
323
+ setTimeout(() => dismiss(id), duration);
324
+ }
325
+ return id;
326
+ },
327
+ [dismiss]
328
+ );
329
+ return /* @__PURE__ */ jsxs6(ToastContext.Provider, { value: { show, dismiss }, children: [
330
+ children,
331
+ /* @__PURE__ */ jsx8(
332
+ "div",
333
+ {
334
+ className: `cp-toast-region cp-toast-region--${position}`,
335
+ role: "region",
336
+ "aria-label": "Notifications",
337
+ "aria-live": "polite",
338
+ children: toasts.map((toast) => /* @__PURE__ */ jsx8(ToastCard, { toast, onDismiss: () => dismiss(toast.id) }, toast.id))
339
+ }
340
+ )
341
+ ] });
342
+ };
343
+ var icons2 = {
344
+ info: "\u2139",
345
+ success: "\u2713",
346
+ warning: "\u26A0",
347
+ error: "\u2715"
348
+ };
349
+ var ToastCard = ({ toast, onDismiss }) => {
350
+ const variant = toast.variant ?? "info";
351
+ return /* @__PURE__ */ jsxs6(
352
+ "div",
353
+ {
354
+ role: "status",
355
+ className: `cp-toast cp-toast--${variant}`,
356
+ children: [
357
+ /* @__PURE__ */ jsx8("span", { className: "cp-toast__icon", "aria-hidden": "true", children: icons2[variant] }),
358
+ /* @__PURE__ */ jsxs6("div", { className: "cp-toast__body", children: [
359
+ toast.title && /* @__PURE__ */ jsx8("p", { className: "cp-toast__title", children: toast.title }),
360
+ /* @__PURE__ */ jsx8("p", { className: "cp-toast__message", children: toast.message }),
361
+ toast.action && /* @__PURE__ */ jsx8("button", { className: "cp-toast__action", onClick: toast.action.onClick, children: toast.action.label })
362
+ ] }),
363
+ /* @__PURE__ */ jsx8("button", { className: "cp-toast__close", onClick: onDismiss, "aria-label": "Dismiss", children: "\u2715" })
364
+ ]
365
+ }
366
+ );
367
+ };
368
+ var useToast = () => {
369
+ const ctx = React5.useContext(ToastContext);
370
+ if (!ctx) throw new Error("useToast must be used within ToastProvider");
371
+ return ctx;
372
+ };
373
+
374
+ // src/components/Tabs.tsx
375
+ import React6 from "react";
376
+ import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
377
+ var Tabs = ({
378
+ tabs,
379
+ defaultTab,
380
+ variant = "underline",
381
+ onChange,
382
+ className = ""
383
+ }) => {
384
+ const [active, setActive] = React6.useState(defaultTab ?? tabs[0]?.id);
385
+ const tablistRef = React6.useRef(null);
386
+ const activate = (id) => {
387
+ setActive(id);
388
+ onChange?.(id);
389
+ };
390
+ const handleKeyDown = (e, currentIndex) => {
391
+ const enabledTabs = tabs.filter((t) => !t.disabled);
392
+ const currentEnabledIndex = enabledTabs.findIndex((t) => t.id === tabs[currentIndex].id);
393
+ let nextIndex = -1;
394
+ if (e.key === "ArrowRight") nextIndex = (currentEnabledIndex + 1) % enabledTabs.length;
395
+ if (e.key === "ArrowLeft")
396
+ nextIndex = (currentEnabledIndex - 1 + enabledTabs.length) % enabledTabs.length;
397
+ if (e.key === "Home") nextIndex = 0;
398
+ if (e.key === "End") nextIndex = enabledTabs.length - 1;
399
+ if (nextIndex >= 0) {
400
+ e.preventDefault();
401
+ const nextTab = enabledTabs[nextIndex];
402
+ activate(nextTab.id);
403
+ const btn = tablistRef.current?.querySelector(
404
+ `[data-tab-id="${nextTab.id}"]`
405
+ );
406
+ btn?.focus();
407
+ }
408
+ };
409
+ const activeTab = tabs.find((t) => t.id === active);
410
+ return /* @__PURE__ */ jsxs7("div", { className: `cp-tabs cp-tabs--${variant} ${className}`.trim(), children: [
411
+ /* @__PURE__ */ jsx9(
412
+ "div",
413
+ {
414
+ ref: tablistRef,
415
+ role: "tablist",
416
+ className: "cp-tabs__list",
417
+ children: tabs.map((tab, i) => /* @__PURE__ */ jsxs7(
418
+ "button",
419
+ {
420
+ role: "tab",
421
+ "data-tab-id": tab.id,
422
+ "aria-selected": active === tab.id,
423
+ "aria-controls": `tabpanel-${tab.id}`,
424
+ id: `tab-${tab.id}`,
425
+ disabled: tab.disabled,
426
+ tabIndex: active === tab.id ? 0 : -1,
427
+ className: [
428
+ "cp-tabs__tab",
429
+ active === tab.id ? "cp-tabs__tab--active" : ""
430
+ ].filter(Boolean).join(" "),
431
+ onClick: () => !tab.disabled && activate(tab.id),
432
+ onKeyDown: (e) => handleKeyDown(e, i),
433
+ children: [
434
+ tab.icon && /* @__PURE__ */ jsx9("span", { className: "cp-tabs__tab-icon", "aria-hidden": "true", children: tab.icon }),
435
+ tab.label,
436
+ tab.badge !== void 0 && /* @__PURE__ */ jsx9("span", { className: "cp-tabs__badge", children: tab.badge })
437
+ ]
438
+ },
439
+ tab.id
440
+ ))
441
+ }
442
+ ),
443
+ tabs.map((tab) => /* @__PURE__ */ jsx9(
444
+ "div",
445
+ {
446
+ role: "tabpanel",
447
+ id: `tabpanel-${tab.id}`,
448
+ "aria-labelledby": `tab-${tab.id}`,
449
+ hidden: active !== tab.id,
450
+ className: "cp-tabs__panel",
451
+ children: tab.content
452
+ },
453
+ tab.id
454
+ ))
455
+ ] });
456
+ };
457
+
458
+ // src/components/Tooltip.tsx
459
+ import React7 from "react";
460
+ import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
461
+ var Tooltip = ({
462
+ content,
463
+ placement = "top",
464
+ children
465
+ }) => {
466
+ const id = React7.useId();
467
+ return /* @__PURE__ */ jsxs8("span", { className: `cp-tooltip-host cp-tooltip-host--${placement}`, children: [
468
+ React7.cloneElement(children, {
469
+ "aria-describedby": id
470
+ }),
471
+ /* @__PURE__ */ jsx10(
472
+ "span",
473
+ {
474
+ role: "tooltip",
475
+ id,
476
+ className: `cp-tooltip cp-tooltip--${placement}`,
477
+ children: content
478
+ }
479
+ )
480
+ ] });
481
+ };
482
+
483
+ // src/components/Breadcrumb.tsx
484
+ import { jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
485
+ var separatorChar = {
486
+ chevron: "\u203A",
487
+ slash: "/",
488
+ dot: "\xB7"
489
+ };
490
+ var Breadcrumb = ({
491
+ items,
492
+ separator = "chevron",
493
+ className = ""
494
+ }) => {
495
+ const sep = separatorChar[separator];
496
+ return /* @__PURE__ */ jsx11("nav", { "aria-label": "Breadcrumb", className: `cp-breadcrumb ${className}`.trim(), children: /* @__PURE__ */ jsx11("ol", { className: "cp-breadcrumb__list", children: items.map((item, i) => {
497
+ const isLast = i === items.length - 1;
498
+ return /* @__PURE__ */ jsxs9("li", { className: "cp-breadcrumb__item", children: [
499
+ i > 0 && /* @__PURE__ */ jsx11("span", { className: "cp-breadcrumb__sep", "aria-hidden": "true", children: sep }),
500
+ isLast ? /* @__PURE__ */ jsx11("span", { "aria-current": "page", className: "cp-breadcrumb__current", children: item.label }) : /* @__PURE__ */ jsx11("a", { href: item.href ?? "#", className: "cp-breadcrumb__link", children: item.label })
501
+ ] }, i);
502
+ }) }) });
503
+ };
504
+
505
+ // src/components/Pagination.tsx
506
+ import { jsx as jsx12, jsxs as jsxs10 } from "react/jsx-runtime";
507
+ function buildPages(current, total) {
508
+ if (total <= 7) return Array.from({ length: total }, (_, i) => i + 1);
509
+ if (current <= 4) return [1, 2, 3, 4, 5, "\u2026", total];
510
+ if (current >= total - 3) return [1, "\u2026", total - 4, total - 3, total - 2, total - 1, total];
511
+ return [1, "\u2026", current - 1, current, current + 1, "\u2026", total];
512
+ }
513
+ var Pagination = ({
514
+ total,
515
+ page,
516
+ perPage = 10,
517
+ onChange,
518
+ className = ""
519
+ }) => {
520
+ const totalPages = Math.max(1, Math.ceil(total / perPage));
521
+ const pages = buildPages(page, totalPages);
522
+ return /* @__PURE__ */ jsxs10(
523
+ "nav",
524
+ {
525
+ "aria-label": "Pagination",
526
+ className: `cp-pagination ${className}`.trim(),
527
+ children: [
528
+ /* @__PURE__ */ jsx12(
529
+ "button",
530
+ {
531
+ className: "cp-pagination__btn cp-pagination__btn--prev",
532
+ onClick: () => onChange(page - 1),
533
+ disabled: page <= 1,
534
+ "aria-label": "Previous page",
535
+ children: "\u2039"
536
+ }
537
+ ),
538
+ pages.map(
539
+ (p, i) => p === "\u2026" ? /* @__PURE__ */ jsx12("span", { className: "cp-pagination__ellipsis", "aria-hidden": "true", children: "\u2026" }, `ellipsis-${i}`) : /* @__PURE__ */ jsx12(
540
+ "button",
541
+ {
542
+ className: [
543
+ "cp-pagination__btn",
544
+ p === page ? "cp-pagination__btn--active" : ""
545
+ ].filter(Boolean).join(" "),
546
+ onClick: () => onChange(p),
547
+ "aria-current": p === page ? "page" : void 0,
548
+ "aria-label": `Page ${p}`,
549
+ children: p
550
+ },
551
+ p
552
+ )
553
+ ),
554
+ /* @__PURE__ */ jsx12(
555
+ "button",
556
+ {
557
+ className: "cp-pagination__btn cp-pagination__btn--next",
558
+ onClick: () => onChange(page + 1),
559
+ disabled: page >= totalPages,
560
+ "aria-label": "Next page",
561
+ children: "\u203A"
562
+ }
563
+ )
564
+ ]
565
+ }
566
+ );
567
+ };
568
+
569
+ // src/components/Table.tsx
570
+ import { jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
571
+ var Table = ({
572
+ columns,
573
+ rows,
574
+ striped = false,
575
+ hoverable = false,
576
+ loading = false,
577
+ className = ""
578
+ }) => {
579
+ const classes = [
580
+ "cp-table",
581
+ striped ? "cp-table--striped" : "",
582
+ hoverable ? "cp-table--hoverable" : "",
583
+ className
584
+ ].filter(Boolean).join(" ");
585
+ const skeletonRows = Array.from({ length: 5 });
586
+ return /* @__PURE__ */ jsx13("div", { className: "cp-table-wrapper", children: /* @__PURE__ */ jsxs11("table", { className: classes, children: [
587
+ /* @__PURE__ */ jsx13("thead", { className: "cp-table__head", children: /* @__PURE__ */ jsx13("tr", { children: columns.map((col) => /* @__PURE__ */ jsx13(
588
+ "th",
589
+ {
590
+ className: "cp-table__th",
591
+ style: col.width != null ? { width: col.width } : void 0,
592
+ children: col.label
593
+ },
594
+ col.key
595
+ )) }) }),
596
+ /* @__PURE__ */ jsx13("tbody", { className: "cp-table__body", children: loading ? skeletonRows.map((_, i) => /* @__PURE__ */ jsx13("tr", { className: "cp-table__row", children: columns.map((col) => /* @__PURE__ */ jsx13("td", { className: "cp-table__td", children: /* @__PURE__ */ jsx13("span", { className: "cp-skeleton cp-skeleton--pulse", style: { display: "block", height: 16, borderRadius: 4 } }) }, col.key)) }, i)) : rows.map((row, i) => /* @__PURE__ */ jsx13("tr", { className: "cp-table__row", children: columns.map((col) => /* @__PURE__ */ jsx13("td", { className: "cp-table__td", children: row[col.key] }, col.key)) }, i)) })
597
+ ] }) });
598
+ };
599
+
600
+ // src/components/Skeleton.tsx
601
+ import { jsx as jsx14, jsxs as jsxs12 } from "react/jsx-runtime";
602
+ var Skeleton = ({
603
+ width,
604
+ height = 16,
605
+ rounded = false,
606
+ lines,
607
+ className = ""
608
+ }) => {
609
+ if (lines != null && lines > 1) {
610
+ return /* @__PURE__ */ jsx14("div", { className: `cp-skeleton-lines ${className}`.trim(), children: Array.from({ length: lines }).map((_, i) => /* @__PURE__ */ jsx14(
611
+ "span",
612
+ {
613
+ className: "cp-skeleton cp-skeleton--pulse",
614
+ style: {
615
+ display: "block",
616
+ width: i === lines - 1 ? "65%" : width ?? "100%",
617
+ height,
618
+ borderRadius: rounded ? 9999 : 4
619
+ }
620
+ },
621
+ i
622
+ )) });
623
+ }
624
+ return /* @__PURE__ */ jsx14(
625
+ "span",
626
+ {
627
+ className: ["cp-skeleton", "cp-skeleton--pulse", className].filter(Boolean).join(" "),
628
+ style: {
629
+ display: "block",
630
+ width: width ?? "100%",
631
+ height,
632
+ borderRadius: rounded ? 9999 : 4
633
+ }
634
+ }
635
+ );
636
+ };
637
+ var SkeletonText = ({ lines = 3, className = "" }) => /* @__PURE__ */ jsx14("div", { className: `cp-skeleton-lines ${className}`.trim(), style: { display: "flex", flexDirection: "column", gap: 8 }, children: Array.from({ length: lines }).map((_, i) => /* @__PURE__ */ jsx14(
638
+ "span",
639
+ {
640
+ className: "cp-skeleton cp-skeleton--pulse",
641
+ style: {
642
+ display: "block",
643
+ width: i === lines - 1 ? "60%" : "100%",
644
+ height: 14,
645
+ borderRadius: 4
646
+ }
647
+ },
648
+ i
649
+ )) });
650
+ var SkeletonCard = ({ className = "" }) => /* @__PURE__ */ jsxs12(
651
+ "div",
652
+ {
653
+ className: `cp-skeleton-card ${className}`.trim(),
654
+ style: {
655
+ background: "var(--cp-card)",
656
+ border: "1px solid var(--cp-border)",
657
+ borderRadius: 12,
658
+ padding: 24,
659
+ display: "flex",
660
+ flexDirection: "column",
661
+ gap: 16
662
+ },
663
+ children: [
664
+ /* @__PURE__ */ jsxs12("div", { style: { display: "flex", alignItems: "center", gap: 12 }, children: [
665
+ /* @__PURE__ */ jsx14(
666
+ "span",
667
+ {
668
+ className: "cp-skeleton cp-skeleton--pulse",
669
+ style: { display: "block", width: 40, height: 40, borderRadius: 9999, flexShrink: 0 }
670
+ }
671
+ ),
672
+ /* @__PURE__ */ jsxs12("div", { style: { flex: 1, display: "flex", flexDirection: "column", gap: 8 }, children: [
673
+ /* @__PURE__ */ jsx14(
674
+ "span",
675
+ {
676
+ className: "cp-skeleton cp-skeleton--pulse",
677
+ style: { display: "block", width: "60%", height: 14, borderRadius: 4 }
678
+ }
679
+ ),
680
+ /* @__PURE__ */ jsx14(
681
+ "span",
682
+ {
683
+ className: "cp-skeleton cp-skeleton--pulse",
684
+ style: { display: "block", width: "40%", height: 12, borderRadius: 4 }
685
+ }
686
+ )
687
+ ] })
688
+ ] }),
689
+ /* @__PURE__ */ jsx14(SkeletonText, { lines: 3 }),
690
+ /* @__PURE__ */ jsxs12("div", { style: { display: "flex", gap: 8 }, children: [
691
+ /* @__PURE__ */ jsx14(
692
+ "span",
693
+ {
694
+ className: "cp-skeleton cp-skeleton--pulse",
695
+ style: { display: "block", width: 80, height: 32, borderRadius: 6 }
696
+ }
697
+ ),
698
+ /* @__PURE__ */ jsx14(
699
+ "span",
700
+ {
701
+ className: "cp-skeleton cp-skeleton--pulse",
702
+ style: { display: "block", width: 80, height: 32, borderRadius: 6 }
703
+ }
704
+ )
705
+ ] })
706
+ ]
707
+ }
708
+ );
709
+
710
+ // src/components/Navbar.tsx
711
+ import React8 from "react";
712
+ import { jsx as jsx15, jsxs as jsxs13 } from "react/jsx-runtime";
713
+ var Navbar = ({
714
+ logo,
715
+ links = [],
716
+ actions,
717
+ sticky = false,
718
+ className = ""
719
+ }) => {
720
+ const [menuOpen, setMenuOpen] = React8.useState(false);
721
+ const classes = [
722
+ "cp-navbar",
723
+ sticky ? "cp-navbar--sticky" : "",
724
+ className
725
+ ].filter(Boolean).join(" ");
726
+ return /* @__PURE__ */ jsxs13("nav", { className: classes, children: [
727
+ /* @__PURE__ */ jsxs13("div", { className: "cp-navbar__inner", children: [
728
+ logo && /* @__PURE__ */ jsx15("div", { className: "cp-navbar__logo", children: logo }),
729
+ links.length > 0 && /* @__PURE__ */ jsx15("ul", { className: "cp-navbar__links", role: "list", children: links.map((link, i) => /* @__PURE__ */ jsx15("li", { children: /* @__PURE__ */ jsx15(
730
+ "a",
731
+ {
732
+ href: link.href,
733
+ className: ["cp-navbar__link", link.active ? "cp-navbar__link--active" : ""].filter(Boolean).join(" "),
734
+ "aria-current": link.active ? "page" : void 0,
735
+ children: link.label
736
+ }
737
+ ) }, i)) }),
738
+ actions && /* @__PURE__ */ jsx15("div", { className: "cp-navbar__actions", children: actions }),
739
+ /* @__PURE__ */ jsxs13(
740
+ "button",
741
+ {
742
+ className: "cp-navbar__hamburger",
743
+ "aria-label": menuOpen ? "Close menu" : "Open menu",
744
+ "aria-expanded": menuOpen,
745
+ onClick: () => setMenuOpen((prev) => !prev),
746
+ children: [
747
+ /* @__PURE__ */ jsx15("span", { className: "cp-navbar__hamburger-bar" }),
748
+ /* @__PURE__ */ jsx15("span", { className: "cp-navbar__hamburger-bar" }),
749
+ /* @__PURE__ */ jsx15("span", { className: "cp-navbar__hamburger-bar" })
750
+ ]
751
+ }
752
+ )
753
+ ] }),
754
+ menuOpen && links.length > 0 && /* @__PURE__ */ jsxs13("div", { className: "cp-navbar__mobile-menu", children: [
755
+ /* @__PURE__ */ jsx15("ul", { role: "list", children: links.map((link, i) => /* @__PURE__ */ jsx15("li", { children: /* @__PURE__ */ jsx15(
756
+ "a",
757
+ {
758
+ href: link.href,
759
+ className: ["cp-navbar__mobile-link", link.active ? "cp-navbar__mobile-link--active" : ""].filter(Boolean).join(" "),
760
+ "aria-current": link.active ? "page" : void 0,
761
+ onClick: () => setMenuOpen(false),
762
+ children: link.label
763
+ }
764
+ ) }, i)) }),
765
+ actions && /* @__PURE__ */ jsx15("div", { className: "cp-navbar__mobile-actions", children: actions })
766
+ ] })
767
+ ] });
768
+ };
769
+
770
+ // src/components/Sidebar.tsx
771
+ import React9 from "react";
772
+ import { Fragment, jsx as jsx16, jsxs as jsxs14 } from "react/jsx-runtime";
773
+ var Sidebar = ({
774
+ links = [],
775
+ collapsed = false,
776
+ onCollapse,
777
+ className = ""
778
+ }) => {
779
+ const [expandedGroups, setExpandedGroups] = React9.useState({});
780
+ const toggleGroup = (index) => {
781
+ setExpandedGroups((prev) => ({ ...prev, [index]: !prev[index] }));
782
+ };
783
+ const classes = [
784
+ "cp-sidebar",
785
+ collapsed ? "cp-sidebar--collapsed" : "",
786
+ className
787
+ ].filter(Boolean).join(" ");
788
+ return /* @__PURE__ */ jsxs14("aside", { className: classes, children: [
789
+ onCollapse && /* @__PURE__ */ jsx16("div", { className: "cp-sidebar__toggle-wrap", children: /* @__PURE__ */ jsx16(
790
+ "button",
791
+ {
792
+ className: "cp-sidebar__toggle",
793
+ "aria-label": collapsed ? "Expand sidebar" : "Collapse sidebar",
794
+ onClick: () => onCollapse(!collapsed),
795
+ children: collapsed ? "\u203A" : "\u2039"
796
+ }
797
+ ) }),
798
+ /* @__PURE__ */ jsx16("nav", { className: "cp-sidebar__nav", "aria-label": "Sidebar navigation", children: /* @__PURE__ */ jsx16("ul", { className: "cp-sidebar__list", role: "list", children: links.map((link, i) => {
799
+ const hasChildren = link.children && link.children.length > 0;
800
+ const isExpanded = expandedGroups[i] ?? false;
801
+ return /* @__PURE__ */ jsx16("li", { className: "cp-sidebar__item", children: hasChildren ? /* @__PURE__ */ jsxs14(Fragment, { children: [
802
+ /* @__PURE__ */ jsxs14(
803
+ "button",
804
+ {
805
+ className: [
806
+ "cp-sidebar__link",
807
+ link.active ? "cp-sidebar__link--active" : ""
808
+ ].filter(Boolean).join(" "),
809
+ "aria-expanded": isExpanded,
810
+ onClick: () => toggleGroup(i),
811
+ children: [
812
+ link.icon && /* @__PURE__ */ jsx16("span", { className: "cp-sidebar__icon", "aria-hidden": "true", children: link.icon }),
813
+ !collapsed && /* @__PURE__ */ jsxs14(Fragment, { children: [
814
+ /* @__PURE__ */ jsx16("span", { className: "cp-sidebar__label", children: link.label }),
815
+ link.badge != null && /* @__PURE__ */ jsx16("span", { className: "cp-sidebar__badge", children: link.badge }),
816
+ /* @__PURE__ */ jsx16("span", { className: "cp-sidebar__chevron", "aria-hidden": "true", children: isExpanded ? "\u25BE" : "\u25B8" })
817
+ ] })
818
+ ]
819
+ }
820
+ ),
821
+ isExpanded && !collapsed && /* @__PURE__ */ jsx16("ul", { className: "cp-sidebar__sub-list", role: "list", children: link.children.map((child, j) => /* @__PURE__ */ jsx16("li", { className: "cp-sidebar__sub-item", children: /* @__PURE__ */ jsx16(
822
+ "a",
823
+ {
824
+ href: child.href,
825
+ className: [
826
+ "cp-sidebar__sub-link",
827
+ child.active ? "cp-sidebar__sub-link--active" : ""
828
+ ].filter(Boolean).join(" "),
829
+ "aria-current": child.active ? "page" : void 0,
830
+ children: child.label
831
+ }
832
+ ) }, j)) })
833
+ ] }) : /* @__PURE__ */ jsxs14(
834
+ "a",
835
+ {
836
+ href: link.href,
837
+ className: [
838
+ "cp-sidebar__link",
839
+ link.active ? "cp-sidebar__link--active" : ""
840
+ ].filter(Boolean).join(" "),
841
+ "aria-current": link.active ? "page" : void 0,
842
+ children: [
843
+ link.icon && /* @__PURE__ */ jsx16("span", { className: "cp-sidebar__icon", "aria-hidden": "true", children: link.icon }),
844
+ !collapsed && /* @__PURE__ */ jsxs14(Fragment, { children: [
845
+ /* @__PURE__ */ jsx16("span", { className: "cp-sidebar__label", children: link.label }),
846
+ link.badge != null && /* @__PURE__ */ jsx16("span", { className: "cp-sidebar__badge", children: link.badge })
847
+ ] })
848
+ ]
849
+ }
850
+ ) }, i);
851
+ }) }) })
852
+ ] });
853
+ };
854
+
855
+ // src/components/Popover.tsx
856
+ import React10 from "react";
857
+ import { jsx as jsx17, jsxs as jsxs15 } from "react/jsx-runtime";
858
+ var Popover = ({
859
+ trigger,
860
+ placement = "bottom",
861
+ children,
862
+ className = ""
863
+ }) => {
864
+ const [open, setOpen] = React10.useState(false);
865
+ const wrapperRef = React10.useRef(null);
866
+ React10.useEffect(() => {
867
+ if (!open) return;
868
+ const handleClick = (e) => {
869
+ if (wrapperRef.current && !wrapperRef.current.contains(e.target)) {
870
+ setOpen(false);
871
+ }
872
+ };
873
+ const handleKey = (e) => {
874
+ if (e.key === "Escape") setOpen(false);
875
+ };
876
+ document.addEventListener("mousedown", handleClick);
877
+ document.addEventListener("keydown", handleKey);
878
+ return () => {
879
+ document.removeEventListener("mousedown", handleClick);
880
+ document.removeEventListener("keydown", handleKey);
881
+ };
882
+ }, [open]);
883
+ const id = React10.useId();
884
+ return /* @__PURE__ */ jsxs15(
885
+ "div",
886
+ {
887
+ ref: wrapperRef,
888
+ className: ["cp-popover-host", `cp-popover-host--${placement}`, className].filter(Boolean).join(" "),
889
+ style: { position: "relative", display: "inline-flex" },
890
+ children: [
891
+ /* @__PURE__ */ jsx17(
892
+ "div",
893
+ {
894
+ className: "cp-popover-trigger",
895
+ onClick: () => setOpen((prev) => !prev),
896
+ "aria-expanded": open,
897
+ "aria-controls": id,
898
+ children: trigger
899
+ }
900
+ ),
901
+ open && /* @__PURE__ */ jsx17(
902
+ "div",
903
+ {
904
+ id,
905
+ role: "dialog",
906
+ className: ["cp-popover", `cp-popover--${placement}`].join(" "),
907
+ children
908
+ }
909
+ )
910
+ ]
911
+ }
912
+ );
913
+ };
914
+ export {
915
+ Alert,
916
+ Avatar,
917
+ Badge,
918
+ Breadcrumb,
919
+ Button,
920
+ Card,
921
+ CardBody,
922
+ CardFooter,
923
+ CardHeader,
924
+ Field,
925
+ Input,
926
+ Label,
927
+ Modal,
928
+ Navbar,
929
+ Pagination,
930
+ Popover,
931
+ Select,
932
+ Sidebar,
933
+ Skeleton,
934
+ SkeletonCard,
935
+ SkeletonText,
936
+ Table,
937
+ Tabs,
938
+ Textarea,
939
+ ToastProvider,
940
+ Tooltip,
941
+ useToast
942
+ };
943
+ //# sourceMappingURL=index.js.map