@entropix/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,782 @@
1
+ import { forwardRef, useMemo, useCallback, createContext, useState, useEffect, useRef, useContext } from 'react';
2
+ import { useButton, useToggle, useDialog, useTabs, useAccordion, useMenu } from '@entropix/core';
3
+ import { jsx } from 'react/jsx-runtime';
4
+ import { createPortal } from 'react-dom';
5
+
6
+ // src/utils/map-accessibility-to-aria.ts
7
+ var ARIA_MAP = {
8
+ role: "role",
9
+ label: "aria-label",
10
+ labelledBy: "aria-labelledby",
11
+ describedBy: "aria-describedby",
12
+ disabled: "aria-disabled",
13
+ expanded: "aria-expanded",
14
+ selected: "aria-selected",
15
+ checked: "aria-checked",
16
+ pressed: "aria-pressed",
17
+ busy: "aria-busy",
18
+ modal: "aria-modal",
19
+ hasPopup: "aria-haspopup",
20
+ controls: "aria-controls",
21
+ owns: "aria-owns",
22
+ live: "aria-live",
23
+ orientation: "aria-orientation",
24
+ tabIndex: "tabIndex",
25
+ hidden: "aria-hidden",
26
+ valueNow: "aria-valuenow",
27
+ valueMin: "aria-valuemin",
28
+ valueMax: "aria-valuemax",
29
+ valueText: "aria-valuetext"
30
+ };
31
+ function mapAccessibilityToAria(props) {
32
+ const result = {};
33
+ for (const [key, attrName] of Object.entries(ARIA_MAP)) {
34
+ const value = props[key];
35
+ if (value !== void 0) {
36
+ result[attrName] = value;
37
+ }
38
+ }
39
+ return result;
40
+ }
41
+ function useKeyboardHandler(keyboardConfig, actionMap) {
42
+ const handler = useCallback(
43
+ (event) => {
44
+ if (!keyboardConfig) return;
45
+ const intent = keyboardConfig.getIntent(event.key, {
46
+ shift: event.shiftKey,
47
+ meta: event.metaKey,
48
+ alt: event.altKey
49
+ });
50
+ if (intent && actionMap[intent]) {
51
+ event.preventDefault();
52
+ actionMap[intent]();
53
+ }
54
+ },
55
+ [keyboardConfig, actionMap]
56
+ );
57
+ if (!keyboardConfig) return void 0;
58
+ return handler;
59
+ }
60
+ var FOCUSABLE_SELECTOR = [
61
+ "a[href]",
62
+ "button:not([disabled])",
63
+ "input:not([disabled])",
64
+ "select:not([disabled])",
65
+ "textarea:not([disabled])",
66
+ '[tabindex]:not([tabindex="-1"])'
67
+ ].join(", ");
68
+ function useFocusTrap(containerRef, isActive) {
69
+ useEffect(() => {
70
+ if (!isActive) return;
71
+ const container = containerRef.current;
72
+ if (!container) return;
73
+ const focusableElements = container.querySelectorAll(FOCUSABLE_SELECTOR);
74
+ if (focusableElements.length > 0) {
75
+ focusableElements[0].focus();
76
+ }
77
+ function handleKeyDown(event) {
78
+ if (event.key !== "Tab") return;
79
+ const focusable = container.querySelectorAll(FOCUSABLE_SELECTOR);
80
+ if (focusable.length === 0) return;
81
+ const first = focusable[0];
82
+ const last = focusable[focusable.length - 1];
83
+ if (event.shiftKey) {
84
+ if (document.activeElement === first) {
85
+ event.preventDefault();
86
+ last.focus();
87
+ }
88
+ } else {
89
+ if (document.activeElement === last) {
90
+ event.preventDefault();
91
+ first.focus();
92
+ }
93
+ }
94
+ }
95
+ container.addEventListener("keydown", handleKeyDown);
96
+ return () => {
97
+ container.removeEventListener("keydown", handleKeyDown);
98
+ };
99
+ }, [isActive, containerRef]);
100
+ }
101
+ function useFocusRestore(isActive) {
102
+ const savedElement = useRef(null);
103
+ useEffect(() => {
104
+ if (isActive) {
105
+ savedElement.current = document.activeElement;
106
+ } else if (savedElement.current) {
107
+ const el = savedElement.current;
108
+ if (el && document.body.contains(el) && typeof el.focus === "function") {
109
+ el.focus();
110
+ }
111
+ savedElement.current = null;
112
+ }
113
+ }, [isActive]);
114
+ }
115
+
116
+ // src/utils/cn.ts
117
+ function cn(...classes) {
118
+ return classes.filter(Boolean).join(" ");
119
+ }
120
+ var Button = forwardRef(function Button2({
121
+ disabled,
122
+ loading,
123
+ onPress,
124
+ as: Component = "button",
125
+ variant,
126
+ size,
127
+ className,
128
+ style,
129
+ children,
130
+ onClick,
131
+ onKeyDown: externalOnKeyDown,
132
+ ...rest
133
+ }, ref) {
134
+ const elementType = typeof Component === "string" ? Component : "div";
135
+ const { isDisabled, isLoading, getButtonProps } = useButton({
136
+ disabled,
137
+ loading,
138
+ onPress,
139
+ elementType
140
+ });
141
+ const propGetterReturn = getButtonProps();
142
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
143
+ const actionMap = useMemo(
144
+ () => ({
145
+ activate: propGetterReturn.onAction ?? (() => {
146
+ })
147
+ }),
148
+ [propGetterReturn.onAction]
149
+ );
150
+ const onKeyDown = useKeyboardHandler(
151
+ propGetterReturn.keyboardConfig,
152
+ actionMap
153
+ );
154
+ const handleClick = useCallback(
155
+ (event) => {
156
+ propGetterReturn.onAction?.();
157
+ onClick?.(event);
158
+ },
159
+ [propGetterReturn.onAction, onClick]
160
+ );
161
+ const handleKeyDown = useCallback(
162
+ (event) => {
163
+ onKeyDown?.(event);
164
+ externalOnKeyDown?.(event);
165
+ },
166
+ [onKeyDown, externalOnKeyDown]
167
+ );
168
+ const dataState = isLoading ? "loading" : isDisabled ? "disabled" : void 0;
169
+ return /* @__PURE__ */ jsx(
170
+ Component,
171
+ {
172
+ ref,
173
+ className: cn(
174
+ "entropix-button",
175
+ variant && `entropix-button--${variant}`,
176
+ size && `entropix-button--${size}`,
177
+ className
178
+ ),
179
+ style,
180
+ ...ariaProps,
181
+ ...rest,
182
+ type: Component === "button" ? "button" : void 0,
183
+ disabled: Component === "button" && isDisabled ? true : void 0,
184
+ onClick: propGetterReturn.onAction || onClick ? handleClick : void 0,
185
+ onKeyDown: onKeyDown || externalOnKeyDown ? handleKeyDown : void 0,
186
+ "data-state": dataState,
187
+ "data-variant": variant,
188
+ "data-size": size,
189
+ children
190
+ }
191
+ );
192
+ });
193
+ var Toggle = forwardRef(
194
+ function Toggle2(props, ref) {
195
+ return /* @__PURE__ */ jsx(ToggleInner, { ...props, ref, role: "checkbox", componentClass: "entropix-toggle" });
196
+ }
197
+ );
198
+ var ToggleInner = forwardRef(
199
+ function ToggleInner2({
200
+ checked,
201
+ defaultChecked,
202
+ onChange,
203
+ disabled,
204
+ label,
205
+ role = "checkbox",
206
+ componentClass = "entropix-toggle",
207
+ className,
208
+ style,
209
+ children,
210
+ onClick,
211
+ onKeyDown: externalOnKeyDown,
212
+ ...rest
213
+ }, ref) {
214
+ const { isChecked, isDisabled, getToggleProps } = useToggle({
215
+ checked,
216
+ defaultChecked,
217
+ onChange,
218
+ disabled,
219
+ role
220
+ });
221
+ const propGetterReturn = getToggleProps();
222
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
223
+ if (label && !children) {
224
+ ariaProps["aria-label"] = label;
225
+ }
226
+ const actionMap = useMemo(
227
+ () => ({
228
+ toggle: propGetterReturn.onAction ?? (() => {
229
+ })
230
+ }),
231
+ [propGetterReturn.onAction]
232
+ );
233
+ const onKeyDown = useKeyboardHandler(
234
+ propGetterReturn.keyboardConfig,
235
+ actionMap
236
+ );
237
+ const handleClick = useCallback(
238
+ (event) => {
239
+ propGetterReturn.onAction?.();
240
+ onClick?.(event);
241
+ },
242
+ [propGetterReturn.onAction, onClick]
243
+ );
244
+ const handleKeyDown = useCallback(
245
+ (event) => {
246
+ onKeyDown?.(event);
247
+ externalOnKeyDown?.(event);
248
+ },
249
+ [onKeyDown, externalOnKeyDown]
250
+ );
251
+ return /* @__PURE__ */ jsx(
252
+ "button",
253
+ {
254
+ ref,
255
+ type: "button",
256
+ className: cn(componentClass, className),
257
+ style,
258
+ ...ariaProps,
259
+ ...rest,
260
+ disabled: isDisabled || void 0,
261
+ onClick: propGetterReturn.onAction || onClick ? handleClick : void 0,
262
+ onKeyDown: onKeyDown || externalOnKeyDown ? handleKeyDown : void 0,
263
+ "data-state": isChecked ? "checked" : "unchecked",
264
+ children
265
+ }
266
+ );
267
+ }
268
+ );
269
+ var Switch = forwardRef(
270
+ function Switch2(props, ref) {
271
+ return /* @__PURE__ */ jsx(ToggleInner, { ...props, ref, role: "switch", componentClass: "entropix-switch" });
272
+ }
273
+ );
274
+ var DialogContext = createContext(null);
275
+ function useDialogContext() {
276
+ const context = useContext(DialogContext);
277
+ if (!context) {
278
+ throw new Error(
279
+ "Dialog compound components must be used within a <Dialog> provider."
280
+ );
281
+ }
282
+ return context;
283
+ }
284
+ function Dialog({
285
+ children,
286
+ isOpen,
287
+ defaultOpen,
288
+ onOpenChange,
289
+ closeOnOverlayPress,
290
+ closeOnEscape,
291
+ modal,
292
+ role
293
+ }) {
294
+ const dialog = useDialog({
295
+ isOpen,
296
+ defaultOpen,
297
+ onOpenChange,
298
+ closeOnOverlayPress,
299
+ closeOnEscape,
300
+ modal,
301
+ role
302
+ });
303
+ return /* @__PURE__ */ jsx(DialogContext.Provider, { value: dialog, children });
304
+ }
305
+ var DialogTrigger = forwardRef(
306
+ function DialogTrigger2({ children, className, onClick, ...rest }, ref) {
307
+ const { getTriggerProps } = useDialogContext();
308
+ const propGetterReturn = getTriggerProps();
309
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
310
+ const handleClick = useCallback(
311
+ (event) => {
312
+ propGetterReturn.onAction?.();
313
+ onClick?.(event);
314
+ },
315
+ [propGetterReturn.onAction, onClick]
316
+ );
317
+ return /* @__PURE__ */ jsx(
318
+ "button",
319
+ {
320
+ ref,
321
+ type: "button",
322
+ ...ariaProps,
323
+ ...rest,
324
+ className: cn("entropix-dialog-trigger", className),
325
+ onClick: handleClick,
326
+ children
327
+ }
328
+ );
329
+ }
330
+ );
331
+ var DialogContent = forwardRef(
332
+ function DialogContent2({ children, className, onKeyDown: externalOnKeyDown, ...rest }, ref) {
333
+ const { isOpen, close, ids, focusManagement, getContentProps } = useDialogContext();
334
+ const [mounted, setMounted] = useState(false);
335
+ useEffect(() => {
336
+ setMounted(true);
337
+ }, []);
338
+ const internalRef = useRef(null);
339
+ useFocusTrap(internalRef, isOpen && focusManagement.trapFocus);
340
+ useFocusRestore(isOpen && focusManagement.restoreFocus);
341
+ const propGetterReturn = getContentProps();
342
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
343
+ const actionMap = useMemo(() => ({ dismiss: close }), [close]);
344
+ const onKeyDown = useKeyboardHandler(
345
+ propGetterReturn.keyboardConfig,
346
+ actionMap
347
+ );
348
+ if (!mounted || !isOpen) return null;
349
+ const content = /* @__PURE__ */ jsx(
350
+ "div",
351
+ {
352
+ ref: (node) => {
353
+ internalRef.current = node;
354
+ if (typeof ref === "function") {
355
+ ref(node);
356
+ } else if (ref) {
357
+ ref.current = node;
358
+ }
359
+ },
360
+ id: ids.content,
361
+ ...ariaProps,
362
+ ...rest,
363
+ className: cn("entropix-dialog-content", className),
364
+ onKeyDown: onKeyDown ? (event) => {
365
+ onKeyDown(event);
366
+ externalOnKeyDown?.(event);
367
+ } : externalOnKeyDown,
368
+ "data-state": isOpen ? "open" : "closed",
369
+ children
370
+ }
371
+ );
372
+ return createPortal(content, document.body);
373
+ }
374
+ );
375
+ var DialogTitle = forwardRef(
376
+ function DialogTitle2({ children, className, ...rest }, ref) {
377
+ const { ids } = useDialogContext();
378
+ return /* @__PURE__ */ jsx("h2", { ref, id: ids.title, ...rest, className: cn("entropix-dialog-title", className), children });
379
+ }
380
+ );
381
+ var DialogDescription = forwardRef(function DialogDescription2({ children, className, ...rest }, ref) {
382
+ const { ids } = useDialogContext();
383
+ return /* @__PURE__ */ jsx("p", { ref, id: ids.description, ...rest, className: cn("entropix-dialog-description", className), children });
384
+ });
385
+ var DialogClose = forwardRef(
386
+ function DialogClose2({ children, className, onClick, ...rest }, ref) {
387
+ const { getCloseProps } = useDialogContext();
388
+ const propGetterReturn = getCloseProps();
389
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
390
+ const handleClick = useCallback(
391
+ (event) => {
392
+ propGetterReturn.onAction?.();
393
+ onClick?.(event);
394
+ },
395
+ [propGetterReturn.onAction, onClick]
396
+ );
397
+ return /* @__PURE__ */ jsx(
398
+ "button",
399
+ {
400
+ ref,
401
+ type: "button",
402
+ ...ariaProps,
403
+ ...rest,
404
+ className: cn("entropix-dialog-close", className),
405
+ onClick: handleClick,
406
+ children
407
+ }
408
+ );
409
+ }
410
+ );
411
+ var DialogOverlay = forwardRef(
412
+ function DialogOverlay2({ className, onClick, ...rest }, ref) {
413
+ const { isOpen, getOverlayProps } = useDialogContext();
414
+ const propGetterReturn = getOverlayProps();
415
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
416
+ const handleClick = useCallback(
417
+ (event) => {
418
+ propGetterReturn.onAction?.();
419
+ onClick?.(event);
420
+ },
421
+ [propGetterReturn.onAction, onClick]
422
+ );
423
+ if (!isOpen) return null;
424
+ return /* @__PURE__ */ jsx(
425
+ "div",
426
+ {
427
+ ref,
428
+ ...ariaProps,
429
+ ...rest,
430
+ className: cn("entropix-dialog-overlay", className),
431
+ onClick: propGetterReturn.onAction || onClick ? handleClick : void 0,
432
+ "data-state": isOpen ? "open" : "closed"
433
+ }
434
+ );
435
+ }
436
+ );
437
+ var TabsContext = createContext(null);
438
+ function useTabsContext() {
439
+ const context = useContext(TabsContext);
440
+ if (!context) {
441
+ throw new Error(
442
+ "Tabs compound components must be used within a <Tabs> provider."
443
+ );
444
+ }
445
+ return context;
446
+ }
447
+ function Tabs({
448
+ children,
449
+ className,
450
+ orientation = "horizontal",
451
+ activationMode = "automatic",
452
+ ...options
453
+ }) {
454
+ const tabs = useTabs({ ...options, orientation, activationMode });
455
+ return /* @__PURE__ */ jsx(TabsContext.Provider, { value: { ...tabs, orientation, activationMode }, children: /* @__PURE__ */ jsx("div", { className: cn("entropix-tabs", className), "data-orientation": orientation, children }) });
456
+ }
457
+ function TabList({ children, className }) {
458
+ const { getTabListProps } = useTabsContext();
459
+ const propGetterReturn = getTabListProps();
460
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
461
+ return /* @__PURE__ */ jsx("div", { ...ariaProps, className: cn("entropix-tablist", className), children });
462
+ }
463
+ function Tab({ value, children, className }) {
464
+ const { getTabProps, select, selectedKey, orientation } = useTabsContext();
465
+ const propGetterReturn = getTabProps(value);
466
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
467
+ const baseId = ariaProps["aria-controls"] ? String(ariaProps["aria-controls"]).replace(`-panel-${value}`, "") : "";
468
+ const handleClick = useCallback(() => {
469
+ propGetterReturn.onAction?.();
470
+ }, [propGetterReturn.onAction]);
471
+ const onKeyDown = useKeyboardHandler(propGetterReturn.keyboardConfig, {
472
+ activate: () => select(value)
473
+ });
474
+ return /* @__PURE__ */ jsx(
475
+ "button",
476
+ {
477
+ ...ariaProps,
478
+ id: `${baseId}-tab-${value}`,
479
+ className: cn("entropix-tab", className),
480
+ onClick: handleClick,
481
+ onKeyDown,
482
+ "data-state": selectedKey === value ? "active" : "inactive",
483
+ "data-orientation": orientation,
484
+ children
485
+ }
486
+ );
487
+ }
488
+ function TabPanel({ value, children, className }) {
489
+ const { getTabPanelProps, selectedKey } = useTabsContext();
490
+ const propGetterReturn = getTabPanelProps(value);
491
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
492
+ const baseId = ariaProps["aria-labelledby"] ? String(ariaProps["aria-labelledby"]).replace(`-tab-${value}`, "") : "";
493
+ if (selectedKey !== value) return null;
494
+ return /* @__PURE__ */ jsx(
495
+ "div",
496
+ {
497
+ ...ariaProps,
498
+ id: `${baseId}-panel-${value}`,
499
+ className: cn("entropix-tabpanel", className),
500
+ "data-state": "active",
501
+ children
502
+ }
503
+ );
504
+ }
505
+ var AccordionContext = createContext(null);
506
+ function useAccordionContext() {
507
+ const context = useContext(AccordionContext);
508
+ if (!context) {
509
+ throw new Error(
510
+ "Accordion compound components must be used within an <Accordion> provider."
511
+ );
512
+ }
513
+ return context;
514
+ }
515
+ var AccordionItemContext = createContext(null);
516
+ function useAccordionItemContext() {
517
+ const context = useContext(AccordionItemContext);
518
+ if (context === null) {
519
+ throw new Error(
520
+ "AccordionTrigger and AccordionPanel must be used within an <AccordionItem>."
521
+ );
522
+ }
523
+ return context;
524
+ }
525
+ function Accordion({ children, className, ...options }) {
526
+ const accordion = useAccordion(options);
527
+ return /* @__PURE__ */ jsx(AccordionContext.Provider, { value: accordion, children: /* @__PURE__ */ jsx("div", { className: cn("entropix-accordion", className), children }) });
528
+ }
529
+ function AccordionItem({
530
+ value,
531
+ children,
532
+ className
533
+ }) {
534
+ const { isExpanded } = useAccordionContext();
535
+ return /* @__PURE__ */ jsx(AccordionItemContext.Provider, { value, children: /* @__PURE__ */ jsx(
536
+ "div",
537
+ {
538
+ className: cn("entropix-accordion-item", className),
539
+ "data-state": isExpanded(value) ? "open" : "closed",
540
+ children
541
+ }
542
+ ) });
543
+ }
544
+ function AccordionTrigger({
545
+ children,
546
+ className
547
+ }) {
548
+ const itemKey = useAccordionItemContext();
549
+ const { getItemTriggerProps, toggle } = useAccordionContext();
550
+ const propGetterReturn = getItemTriggerProps(itemKey);
551
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
552
+ const triggerId = propGetterReturn.accessibility.controls ? String(propGetterReturn.accessibility.controls).replace("panel-", "trigger-") : void 0;
553
+ const handleClick = useCallback(() => {
554
+ propGetterReturn.onAction?.();
555
+ }, [propGetterReturn.onAction]);
556
+ const onKeyDown = useKeyboardHandler(propGetterReturn.keyboardConfig, {
557
+ activate: () => toggle(itemKey)
558
+ });
559
+ return /* @__PURE__ */ jsx(
560
+ "button",
561
+ {
562
+ ...ariaProps,
563
+ id: triggerId,
564
+ className: cn("entropix-accordion-trigger", className),
565
+ onClick: handleClick,
566
+ onKeyDown,
567
+ children
568
+ }
569
+ );
570
+ }
571
+ function AccordionPanel({ children, className }) {
572
+ const itemKey = useAccordionItemContext();
573
+ const { getItemPanelProps, isExpanded } = useAccordionContext();
574
+ const propGetterReturn = getItemPanelProps(itemKey);
575
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
576
+ const panelId = propGetterReturn.accessibility.labelledBy ? String(propGetterReturn.accessibility.labelledBy).replace(
577
+ "trigger-",
578
+ "panel-"
579
+ ) : void 0;
580
+ if (!isExpanded(itemKey)) return null;
581
+ return /* @__PURE__ */ jsx("div", { ...ariaProps, id: panelId, className: cn("entropix-accordion-panel", className), "data-state": "open", children });
582
+ }
583
+ var MenuContext = createContext(null);
584
+ function useMenuContext() {
585
+ const context = useContext(MenuContext);
586
+ if (!context) {
587
+ throw new Error(
588
+ "Menu compound components must be used within a <Menu> provider."
589
+ );
590
+ }
591
+ return context;
592
+ }
593
+ function Menu({ children, ...options }) {
594
+ const menu = useMenu(options);
595
+ return /* @__PURE__ */ jsx(MenuContext.Provider, { value: menu, children });
596
+ }
597
+ function MenuTrigger({ children, className }) {
598
+ const { getTriggerProps, toggle, open } = useMenuContext();
599
+ const propGetterReturn = getTriggerProps();
600
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
601
+ const handleClick = useCallback(() => {
602
+ propGetterReturn.onAction?.();
603
+ }, [propGetterReturn.onAction]);
604
+ const onKeyDown = useKeyboardHandler(propGetterReturn.keyboardConfig, {
605
+ activate: toggle,
606
+ moveDown: open,
607
+ moveUp: open
608
+ });
609
+ return /* @__PURE__ */ jsx(
610
+ "button",
611
+ {
612
+ ...ariaProps,
613
+ className: cn("entropix-menu-trigger", className),
614
+ onClick: handleClick,
615
+ onKeyDown,
616
+ children
617
+ }
618
+ );
619
+ }
620
+ function MenuContent({ children, className }) {
621
+ const { isOpen, getMenuProps, close } = useMenuContext();
622
+ const propGetterReturn = getMenuProps();
623
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
624
+ const onKeyDown = useKeyboardHandler(propGetterReturn.keyboardConfig, {
625
+ dismiss: close
626
+ });
627
+ if (!isOpen) return null;
628
+ return /* @__PURE__ */ jsx(
629
+ "div",
630
+ {
631
+ ...ariaProps,
632
+ className: cn("entropix-menu-content", className),
633
+ onKeyDown,
634
+ "data-state": "open",
635
+ children
636
+ }
637
+ );
638
+ }
639
+ function MenuItem({
640
+ index,
641
+ onSelect,
642
+ disabled,
643
+ children,
644
+ className
645
+ }) {
646
+ const { getItemProps, activeIndex } = useMenuContext();
647
+ const propGetterReturn = getItemProps(index, { onSelect, disabled });
648
+ const ariaProps = mapAccessibilityToAria(propGetterReturn.accessibility);
649
+ const handleClick = useCallback(() => {
650
+ propGetterReturn.onAction?.();
651
+ }, [propGetterReturn.onAction]);
652
+ return /* @__PURE__ */ jsx(
653
+ "div",
654
+ {
655
+ ...ariaProps,
656
+ className: cn("entropix-menu-item", className),
657
+ onClick: handleClick,
658
+ "data-state": activeIndex === index ? "active" : "inactive",
659
+ "data-disabled": disabled || void 0,
660
+ children
661
+ }
662
+ );
663
+ }
664
+ var BREAKPOINTS = {
665
+ sm: 640,
666
+ md: 768,
667
+ lg: 1024,
668
+ xl: 1280,
669
+ "2xl": 1536
670
+ };
671
+ function useBreakpoint() {
672
+ const getBreakpoint = useCallback(() => {
673
+ if (typeof window === "undefined") return "base";
674
+ const width = window.innerWidth;
675
+ if (width >= BREAKPOINTS["2xl"]) return "2xl";
676
+ if (width >= BREAKPOINTS.xl) return "xl";
677
+ if (width >= BREAKPOINTS.lg) return "lg";
678
+ if (width >= BREAKPOINTS.md) return "md";
679
+ if (width >= BREAKPOINTS.sm) return "sm";
680
+ return "base";
681
+ }, []);
682
+ const [breakpoint, setBreakpoint] = useState(getBreakpoint);
683
+ useEffect(() => {
684
+ const handleResize = () => {
685
+ const next = getBreakpoint();
686
+ setBreakpoint((prev) => prev !== next ? next : prev);
687
+ };
688
+ window.addEventListener("resize", handleResize);
689
+ handleResize();
690
+ return () => window.removeEventListener("resize", handleResize);
691
+ }, [getBreakpoint]);
692
+ return breakpoint;
693
+ }
694
+ function useMediaQuery(query) {
695
+ const [matches, setMatches] = useState(() => {
696
+ if (typeof window === "undefined") return false;
697
+ return window.matchMedia(query).matches;
698
+ });
699
+ useEffect(() => {
700
+ const mql = window.matchMedia(query);
701
+ const handler = (event) => setMatches(event.matches);
702
+ setMatches(mql.matches);
703
+ mql.addEventListener("change", handler);
704
+ return () => mql.removeEventListener("change", handler);
705
+ }, [query]);
706
+ return matches;
707
+ }
708
+ function useBreakpointValue(breakpoint) {
709
+ return useMediaQuery(`(min-width: ${BREAKPOINTS[breakpoint]}px)`);
710
+ }
711
+ var Stack = forwardRef(function Stack2({ gap, align, fullWidth, as: Component = "div", className, children, ...rest }, ref) {
712
+ return /* @__PURE__ */ jsx(
713
+ Component,
714
+ {
715
+ ref,
716
+ className: cn(
717
+ "entropix-stack",
718
+ gap && `entropix-stack--gap-${gap}`,
719
+ align && `entropix-stack--align-${align}`,
720
+ fullWidth && "entropix-stack--full-width",
721
+ className
722
+ ),
723
+ ...rest,
724
+ children
725
+ }
726
+ );
727
+ });
728
+ var Inline = forwardRef(function Inline2({ gap, align, justify, wrap, as: Component = "div", className, children, ...rest }, ref) {
729
+ return /* @__PURE__ */ jsx(
730
+ Component,
731
+ {
732
+ ref,
733
+ className: cn(
734
+ "entropix-inline",
735
+ gap && `entropix-inline--gap-${gap}`,
736
+ align && `entropix-inline--align-${align}`,
737
+ justify && `entropix-inline--justify-${justify}`,
738
+ wrap && "entropix-inline--wrap",
739
+ className
740
+ ),
741
+ ...rest,
742
+ children
743
+ }
744
+ );
745
+ });
746
+ var Container = forwardRef(function Container2({ maxWidth = "lg", center, as: Component = "div", className, children, ...rest }, ref) {
747
+ return /* @__PURE__ */ jsx(
748
+ Component,
749
+ {
750
+ ref,
751
+ className: cn(
752
+ "entropix-container",
753
+ `entropix-container--${maxWidth}`,
754
+ center && "entropix-container--center",
755
+ className
756
+ ),
757
+ ...rest,
758
+ children
759
+ }
760
+ );
761
+ });
762
+ var Divider = forwardRef(function Divider2({ orientation = "horizontal", spacing, className, ...rest }, ref) {
763
+ return /* @__PURE__ */ jsx(
764
+ "hr",
765
+ {
766
+ ref,
767
+ role: orientation === "vertical" ? "separator" : void 0,
768
+ "aria-orientation": orientation === "vertical" ? "vertical" : void 0,
769
+ className: cn(
770
+ "entropix-divider",
771
+ orientation === "vertical" && "entropix-divider--vertical",
772
+ spacing && `entropix-divider--spacing-${spacing}`,
773
+ className
774
+ ),
775
+ ...rest
776
+ }
777
+ );
778
+ });
779
+
780
+ export { Accordion, AccordionItem, AccordionPanel, AccordionTrigger, BREAKPOINTS, Button, Container, Dialog, DialogClose, DialogContent, DialogDescription, DialogOverlay, DialogTitle, DialogTrigger, Divider, Inline, Menu, MenuContent, MenuItem, MenuTrigger, Stack, Switch, Tab, TabList, TabPanel, Tabs, Toggle, mapAccessibilityToAria, useBreakpoint, useBreakpointValue, useFocusRestore, useFocusTrap, useKeyboardHandler, useMediaQuery };
781
+ //# sourceMappingURL=index.js.map
782
+ //# sourceMappingURL=index.js.map