@cloud-ru/ds-bottom-sheet 1.0.3-preview-d4c70f71.0 → 1.0.3-preview-fe0a44cc.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.
@@ -18,6 +18,17 @@ const helperComponents_1 = require("../../helperComponents");
18
18
  const constants_2 = require("./constants");
19
19
  const hooks_1 = require("./hooks");
20
20
  const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
21
+ /** Резолв portal-target'а. Вызывается после `isMounted=true` (браузер), `document` доступен. */
22
+ function resolveContainer(container, portalContextNode) {
23
+ if (typeof container === 'string') {
24
+ // eslint-disable-next-line @cloud-ru/ssr-safe-react/domApi -- guarded by isMounted (browser only)
25
+ return document.querySelector(container);
26
+ }
27
+ if (container instanceof HTMLElement)
28
+ return container;
29
+ // eslint-disable-next-line @cloud-ru/ssr-safe-react/domApi -- guarded by isMounted (browser only)
30
+ return portalContextNode ?? document.body;
31
+ }
21
32
  /**
22
33
  * Низкоуровневая обёртка bottom-sheet'а: portal + backdrop + slide-up motion + focus-trap +
23
34
  * Pointer-Events swipe / snap-engine. Готовая анатомия — `BottomSheet`.
@@ -95,14 +106,14 @@ function BottomSheetCustom(props) {
95
106
  const densityClassName = (0, theme_1.useThemeClassnames)({ density: 'comfort' });
96
107
  if (!isMounted)
97
108
  return null;
98
- const targetNode = (0, portal_context_1.resolvePortalContainer)(container, portalContextRef.current);
109
+ const targetNode = resolveContainer(container, portalContextRef.current);
99
110
  if (!targetNode)
100
111
  return null;
101
112
  const supportProps = (0, utils_1.extractSupportProps)(rest);
102
113
  return (0, react_dom_1.createPortal)(
103
114
  // RemoveScroll лочит фон-скролл (refcount для вложенных sheet'ов); `enabled={lockScroll}` —
104
115
  // для non-modal фон остаётся прокручиваемым.
105
- (0, jsx_runtime_1.jsx)(react_remove_scroll_1.RemoveScroll, { enabled: lockScroll, children: (0, jsx_runtime_1.jsxs)("div", { className: (0, classnames_1.default)(styles_module_scss_1.default.root, portal_context_1.PORTAL_ROOT_CLASS_NAME, rootClassName), "data-active": isActive || undefined, "data-disable-motions": disableMotions || undefined, children: [showBackdrop && ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.backdrop, "data-test-id": constants_1.TEST_IDS.backdrop, onClick: handleBackdropClick, "aria-hidden": true })), (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.contentWrapper, "data-active": isActive || undefined, "data-full-height": isFullHeight || undefined, children: (0, jsx_runtime_1.jsxs)("div", { ref: mergeRefCb, className: (0, classnames_1.default)(styles_module_scss_1.default.content, densityClassName, className), role: 'dialog', "aria-modal": isModal ? 'true' : undefined, "data-test-id": constants_1.TEST_IDS.root, "data-safe-area": safeArea || undefined, "data-snap-index": activeSnapIndex, "data-snap-points": snapPoints && snapPoints.length > 0 ? snapPoints.length : undefined, "data-swipe-enabled": swipeEnabled || undefined, "data-dragging": isDragging || undefined, "data-full-height": isFullHeight || undefined, ...supportProps, ...(swipeEnabled ? dragHandlers : {}), children: [swipeEnabled && (0, jsx_runtime_1.jsx)(helperComponents_1.Handle, {}), (0, jsx_runtime_1.jsx)(popup_private_1.OverlaySurfaceProvider, { surface: popup_private_1.OVERLAY_SURFACE.Sheet, children: children })] }) })] }) }), targetNode);
116
+ (0, jsx_runtime_1.jsx)(react_remove_scroll_1.RemoveScroll, { enabled: lockScroll, children: (0, jsx_runtime_1.jsxs)("div", { className: (0, classnames_1.default)(styles_module_scss_1.default.root, rootClassName), "data-active": isActive || undefined, "data-disable-motions": disableMotions || undefined, children: [showBackdrop && ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.backdrop, "data-test-id": constants_1.TEST_IDS.backdrop, onClick: handleBackdropClick, "aria-hidden": true })), (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.contentWrapper, "data-active": isActive || undefined, "data-full-height": isFullHeight || undefined, children: (0, jsx_runtime_1.jsxs)("div", { ref: mergeRefCb, className: (0, classnames_1.default)(styles_module_scss_1.default.content, densityClassName, className), role: 'dialog', "aria-modal": isModal ? 'true' : undefined, "data-test-id": constants_1.TEST_IDS.root, "data-safe-area": safeArea || undefined, "data-snap-index": activeSnapIndex, "data-snap-points": snapPoints && snapPoints.length > 0 ? snapPoints.length : undefined, "data-swipe-enabled": swipeEnabled || undefined, "data-dragging": isDragging || undefined, "data-full-height": isFullHeight || undefined, ...supportProps, ...(swipeEnabled ? dragHandlers : {}), children: [swipeEnabled && (0, jsx_runtime_1.jsx)(helperComponents_1.Handle, {}), (0, jsx_runtime_1.jsx)(popup_private_1.OverlaySurfaceProvider, { surface: popup_private_1.OVERLAY_SURFACE.Sheet, children: children })] }) })] }) }), targetNode);
106
117
  }
107
118
  BottomSheetCustom.Header = popup_private_1.PopupHeader;
108
119
  BottomSheetCustom.Body = popup_private_1.PopupBody;
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { OVERLAY_SURFACE, OverlaySurfaceProvider, PopupBody, PopupFooter, PopupHeader, PopupMedia, } from '@cloud-ru/ds-popup-private';
3
- import { PORTAL_ROOT_CLASS_NAME, resolvePortalContainer, usePortalContext } from '@cloud-ru/ds-portal-context';
3
+ import { usePortalContext } from '@cloud-ru/ds-portal-context';
4
4
  import { useThemeClassnames } from '@cloud-ru/ds-theme';
5
5
  import { extractSupportProps, isBrowser, useLayoutEffect, useModalOpenState } from '@cloud-ru/ds-utils';
6
6
  import cn from 'classnames';
@@ -12,6 +12,17 @@ import { Handle } from '../../helperComponents/index.js';
12
12
  import { CLOSING_TIMEOUT } from './constants.js';
13
13
  import { useDragEngine, useFocusTrap, useTransitionPhase } from './hooks/index.js';
14
14
  import styles from './styles.module.css';
15
+ /** Резолв portal-target'а. Вызывается после `isMounted=true` (браузер), `document` доступен. */
16
+ function resolveContainer(container, portalContextNode) {
17
+ if (typeof container === 'string') {
18
+ // eslint-disable-next-line @cloud-ru/ssr-safe-react/domApi -- guarded by isMounted (browser only)
19
+ return document.querySelector(container);
20
+ }
21
+ if (container instanceof HTMLElement)
22
+ return container;
23
+ // eslint-disable-next-line @cloud-ru/ssr-safe-react/domApi -- guarded by isMounted (browser only)
24
+ return portalContextNode ?? document.body;
25
+ }
15
26
  /**
16
27
  * Низкоуровневая обёртка bottom-sheet'а: portal + backdrop + slide-up motion + focus-trap +
17
28
  * Pointer-Events swipe / snap-engine. Готовая анатомия — `BottomSheet`.
@@ -89,14 +100,14 @@ export function BottomSheetCustom(props) {
89
100
  const densityClassName = useThemeClassnames({ density: 'comfort' });
90
101
  if (!isMounted)
91
102
  return null;
92
- const targetNode = resolvePortalContainer(container, portalContextRef.current);
103
+ const targetNode = resolveContainer(container, portalContextRef.current);
93
104
  if (!targetNode)
94
105
  return null;
95
106
  const supportProps = extractSupportProps(rest);
96
107
  return createPortal(
97
108
  // RemoveScroll лочит фон-скролл (refcount для вложенных sheet'ов); `enabled={lockScroll}` —
98
109
  // для non-modal фон остаётся прокручиваемым.
99
- _jsx(RemoveScroll, { enabled: lockScroll, children: _jsxs("div", { className: cn(styles.root, PORTAL_ROOT_CLASS_NAME, rootClassName), "data-active": isActive || undefined, "data-disable-motions": disableMotions || undefined, children: [showBackdrop && (_jsx("div", { className: styles.backdrop, "data-test-id": TEST_IDS.backdrop, onClick: handleBackdropClick, "aria-hidden": true })), _jsx("div", { className: styles.contentWrapper, "data-active": isActive || undefined, "data-full-height": isFullHeight || undefined, children: _jsxs("div", { ref: mergeRefCb, className: cn(styles.content, densityClassName, className), role: 'dialog', "aria-modal": isModal ? 'true' : undefined, "data-test-id": TEST_IDS.root, "data-safe-area": safeArea || undefined, "data-snap-index": activeSnapIndex, "data-snap-points": snapPoints && snapPoints.length > 0 ? snapPoints.length : undefined, "data-swipe-enabled": swipeEnabled || undefined, "data-dragging": isDragging || undefined, "data-full-height": isFullHeight || undefined, ...supportProps, ...(swipeEnabled ? dragHandlers : {}), children: [swipeEnabled && _jsx(Handle, {}), _jsx(OverlaySurfaceProvider, { surface: OVERLAY_SURFACE.Sheet, children: children })] }) })] }) }), targetNode);
110
+ _jsx(RemoveScroll, { enabled: lockScroll, children: _jsxs("div", { className: cn(styles.root, rootClassName), "data-active": isActive || undefined, "data-disable-motions": disableMotions || undefined, children: [showBackdrop && (_jsx("div", { className: styles.backdrop, "data-test-id": TEST_IDS.backdrop, onClick: handleBackdropClick, "aria-hidden": true })), _jsx("div", { className: styles.contentWrapper, "data-active": isActive || undefined, "data-full-height": isFullHeight || undefined, children: _jsxs("div", { ref: mergeRefCb, className: cn(styles.content, densityClassName, className), role: 'dialog', "aria-modal": isModal ? 'true' : undefined, "data-test-id": TEST_IDS.root, "data-safe-area": safeArea || undefined, "data-snap-index": activeSnapIndex, "data-snap-points": snapPoints && snapPoints.length > 0 ? snapPoints.length : undefined, "data-swipe-enabled": swipeEnabled || undefined, "data-dragging": isDragging || undefined, "data-full-height": isFullHeight || undefined, ...supportProps, ...(swipeEnabled ? dragHandlers : {}), children: [swipeEnabled && _jsx(Handle, {}), _jsx(OverlaySurfaceProvider, { surface: OVERLAY_SURFACE.Sheet, children: children })] }) })] }) }), targetNode);
100
111
  }
101
112
  BottomSheetCustom.Header = PopupHeader;
102
113
  BottomSheetCustom.Body = PopupBody;