@cloud-ru/ds-drawer 2.0.0 → 2.0.1-preview-97040951.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 +4 -2
- package/dist/cjs/components/DrawerCustom/hooks/useDrawerResize.js +8 -0
- package/dist/cjs/components/DrawerCustom/types.d.ts +6 -3
- package/dist/cjs/constants.d.ts +4 -0
- package/dist/cjs/constants.js +5 -1
- package/dist/cjs/types.d.ts +2 -1
- package/dist/esm/components/DrawerCustom/hooks/useDrawerResize.js +8 -0
- package/dist/esm/components/DrawerCustom/types.d.ts +6 -3
- package/dist/esm/constants.d.ts +4 -0
- package/dist/esm/constants.js +4 -0
- package/dist/esm/types.d.ts +2 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/src/components/DrawerCustom/hooks/useDrawerResize.tsx +14 -0
- package/src/components/DrawerCustom/types.ts +6 -3
- package/src/constants.ts +6 -0
- package/src/types.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloud-ru/ds-drawer",
|
|
3
|
-
"version": "2.0.0",
|
|
3
|
+
"version": "2.0.1-preview-97040951.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-adaptive": "
|
|
44
|
-
"@cloud-ru/ds-bottom-sheet": "
|
|
45
|
-
"@cloud-ru/ds-materials": "
|
|
46
|
-
"@cloud-ru/ds-
|
|
47
|
-
"@cloud-ru/ds-
|
|
48
|
-
"@cloud-ru/ds-tooltip": "
|
|
49
|
-
"@cloud-ru/ds-
|
|
50
|
-
"@cloud-ru/ds-
|
|
43
|
+
"@cloud-ru/ds-adaptive": "1.0.2",
|
|
44
|
+
"@cloud-ru/ds-bottom-sheet": "2.0.0",
|
|
45
|
+
"@cloud-ru/ds-materials": "2.0.1",
|
|
46
|
+
"@cloud-ru/ds-popup-private": "1.1.9",
|
|
47
|
+
"@cloud-ru/ds-scroll": "1.0.5",
|
|
48
|
+
"@cloud-ru/ds-tooltip": "1.0.11",
|
|
49
|
+
"@cloud-ru/ds-utils": "1.2.0",
|
|
50
|
+
"@cloud-ru/ds-portal-context": "1.0.2"
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -3,6 +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
7
|
import styles from '../styles.module.scss';
|
|
7
8
|
import { DrawerCustomProps } from '../types';
|
|
8
9
|
|
|
@@ -21,6 +22,9 @@ type UseDrawerResizeResult = {
|
|
|
21
22
|
width?: number;
|
|
22
23
|
};
|
|
23
24
|
|
|
25
|
+
const getFullMaxWidth = () =>
|
|
26
|
+
isBrowser() ? Math.max(0, document.documentElement.clientWidth - FULL_WIDTH_OFFSET) : Infinity;
|
|
27
|
+
|
|
24
28
|
export function useDrawerResize({ position, resizable: resizableProp }: UseDrawerResizeParams): UseDrawerResizeResult {
|
|
25
29
|
const targetRef = useRef<HTMLElement | null>(null);
|
|
26
30
|
const targetRefCallbackRef = useRef<(node: HTMLElement) => void | undefined>();
|
|
@@ -62,6 +66,16 @@ export function useDrawerResize({ position, resizable: resizableProp }: UseDrawe
|
|
|
62
66
|
? ({
|
|
63
67
|
onResize: value => {
|
|
64
68
|
if (value < (resizableProp?.min || 0)) return;
|
|
69
|
+
|
|
70
|
+
if (resizableProp?.max === RESIZABLE_MAX_FULL) {
|
|
71
|
+
const next = Math.min(value, getFullMaxWidth());
|
|
72
|
+
|
|
73
|
+
setWidth(next);
|
|
74
|
+
resizableProp?.onResize?.(next);
|
|
75
|
+
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
65
79
|
if (value > (resizableProp?.max || Infinity)) return;
|
|
66
80
|
|
|
67
81
|
setWidth(value);
|
|
@@ -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, Width } from '../../types';
|
|
6
|
+
import { Position, ResizableMax, Width } from '../../types';
|
|
7
7
|
|
|
8
8
|
export type DrawerCustomProps = WithSupportProps<
|
|
9
9
|
PropsWithChildren<{
|
|
@@ -60,8 +60,11 @@ export type DrawerCustomProps = WithSupportProps<
|
|
|
60
60
|
resizable?: {
|
|
61
61
|
/** Минимальная доступная ширина */
|
|
62
62
|
min: number;
|
|
63
|
-
/**
|
|
64
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Максимальная доступная ширина: число в px либо `'full'` — вся ширина окна за вычетом 48px
|
|
65
|
+
* (двойной отступ обёртки).
|
|
66
|
+
*/
|
|
67
|
+
max?: ResizableMax;
|
|
65
68
|
/** Ширина по умолчанию */
|
|
66
69
|
default?: number;
|
|
67
70
|
/** Колбэк на изменение размера */
|
package/src/constants.ts
CHANGED
|
@@ -29,3 +29,9 @@ export const POSITION = {
|
|
|
29
29
|
Top: 'top',
|
|
30
30
|
Bottom: 'bottom',
|
|
31
31
|
} as const;
|
|
32
|
+
|
|
33
|
+
/** Значение `resizable.max`: растягивать до ширины окна за вычетом двойного отступа обёртки. */
|
|
34
|
+
export const RESIZABLE_MAX_FULL = 'full';
|
|
35
|
+
|
|
36
|
+
/** Суммарный горизонтальный отступ `content-wrapper` (по 24px с каждой стороны). */
|
|
37
|
+
export const FULL_WIDTH_OFFSET = 48;
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ValueOf } from '@cloud-ru/ds-utils';
|
|
2
2
|
|
|
3
|
-
import { POSITION, WIDTH } from './constants';
|
|
3
|
+
import { POSITION, RESIZABLE_MAX_FULL, 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;
|