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