@cloud-ru/ds-drawer 2.0.1-preview-baf8f3bd.0 → 2.0.1-preview-e8fab9b7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-ru/ds-drawer",
3
- "version": "2.0.1-preview-baf8f3bd.0",
3
+ "version": "2.0.1-preview-e8fab9b7.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-bottom-sheet": "2.0.1-preview-e8fab9b7.0",
43
44
  "@cloud-ru/ds-adaptive": "1.0.2",
44
- "@cloud-ru/ds-bottom-sheet": "2.0.0",
45
45
  "@cloud-ru/ds-materials": "2.0.1",
46
46
  "@cloud-ru/ds-portal-context": "1.0.2",
47
- "@cloud-ru/ds-utils": "1.2.0",
48
- "@cloud-ru/ds-tooltip": "1.0.11",
49
- "@cloud-ru/ds-popup-private": "1.1.9",
50
- "@cloud-ru/ds-scroll": "1.0.5"
47
+ "@cloud-ru/ds-scroll": "1.0.5",
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"
51
51
  }
52
52
  }
@@ -3,7 +3,7 @@ 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 { FULL_WIDTH_OFFSET, RESIZABLE_MAX_FULL } from '../../../constants';
6
+ import { RESIZABLE_MAX_FULL } from '../../../constants';
7
7
  import styles from '../styles.module.scss';
8
8
  import { DrawerCustomProps } from '../types';
9
9
 
@@ -22,8 +22,7 @@ type UseDrawerResizeResult = {
22
22
  width?: number;
23
23
  };
24
24
 
25
- const getFullMaxWidth = () =>
26
- isBrowser() ? Math.max(0, document.documentElement.clientWidth - FULL_WIDTH_OFFSET) : Infinity;
25
+ const getFullMaxWidth = () => (isBrowser() ? Math.max(0, document.documentElement.clientWidth) : Infinity);
27
26
 
28
27
  export function useDrawerResize({ position, resizable: resizableProp }: UseDrawerResizeParams): UseDrawerResizeResult {
29
28
  const targetRef = useRef<HTMLElement | null>(null);
@@ -60,41 +59,48 @@ export function useDrawerResize({ position, resizable: resizableProp }: UseDrawe
60
59
  </Tooltip>
61
60
  ) : null;
62
61
 
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
+
63
69
  const resizable = useMemo(
64
70
  () =>
65
- resizableProp
71
+ resizeEnabled
66
72
  ? ({
67
73
  onResize: value => {
68
- if (value < (resizableProp?.min || 0)) return;
74
+ if (value < (min || 0)) return;
69
75
 
70
- if (resizableProp?.max === RESIZABLE_MAX_FULL) {
76
+ if (max === RESIZABLE_MAX_FULL) {
71
77
  const next = Math.min(value, getFullMaxWidth());
72
78
 
73
79
  setWidth(next);
74
- resizableProp?.onResize?.(next);
80
+ onResize?.(next);
75
81
 
76
82
  return;
77
83
  }
78
84
 
79
- if (value > (resizableProp?.max || Infinity)) return;
85
+ if (value > (max || Infinity)) return;
80
86
 
81
87
  setWidth(value);
82
88
 
83
- resizableProp?.onResize?.(value);
89
+ onResize?.(value);
84
90
  },
85
91
  onResizeEnd: () => {
86
92
  setOpen(false);
87
93
  setMuted(false);
88
94
 
89
- resizableProp?.onResizeEnd?.(width ?? 0);
95
+ onResizeEnd?.(effectiveWidth ?? 0);
90
96
  },
91
97
  onResizeStart: () => {
92
98
  setMuted(true);
93
99
  },
94
100
  } satisfies DrawerProps['resizable'])
95
101
  : undefined,
96
- [resizableProp, width],
102
+ [effectiveWidth, max, min, onResize, onResizeEnd, resizeEnabled],
97
103
  );
98
104
 
99
- return { tooltip, checkElement, resizable, width };
105
+ return { tooltip, checkElement, resizable, width: effectiveWidth };
100
106
  }
package/src/constants.ts CHANGED
@@ -30,8 +30,5 @@ export const POSITION = {
30
30
  Bottom: 'bottom',
31
31
  } as const;
32
32
 
33
- /** Значение `resizable.max`: растягивать до ширины окна за вычетом двойного отступа обёртки. */
33
+ /** Значение `resizable.max`: растягивать до ширины окна. */
34
34
  export const RESIZABLE_MAX_FULL = 'full';
35
-
36
- /** Суммарный горизонтальный отступ `content-wrapper` (по 24px с каждой стороны). */
37
- export const FULL_WIDTH_OFFSET = 48;