@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/README.md
CHANGED
|
@@ -448,7 +448,7 @@ export function CustomComposition() {
|
|
|
448
448
|
| `open` | `boolean` | — | Управление состоянием показан/не показан. |
|
|
449
449
|
| `position` | `"bottom"` \| `"left"` \| `"right"` \| `"top"` | — | Расположение |
|
|
450
450
|
| `push` | `boolean \| PushConfig` | — | Смещение при открытии "вложенного" компонента |
|
|
451
|
-
| `resizable` | `
|
|
451
|
+
| `resizable` | `{ min: number; max?: number; default?: number; onResize?: ((width: number) => void) \| undefined; onResizeEnd?: ((width: number) => void) \| undefined; draggerTooltip?: string \| undefined; } \| undefined` | `'s'` | Ширина (только при position: "left" \| "right") |
|
|
452
452
|
| `rootClassName` | `string` | — | CSS-класс для корневого элемента |
|
|
453
453
|
| `safeAreaBottom` | `boolean` | `true` | Нижний safe-area отступ под iOS home-indicator и Android nav-bar. Размер — токен <br/> `safeArea.bottom.minHeight`, на устройстве с большим `env(safe-area-inset-bottom)` — значение inset. |
|
|
454
454
|
| `safeAreaTop` | `boolean` | `true` | Верхний safe-area отступ под iOS notch / status-bar. Размер — токен `safeArea.top.minHeight`, <br/> на устройстве с большим `env(safe-area-inset-top)` — значение inset. Применяется, только когда <br/> sheet раскрыт на полный вьюпорт: у неполного sheet'а верх и так не заходит под notch. |
|
|
@@ -477,7 +477,7 @@ export function CustomComposition() {
|
|
|
477
477
|
| `open` | `boolean` | — | Управление состоянием показан/не показан. |
|
|
478
478
|
| `position` | `"bottom"` \| `"left"` \| `"right"` \| `"top"` | — | Расположение |
|
|
479
479
|
| `push` | `boolean \| PushConfig \| undefined` | — | Смещение при открытии "вложенного" компонента |
|
|
480
|
-
| `resizable` | `
|
|
480
|
+
| `resizable` | `{ min: number; max?: number; default?: number; onResize?: (width: number) => void; onResizeEnd?: (width: number) => void; draggerTooltip?: string; } \| undefined` | — | Ширина (только при position: "left" \| "right") |
|
|
481
481
|
| `rootClassName` | `string \| undefined` | — | CSS-класс для корневого элемента |
|
|
482
482
|
| `safeAreaBottom` | `boolean \| undefined` | — | Нижний safe-area отступ под iOS home-indicator и Android nav-bar. Размер — токен <br/> `safeArea.bottom.minHeight`, на устройстве с большим `env(safe-area-inset-bottom)` — значение inset. |
|
|
483
483
|
| `safeAreaTop` | `boolean \| undefined` | — | Верхний safe-area отступ под iOS notch / status-bar. Размер — токен `safeArea.top.minHeight`, <br/> на устройстве с большим `env(safe-area-inset-top)` — значение inset. Применяется, только когда <br/> sheet раскрыт на полный вьюпорт: у неполного sheet'а верх и так не заходит под notch. |
|
|
@@ -489,6 +489,4 @@ export function CustomComposition() {
|
|
|
489
489
|
|
|
490
490
|
- `Position` = `"bottom"` \| `"left"` \| `"right"` \| `"top"`
|
|
491
491
|
|
|
492
|
-
- `ResizableMax` = `number | "full"`
|
|
493
|
-
|
|
494
492
|
- `Width` = `"l"` \| `"m"` \| `"s"`
|
|
@@ -8,10 +8,8 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
8
8
|
const tooltip_1 = require("@cloud-ru/ds-tooltip");
|
|
9
9
|
const utils_1 = require("@cloud-ru/ds-utils");
|
|
10
10
|
const react_1 = require("react");
|
|
11
|
-
const constants_1 = require("../../../constants");
|
|
12
11
|
const styles_module_scss_1 = __importDefault(require('../styles.module.css'));
|
|
13
12
|
const DRAGGER_SELECTOR = `.${styles_module_scss_1.default.prefixCls}-resizable-dragger`;
|
|
14
|
-
const getFullMaxWidth = () => ((0, utils_1.isBrowser)() ? Math.max(0, document.documentElement.clientWidth) : Infinity);
|
|
15
13
|
function useDrawerResize({ position, resizable: resizableProp }) {
|
|
16
14
|
const targetRef = (0, react_1.useRef)(null);
|
|
17
15
|
const targetRefCallbackRef = (0, react_1.useRef)();
|
|
@@ -32,36 +30,25 @@ function useDrawerResize({ position, resizable: resizableProp }) {
|
|
|
32
30
|
return null;
|
|
33
31
|
targetRef.current ? targetRefCallback(targetRef.current) : (targetRefCallbackRef.current = targetRefCallback);
|
|
34
32
|
} })) : null;
|
|
35
|
-
const
|
|
36
|
-
const resizeEnabled = Boolean(resizableProp);
|
|
37
|
-
// Ширина окна могла измениться, пока дровер был закрыт: хранимое значение режем по текущей ширине на каждом
|
|
38
|
-
// рендере. Иначе rc-drawer начинает ресайз от «виртуальной» ширины, которая больше видимой панели.
|
|
39
|
-
const effectiveWidth = width !== undefined && max === constants_1.RESIZABLE_MAX_FULL ? Math.min(width, getFullMaxWidth()) : width;
|
|
40
|
-
const resizable = (0, react_1.useMemo)(() => resizeEnabled
|
|
33
|
+
const resizable = (0, react_1.useMemo)(() => resizableProp
|
|
41
34
|
? {
|
|
42
35
|
onResize: value => {
|
|
43
|
-
if (value < (min || 0))
|
|
36
|
+
if (value < (resizableProp?.min || 0))
|
|
44
37
|
return;
|
|
45
|
-
if (max
|
|
46
|
-
const next = Math.min(value, getFullMaxWidth());
|
|
47
|
-
setWidth(next);
|
|
48
|
-
onResize?.(next);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (value > (max || Infinity))
|
|
38
|
+
if (value > (resizableProp?.max || Infinity))
|
|
52
39
|
return;
|
|
53
40
|
setWidth(value);
|
|
54
|
-
onResize?.(value);
|
|
41
|
+
resizableProp?.onResize?.(value);
|
|
55
42
|
},
|
|
56
43
|
onResizeEnd: () => {
|
|
57
44
|
setOpen(false);
|
|
58
45
|
setMuted(false);
|
|
59
|
-
onResizeEnd?.(
|
|
46
|
+
resizableProp?.onResizeEnd?.(width ?? 0);
|
|
60
47
|
},
|
|
61
48
|
onResizeStart: () => {
|
|
62
49
|
setMuted(true);
|
|
63
50
|
},
|
|
64
51
|
}
|
|
65
|
-
: undefined, [
|
|
66
|
-
return { tooltip, checkElement, resizable, width
|
|
52
|
+
: undefined, [resizableProp, width]);
|
|
53
|
+
return { tooltip, checkElement, resizable, width };
|
|
67
54
|
}
|
|
@@ -126,7 +126,6 @@
|
|
|
126
126
|
.drawerRoot:global(.cloud-ru-ds-drawer-v1) :global .cloud-ru-ds-drawer-v1-content-wrapper[data-position=left], .drawerRoot:global(.cloud-ru-ds-drawer-v1) :global .cloud-ru-ds-drawer-v1-content-wrapper[data-position=right]{
|
|
127
127
|
align-items:stretch;
|
|
128
128
|
box-sizing:content-box;
|
|
129
|
-
max-width:calc(100% - var(--sn-drawer-anatomy-container-vertical-positionLeft-paddingLeft, var(--sn-primitive-dimension-0, 0px)) - var(--sn-drawer-anatomy-container-vertical-positionLeft-paddingRight, var(--sn-density-spacing-interval-l, var(--sn-platform-comfort-spacing-interval-l, var(--sn-primitive-dimension-32, 32px)))));
|
|
130
129
|
height:100%;
|
|
131
130
|
}
|
|
132
131
|
.drawerRoot:global(.cloud-ru-ds-drawer-v1) :global .cloud-ru-ds-drawer-v1-content-wrapper[data-position=left][data-width=s], .drawerRoot:global(.cloud-ru-ds-drawer-v1) :global .cloud-ru-ds-drawer-v1-content-wrapper[data-position=right][data-width=s]{
|
|
@@ -2,7 +2,7 @@ import { BottomSheetCustomProps } from '@cloud-ru/ds-bottom-sheet';
|
|
|
2
2
|
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
|
-
import { Position,
|
|
5
|
+
import { Position, Width } from '../../types';
|
|
6
6
|
export type DrawerCustomProps = WithSupportProps<PropsWithChildren<{
|
|
7
7
|
/** Управление состоянием показан/не показан. */
|
|
8
8
|
open: boolean;
|
|
@@ -57,11 +57,8 @@ export type DrawerCustomProps = WithSupportProps<PropsWithChildren<{
|
|
|
57
57
|
resizable?: {
|
|
58
58
|
/** Минимальная доступная ширина */
|
|
59
59
|
min: number;
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
* (двойной отступ обёртки).
|
|
63
|
-
*/
|
|
64
|
-
max?: ResizableMax;
|
|
60
|
+
/** Максимальная доступная ширина */
|
|
61
|
+
max?: number;
|
|
65
62
|
/** Ширина по умолчанию */
|
|
66
63
|
default?: number;
|
|
67
64
|
/** Колбэк на изменение размера */
|
package/dist/cjs/constants.d.ts
CHANGED
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.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,5 +29,3 @@ exports.POSITION = {
|
|
|
29
29
|
Top: 'top',
|
|
30
30
|
Bottom: 'bottom',
|
|
31
31
|
};
|
|
32
|
-
/** Значение `resizable.max`: растягивать до ширины окна. */
|
|
33
|
-
exports.RESIZABLE_MAX_FULL = 'full';
|
package/dist/cjs/style.css
CHANGED
|
@@ -129,7 +129,6 @@
|
|
|
129
129
|
.drawerRoot:global(.cloud-ru-ds-drawer-v1) :global .cloud-ru-ds-drawer-v1-content-wrapper[data-position=left], .drawerRoot:global(.cloud-ru-ds-drawer-v1) :global .cloud-ru-ds-drawer-v1-content-wrapper[data-position=right]{
|
|
130
130
|
align-items:stretch;
|
|
131
131
|
box-sizing:content-box;
|
|
132
|
-
max-width:calc(100% - var(--sn-drawer-anatomy-container-vertical-positionLeft-paddingLeft, var(--sn-primitive-dimension-0, 0px)) - var(--sn-drawer-anatomy-container-vertical-positionLeft-paddingRight, var(--sn-density-spacing-interval-l, var(--sn-platform-comfort-spacing-interval-l, var(--sn-primitive-dimension-32, 32px)))));
|
|
133
132
|
height:100%;
|
|
134
133
|
}
|
|
135
134
|
.drawerRoot:global(.cloud-ru-ds-drawer-v1) :global .cloud-ru-ds-drawer-v1-content-wrapper[data-position=left][data-width=s], .drawerRoot:global(.cloud-ru-ds-drawer-v1) :global .cloud-ru-ds-drawer-v1-content-wrapper[data-position=right][data-width=s]{
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ValueOf } from '@cloud-ru/ds-utils';
|
|
2
|
-
import { POSITION,
|
|
2
|
+
import { POSITION, WIDTH } from './constants';
|
|
3
3
|
export type Width = ValueOf<typeof WIDTH>;
|
|
4
4
|
export type Position = ValueOf<typeof POSITION>;
|
|
5
|
-
export type ResizableMax = number | typeof RESIZABLE_MAX_FULL;
|
|
@@ -2,10 +2,8 @@ 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 { RESIZABLE_MAX_FULL } from '../../../constants.js';
|
|
6
5
|
import styles from '../styles.module.css';
|
|
7
6
|
const DRAGGER_SELECTOR = `.${styles.prefixCls}-resizable-dragger`;
|
|
8
|
-
const getFullMaxWidth = () => (isBrowser() ? Math.max(0, document.documentElement.clientWidth) : Infinity);
|
|
9
7
|
export function useDrawerResize({ position, resizable: resizableProp }) {
|
|
10
8
|
const targetRef = useRef(null);
|
|
11
9
|
const targetRefCallbackRef = useRef();
|
|
@@ -26,36 +24,25 @@ export function useDrawerResize({ position, resizable: resizableProp }) {
|
|
|
26
24
|
return null;
|
|
27
25
|
targetRef.current ? targetRefCallback(targetRef.current) : (targetRefCallbackRef.current = targetRefCallback);
|
|
28
26
|
} })) : null;
|
|
29
|
-
const
|
|
30
|
-
const resizeEnabled = Boolean(resizableProp);
|
|
31
|
-
// Ширина окна могла измениться, пока дровер был закрыт: хранимое значение режем по текущей ширине на каждом
|
|
32
|
-
// рендере. Иначе rc-drawer начинает ресайз от «виртуальной» ширины, которая больше видимой панели.
|
|
33
|
-
const effectiveWidth = width !== undefined && max === RESIZABLE_MAX_FULL ? Math.min(width, getFullMaxWidth()) : width;
|
|
34
|
-
const resizable = useMemo(() => resizeEnabled
|
|
27
|
+
const resizable = useMemo(() => resizableProp
|
|
35
28
|
? {
|
|
36
29
|
onResize: value => {
|
|
37
|
-
if (value < (min || 0))
|
|
30
|
+
if (value < (resizableProp?.min || 0))
|
|
38
31
|
return;
|
|
39
|
-
if (max
|
|
40
|
-
const next = Math.min(value, getFullMaxWidth());
|
|
41
|
-
setWidth(next);
|
|
42
|
-
onResize?.(next);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (value > (max || Infinity))
|
|
32
|
+
if (value > (resizableProp?.max || Infinity))
|
|
46
33
|
return;
|
|
47
34
|
setWidth(value);
|
|
48
|
-
onResize?.(value);
|
|
35
|
+
resizableProp?.onResize?.(value);
|
|
49
36
|
},
|
|
50
37
|
onResizeEnd: () => {
|
|
51
38
|
setOpen(false);
|
|
52
39
|
setMuted(false);
|
|
53
|
-
onResizeEnd?.(
|
|
40
|
+
resizableProp?.onResizeEnd?.(width ?? 0);
|
|
54
41
|
},
|
|
55
42
|
onResizeStart: () => {
|
|
56
43
|
setMuted(true);
|
|
57
44
|
},
|
|
58
45
|
}
|
|
59
|
-
: undefined, [
|
|
60
|
-
return { tooltip, checkElement, resizable, width
|
|
46
|
+
: undefined, [resizableProp, width]);
|
|
47
|
+
return { tooltip, checkElement, resizable, width };
|
|
61
48
|
}
|
|
@@ -126,7 +126,6 @@
|
|
|
126
126
|
.drawerRoot:global(.cloud-ru-ds-drawer-v1) :global .cloud-ru-ds-drawer-v1-content-wrapper[data-position=left], .drawerRoot:global(.cloud-ru-ds-drawer-v1) :global .cloud-ru-ds-drawer-v1-content-wrapper[data-position=right]{
|
|
127
127
|
align-items:stretch;
|
|
128
128
|
box-sizing:content-box;
|
|
129
|
-
max-width:calc(100% - var(--sn-drawer-anatomy-container-vertical-positionLeft-paddingLeft, var(--sn-primitive-dimension-0, 0px)) - var(--sn-drawer-anatomy-container-vertical-positionLeft-paddingRight, var(--sn-density-spacing-interval-l, var(--sn-platform-comfort-spacing-interval-l, var(--sn-primitive-dimension-32, 32px)))));
|
|
130
129
|
height:100%;
|
|
131
130
|
}
|
|
132
131
|
.drawerRoot:global(.cloud-ru-ds-drawer-v1) :global .cloud-ru-ds-drawer-v1-content-wrapper[data-position=left][data-width=s], .drawerRoot:global(.cloud-ru-ds-drawer-v1) :global .cloud-ru-ds-drawer-v1-content-wrapper[data-position=right][data-width=s]{
|
|
@@ -2,7 +2,7 @@ import { BottomSheetCustomProps } from '@cloud-ru/ds-bottom-sheet';
|
|
|
2
2
|
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
|
-
import { Position,
|
|
5
|
+
import { Position, Width } from '../../types.js';
|
|
6
6
|
export type DrawerCustomProps = WithSupportProps<PropsWithChildren<{
|
|
7
7
|
/** Управление состоянием показан/не показан. */
|
|
8
8
|
open: boolean;
|
|
@@ -57,11 +57,8 @@ export type DrawerCustomProps = WithSupportProps<PropsWithChildren<{
|
|
|
57
57
|
resizable?: {
|
|
58
58
|
/** Минимальная доступная ширина */
|
|
59
59
|
min: number;
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
* (двойной отступ обёртки).
|
|
63
|
-
*/
|
|
64
|
-
max?: ResizableMax;
|
|
60
|
+
/** Максимальная доступная ширина */
|
|
61
|
+
max?: number;
|
|
65
62
|
/** Ширина по умолчанию */
|
|
66
63
|
default?: number;
|
|
67
64
|
/** Колбэк на изменение размера */
|
package/dist/esm/constants.d.ts
CHANGED
package/dist/esm/constants.js
CHANGED
package/dist/esm/style.css
CHANGED
|
@@ -129,7 +129,6 @@
|
|
|
129
129
|
.drawerRoot:global(.cloud-ru-ds-drawer-v1) :global .cloud-ru-ds-drawer-v1-content-wrapper[data-position=left], .drawerRoot:global(.cloud-ru-ds-drawer-v1) :global .cloud-ru-ds-drawer-v1-content-wrapper[data-position=right]{
|
|
130
130
|
align-items:stretch;
|
|
131
131
|
box-sizing:content-box;
|
|
132
|
-
max-width:calc(100% - var(--sn-drawer-anatomy-container-vertical-positionLeft-paddingLeft, var(--sn-primitive-dimension-0, 0px)) - var(--sn-drawer-anatomy-container-vertical-positionLeft-paddingRight, var(--sn-density-spacing-interval-l, var(--sn-platform-comfort-spacing-interval-l, var(--sn-primitive-dimension-32, 32px)))));
|
|
133
132
|
height:100%;
|
|
134
133
|
}
|
|
135
134
|
.drawerRoot:global(.cloud-ru-ds-drawer-v1) :global .cloud-ru-ds-drawer-v1-content-wrapper[data-position=left][data-width=s], .drawerRoot:global(.cloud-ru-ds-drawer-v1) :global .cloud-ru-ds-drawer-v1-content-wrapper[data-position=right][data-width=s]{
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ValueOf } from '@cloud-ru/ds-utils';
|
|
2
|
-
import { POSITION,
|
|
2
|
+
import { POSITION, WIDTH } from './constants.js';
|
|
3
3
|
export type Width = ValueOf<typeof WIDTH>;
|
|
4
4
|
export type Position = ValueOf<typeof POSITION>;
|
|
5
|
-
export type ResizableMax = number | typeof RESIZABLE_MAX_FULL;
|