@cloud-ru/ds-drawer 2.0.1-preview-e8fab9b7.0 → 2.0.1-preview-20b4671f.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/README.md +2 -4
- package/dist/cjs/components/DrawerCustom/hooks/useDrawerResize.js +7 -20
- package/dist/cjs/components/DrawerCustom/styles.module.css +0 -1
- package/dist/cjs/components/DrawerCustom/types.d.ts +3 -6
- package/dist/cjs/constants.d.ts +0 -2
- package/dist/cjs/constants.js +1 -3
- package/dist/cjs/style.css +0 -1
- package/dist/cjs/types.d.ts +1 -2
- package/dist/esm/components/DrawerCustom/hooks/useDrawerResize.js +7 -20
- package/dist/esm/components/DrawerCustom/styles.module.css +0 -1
- package/dist/esm/components/DrawerCustom/types.d.ts +3 -6
- package/dist/esm/constants.d.ts +0 -2
- package/dist/esm/constants.js +0 -2
- package/dist/esm/style.css +0 -1
- package/dist/esm/types.d.ts +1 -2
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/components/DrawerCustom/hooks/useDrawerResize.tsx +7 -27
- package/src/components/DrawerCustom/styles.module.scss +0 -6
- package/src/components/DrawerCustom/types.ts +3 -6
- package/src/constants.ts +0 -3
- package/src/types.ts +1 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloud-ru/ds-drawer",
|
|
3
|
-
"version": "2.0.1-preview-
|
|
3
|
+
"version": "2.0.1-preview-20b4671f.0",
|
|
4
4
|
"description": "Пакет выезжающих панелей — компоненты Drawer и DrawerCustom с едиными токенами позиции и ширины.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"classnames": "^2.5.1",
|
|
41
41
|
"react-remove-scroll": "^2.7.2",
|
|
42
42
|
"tabbable": "^6.5.0",
|
|
43
|
-
"@cloud-ru/ds-
|
|
43
|
+
"@cloud-ru/ds-scroll": "1.0.5",
|
|
44
|
+
"@cloud-ru/ds-popup-private": "1.1.10-preview-20b4671f.0",
|
|
45
|
+
"@cloud-ru/ds-portal-context": "1.0.2",
|
|
46
|
+
"@cloud-ru/ds-tooltip": "1.0.12-preview-20b4671f.0",
|
|
44
47
|
"@cloud-ru/ds-adaptive": "1.0.2",
|
|
45
48
|
"@cloud-ru/ds-materials": "2.0.1",
|
|
46
|
-
"@cloud-ru/ds-
|
|
47
|
-
"@cloud-ru/ds-
|
|
48
|
-
"@cloud-ru/ds-tooltip": "1.0.12-preview-e8fab9b7.0",
|
|
49
|
-
"@cloud-ru/ds-popup-private": "1.1.10-preview-e8fab9b7.0",
|
|
50
|
-
"@cloud-ru/ds-utils": "1.2.0"
|
|
49
|
+
"@cloud-ru/ds-utils": "1.2.0",
|
|
50
|
+
"@cloud-ru/ds-bottom-sheet": "2.0.1-preview-20b4671f.0"
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -3,7 +3,6 @@ import { isBrowser } from '@cloud-ru/ds-utils';
|
|
|
3
3
|
import { DrawerProps } from '@rc-component/drawer';
|
|
4
4
|
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
5
5
|
|
|
6
|
-
import { RESIZABLE_MAX_FULL } from '../../../constants';
|
|
7
6
|
import styles from '../styles.module.scss';
|
|
8
7
|
import { DrawerCustomProps } from '../types';
|
|
9
8
|
|
|
@@ -22,8 +21,6 @@ type UseDrawerResizeResult = {
|
|
|
22
21
|
width?: number;
|
|
23
22
|
};
|
|
24
23
|
|
|
25
|
-
const getFullMaxWidth = () => (isBrowser() ? Math.max(0, document.documentElement.clientWidth) : Infinity);
|
|
26
|
-
|
|
27
24
|
export function useDrawerResize({ position, resizable: resizableProp }: UseDrawerResizeParams): UseDrawerResizeResult {
|
|
28
25
|
const targetRef = useRef<HTMLElement | null>(null);
|
|
29
26
|
const targetRefCallbackRef = useRef<(node: HTMLElement) => void | undefined>();
|
|
@@ -59,48 +56,31 @@ export function useDrawerResize({ position, resizable: resizableProp }: UseDrawe
|
|
|
59
56
|
</Tooltip>
|
|
60
57
|
) : null;
|
|
61
58
|
|
|
62
|
-
const { onResize, onResizeEnd, max, min } = resizableProp ?? {};
|
|
63
|
-
const resizeEnabled = Boolean(resizableProp);
|
|
64
|
-
|
|
65
|
-
// Ширина окна могла измениться, пока дровер был закрыт: хранимое значение режем по текущей ширине на каждом
|
|
66
|
-
// рендере. Иначе rc-drawer начинает ресайз от «виртуальной» ширины, которая больше видимой панели.
|
|
67
|
-
const effectiveWidth = width !== undefined && max === RESIZABLE_MAX_FULL ? Math.min(width, getFullMaxWidth()) : width;
|
|
68
|
-
|
|
69
59
|
const resizable = useMemo(
|
|
70
60
|
() =>
|
|
71
|
-
|
|
61
|
+
resizableProp
|
|
72
62
|
? ({
|
|
73
63
|
onResize: value => {
|
|
74
|
-
if (value < (min || 0)) return;
|
|
75
|
-
|
|
76
|
-
if (max === RESIZABLE_MAX_FULL) {
|
|
77
|
-
const next = Math.min(value, getFullMaxWidth());
|
|
78
|
-
|
|
79
|
-
setWidth(next);
|
|
80
|
-
onResize?.(next);
|
|
81
|
-
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (value > (max || Infinity)) return;
|
|
64
|
+
if (value < (resizableProp?.min || 0)) return;
|
|
65
|
+
if (value > (resizableProp?.max || Infinity)) return;
|
|
86
66
|
|
|
87
67
|
setWidth(value);
|
|
88
68
|
|
|
89
|
-
onResize?.(value);
|
|
69
|
+
resizableProp?.onResize?.(value);
|
|
90
70
|
},
|
|
91
71
|
onResizeEnd: () => {
|
|
92
72
|
setOpen(false);
|
|
93
73
|
setMuted(false);
|
|
94
74
|
|
|
95
|
-
onResizeEnd?.(
|
|
75
|
+
resizableProp?.onResizeEnd?.(width ?? 0);
|
|
96
76
|
},
|
|
97
77
|
onResizeStart: () => {
|
|
98
78
|
setMuted(true);
|
|
99
79
|
},
|
|
100
80
|
} satisfies DrawerProps['resizable'])
|
|
101
81
|
: undefined,
|
|
102
|
-
[
|
|
82
|
+
[resizableProp, width],
|
|
103
83
|
);
|
|
104
84
|
|
|
105
|
-
return { tooltip, checkElement, resizable, width
|
|
85
|
+
return { tooltip, checkElement, resizable, width };
|
|
106
86
|
}
|
|
@@ -175,12 +175,6 @@ $panelMotions: (
|
|
|
175
175
|
// Ширина в макете — это ширина самой панели; горизонтальный паддинг обёртки
|
|
176
176
|
// (зона перетаскивания) лежит снаружи и не должен её сужать.
|
|
177
177
|
box-sizing: content-box;
|
|
178
|
-
|
|
179
|
-
// `max-width: 100%` у обёртки считается по контенту, а паддинг (зона перетаскивания и отступ
|
|
180
|
-
// до края) лежит снаружи — вычитаем его, иначе панель упирается в край экрана.
|
|
181
|
-
max-width: calc(
|
|
182
|
-
100% - #{drawer.$sn-drawer-anatomy-container-vertical-positionLeft-paddingLeft} - #{drawer.$sn-drawer-anatomy-container-vertical-positionLeft-paddingRight}
|
|
183
|
-
);
|
|
184
178
|
height: 100%;
|
|
185
179
|
|
|
186
180
|
@each $width in $widthSizes {
|
|
@@ -3,7 +3,7 @@ import { WithSupportProps } from '@cloud-ru/ds-utils';
|
|
|
3
3
|
import { DrawerProps as RcDrawerProps } from '@rc-component/drawer';
|
|
4
4
|
import { PropsWithChildren, ReactElement } from 'react';
|
|
5
5
|
|
|
6
|
-
import { Position,
|
|
6
|
+
import { Position, Width } from '../../types';
|
|
7
7
|
|
|
8
8
|
export type DrawerCustomProps = WithSupportProps<
|
|
9
9
|
PropsWithChildren<{
|
|
@@ -60,11 +60,8 @@ export type DrawerCustomProps = WithSupportProps<
|
|
|
60
60
|
resizable?: {
|
|
61
61
|
/** Минимальная доступная ширина */
|
|
62
62
|
min: number;
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
* (двойной отступ обёртки).
|
|
66
|
-
*/
|
|
67
|
-
max?: ResizableMax;
|
|
63
|
+
/** Максимальная доступная ширина */
|
|
64
|
+
max?: number;
|
|
68
65
|
/** Ширина по умолчанию */
|
|
69
66
|
default?: number;
|
|
70
67
|
/** Колбэк на изменение размера */
|
package/src/constants.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ValueOf } from '@cloud-ru/ds-utils';
|
|
2
2
|
|
|
3
|
-
import { POSITION,
|
|
3
|
+
import { POSITION, WIDTH } from './constants';
|
|
4
4
|
|
|
5
5
|
export type Width = ValueOf<typeof WIDTH>;
|
|
6
6
|
export type Position = ValueOf<typeof POSITION>;
|
|
7
|
-
export type ResizableMax = number | typeof RESIZABLE_MAX_FULL;
|