Skip to content

Commit

Permalink
feat: create lib/sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
inomdzhon committed Oct 29, 2024
1 parent 06cddc4 commit 3c12380
Show file tree
Hide file tree
Showing 10 changed files with 601 additions and 11 deletions.
4 changes: 4 additions & 0 deletions packages/vkui/src/helpers/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ export function rangeIncrement(from: number, to: number, step = 1): number[] {

return range(from, to, step);
}

export function inRange(number: number, from: number, to: number) {
return number >= from && number <= to;
}
9 changes: 8 additions & 1 deletion packages/vkui/src/lib/adaptivity/functions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Exact } from '../../types';
import { getWindow } from '../dom';
import { type PlatformType } from '../platform';
import { BREAKPOINTS } from './breakpoints';
import { BREAKPOINTS, MEDIA_QUERIES } from './breakpoints';
import {
type SizeTypeValues,
VIEW_WIDTH_TO_CSS_BREAKPOINT_MAP,
Expand Down Expand Up @@ -138,6 +139,12 @@ export function tryToCheckIsDesktop(
return (widthIsLikeDesktop && otherParametersIsLikeDesktop) || IS_VKCOM_CRUTCH;
}

export function isSmallTablePlus(el: HTMLElement) {
const win = getWindow(el);
// eslint-disable-next-line no-restricted-properties
return win ? win.matchMedia(MEDIA_QUERIES.SMALL_TABLET_PLUS).matches : false;
}

/**
* Конвертирует `viewWidth` в CSS брейкпоинты (см. тесты для наглядности).
*
Expand Down
6 changes: 6 additions & 0 deletions packages/vkui/src/lib/dom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export {
getNodeScroll,
isHTMLElement,
isElement,
getParentNode,
} from '@vkontakte/vkui-floating-ui/utils/dom';

export { canUseDOM, canUseEventListeners, onDOMLoaded } from '@vkontakte/vkjs';
Expand Down Expand Up @@ -260,3 +261,8 @@ export const initializeBrowserGesturePreventionEffect = (window: Window): VoidFu
window.removeEventListener('touchmove', handleWindowTouchMove, options);
};
};

export const hasSelectionWithRangeType = (node: unknown) => {
const selection = getWindow(node).getSelection();
return selection ? selection.type === 'Range' : false;
};
32 changes: 32 additions & 0 deletions packages/vkui/src/lib/sheet/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/** @public */
export const BLOCK_SHEET_BEHAVIOR_DATA_ATTRIBUTE_KEY = 'data-vkui-block-sheet-behavior';

/** @public */
export const BLOCK_SHEET_BEHAVIOR_DATA_ATTRIBUTE = {
[BLOCK_SHEET_BEHAVIOR_DATA_ATTRIBUTE_KEY]: true,
};

/** @private */
export const DRAG_THRESHOLDS = {
DISTANCE_FOR_MOVING_START: 12 as const,
VELOCITY: 500 as const,
};

/** @private */
export const SNAP_POINT_SAFE_RANGE = {
LOWER: 25 as const,
HIGHEST: 90 as const,
};

/** @private */
export const SNAP_POINT_DETENTS = {
MIN: 0 as const,
MEDIUM: 50 as const,
LARGE: 100 as const,
};

/** @private */
export const DYNAMIC_SNAP_POINT_DATA = {
IDLE_POINT_VALUE: 0 as const,
COMPUTED_INDEX: 1 as const,
};
Loading

0 comments on commit 3c12380

Please sign in to comment.