@cloud-ru/ds-bottom-sheet 1.0.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/CHANGELOG.md +8 -0
- package/LICENSE +201 -0
- package/README.md +997 -0
- package/dist/cjs/components/BottomSheet/BottomSheet.d.ts +3 -0
- package/dist/cjs/components/BottomSheet/BottomSheet.js +39 -0
- package/dist/cjs/components/BottomSheet/index.d.ts +1 -0
- package/dist/cjs/components/BottomSheet/index.js +17 -0
- package/dist/cjs/components/BottomSheet/styles.module.css +27 -0
- package/dist/cjs/components/BottomSheetCustom/BottomSheetCustom.d.ts +19 -0
- package/dist/cjs/components/BottomSheetCustom/BottomSheetCustom.js +121 -0
- package/dist/cjs/components/BottomSheetCustom/constants.d.ts +30 -0
- package/dist/cjs/components/BottomSheetCustom/constants.js +33 -0
- package/dist/cjs/components/BottomSheetCustom/hooks/index.d.ts +3 -0
- package/dist/cjs/components/BottomSheetCustom/hooks/index.js +19 -0
- package/dist/cjs/components/BottomSheetCustom/hooks/useDragEngine.d.ts +44 -0
- package/dist/cjs/components/BottomSheetCustom/hooks/useDragEngine.js +312 -0
- package/dist/cjs/components/BottomSheetCustom/hooks/useFocusTrap.d.ts +7 -0
- package/dist/cjs/components/BottomSheetCustom/hooks/useFocusTrap.js +77 -0
- package/dist/cjs/components/BottomSheetCustom/hooks/useTransitionPhase.d.ts +22 -0
- package/dist/cjs/components/BottomSheetCustom/hooks/useTransitionPhase.js +51 -0
- package/dist/cjs/components/BottomSheetCustom/index.d.ts +1 -0
- package/dist/cjs/components/BottomSheetCustom/index.js +17 -0
- package/dist/cjs/components/BottomSheetCustom/styles.module.css +98 -0
- package/dist/cjs/components/BottomSheetCustom/utils/scroll.d.ts +17 -0
- package/dist/cjs/components/BottomSheetCustom/utils/scroll.js +39 -0
- package/dist/cjs/components/BottomSheetCustom/utils/snapPoints.d.ts +38 -0
- package/dist/cjs/components/BottomSheetCustom/utils/snapPoints.js +102 -0
- package/dist/cjs/components/index.d.ts +2 -0
- package/dist/cjs/components/index.js +18 -0
- package/dist/cjs/constants.d.ts +11 -0
- package/dist/cjs/constants.js +19 -0
- package/dist/cjs/helperComponents/Handle/Handle.d.ts +2 -0
- package/dist/cjs/helperComponents/Handle/Handle.js +13 -0
- package/dist/cjs/helperComponents/Handle/index.d.ts +1 -0
- package/dist/cjs/helperComponents/Handle/index.js +17 -0
- package/dist/cjs/helperComponents/Handle/styles.module.css +18 -0
- package/dist/cjs/helperComponents/index.d.ts +1 -0
- package/dist/cjs/helperComponents/index.js +17 -0
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.js +39 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/style.css +143 -0
- package/dist/cjs/types.d.ts +172 -0
- package/dist/cjs/types.js +2 -0
- package/dist/esm/components/BottomSheet/BottomSheet.d.ts +3 -0
- package/dist/esm/components/BottomSheet/BottomSheet.js +33 -0
- package/dist/esm/components/BottomSheet/index.d.ts +1 -0
- package/dist/esm/components/BottomSheet/index.js +1 -0
- package/dist/esm/components/BottomSheet/styles.module.css +27 -0
- package/dist/esm/components/BottomSheetCustom/BottomSheetCustom.d.ts +19 -0
- package/dist/esm/components/BottomSheetCustom/BottomSheetCustom.js +115 -0
- package/dist/esm/components/BottomSheetCustom/constants.d.ts +30 -0
- package/dist/esm/components/BottomSheetCustom/constants.js +30 -0
- package/dist/esm/components/BottomSheetCustom/hooks/index.d.ts +3 -0
- package/dist/esm/components/BottomSheetCustom/hooks/index.js +3 -0
- package/dist/esm/components/BottomSheetCustom/hooks/useDragEngine.d.ts +44 -0
- package/dist/esm/components/BottomSheetCustom/hooks/useDragEngine.js +309 -0
- package/dist/esm/components/BottomSheetCustom/hooks/useFocusTrap.d.ts +7 -0
- package/dist/esm/components/BottomSheetCustom/hooks/useFocusTrap.js +74 -0
- package/dist/esm/components/BottomSheetCustom/hooks/useTransitionPhase.d.ts +22 -0
- package/dist/esm/components/BottomSheetCustom/hooks/useTransitionPhase.js +48 -0
- package/dist/esm/components/BottomSheetCustom/index.d.ts +1 -0
- package/dist/esm/components/BottomSheetCustom/index.js +1 -0
- package/dist/esm/components/BottomSheetCustom/styles.module.css +98 -0
- package/dist/esm/components/BottomSheetCustom/utils/scroll.d.ts +17 -0
- package/dist/esm/components/BottomSheetCustom/utils/scroll.js +34 -0
- package/dist/esm/components/BottomSheetCustom/utils/snapPoints.d.ts +38 -0
- package/dist/esm/components/BottomSheetCustom/utils/snapPoints.js +96 -0
- package/dist/esm/components/index.d.ts +2 -0
- package/dist/esm/components/index.js +2 -0
- package/dist/esm/constants.d.ts +11 -0
- package/dist/esm/constants.js +13 -0
- package/dist/esm/helperComponents/Handle/Handle.d.ts +2 -0
- package/dist/esm/helperComponents/Handle/Handle.js +7 -0
- package/dist/esm/helperComponents/Handle/index.d.ts +1 -0
- package/dist/esm/helperComponents/Handle/index.js +1 -0
- package/dist/esm/helperComponents/Handle/styles.module.css +18 -0
- package/dist/esm/helperComponents/index.d.ts +1 -0
- package/dist/esm/helperComponents/index.js +1 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/style.css +143 -0
- package/dist/esm/types.d.ts +172 -0
- package/dist/esm/types.js +1 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +47 -0
- package/src/components/BottomSheet/BottomSheet.tsx +116 -0
- package/src/components/BottomSheet/index.ts +1 -0
- package/src/components/BottomSheet/styles.module.scss +38 -0
- package/src/components/BottomSheetCustom/BottomSheetCustom.tsx +221 -0
- package/src/components/BottomSheetCustom/constants.ts +33 -0
- package/src/components/BottomSheetCustom/hooks/index.ts +3 -0
- package/src/components/BottomSheetCustom/hooks/useDragEngine.ts +373 -0
- package/src/components/BottomSheetCustom/hooks/useFocusTrap.ts +80 -0
- package/src/components/BottomSheetCustom/hooks/useTransitionPhase.ts +52 -0
- package/src/components/BottomSheetCustom/index.ts +1 -0
- package/src/components/BottomSheetCustom/styles.module.scss +146 -0
- package/src/components/BottomSheetCustom/utils/scroll.ts +39 -0
- package/src/components/BottomSheetCustom/utils/snapPoints.ts +109 -0
- package/src/components/index.ts +2 -0
- package/src/constants.ts +14 -0
- package/src/helperComponents/Handle/Handle.tsx +11 -0
- package/src/helperComponents/Handle/index.ts +1 -0
- package/src/helperComponents/Handle/styles.module.scss +26 -0
- package/src/helperComponents/index.ts +1 -0
- package/src/index.ts +30 -0
- package/src/types.ts +185 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { FooterActions, PopupMedia } from '@cloud-ru/ds-popup-private';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { isValidElement, ReactNode, useId } from 'react';
|
|
4
|
+
|
|
5
|
+
import { TEST_IDS } from '../../constants';
|
|
6
|
+
import { BottomSheetMediaProps, BottomSheetProps } from '../../types';
|
|
7
|
+
import { BottomSheetCustom } from '../BottomSheetCustom';
|
|
8
|
+
import styles from './styles.module.scss';
|
|
9
|
+
|
|
10
|
+
function isMediaProps(value: BottomSheetMediaProps | ReactNode): value is BottomSheetMediaProps {
|
|
11
|
+
return typeof value === 'object' && value !== null && !isValidElement(value) && 'src' in value && 'alt' in value;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Обёртка `@cloud-ru/ds-bottom-sheet` с готовой анатомией: media + header + body + footer + safeArea + dividers. */
|
|
15
|
+
export function BottomSheet({
|
|
16
|
+
title,
|
|
17
|
+
slotAfterTitle,
|
|
18
|
+
subtitle,
|
|
19
|
+
slotSecondTitle,
|
|
20
|
+
onBackButtonClick,
|
|
21
|
+
actionButton,
|
|
22
|
+
media,
|
|
23
|
+
content,
|
|
24
|
+
bodyPadding = true,
|
|
25
|
+
approveButton,
|
|
26
|
+
cancelButton,
|
|
27
|
+
additionalButton,
|
|
28
|
+
footerActionsOrientation,
|
|
29
|
+
footer,
|
|
30
|
+
footerTestIds,
|
|
31
|
+
withDividers = true,
|
|
32
|
+
swipeEnabled = true,
|
|
33
|
+
// safeArea уходит в `...rest` → BottomSheetCustom (env-паддинг на `.content`).
|
|
34
|
+
className,
|
|
35
|
+
...rest
|
|
36
|
+
}: BottomSheetProps) {
|
|
37
|
+
const hasHeader = Boolean(
|
|
38
|
+
title || onBackButtonClick || actionButton || slotAfterTitle || subtitle || slotSecondTitle,
|
|
39
|
+
);
|
|
40
|
+
const hasMedia = media != null;
|
|
41
|
+
const hasFullWidthMediaImage = hasMedia && isMediaProps(media) && (media.kind ?? 'image') === 'image';
|
|
42
|
+
|
|
43
|
+
// aria-labelledby связывает заголовок с dialog'ом; без title имя задаёт потребитель через aria-label.
|
|
44
|
+
const titleId = useId();
|
|
45
|
+
|
|
46
|
+
// Footer: произвольный `footer`-ReactNode (приоритет) либо сборка из слотов кнопок через общий
|
|
47
|
+
// `FooterActions` (тот же, что у Modal/Drawer, для adaptive-маппинга 1:1).
|
|
48
|
+
const footerContent =
|
|
49
|
+
footer ??
|
|
50
|
+
(approveButton || cancelButton || additionalButton ? (
|
|
51
|
+
<FooterActions
|
|
52
|
+
surface='bottomSheet'
|
|
53
|
+
size='l'
|
|
54
|
+
approveButton={approveButton}
|
|
55
|
+
cancelButton={cancelButton}
|
|
56
|
+
additionalButton={additionalButton}
|
|
57
|
+
footerActionsOrientation={footerActionsOrientation}
|
|
58
|
+
testIds={{
|
|
59
|
+
approve: footerTestIds?.approve ?? TEST_IDS.footerApprove,
|
|
60
|
+
cancel: footerTestIds?.cancel ?? TEST_IDS.footerCancel,
|
|
61
|
+
additional: footerTestIds?.additional ?? TEST_IDS.footerAdditional,
|
|
62
|
+
}}
|
|
63
|
+
/>
|
|
64
|
+
) : null);
|
|
65
|
+
const hasFooter = footerContent != null;
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<BottomSheetCustom
|
|
69
|
+
{...rest}
|
|
70
|
+
swipeEnabled={swipeEnabled}
|
|
71
|
+
// Атрибут пишем только при наличии title (spread, не `: undefined`) — иначе затёр бы
|
|
72
|
+
// aria-label/aria-labelledby из `...rest` для title-less sheet'а.
|
|
73
|
+
{...(title ? { 'aria-labelledby': titleId } : {})}
|
|
74
|
+
className={cn(className)}
|
|
75
|
+
disableMotions={false}
|
|
76
|
+
>
|
|
77
|
+
<div className={styles.root}>
|
|
78
|
+
{hasMedia &&
|
|
79
|
+
(isMediaProps(media) ? (
|
|
80
|
+
<PopupMedia {...media} />
|
|
81
|
+
) : (
|
|
82
|
+
// ReactNode-media: тот же data-media-kind-контракт со значением 'custom'.
|
|
83
|
+
<div data-test-id={TEST_IDS.media} data-media-kind='custom'>
|
|
84
|
+
{media}
|
|
85
|
+
</div>
|
|
86
|
+
))}
|
|
87
|
+
|
|
88
|
+
<div className={cn(styles.contentBlock, hasFullWidthMediaImage && styles.contentBlockNoTopPadding)}>
|
|
89
|
+
{hasHeader && (
|
|
90
|
+
<BottomSheetCustom.Header
|
|
91
|
+
title={title}
|
|
92
|
+
titleId={titleId}
|
|
93
|
+
slotAfterTitle={slotAfterTitle}
|
|
94
|
+
subtitle={subtitle}
|
|
95
|
+
slotSecondTitle={slotSecondTitle}
|
|
96
|
+
onBackButtonClick={onBackButtonClick}
|
|
97
|
+
actionButton={actionButton}
|
|
98
|
+
/>
|
|
99
|
+
)}
|
|
100
|
+
|
|
101
|
+
{withDividers && hasHeader && (
|
|
102
|
+
<div className={styles.divider} data-test-id={TEST_IDS.dividerTop} aria-hidden />
|
|
103
|
+
)}
|
|
104
|
+
|
|
105
|
+
<BottomSheetCustom.Body bodyPadding={bodyPadding}>{content}</BottomSheetCustom.Body>
|
|
106
|
+
|
|
107
|
+
{withDividers && hasFooter && (
|
|
108
|
+
<div className={styles.divider} data-test-id={TEST_IDS.dividerBottom} aria-hidden />
|
|
109
|
+
)}
|
|
110
|
+
|
|
111
|
+
{hasFooter && <BottomSheetCustom.Footer>{footerContent}</BottomSheetCustom.Footer>}
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
</BottomSheetCustom>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './BottomSheet';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
@use '@cloud-ru/ds-figma-variables/build/scss/styles/styles.module' as base;
|
|
2
|
+
@use '@cloud-ru/ds-figma-variables/build/scss/components/bottomSheet.module' as bottomSheet;
|
|
3
|
+
|
|
4
|
+
.root {
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: column;
|
|
7
|
+
flex-grow: 1;
|
|
8
|
+
|
|
9
|
+
box-sizing: border-box;
|
|
10
|
+
height: 100%;
|
|
11
|
+
min-height: 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// safeArea теперь — env-паддинг на `.content` (BottomSheetCustom/styles.module.scss), без spacer-дивов.
|
|
15
|
+
|
|
16
|
+
.divider {
|
|
17
|
+
flex-shrink: 0;
|
|
18
|
+
height: base.$sn-primitive-strokeWeight-strokeRegular;
|
|
19
|
+
background-color: base.$sn-theme-color-available-borderColor;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.contentBlock {
|
|
23
|
+
display: flex;
|
|
24
|
+
flex: 1 1 auto;
|
|
25
|
+
flex-direction: column;
|
|
26
|
+
|
|
27
|
+
box-sizing: border-box;
|
|
28
|
+
min-height: 0;
|
|
29
|
+
// Верхний зазор контента: коллекция bottomSheet больше не несёт `content.padding-top`
|
|
30
|
+
// (chrome уехал в popupPrivate). Верхний отступ шапки теперь owns PopupHeader
|
|
31
|
+
// (popupPrivate `bottomSheet.header.padding-top`); здесь остаётся frame-паддинг `container.padding-top`.
|
|
32
|
+
padding-top: base.simple-var(bottomSheet.$bottomSheet, 'anatomy', 'container', 'padding-top');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.contentBlockNoTopPadding {
|
|
36
|
+
padding-top: 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OVERLAY_SURFACE,
|
|
3
|
+
OverlaySurfaceProvider,
|
|
4
|
+
PopupBody,
|
|
5
|
+
PopupFooter,
|
|
6
|
+
PopupHeader,
|
|
7
|
+
PopupMedia,
|
|
8
|
+
} from '@cloud-ru/ds-popup-private';
|
|
9
|
+
import { usePortalContext } from '@cloud-ru/ds-portal-context';
|
|
10
|
+
import { useThemeClassnames } from '@cloud-ru/ds-theme';
|
|
11
|
+
import { extractSupportProps, isBrowser, useLayoutEffect, useModalOpenState } from '@cloud-ru/ds-utils';
|
|
12
|
+
import cn from 'classnames';
|
|
13
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
14
|
+
import { createPortal } from 'react-dom';
|
|
15
|
+
import { RemoveScroll } from 'react-remove-scroll';
|
|
16
|
+
|
|
17
|
+
import { TEST_IDS } from '../../constants';
|
|
18
|
+
import { Handle } from '../../helperComponents';
|
|
19
|
+
import {
|
|
20
|
+
BottomSheetBodyProps,
|
|
21
|
+
BottomSheetCustomProps,
|
|
22
|
+
BottomSheetFooterProps,
|
|
23
|
+
BottomSheetHeaderProps,
|
|
24
|
+
BottomSheetMediaProps,
|
|
25
|
+
} from '../../types';
|
|
26
|
+
import { CLOSING_TIMEOUT } from './constants';
|
|
27
|
+
import { useDragEngine, useFocusTrap, useTransitionPhase } from './hooks';
|
|
28
|
+
import styles from './styles.module.scss';
|
|
29
|
+
|
|
30
|
+
/** Резолв portal-target'а. Вызывается после `isMounted=true` (браузер), `document` доступен. */
|
|
31
|
+
function resolveContainer(
|
|
32
|
+
container: BottomSheetCustomProps['container'],
|
|
33
|
+
portalContextNode: HTMLElement | null,
|
|
34
|
+
): Element | null {
|
|
35
|
+
if (typeof container === 'string') {
|
|
36
|
+
// eslint-disable-next-line @cloud-ru/ssr-safe-react/domApi -- guarded by isMounted (browser only)
|
|
37
|
+
return document.querySelector(container);
|
|
38
|
+
}
|
|
39
|
+
if (container instanceof HTMLElement) return container;
|
|
40
|
+
// eslint-disable-next-line @cloud-ru/ssr-safe-react/domApi -- guarded by isMounted (browser only)
|
|
41
|
+
return portalContextNode ?? document.body;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Низкоуровневая обёртка bottom-sheet'а: portal + backdrop + slide-up motion + focus-trap +
|
|
46
|
+
* Pointer-Events swipe / snap-engine. Готовая анатомия — `BottomSheet`.
|
|
47
|
+
*/
|
|
48
|
+
export function BottomSheetCustom(props: BottomSheetCustomProps) {
|
|
49
|
+
const {
|
|
50
|
+
open,
|
|
51
|
+
onClose,
|
|
52
|
+
showBackdrop = true,
|
|
53
|
+
lockScroll = true,
|
|
54
|
+
swipeEnabled = true,
|
|
55
|
+
safeArea = true,
|
|
56
|
+
snapPoints,
|
|
57
|
+
defaultSnapIndex,
|
|
58
|
+
snapIndex,
|
|
59
|
+
onSnapIndexChange,
|
|
60
|
+
closeOnPopstate = true,
|
|
61
|
+
disableMotions = false,
|
|
62
|
+
container,
|
|
63
|
+
className,
|
|
64
|
+
rootClassName,
|
|
65
|
+
children,
|
|
66
|
+
...rest
|
|
67
|
+
} = props;
|
|
68
|
+
|
|
69
|
+
// Sheet модальный, если затемняет фон или лочит скролл. Non-modal не прячет фон от AT,
|
|
70
|
+
// не ловит фокус и закрывается по Esc при фокусе снаружи.
|
|
71
|
+
const isModal = showBackdrop || lockScroll;
|
|
72
|
+
|
|
73
|
+
useModalOpenState(open, onClose, { closeOnPopstate });
|
|
74
|
+
|
|
75
|
+
// Возврат фокуса на триггер: запоминаем активный элемент при open=true, возвращаем при open=false.
|
|
76
|
+
const restoreFocusRef = useRef<HTMLElement | null>(null);
|
|
77
|
+
const wasOpenRef = useRef(false);
|
|
78
|
+
useLayoutEffect(() => {
|
|
79
|
+
if (open && !wasOpenRef.current) {
|
|
80
|
+
wasOpenRef.current = true;
|
|
81
|
+
restoreFocusRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
82
|
+
} else if (!open && wasOpenRef.current) {
|
|
83
|
+
wasOpenRef.current = false;
|
|
84
|
+
const previous = restoreFocusRef.current;
|
|
85
|
+
restoreFocusRef.current = null;
|
|
86
|
+
if (
|
|
87
|
+
previous &&
|
|
88
|
+
previous !== document.body &&
|
|
89
|
+
previous !== document.documentElement &&
|
|
90
|
+
document.documentElement.contains(previous)
|
|
91
|
+
) {
|
|
92
|
+
previous.focus({ preventScroll: true });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}, [open]);
|
|
96
|
+
|
|
97
|
+
const { isMounted, isActive } = useTransitionPhase(open, disableMotions ? 0 : CLOSING_TIMEOUT);
|
|
98
|
+
|
|
99
|
+
const portalContextRef = usePortalContext();
|
|
100
|
+
// Фокус-trap только для модального sheet'а: в non-modal Tab уходит на фон.
|
|
101
|
+
const focusTrapRef = useFocusTrap(isActive && isModal);
|
|
102
|
+
|
|
103
|
+
// Esc → закрытие. `useModalOpenState` закрывает через `CloseWatcher` (Chromium-only); в
|
|
104
|
+
// Safari/Firefox навешиваем keydown-fallback ровно когда `CloseWatcher` недоступен.
|
|
105
|
+
// Nested-safe для модального sheet'а: закрываем только если фокус внутри этой панели; для
|
|
106
|
+
// non-modal фокус снаружи — закрываем безусловно.
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (!isActive || !isBrowser() || 'CloseWatcher' in window) return;
|
|
109
|
+
|
|
110
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
111
|
+
if (event.key !== 'Escape') return;
|
|
112
|
+
const panel = focusTrapRef.current;
|
|
113
|
+
const focusInside = Boolean(
|
|
114
|
+
panel && (panel === document.activeElement || panel.contains(document.activeElement)),
|
|
115
|
+
);
|
|
116
|
+
if (!isModal || focusInside) {
|
|
117
|
+
onClose();
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
document.addEventListener('keydown', handleKeyDown, true);
|
|
121
|
+
return () => document.removeEventListener('keydown', handleKeyDown, true);
|
|
122
|
+
}, [isActive, isModal, onClose, focusTrapRef]);
|
|
123
|
+
|
|
124
|
+
const {
|
|
125
|
+
setContentNode,
|
|
126
|
+
dragHandlers,
|
|
127
|
+
snapIndex: activeSnapIndex,
|
|
128
|
+
isDragging,
|
|
129
|
+
} = useDragEngine({
|
|
130
|
+
snapPoints,
|
|
131
|
+
defaultSnapIndex,
|
|
132
|
+
snapIndex,
|
|
133
|
+
onSnapIndexChange,
|
|
134
|
+
onClose,
|
|
135
|
+
swipeEnabled,
|
|
136
|
+
isActive,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// Верхний safe-area отступ нужен только на full-height (верх под notch); флаг — в `data-full-height`.
|
|
140
|
+
const activeSnap = snapPoints?.[activeSnapIndex ?? 0];
|
|
141
|
+
const isFullHeight = activeSnap === 1 || (typeof activeSnap === 'string' && /^100(%|dvh|svh|lvh)$/.test(activeSnap));
|
|
142
|
+
|
|
143
|
+
const mergeRefCb = useCallback(
|
|
144
|
+
(node: HTMLDivElement | null) => {
|
|
145
|
+
(focusTrapRef as { current: HTMLDivElement | null }).current = node;
|
|
146
|
+
setContentNode(node);
|
|
147
|
+
},
|
|
148
|
+
[focusTrapRef, setContentNode],
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const handleBackdropClick = useCallback(() => {
|
|
152
|
+
if (showBackdrop) onClose();
|
|
153
|
+
}, [showBackdrop, onClose]);
|
|
154
|
+
|
|
155
|
+
// Мобильная поверхность — comfort-плотность.
|
|
156
|
+
const densityClassName = useThemeClassnames({ density: 'comfort' });
|
|
157
|
+
|
|
158
|
+
if (!isMounted) return null;
|
|
159
|
+
|
|
160
|
+
const targetNode = resolveContainer(container, portalContextRef.current);
|
|
161
|
+
if (!targetNode) return null;
|
|
162
|
+
|
|
163
|
+
const supportProps = extractSupportProps(rest);
|
|
164
|
+
|
|
165
|
+
return createPortal(
|
|
166
|
+
// RemoveScroll лочит фон-скролл (refcount для вложенных sheet'ов); `enabled={lockScroll}` —
|
|
167
|
+
// для non-modal фон остаётся прокручиваемым.
|
|
168
|
+
<RemoveScroll enabled={lockScroll}>
|
|
169
|
+
<div
|
|
170
|
+
className={cn(styles.root, rootClassName)}
|
|
171
|
+
data-active={isActive || undefined}
|
|
172
|
+
data-disable-motions={disableMotions || undefined}
|
|
173
|
+
>
|
|
174
|
+
{showBackdrop && (
|
|
175
|
+
<div className={styles.backdrop} data-test-id={TEST_IDS.backdrop} onClick={handleBackdropClick} aria-hidden />
|
|
176
|
+
)}
|
|
177
|
+
|
|
178
|
+
<div
|
|
179
|
+
className={styles.contentWrapper}
|
|
180
|
+
data-active={isActive || undefined}
|
|
181
|
+
// Full-height снимает верхний зазор max-height на `.contentWrapper`.
|
|
182
|
+
data-full-height={isFullHeight || undefined}
|
|
183
|
+
>
|
|
184
|
+
<div
|
|
185
|
+
ref={mergeRefCb}
|
|
186
|
+
className={cn(styles.content, densityClassName, className)}
|
|
187
|
+
role='dialog'
|
|
188
|
+
// aria-modal только для модального sheet'а: non-modal оставляет фон доступным AT.
|
|
189
|
+
aria-modal={isModal ? 'true' : undefined}
|
|
190
|
+
data-test-id={TEST_IDS.root}
|
|
191
|
+
data-safe-area={safeArea || undefined}
|
|
192
|
+
data-snap-index={activeSnapIndex}
|
|
193
|
+
// Пустой массив ведёт себя как single fit-content — атрибут не выставляем.
|
|
194
|
+
data-snap-points={snapPoints && snapPoints.length > 0 ? snapPoints.length : undefined}
|
|
195
|
+
data-swipe-enabled={swipeEnabled || undefined}
|
|
196
|
+
data-dragging={isDragging || undefined}
|
|
197
|
+
data-full-height={isFullHeight || undefined}
|
|
198
|
+
{...supportProps}
|
|
199
|
+
{...(swipeEnabled ? dragHandlers : {})}
|
|
200
|
+
>
|
|
201
|
+
{swipeEnabled && <Handle />}
|
|
202
|
+
<OverlaySurfaceProvider surface={OVERLAY_SURFACE.Sheet}>{children}</OverlaySurfaceProvider>
|
|
203
|
+
</div>
|
|
204
|
+
</div>
|
|
205
|
+
</div>
|
|
206
|
+
</RemoveScroll>,
|
|
207
|
+
targetNode,
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
BottomSheetCustom.Header = PopupHeader;
|
|
212
|
+
BottomSheetCustom.Body = PopupBody;
|
|
213
|
+
BottomSheetCustom.Footer = PopupFooter;
|
|
214
|
+
BottomSheetCustom.Media = PopupMedia;
|
|
215
|
+
|
|
216
|
+
export namespace BottomSheetCustom {
|
|
217
|
+
export type HeaderProps = BottomSheetHeaderProps;
|
|
218
|
+
export type BodyProps = BottomSheetBodyProps;
|
|
219
|
+
export type FooterProps = BottomSheetFooterProps;
|
|
220
|
+
export type MediaProps = BottomSheetMediaProps;
|
|
221
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Задержка размонтирования портала после `open=false` (мс). Должна быть ≥ длительности leave-анимации
|
|
3
|
+
* (slide-down `.contentWrapper` + fade `.backdrop` = 0.2s = 200ms в `styles.module.scss`), чтобы DOM
|
|
4
|
+
* не исчезал до завершения анимации. Держим 200мс — leave симметричен enter (0.2s). При правке этих
|
|
5
|
+
* CSS-длительностей синхронизируй и эту константу (фиксированный таймер, не `transitionend`).
|
|
6
|
+
* Под `prefers-reduced-motion` анимация мгновенна, а портал всё равно живёт по таймеру (≤200мс
|
|
7
|
+
* невидимого scroll-lock/focus-trap — приемлемо).
|
|
8
|
+
*/
|
|
9
|
+
export const CLOSING_TIMEOUT = 200;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Минимальное вертикальное смещение указателя (px), после которого жест трактуется как drag.
|
|
13
|
+
* До порога касание считается тапом — это защищает клики по контенту от ложного захвата drag'ом.
|
|
14
|
+
*/
|
|
15
|
+
export const DRAG_START_THRESHOLD_PX = 6;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Cooldown (ms) после того, как вложенный скролл достиг края: в течение него повторный жест
|
|
19
|
+
* не превращается в drag sheet'а. Без него инерционный скролл, доехавший до верха, мгновенно
|
|
20
|
+
* читается как «потяни вниз → закрой». Аналог `SCROLL_LOCK_TIMEOUT` в vaul.
|
|
21
|
+
*/
|
|
22
|
+
export const SCROLL_LOCK_COOLDOWN_MS = 100;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Доля высоты sheet'а, при превышении которой медленный drag вниз всё равно закрывает
|
|
26
|
+
* single-snap sheet (distance-критерий, когда скорость ниже velocity-порога). Отдельная константа
|
|
27
|
+
* от `CLOSE_THRESHOLD_RATIO_DEFAULT` в `utils/snapPoints.ts` намеренно: это два независимых регулятора
|
|
28
|
+
* (single-snap-закрытие vs multi-snap close-порог), совпадение значения (0.3) — не повод их связывать.
|
|
29
|
+
*
|
|
30
|
+
* Velocity-порог быстрого флика, наоборот, единый — `VELOCITY_THRESHOLD_PX_PER_MS` из
|
|
31
|
+
* `utils/snapPoints.ts` (один источник и для multi-snap-навигации, и для single-snap-закрытия).
|
|
32
|
+
*/
|
|
33
|
+
export const SINGLE_CLOSE_DISTANCE_RATIO = 0.3;
|