@cloud-ru/ds-drawer 2.0.0 → 2.0.1-preview-22cd4af5.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 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` | `{ min: number; max?: number; default?: number; onResize?: ((width: number) => void) \| undefined; onResizeEnd?: ((width: number) => void) \| undefined; draggerTooltip?: string \| undefined; } \| undefined` | `'s'` | Ширина (только при position: "left" \| "right") |
451
+ | `resizable` | `ResizableMax` | `'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` | `{ min: number; max?: number; default?: number; onResize?: (width: number) => void; onResizeEnd?: (width: number) => void; draggerTooltip?: string; } \| undefined` | — | Ширина (только при position: "left" \| "right") |
480
+ | `resizable` | `ResizableMax` | — | Ширина (только при 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,4 +489,6 @@ export function CustomComposition() {
489
489
 
490
490
  - `Position` = `"bottom"` \| `"left"` \| `"right"` \| `"top"`
491
491
 
492
+ - `ResizableMax` = `number | "full"`
493
+
492
494
  - `Width` = `"l"` \| `"m"` \| `"s"`
@@ -8,8 +8,10 @@ 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");
11
12
  const styles_module_scss_1 = __importDefault(require('../styles.module.css'));
12
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 - constants_1.FULL_WIDTH_OFFSET) : Infinity;
13
15
  function useDrawerResize({ position, resizable: resizableProp }) {
14
16
  const targetRef = (0, react_1.useRef)(null);
15
17
  const targetRefCallbackRef = (0, react_1.useRef)();
@@ -35,6 +37,12 @@ function useDrawerResize({ position, resizable: resizableProp }) {
35
37
  onResize: value => {
36
38
  if (value < (resizableProp?.min || 0))
37
39
  return;
40
+ if (resizableProp?.max === constants_1.RESIZABLE_MAX_FULL) {
41
+ const next = Math.min(value, getFullMaxWidth());
42
+ setWidth(next);
43
+ resizableProp?.onResize?.(next);
44
+ return;
45
+ }
38
46
  if (value > (resizableProp?.max || Infinity))
39
47
  return;
40
48
  setWidth(value);
@@ -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, Width } from '../../types';
5
+ import { Position, ResizableMax, Width } from '../../types';
6
6
  export type DrawerCustomProps = WithSupportProps<PropsWithChildren<{
7
7
  /** Управление состоянием показан/не показан. */
8
8
  open: boolean;
@@ -57,8 +57,11 @@ export type DrawerCustomProps = WithSupportProps<PropsWithChildren<{
57
57
  resizable?: {
58
58
  /** Минимальная доступная ширина */
59
59
  min: number;
60
- /** Максимальная доступная ширина */
61
- max?: number;
60
+ /**
61
+ * Максимальная доступная ширина: число в px либо `'full'` — вся ширина окна за вычетом 48px
62
+ * (двойной отступ обёртки).
63
+ */
64
+ max?: ResizableMax;
62
65
  /** Ширина по умолчанию */
63
66
  default?: number;
64
67
  /** Колбэк на изменение размера */
@@ -26,3 +26,7 @@ export declare const POSITION: {
26
26
  readonly Top: "top";
27
27
  readonly Bottom: "bottom";
28
28
  };
29
+ /** Значение `resizable.max`: растягивать до ширины окна за вычетом двойного отступа обёртки. */
30
+ export declare const RESIZABLE_MAX_FULL = "full";
31
+ /** Суммарный горизонтальный отступ `content-wrapper` (по 24px с каждой стороны). */
32
+ export declare const FULL_WIDTH_OFFSET = 48;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.POSITION = exports.WIDTH_AS_VALUES = exports.WIDTH = exports.TEST_IDS = void 0;
3
+ exports.FULL_WIDTH_OFFSET = 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,3 +29,7 @@ exports.POSITION = {
29
29
  Top: 'top',
30
30
  Bottom: 'bottom',
31
31
  };
32
+ /** Значение `resizable.max`: растягивать до ширины окна за вычетом двойного отступа обёртки. */
33
+ exports.RESIZABLE_MAX_FULL = 'full';
34
+ /** Суммарный горизонтальный отступ `content-wrapper` (по 24px с каждой стороны). */
35
+ exports.FULL_WIDTH_OFFSET = 48;
@@ -1,4 +1,5 @@
1
1
  import { ValueOf } from '@cloud-ru/ds-utils';
2
- import { POSITION, WIDTH } from './constants';
2
+ import { POSITION, RESIZABLE_MAX_FULL, 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,8 +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 { FULL_WIDTH_OFFSET, RESIZABLE_MAX_FULL } from '../../../constants.js';
5
6
  import styles from '../styles.module.css';
6
7
  const DRAGGER_SELECTOR = `.${styles.prefixCls}-resizable-dragger`;
8
+ const getFullMaxWidth = () => isBrowser() ? Math.max(0, document.documentElement.clientWidth - FULL_WIDTH_OFFSET) : Infinity;
7
9
  export function useDrawerResize({ position, resizable: resizableProp }) {
8
10
  const targetRef = useRef(null);
9
11
  const targetRefCallbackRef = useRef();
@@ -29,6 +31,12 @@ export function useDrawerResize({ position, resizable: resizableProp }) {
29
31
  onResize: value => {
30
32
  if (value < (resizableProp?.min || 0))
31
33
  return;
34
+ if (resizableProp?.max === RESIZABLE_MAX_FULL) {
35
+ const next = Math.min(value, getFullMaxWidth());
36
+ setWidth(next);
37
+ resizableProp?.onResize?.(next);
38
+ return;
39
+ }
32
40
  if (value > (resizableProp?.max || Infinity))
33
41
  return;
34
42
  setWidth(value);
@@ -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, Width } from '../../types.js';
5
+ import { Position, ResizableMax, Width } from '../../types.js';
6
6
  export type DrawerCustomProps = WithSupportProps<PropsWithChildren<{
7
7
  /** Управление состоянием показан/не показан. */
8
8
  open: boolean;
@@ -57,8 +57,11 @@ export type DrawerCustomProps = WithSupportProps<PropsWithChildren<{
57
57
  resizable?: {
58
58
  /** Минимальная доступная ширина */
59
59
  min: number;
60
- /** Максимальная доступная ширина */
61
- max?: number;
60
+ /**
61
+ * Максимальная доступная ширина: число в px либо `'full'` — вся ширина окна за вычетом 48px
62
+ * (двойной отступ обёртки).
63
+ */
64
+ max?: ResizableMax;
62
65
  /** Ширина по умолчанию */
63
66
  default?: number;
64
67
  /** Колбэк на изменение размера */
@@ -26,3 +26,7 @@ export declare const POSITION: {
26
26
  readonly Top: "top";
27
27
  readonly Bottom: "bottom";
28
28
  };
29
+ /** Значение `resizable.max`: растягивать до ширины окна за вычетом двойного отступа обёртки. */
30
+ export declare const RESIZABLE_MAX_FULL = "full";
31
+ /** Суммарный горизонтальный отступ `content-wrapper` (по 24px с каждой стороны). */
32
+ export declare const FULL_WIDTH_OFFSET = 48;
@@ -26,3 +26,7 @@ export const POSITION = {
26
26
  Top: 'top',
27
27
  Bottom: 'bottom',
28
28
  };
29
+ /** Значение `resizable.max`: растягивать до ширины окна за вычетом двойного отступа обёртки. */
30
+ export const RESIZABLE_MAX_FULL = 'full';
31
+ /** Суммарный горизонтальный отступ `content-wrapper` (по 24px с каждой стороны). */
32
+ export const FULL_WIDTH_OFFSET = 48;
@@ -1,4 +1,5 @@
1
1
  import { ValueOf } from '@cloud-ru/ds-utils';
2
- import { POSITION, WIDTH } from './constants.js';
2
+ import { POSITION, RESIZABLE_MAX_FULL, 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;