@opengovsg/oui 0.0.28 → 0.0.29

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 (131) hide show
  1. package/dist/cjs/badge/badge.cjs +4 -4
  2. package/dist/cjs/badge/use-badge.cjs +6 -6
  3. package/dist/cjs/banner/banner.cjs +3 -3
  4. package/dist/cjs/button/button.cjs +4 -4
  5. package/dist/cjs/calendar/calendar-bottom-content.cjs +3 -3
  6. package/dist/cjs/calendar/calendar-header.cjs +2 -2
  7. package/dist/cjs/calendar/calendar-month-day-selector.cjs +4 -4
  8. package/dist/cjs/calendar/calendar.cjs +4 -4
  9. package/dist/cjs/calendar/hooks/use-calendar-selectors.cjs +4 -4
  10. package/dist/cjs/calendar/utils.cjs +3 -3
  11. package/dist/cjs/combo-box/combo-box-fuzzy.cjs +6 -6
  12. package/dist/cjs/combo-box/combo-box-item.cjs +2 -2
  13. package/dist/cjs/combo-box/combo-box.cjs +4 -4
  14. package/dist/cjs/date-field/date-field.cjs +3 -3
  15. package/dist/cjs/date-picker/date-picker.cjs +3 -3
  16. package/dist/cjs/date-range-picker/date-range-picker.cjs +5 -5
  17. package/dist/cjs/field/field.cjs +2 -2
  18. package/dist/cjs/file-dropzone/file-dropzone.cjs +11 -11
  19. package/dist/cjs/file-dropzone/file-info.cjs +3 -3
  20. package/dist/cjs/govt-banner/govt-banner.cjs +3 -3
  21. package/dist/cjs/hooks/use-callback-ref.cjs +4 -4
  22. package/dist/cjs/hooks/use-controllable-state.cjs +2 -2
  23. package/dist/cjs/hooks/use-draggable.cjs +8 -8
  24. package/dist/cjs/index.cjs +84 -65
  25. package/dist/cjs/input/input.cjs +2 -2
  26. package/dist/cjs/menu/menu.cjs +8 -8
  27. package/dist/cjs/modal/modal-body.cjs +2 -2
  28. package/dist/cjs/modal/modal-content.cjs +3 -3
  29. package/dist/cjs/modal/modal-footer.cjs +2 -2
  30. package/dist/cjs/modal/modal-header.cjs +2 -2
  31. package/dist/cjs/modal/modal.cjs +3 -3
  32. package/dist/cjs/navbar/index.cjs +25 -0
  33. package/dist/cjs/navbar/navbar-brand.cjs +28 -0
  34. package/dist/cjs/navbar/navbar-content.cjs +33 -0
  35. package/dist/cjs/navbar/navbar-context.cjs +14 -0
  36. package/dist/cjs/navbar/navbar-item.cjs +29 -0
  37. package/dist/cjs/navbar/navbar-menu/i18n.cjs +23 -0
  38. package/dist/cjs/navbar/navbar-menu/item.cjs +44 -0
  39. package/dist/cjs/navbar/navbar-menu/menu.cjs +62 -0
  40. package/dist/cjs/navbar/navbar-menu/toggle.cjs +94 -0
  41. package/dist/cjs/navbar/navbar.cjs +26 -0
  42. package/dist/cjs/navbar/use-navbar.cjs +116 -0
  43. package/dist/cjs/node_modules/.pnpm/@react-aria_overlays@3.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@react-aria/overlays/dist/Overlay.cjs +55 -0
  44. package/dist/cjs/node_modules/.pnpm/@react-aria_overlays@3.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@react-aria/overlays/dist/PortalProvider.cjs +23 -0
  45. package/dist/cjs/node_modules/.pnpm/@react-aria_overlays@3.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@react-aria/overlays/dist/usePreventScroll.cjs +208 -0
  46. package/dist/cjs/node_modules/.pnpm/@react-aria_ssr@3.9.10_react@19.2.3/node_modules/@react-aria/ssr/dist/SSRProvider.cjs +104 -0
  47. package/dist/cjs/node_modules/.pnpm/lucide-react@0.475.0_react@19.2.3/node_modules/lucide-react/dist/esm/Icon.cjs +4 -4
  48. package/dist/cjs/node_modules/.pnpm/lucide-react@0.475.0_react@19.2.3/node_modules/lucide-react/dist/esm/createLucideIcon.cjs +3 -3
  49. package/dist/cjs/pagination/hooks/use-pagination.cjs +7 -7
  50. package/dist/cjs/pagination/pagination.cjs +6 -6
  51. package/dist/cjs/pagination/use-pagination-item.cjs +3 -3
  52. package/dist/cjs/pagination/use-pagination.cjs +8 -8
  53. package/dist/cjs/range-calendar/range-calendar.cjs +6 -6
  54. package/dist/cjs/ripple/use-ripple.cjs +4 -4
  55. package/dist/cjs/select/select.cjs +3 -3
  56. package/dist/cjs/spinner/use-spinner.cjs +3 -3
  57. package/dist/cjs/system/react-utils/children.cjs +26 -0
  58. package/dist/cjs/system/react-utils/context.cjs +3 -3
  59. package/dist/cjs/system/react-utils/refs.cjs +3 -3
  60. package/dist/cjs/system/utils.cjs +2 -2
  61. package/dist/cjs/tabs/tabs.cjs +2 -2
  62. package/dist/cjs/tag-field/tag-field-item.cjs +2 -2
  63. package/dist/cjs/tag-field/tag-field-list.cjs +4 -4
  64. package/dist/cjs/tag-field/tag-field-root.cjs +14 -14
  65. package/dist/cjs/tag-field/tag-field-state-context.cjs +2 -2
  66. package/dist/cjs/tag-field/tag-field-tag-list.cjs +3 -3
  67. package/dist/cjs/tag-field/tag-field-trigger.cjs +2 -2
  68. package/dist/cjs/tag-field/tag-field.cjs +3 -3
  69. package/dist/cjs/tag-field/use-tag-field-state.cjs +6 -6
  70. package/dist/cjs/tag-field/use-tag-field.cjs +4 -4
  71. package/dist/cjs/text-area/text-area.cjs +2 -2
  72. package/dist/cjs/toast/toast.cjs +1 -1
  73. package/dist/cjs/toggle/toggle.cjs +3 -3
  74. package/dist/esm/button/button.js +1 -1
  75. package/dist/esm/calendar/calendar-month-day-selector.js +2 -2
  76. package/dist/esm/combo-box/combo-box.js +1 -1
  77. package/dist/esm/date-picker/date-picker.js +1 -1
  78. package/dist/esm/date-range-picker/date-range-picker.js +2 -2
  79. package/dist/esm/file-dropzone/file-dropzone.js +1 -1
  80. package/dist/esm/index.js +33 -24
  81. package/dist/esm/menu/menu.js +2 -2
  82. package/dist/esm/navbar/index.js +10 -0
  83. package/dist/esm/navbar/navbar-brand.js +26 -0
  84. package/dist/esm/navbar/navbar-content.js +31 -0
  85. package/dist/esm/navbar/navbar-context.js +11 -0
  86. package/dist/esm/navbar/navbar-item.js +27 -0
  87. package/dist/esm/navbar/navbar-menu/i18n.js +21 -0
  88. package/dist/esm/navbar/navbar-menu/item.js +42 -0
  89. package/dist/esm/navbar/navbar-menu/menu.js +60 -0
  90. package/dist/esm/navbar/navbar-menu/toggle.js +92 -0
  91. package/dist/esm/navbar/navbar.js +24 -0
  92. package/dist/esm/navbar/use-navbar.js +114 -0
  93. package/dist/esm/node_modules/.pnpm/@react-aria_overlays@3.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@react-aria/overlays/dist/Overlay.js +52 -0
  94. package/dist/esm/node_modules/.pnpm/@react-aria_overlays@3.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@react-aria/overlays/dist/PortalProvider.js +20 -0
  95. package/dist/esm/node_modules/.pnpm/@react-aria_overlays@3.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@react-aria/overlays/dist/usePreventScroll.js +206 -0
  96. package/dist/esm/node_modules/.pnpm/@react-aria_ssr@3.9.10_react@19.2.3/node_modules/@react-aria/ssr/dist/SSRProvider.js +102 -0
  97. package/dist/esm/pagination/use-pagination-item.js +1 -1
  98. package/dist/esm/select/select.js +1 -1
  99. package/dist/esm/system/react-utils/children.js +23 -0
  100. package/dist/esm/tag-field/tag-field.js +1 -1
  101. package/dist/esm/toast/toast.js +1 -1
  102. package/dist/types/index.d.mts +1 -0
  103. package/dist/types/index.d.ts +1 -0
  104. package/dist/types/index.d.ts.map +1 -1
  105. package/dist/types/navbar/index.d.ts +17 -0
  106. package/dist/types/navbar/index.d.ts.map +1 -0
  107. package/dist/types/navbar/navbar-brand.d.ts +6 -0
  108. package/dist/types/navbar/navbar-brand.d.ts.map +1 -0
  109. package/dist/types/navbar/navbar-content.d.ts +14 -0
  110. package/dist/types/navbar/navbar-content.d.ts.map +1 -0
  111. package/dist/types/navbar/navbar-context.d.ts +174 -0
  112. package/dist/types/navbar/navbar-context.d.ts.map +1 -0
  113. package/dist/types/navbar/navbar-item.d.ts +11 -0
  114. package/dist/types/navbar/navbar-item.d.ts.map +1 -0
  115. package/dist/types/navbar/navbar-menu/i18n.d.ts +3 -0
  116. package/dist/types/navbar/navbar-menu/i18n.d.ts.map +1 -0
  117. package/dist/types/navbar/navbar-menu/item.d.ts +16 -0
  118. package/dist/types/navbar/navbar-menu/item.d.ts.map +1 -0
  119. package/dist/types/navbar/navbar-menu/menu.d.ts +11 -0
  120. package/dist/types/navbar/navbar-menu/menu.d.ts.map +1 -0
  121. package/dist/types/navbar/navbar-menu/toggle.d.ts +12 -0
  122. package/dist/types/navbar/navbar-menu/toggle.d.ts.map +1 -0
  123. package/dist/types/navbar/navbar.d.ts +6 -0
  124. package/dist/types/navbar/navbar.d.ts.map +1 -0
  125. package/dist/types/navbar/use-navbar.d.ts +131 -0
  126. package/dist/types/navbar/use-navbar.d.ts.map +1 -0
  127. package/dist/types/system/react-utils/children.d.ts +10 -0
  128. package/dist/types/system/react-utils/children.d.ts.map +1 -0
  129. package/dist/types/system/react-utils/index.d.ts +5 -3
  130. package/dist/types/system/react-utils/index.d.ts.map +1 -1
  131. package/package.json +4 -4
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ "use client";
3
+ import { jsx } from 'react/jsx-runtime';
4
+ import { useRenderProps, composeRenderProps } from 'react-aria-components';
5
+ import { navbarMenuItemStyles, cn, dataAttr } from '@opengovsg/oui-theme';
6
+ import { forwardRef } from '../../system/utils.js';
7
+ import { useNavbarContext } from '../navbar-context.js';
8
+ import { useDomRef } from '../../system/react-utils/refs.js';
9
+
10
+ const NavbarMenuItem = forwardRef(
11
+ (props, ref) => {
12
+ const { className, children, isActive, ...otherProps } = props;
13
+ const domRef = useDomRef(ref);
14
+ const { isMenuOpen, classNames } = useNavbarContext();
15
+ const renderProps = useRenderProps({
16
+ className: composeRenderProps(
17
+ className,
18
+ (className2, renderProps2) => navbarMenuItemStyles({
19
+ className: cn(classNames?.menuItem, className2),
20
+ ...renderProps2
21
+ })
22
+ ),
23
+ values: {
24
+ isActive: !!isActive
25
+ }
26
+ });
27
+ return /* @__PURE__ */ jsx(
28
+ "li",
29
+ {
30
+ ref: domRef,
31
+ className: renderProps.className,
32
+ "data-active": dataAttr(isActive),
33
+ "data-open": dataAttr(isMenuOpen),
34
+ ...otherProps,
35
+ children
36
+ }
37
+ );
38
+ }
39
+ );
40
+ NavbarMenuItem.displayName = "NavbarMenuItem";
41
+
42
+ export { NavbarMenuItem };
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ "use client";
3
+ import { jsx } from 'react/jsx-runtime';
4
+ import { Overlay as $337b884510726a0d$export$c6fdb837b070b4ff } from '../../node_modules/.pnpm/@react-aria_overlays@3.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@react-aria/overlays/dist/Overlay.js';
5
+ import { chain } from 'react-aria';
6
+ import { dataAttr, cn } from '@opengovsg/oui-theme';
7
+ import { forwardRef } from '../../system/utils.js';
8
+ import { useNavbarContext } from '../navbar-context.js';
9
+ import { useDomRef } from '../../system/react-utils/refs.js';
10
+
11
+ const NavbarMenu = forwardRef(
12
+ ({ className, children, portalContainer, style, onKeyDown, ...props }, ref) => {
13
+ const domRef = useDomRef(ref);
14
+ const {
15
+ slots,
16
+ isMenuOpen,
17
+ height,
18
+ classNames,
19
+ setIsMenuOpen,
20
+ domRef: parentRef,
21
+ menuRef
22
+ } = useNavbarContext();
23
+ const handleKeyDown = (e) => {
24
+ if (e.key === "Escape") {
25
+ e.stopPropagation();
26
+ setIsMenuOpen(false);
27
+ menuRef.current?.focus();
28
+ }
29
+ };
30
+ if (!isMenuOpen) return null;
31
+ return /* @__PURE__ */ jsx(
32
+ $337b884510726a0d$export$c6fdb837b070b4ff,
33
+ {
34
+ disableFocusManagement: true,
35
+ portalContainer: portalContainer ?? parentRef.current ?? void 0,
36
+ children: /* @__PURE__ */ jsx(
37
+ "ul",
38
+ {
39
+ ref: domRef,
40
+ className: slots.menu?.({
41
+ className: cn(classNames?.menu, className)
42
+ }),
43
+ "data-open": dataAttr(isMenuOpen),
44
+ style: {
45
+ ...style,
46
+ // @ts-expect-error due to not having any type declaration for CSS variables in React style prop
47
+ "--navbar-height": typeof height === "number" ? `${height}px` : height
48
+ },
49
+ onKeyDown: chain(handleKeyDown, onKeyDown),
50
+ ...props,
51
+ children
52
+ }
53
+ )
54
+ }
55
+ );
56
+ }
57
+ );
58
+ NavbarMenu.displayName = "NavbarMenu";
59
+
60
+ export { NavbarMenu };
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ "use client";
3
+ import { jsx } from 'react/jsx-runtime';
4
+ import { useMemo } from 'react';
5
+ import { useMessageFormatter, chain } from 'react-aria';
6
+ import { ToggleButton } from 'react-aria-components';
7
+ import { buttonStyles, cn, dataAttr } from '@opengovsg/oui-theme';
8
+ import { useNavbarContext } from '../navbar-context.js';
9
+ import { i18nStrings } from './i18n.js';
10
+
11
+ const NavbarMenuToggle = ({
12
+ icon,
13
+ className,
14
+ onChange,
15
+ classNames,
16
+ size = "sm",
17
+ radius,
18
+ isIconOnly = true,
19
+ ...props
20
+ }) => {
21
+ const {
22
+ slots,
23
+ classNames: contextClassNames,
24
+ isMenuOpen,
25
+ setIsMenuOpen,
26
+ menuRef,
27
+ position
28
+ } = useNavbarContext();
29
+ const shouldScrollToTop = (isMenuOpen2) => {
30
+ if (!isMenuOpen2 || position === "sticky" || typeof window === "undefined") {
31
+ return;
32
+ }
33
+ window.scrollTo({ top: 0, behavior: "instant" });
34
+ };
35
+ const formatMessage = useMessageFormatter(i18nStrings);
36
+ const toggleStyles = useMemo(() => {
37
+ return buttonStyles({
38
+ variant: "unstyled",
39
+ size,
40
+ radius,
41
+ isIconOnly,
42
+ className: slots.toggle({
43
+ className: cn(
44
+ contextClassNames?.toggle,
45
+ className ?? classNames?.toggle
46
+ )
47
+ })
48
+ });
49
+ }, [
50
+ className,
51
+ classNames?.toggle,
52
+ contextClassNames?.toggle,
53
+ isIconOnly,
54
+ radius,
55
+ size,
56
+ slots
57
+ ]);
58
+ const child = useMemo(() => {
59
+ if (typeof icon === "function") {
60
+ return icon(isMenuOpen ?? false);
61
+ }
62
+ return icon || /* @__PURE__ */ jsx(
63
+ "span",
64
+ {
65
+ className: slots.toggleIcon({
66
+ class: cn(contextClassNames?.toggleIcon, classNames?.toggleIcon)
67
+ })
68
+ }
69
+ );
70
+ }, [
71
+ icon,
72
+ slots,
73
+ classNames?.toggleIcon,
74
+ contextClassNames?.toggleIcon,
75
+ isMenuOpen
76
+ ]);
77
+ return /* @__PURE__ */ jsx(
78
+ ToggleButton,
79
+ {
80
+ "aria-label": isMenuOpen ? formatMessage("closeMenu") : formatMessage("openMenu"),
81
+ ref: menuRef,
82
+ "data-open": dataAttr(isMenuOpen),
83
+ className: toggleStyles,
84
+ isSelected: isMenuOpen,
85
+ onChange: chain(onChange, shouldScrollToTop, setIsMenuOpen),
86
+ ...props,
87
+ children: child
88
+ }
89
+ );
90
+ };
91
+
92
+ export { NavbarMenuToggle };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ "use client";
3
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
4
+ import { FocusScope } from 'react-aria';
5
+ import { pickChildren } from '../system/react-utils/children.js';
6
+ import { forwardRef } from '../system/utils.js';
7
+ import { NavbarProvider } from './navbar-context.js';
8
+ import { NavbarMenu } from './navbar-menu/menu.js';
9
+ import { useNavbar } from './use-navbar.js';
10
+
11
+ const Navbar = forwardRef((props, ref) => {
12
+ const { children, ...otherProps } = props;
13
+ const context = useNavbar({ ...otherProps, ref });
14
+ const Component = context.Component;
15
+ const [childrenWithoutMenu, menu] = pickChildren(children, NavbarMenu);
16
+ const content = /* @__PURE__ */ jsxs(Fragment, { children: [
17
+ /* @__PURE__ */ jsx("header", { ...context.getWrapperProps(), children: childrenWithoutMenu }),
18
+ menu
19
+ ] });
20
+ return /* @__PURE__ */ jsx(NavbarProvider, { value: context, children: /* @__PURE__ */ jsx(FocusScope, { contain: context.isMenuOpen, children: /* @__PURE__ */ jsx(Component, { ...context.getBaseProps(), children: content }) }) });
21
+ });
22
+ Navbar.displayName = "Navbar";
23
+
24
+ export { Navbar };
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ "use client";
3
+ import { useRef, useCallback, useEffect } from 'react';
4
+ import { usePreventScroll as $49c51c25361d4cd2$export$ee0f7cc6afcd1c18 } from '../node_modules/.pnpm/@react-aria_overlays@3.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@react-aria/overlays/dist/usePreventScroll.js';
5
+ import { useResizeObserver, mergeProps } from '@react-aria/utils';
6
+ import { useControlledState } from '@react-stately/utils';
7
+ import { useDeepCompareMemo } from 'use-deep-compare';
8
+ import { navbarStyles, cn, dataAttr } from '@opengovsg/oui-theme';
9
+ import { mapPropsVariants } from '../system/utils.js';
10
+ import { useDomRef } from '../system/react-utils/refs.js';
11
+
12
+ function useNavbar(originalProps) {
13
+ const [
14
+ {
15
+ ref,
16
+ as,
17
+ height = "4rem",
18
+ shouldBlockScroll = true,
19
+ isMenuOpen: isMenuOpenProp,
20
+ isMenuDefaultOpen,
21
+ onMenuOpenChange = () => {
22
+ },
23
+ className,
24
+ classNames,
25
+ ...otherProps
26
+ },
27
+ variantProps
28
+ ] = mapPropsVariants(originalProps, navbarStyles.variantKeys);
29
+ const Component = as || "nav";
30
+ const domRef = useDomRef(ref);
31
+ const menuRef = useRef(null);
32
+ const prevWidth = useRef(0);
33
+ const navHeight = useRef(0);
34
+ const handleMenuOpenChange = useCallback(
35
+ (isOpen) => {
36
+ onMenuOpenChange(isOpen || false);
37
+ },
38
+ [onMenuOpenChange]
39
+ );
40
+ const [isMenuOpen, setIsMenuOpen] = useControlledState(
41
+ isMenuOpenProp,
42
+ isMenuDefaultOpen ?? false,
43
+ handleMenuOpenChange
44
+ );
45
+ const updateWidth = useCallback(() => {
46
+ if (domRef.current) {
47
+ const width = domRef.current.offsetWidth;
48
+ if (width !== prevWidth.current) {
49
+ prevWidth.current = width;
50
+ }
51
+ }
52
+ }, [domRef]);
53
+ $49c51c25361d4cd2$export$ee0f7cc6afcd1c18({
54
+ isDisabled: !(shouldBlockScroll && isMenuOpen)
55
+ });
56
+ useResizeObserver({
57
+ ref: domRef,
58
+ onResize: () => {
59
+ const currentWidth = domRef.current?.offsetWidth;
60
+ const scrollWidth = window.innerWidth - document.documentElement.clientWidth;
61
+ if (currentWidth && currentWidth + scrollWidth == prevWidth.current) {
62
+ return;
63
+ }
64
+ if (currentWidth !== prevWidth.current) {
65
+ updateWidth();
66
+ setIsMenuOpen(false);
67
+ }
68
+ }
69
+ });
70
+ useEffect(() => {
71
+ updateWidth();
72
+ navHeight.current = domRef.current?.offsetHeight || 0;
73
+ }, [domRef, updateWidth]);
74
+ const slots = useDeepCompareMemo(
75
+ () => navbarStyles({
76
+ ...variantProps
77
+ }),
78
+ [variantProps]
79
+ );
80
+ const baseStyles = cn(classNames?.base, className);
81
+ const getBaseProps = (props = {}) => ({
82
+ ...mergeProps(otherProps, props),
83
+ "data-menu-open": dataAttr(isMenuOpen),
84
+ ref: domRef,
85
+ className: slots.base({ class: cn(baseStyles, props?.className) }),
86
+ style: {
87
+ "--navbar-height": typeof height === "number" ? `${height}px` : height,
88
+ ...otherProps?.style,
89
+ ...props?.style
90
+ }
91
+ });
92
+ const getWrapperProps = (props = {}) => ({
93
+ ...props,
94
+ "data-menu-open": dataAttr(isMenuOpen),
95
+ className: slots.wrapper({
96
+ class: cn(classNames?.wrapper, props?.className)
97
+ })
98
+ });
99
+ return {
100
+ Component,
101
+ slots,
102
+ domRef,
103
+ height,
104
+ isMenuOpen,
105
+ classNames,
106
+ setIsMenuOpen,
107
+ menuRef,
108
+ getBaseProps,
109
+ getWrapperProps,
110
+ position: variantProps.position ?? "sticky"
111
+ };
112
+ }
113
+
114
+ export { useNavbar };
@@ -0,0 +1,52 @@
1
+ import { useUNSAFE_PortalContext as $96b38030c423d352$export$9fc1347d4195ccb3 } from './PortalProvider.js';
2
+ import { ClearPressResponder } from '@react-aria/interactions';
3
+ import { FocusScope } from '@react-aria/focus';
4
+ import $670gB$react, { useState, useMemo } from 'react';
5
+ import $4AOtR$reactdom from 'react-dom';
6
+ import { useIsSSR as $b5e257d569688ac6$export$535bd6ca7f90a273 } from '../../../../../@react-aria_ssr@3.9.10_react@19.2.3/node_modules/@react-aria/ssr/dist/SSRProvider.js';
7
+ import '@react-aria/utils';
8
+
9
+ /*
10
+ * Copyright 2022 Adobe. All rights reserved.
11
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License. You may obtain a copy
13
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software distributed under
16
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
+ * OF ANY KIND, either express or implied. See the License for the specific language
18
+ * governing permissions and limitations under the License.
19
+ */
20
+
21
+
22
+
23
+
24
+
25
+
26
+ const $337b884510726a0d$export$a2200b96afd16271 = /*#__PURE__*/ ($670gB$react).createContext(null);
27
+ function $337b884510726a0d$export$c6fdb837b070b4ff(props) {
28
+ let isSSR = ($b5e257d569688ac6$export$535bd6ca7f90a273)();
29
+ let { portalContainer: portalContainer = isSSR ? null : document.body, isExiting: isExiting } = props;
30
+ let [contain, setContain] = (useState)(false);
31
+ let contextValue = (useMemo)(()=>({
32
+ contain: contain,
33
+ setContain: setContain
34
+ }), [
35
+ contain,
36
+ setContain
37
+ ]);
38
+ let { getContainer: getContainer } = ($96b38030c423d352$export$9fc1347d4195ccb3)();
39
+ if (!props.portalContainer && getContainer) portalContainer = getContainer();
40
+ if (!portalContainer) return null;
41
+ let contents = props.children;
42
+ if (!props.disableFocusManagement) contents = /*#__PURE__*/ ($670gB$react).createElement((FocusScope), {
43
+ restoreFocus: true,
44
+ contain: (props.shouldContainFocus || contain) && !isExiting
45
+ }, contents);
46
+ contents = /*#__PURE__*/ ($670gB$react).createElement($337b884510726a0d$export$a2200b96afd16271.Provider, {
47
+ value: contextValue
48
+ }, /*#__PURE__*/ ($670gB$react).createElement((ClearPressResponder), null, contents));
49
+ return /*#__PURE__*/ ($4AOtR$reactdom).createPortal(contents, portalContainer);
50
+ }
51
+
52
+ export { $337b884510726a0d$export$c6fdb837b070b4ff as Overlay, $337b884510726a0d$export$a2200b96afd16271 as OverlayContext };
@@ -0,0 +1,20 @@
1
+ import { useContext, createContext } from 'react';
2
+
3
+ /*
4
+ * Copyright 2024 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+ const $96b38030c423d352$export$60d741e20e0aa309 = /*#__PURE__*/ (createContext)({});
15
+ function $96b38030c423d352$export$9fc1347d4195ccb3() {
16
+ var _useContext;
17
+ return (_useContext = (useContext)($96b38030c423d352$export$60d741e20e0aa309)) !== null && _useContext !== void 0 ? _useContext : {};
18
+ }
19
+
20
+ export { $96b38030c423d352$export$60d741e20e0aa309 as PortalContext, $96b38030c423d352$export$9fc1347d4195ccb3 as useUNSAFE_PortalContext };
@@ -0,0 +1,206 @@
1
+ import { useLayoutEffect, isIOS, willOpenKeyboard, chain, getScrollParent, isScrollable } from '@react-aria/utils';
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+ const $49c51c25361d4cd2$var$visualViewport = typeof document !== 'undefined' && window.visualViewport;
15
+ // The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position
16
+ let $49c51c25361d4cd2$var$preventScrollCount = 0;
17
+ let $49c51c25361d4cd2$var$restore;
18
+ function $49c51c25361d4cd2$export$ee0f7cc6afcd1c18(options = {}) {
19
+ let { isDisabled: isDisabled } = options;
20
+ (useLayoutEffect)(()=>{
21
+ if (isDisabled) return;
22
+ $49c51c25361d4cd2$var$preventScrollCount++;
23
+ if ($49c51c25361d4cd2$var$preventScrollCount === 1) {
24
+ if ((isIOS)()) $49c51c25361d4cd2$var$restore = $49c51c25361d4cd2$var$preventScrollMobileSafari();
25
+ else $49c51c25361d4cd2$var$restore = $49c51c25361d4cd2$var$preventScrollStandard();
26
+ }
27
+ return ()=>{
28
+ $49c51c25361d4cd2$var$preventScrollCount--;
29
+ if ($49c51c25361d4cd2$var$preventScrollCount === 0) $49c51c25361d4cd2$var$restore();
30
+ };
31
+ }, [
32
+ isDisabled
33
+ ]);
34
+ }
35
+ // For most browsers, all we need to do is set `overflow: hidden` on the root element, and
36
+ // add some padding to prevent the page from shifting when the scrollbar is hidden.
37
+ function $49c51c25361d4cd2$var$preventScrollStandard() {
38
+ let scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
39
+ return (chain)(scrollbarWidth > 0 && // Use scrollbar-gutter when supported because it also works for fixed positioned elements.
40
+ ('scrollbarGutter' in document.documentElement.style ? $49c51c25361d4cd2$var$setStyle(document.documentElement, 'scrollbarGutter', 'stable') : $49c51c25361d4cd2$var$setStyle(document.documentElement, 'paddingRight', `${scrollbarWidth}px`)), $49c51c25361d4cd2$var$setStyle(document.documentElement, 'overflow', 'hidden'));
41
+ }
42
+ // Mobile Safari is a whole different beast. Even with overflow: hidden,
43
+ // it still scrolls the page in many situations:
44
+ //
45
+ // 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.
46
+ // 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of
47
+ // it, so it becomes scrollable.
48
+ // 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.
49
+ // This may cause even fixed position elements to scroll off the screen.
50
+ // 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always
51
+ // scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.
52
+ //
53
+ // In order to work around these cases, and prevent scrolling without jankiness, we do a few things:
54
+ //
55
+ // 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling
56
+ // on the window.
57
+ // 2. Set `overscroll-behavior: contain` on nested scrollable regions so they do not scroll the page when at
58
+ // the top or bottom. Work around a bug where this does not work when the element does not actually overflow
59
+ // by preventing default in a `touchmove` event. This is best effort: we can't prevent default when pinch
60
+ // zooming or when an element contains text selection, which may allow scrolling in some cases.
61
+ // 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.
62
+ // 4. When focus moves to an input, create an off screen input and focus that temporarily. This prevents
63
+ // Safari from scrolling the page. After a small delay, focus the real input and scroll it into view
64
+ // ourselves, without scrolling the whole page.
65
+ function $49c51c25361d4cd2$var$preventScrollMobileSafari() {
66
+ let scrollable;
67
+ let allowTouchMove = false;
68
+ let onTouchStart = (e)=>{
69
+ // Store the nearest scrollable parent element from the element that the user touched.
70
+ let target = e.target;
71
+ scrollable = (isScrollable)(target) ? target : (getScrollParent)(target, true);
72
+ allowTouchMove = false;
73
+ // If the target is selected, don't preventDefault in touchmove to allow user to adjust selection.
74
+ let selection = target.ownerDocument.defaultView.getSelection();
75
+ if (selection && !selection.isCollapsed && selection.containsNode(target, true)) allowTouchMove = true;
76
+ // If this is a focused input element with a selected range, allow user to drag the selection handles.
77
+ if ('selectionStart' in target && 'selectionEnd' in target && target.selectionStart < target.selectionEnd && target.ownerDocument.activeElement === target) allowTouchMove = true;
78
+ };
79
+ // Prevent scrolling up when at the top and scrolling down when at the bottom
80
+ // of a nested scrollable area, otherwise mobile Safari will start scrolling
81
+ // the window instead.
82
+ // This must be applied before the touchstart event as of iOS 26, so inject it as a <style> element.
83
+ let style = document.createElement('style');
84
+ style.textContent = `
85
+ @layer {
86
+ * {
87
+ overscroll-behavior: contain;
88
+ }
89
+ }`.trim();
90
+ document.head.prepend(style);
91
+ let onTouchMove = (e)=>{
92
+ // Allow pinch-zooming.
93
+ if (e.touches.length === 2 || allowTouchMove) return;
94
+ // Prevent scrolling the window.
95
+ if (!scrollable || scrollable === document.documentElement || scrollable === document.body) {
96
+ e.preventDefault();
97
+ return;
98
+ }
99
+ // overscroll-behavior should prevent scroll chaining, but currently does not
100
+ // if the element doesn't actually overflow. https://bugs.webkit.org/show_bug.cgi?id=243452
101
+ // This checks that both the width and height do not overflow, otherwise we might
102
+ // block horizontal scrolling too. In that case, adding `touch-action: pan-x` to
103
+ // the element will prevent vertical page scrolling. We can't add that automatically
104
+ // because it must be set before the touchstart event.
105
+ if (scrollable.scrollHeight === scrollable.clientHeight && scrollable.scrollWidth === scrollable.clientWidth) e.preventDefault();
106
+ };
107
+ let onBlur = (e)=>{
108
+ let target = e.target;
109
+ let relatedTarget = e.relatedTarget;
110
+ if (relatedTarget && (willOpenKeyboard)(relatedTarget)) {
111
+ // Focus without scrolling the whole page, and then scroll into view manually.
112
+ relatedTarget.focus({
113
+ preventScroll: true
114
+ });
115
+ $49c51c25361d4cd2$var$scrollIntoViewWhenReady(relatedTarget, (willOpenKeyboard)(target));
116
+ } else if (!relatedTarget) {
117
+ var _target_parentElement;
118
+ // When tapping the Done button on the keyboard, focus moves to the body.
119
+ // FocusScope will then restore focus back to the input. Later when tapping
120
+ // the same input again, it is already focused, so no blur event will fire,
121
+ // resulting in the flow above never running and Safari's native scrolling occurring.
122
+ // Instead, move focus to the parent focusable element (e.g. the dialog).
123
+ let focusable = (_target_parentElement = target.parentElement) === null || _target_parentElement === void 0 ? void 0 : _target_parentElement.closest('[tabindex]');
124
+ focusable === null || focusable === void 0 ? void 0 : focusable.focus({
125
+ preventScroll: true
126
+ });
127
+ }
128
+ };
129
+ // Override programmatic focus to scroll into view without scrolling the whole page.
130
+ let focus = HTMLElement.prototype.focus;
131
+ HTMLElement.prototype.focus = function(opts) {
132
+ // Track whether the keyboard was already visible before.
133
+ let wasKeyboardVisible = document.activeElement != null && (willOpenKeyboard)(document.activeElement);
134
+ // Focus the element without scrolling the page.
135
+ focus.call(this, {
136
+ ...opts,
137
+ preventScroll: true
138
+ });
139
+ if (!opts || !opts.preventScroll) $49c51c25361d4cd2$var$scrollIntoViewWhenReady(this, wasKeyboardVisible);
140
+ };
141
+ let removeEvents = (chain)($49c51c25361d4cd2$var$addEvent(document, 'touchstart', onTouchStart, {
142
+ passive: false,
143
+ capture: true
144
+ }), $49c51c25361d4cd2$var$addEvent(document, 'touchmove', onTouchMove, {
145
+ passive: false,
146
+ capture: true
147
+ }), $49c51c25361d4cd2$var$addEvent(document, 'blur', onBlur, true));
148
+ return ()=>{
149
+ removeEvents();
150
+ style.remove();
151
+ HTMLElement.prototype.focus = focus;
152
+ };
153
+ }
154
+ // Sets a CSS property on an element, and returns a function to revert it to the previous value.
155
+ function $49c51c25361d4cd2$var$setStyle(element, style, value) {
156
+ let cur = element.style[style];
157
+ element.style[style] = value;
158
+ return ()=>{
159
+ element.style[style] = cur;
160
+ };
161
+ }
162
+ // Adds an event listener to an element, and returns a function to remove it.
163
+ function $49c51c25361d4cd2$var$addEvent(target, event, handler, options) {
164
+ // internal function, so it's ok to ignore the difficult to fix type error
165
+ // @ts-ignore
166
+ target.addEventListener(event, handler, options);
167
+ return ()=>{
168
+ // @ts-ignore
169
+ target.removeEventListener(event, handler, options);
170
+ };
171
+ }
172
+ function $49c51c25361d4cd2$var$scrollIntoViewWhenReady(target, wasKeyboardVisible) {
173
+ if (wasKeyboardVisible || !$49c51c25361d4cd2$var$visualViewport) // If the keyboard was already visible, scroll the target into view immediately.
174
+ $49c51c25361d4cd2$var$scrollIntoView(target);
175
+ else // Otherwise, wait for the visual viewport to resize before scrolling so we can
176
+ // measure the correct position to scroll to.
177
+ $49c51c25361d4cd2$var$visualViewport.addEventListener('resize', ()=>$49c51c25361d4cd2$var$scrollIntoView(target), {
178
+ once: true
179
+ });
180
+ }
181
+ function $49c51c25361d4cd2$var$scrollIntoView(target) {
182
+ let root = document.scrollingElement || document.documentElement;
183
+ let nextTarget = target;
184
+ while(nextTarget && nextTarget !== root){
185
+ // Find the parent scrollable element and adjust the scroll position if the target is not already in view.
186
+ let scrollable = (getScrollParent)(nextTarget);
187
+ if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== nextTarget) {
188
+ let scrollableRect = scrollable.getBoundingClientRect();
189
+ let targetRect = nextTarget.getBoundingClientRect();
190
+ if (targetRect.top < scrollableRect.top || targetRect.bottom > scrollableRect.top + nextTarget.clientHeight) {
191
+ let bottom = scrollableRect.bottom;
192
+ if ($49c51c25361d4cd2$var$visualViewport) bottom = Math.min(bottom, $49c51c25361d4cd2$var$visualViewport.offsetTop + $49c51c25361d4cd2$var$visualViewport.height);
193
+ // Center within the viewport.
194
+ let adjustment = targetRect.top - scrollableRect.top - ((bottom - scrollableRect.top) / 2 - targetRect.height / 2);
195
+ scrollable.scrollTo({
196
+ // Clamp to the valid range to prevent over-scrolling.
197
+ top: Math.max(0, Math.min(scrollable.scrollHeight - scrollable.clientHeight, scrollable.scrollTop + adjustment)),
198
+ behavior: 'smooth'
199
+ });
200
+ }
201
+ }
202
+ nextTarget = scrollable.parentElement;
203
+ }
204
+ }
205
+
206
+ export { $49c51c25361d4cd2$export$ee0f7cc6afcd1c18 as usePreventScroll };