@cloud-ru/ds-drawer 2.0.1-preview-baf8f3bd.0 → 2.0.1-preview-882bc8d5.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/dist/cjs/components/DrawerCustom/hooks/useDrawerResize.js +11 -9
- package/dist/cjs/constants.d.ts +1 -3
- package/dist/cjs/constants.js +2 -4
- package/dist/esm/components/DrawerCustom/hooks/useDrawerResize.js +12 -10
- package/dist/esm/constants.d.ts +1 -3
- package/dist/esm/constants.js +1 -3
- 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 +13 -11
- package/src/constants.ts +1 -4
|
@@ -11,7 +11,7 @@ const react_1 = require("react");
|
|
|
11
11
|
const constants_1 = require("../../../constants");
|
|
12
12
|
const styles_module_scss_1 = __importDefault(require('../styles.module.css'));
|
|
13
13
|
const DRAGGER_SELECTOR = `.${styles_module_scss_1.default.prefixCls}-resizable-dragger`;
|
|
14
|
-
const getFullMaxWidth = () => (0, utils_1.isBrowser)() ? Math.max(0, document.documentElement.clientWidth
|
|
14
|
+
const getFullMaxWidth = () => ((0, utils_1.isBrowser)() ? Math.max(0, document.documentElement.clientWidth) : Infinity);
|
|
15
15
|
function useDrawerResize({ position, resizable: resizableProp }) {
|
|
16
16
|
const targetRef = (0, react_1.useRef)(null);
|
|
17
17
|
const targetRefCallbackRef = (0, react_1.useRef)();
|
|
@@ -32,31 +32,33 @@ function useDrawerResize({ position, resizable: resizableProp }) {
|
|
|
32
32
|
return null;
|
|
33
33
|
targetRef.current ? targetRefCallback(targetRef.current) : (targetRefCallbackRef.current = targetRefCallback);
|
|
34
34
|
} })) : null;
|
|
35
|
-
const
|
|
35
|
+
const { onResize, onResizeEnd, max, min } = resizableProp ?? {};
|
|
36
|
+
const resizeEnabled = Boolean(resizableProp);
|
|
37
|
+
const resizable = (0, react_1.useMemo)(() => resizeEnabled
|
|
36
38
|
? {
|
|
37
39
|
onResize: value => {
|
|
38
|
-
if (value < (
|
|
40
|
+
if (value < (min || 0))
|
|
39
41
|
return;
|
|
40
|
-
if (
|
|
42
|
+
if (max === constants_1.RESIZABLE_MAX_FULL) {
|
|
41
43
|
const next = Math.min(value, getFullMaxWidth());
|
|
42
44
|
setWidth(next);
|
|
43
|
-
|
|
45
|
+
onResize?.(next);
|
|
44
46
|
return;
|
|
45
47
|
}
|
|
46
|
-
if (value > (
|
|
48
|
+
if (value > (max || Infinity))
|
|
47
49
|
return;
|
|
48
50
|
setWidth(value);
|
|
49
|
-
|
|
51
|
+
onResize?.(value);
|
|
50
52
|
},
|
|
51
53
|
onResizeEnd: () => {
|
|
52
54
|
setOpen(false);
|
|
53
55
|
setMuted(false);
|
|
54
|
-
|
|
56
|
+
onResizeEnd?.(width ?? 0);
|
|
55
57
|
},
|
|
56
58
|
onResizeStart: () => {
|
|
57
59
|
setMuted(true);
|
|
58
60
|
},
|
|
59
61
|
}
|
|
60
|
-
: undefined, [
|
|
62
|
+
: undefined, [width, max, min, onResize, onResizeEnd, resizeEnabled]);
|
|
61
63
|
return { tooltip, checkElement, resizable, width };
|
|
62
64
|
}
|
package/dist/cjs/constants.d.ts
CHANGED
|
@@ -26,7 +26,5 @@ export declare const POSITION: {
|
|
|
26
26
|
readonly Top: "top";
|
|
27
27
|
readonly Bottom: "bottom";
|
|
28
28
|
};
|
|
29
|
-
/** Значение `resizable.max`: растягивать до ширины
|
|
29
|
+
/** Значение `resizable.max`: растягивать до ширины окна. */
|
|
30
30
|
export declare const RESIZABLE_MAX_FULL = "full";
|
|
31
|
-
/** Суммарный горизонтальный отступ `content-wrapper` (по 24px с каждой стороны). */
|
|
32
|
-
export declare const FULL_WIDTH_OFFSET = 48;
|
package/dist/cjs/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RESIZABLE_MAX_FULL = exports.POSITION = exports.WIDTH_AS_VALUES = exports.WIDTH = exports.TEST_IDS = void 0;
|
|
4
4
|
exports.TEST_IDS = {
|
|
5
5
|
closeButton: 'drawer__close-button',
|
|
6
6
|
header: 'drawer__header',
|
|
@@ -29,7 +29,5 @@ exports.POSITION = {
|
|
|
29
29
|
Top: 'top',
|
|
30
30
|
Bottom: 'bottom',
|
|
31
31
|
};
|
|
32
|
-
/** Значение `resizable.max`: растягивать до ширины
|
|
32
|
+
/** Значение `resizable.max`: растягивать до ширины окна. */
|
|
33
33
|
exports.RESIZABLE_MAX_FULL = 'full';
|
|
34
|
-
/** Суммарный горизонтальный отступ `content-wrapper` (по 24px с каждой стороны). */
|
|
35
|
-
exports.FULL_WIDTH_OFFSET = 48;
|
|
@@ -2,10 +2,10 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { Tooltip } from '@cloud-ru/ds-tooltip';
|
|
3
3
|
import { isBrowser } from '@cloud-ru/ds-utils';
|
|
4
4
|
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
5
|
-
import {
|
|
5
|
+
import { RESIZABLE_MAX_FULL } from '../../../constants.js';
|
|
6
6
|
import styles from '../styles.module.css';
|
|
7
7
|
const DRAGGER_SELECTOR = `.${styles.prefixCls}-resizable-dragger`;
|
|
8
|
-
const getFullMaxWidth = () => isBrowser() ? Math.max(0, document.documentElement.clientWidth
|
|
8
|
+
const getFullMaxWidth = () => (isBrowser() ? Math.max(0, document.documentElement.clientWidth) : Infinity);
|
|
9
9
|
export function useDrawerResize({ position, resizable: resizableProp }) {
|
|
10
10
|
const targetRef = useRef(null);
|
|
11
11
|
const targetRefCallbackRef = useRef();
|
|
@@ -26,31 +26,33 @@ export function useDrawerResize({ position, resizable: resizableProp }) {
|
|
|
26
26
|
return null;
|
|
27
27
|
targetRef.current ? targetRefCallback(targetRef.current) : (targetRefCallbackRef.current = targetRefCallback);
|
|
28
28
|
} })) : null;
|
|
29
|
-
const
|
|
29
|
+
const { onResize, onResizeEnd, max, min } = resizableProp ?? {};
|
|
30
|
+
const resizeEnabled = Boolean(resizableProp);
|
|
31
|
+
const resizable = useMemo(() => resizeEnabled
|
|
30
32
|
? {
|
|
31
33
|
onResize: value => {
|
|
32
|
-
if (value < (
|
|
34
|
+
if (value < (min || 0))
|
|
33
35
|
return;
|
|
34
|
-
if (
|
|
36
|
+
if (max === RESIZABLE_MAX_FULL) {
|
|
35
37
|
const next = Math.min(value, getFullMaxWidth());
|
|
36
38
|
setWidth(next);
|
|
37
|
-
|
|
39
|
+
onResize?.(next);
|
|
38
40
|
return;
|
|
39
41
|
}
|
|
40
|
-
if (value > (
|
|
42
|
+
if (value > (max || Infinity))
|
|
41
43
|
return;
|
|
42
44
|
setWidth(value);
|
|
43
|
-
|
|
45
|
+
onResize?.(value);
|
|
44
46
|
},
|
|
45
47
|
onResizeEnd: () => {
|
|
46
48
|
setOpen(false);
|
|
47
49
|
setMuted(false);
|
|
48
|
-
|
|
50
|
+
onResizeEnd?.(width ?? 0);
|
|
49
51
|
},
|
|
50
52
|
onResizeStart: () => {
|
|
51
53
|
setMuted(true);
|
|
52
54
|
},
|
|
53
55
|
}
|
|
54
|
-
: undefined, [
|
|
56
|
+
: undefined, [width, max, min, onResize, onResizeEnd, resizeEnabled]);
|
|
55
57
|
return { tooltip, checkElement, resizable, width };
|
|
56
58
|
}
|
package/dist/esm/constants.d.ts
CHANGED
|
@@ -26,7 +26,5 @@ export declare const POSITION: {
|
|
|
26
26
|
readonly Top: "top";
|
|
27
27
|
readonly Bottom: "bottom";
|
|
28
28
|
};
|
|
29
|
-
/** Значение `resizable.max`: растягивать до ширины
|
|
29
|
+
/** Значение `resizable.max`: растягивать до ширины окна. */
|
|
30
30
|
export declare const RESIZABLE_MAX_FULL = "full";
|
|
31
|
-
/** Суммарный горизонтальный отступ `content-wrapper` (по 24px с каждой стороны). */
|
|
32
|
-
export declare const FULL_WIDTH_OFFSET = 48;
|
package/dist/esm/constants.js
CHANGED
|
@@ -26,7 +26,5 @@ export const POSITION = {
|
|
|
26
26
|
Top: 'top',
|
|
27
27
|
Bottom: 'bottom',
|
|
28
28
|
};
|
|
29
|
-
/** Значение `resizable.max`: растягивать до ширины
|
|
29
|
+
/** Значение `resizable.max`: растягивать до ширины окна. */
|
|
30
30
|
export const RESIZABLE_MAX_FULL = 'full';
|
|
31
|
-
/** Суммарный горизонтальный отступ `content-wrapper` (по 24px с каждой стороны). */
|
|
32
|
-
export const FULL_WIDTH_OFFSET = 48;
|