@via-profit/ui-kit 0.2.1-alpha.1 → 0.2.2
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/Autocomplete/AutocompleteContainer.d.ts +33 -6
- package/Autocomplete/AutocompleteContainer.js +48 -36
- package/Autocomplete/AutocompleteItem.d.ts +1 -1
- package/Autocomplete/AutocompleteTextField.d.ts +3 -0
- package/Autocomplete/AutocompleteTextField.js +63 -1
- package/Autocomplete/OverrideMenuList.d.ts +4 -0
- package/Autocomplete/OverrideMenuList.js +39 -0
- package/Autocomplete/context.d.ts +9 -1
- package/Autocomplete/context.js +15 -1
- package/Autocomplete/index.js +9 -10
- package/Autocomplete2/Autocomplete2.d.ts +12 -0
- package/Autocomplete2/Autocomplete2.js +83 -0
- package/Autocomplete2/Autocomplete2TextField.d.ts +7 -0
- package/Autocomplete2/Autocomplete2TextField.js +39 -0
- package/Autocomplete2/index.d.ts +2 -0
- package/Autocomplete2/index.js +7 -0
- package/Avatar/index.js +1 -1
- package/Badge/BadgeDeleteButton.js +6 -6
- package/Badge/BadgeOutlined.js +2 -2
- package/Badge/BadgeStandard.js +1 -1
- package/Button/ButtonOutlined.js +1 -1
- package/Button/ButtonPlain.js +1 -1
- package/Button/ButtonStandard.js +4 -11
- package/Calendar/CalendarCell.js +6 -2
- package/Calendar/CalendarComponent.d.ts +226 -0
- package/Calendar/CalendarComponent.js +572 -0
- package/Calendar/CalendarControlButton.js +16 -9
- package/Calendar/CalendarDayBadge.js +1 -1
- package/Calendar/CalendarEmptyCell.d.ts +2 -2
- package/Calendar/CalendarEmptyCell.js +8 -3
- package/Calendar/CalendarHeading.js +2 -1
- package/Calendar/CalendarSubheading.js +3 -2
- package/Calendar/CalendarWeekDayCell.d.ts +10 -0
- package/Calendar/CalendarWeekDayCell.js +32 -0
- package/Calendar/CalendarWeekDayWeekNumber.d.ts +7 -0
- package/Calendar/CalendarWeekDayWeekNumber.js +38 -0
- package/Calendar/CalendarWeekRow.d.ts +2 -2
- package/Calendar/CalendarWeekRow.js +2 -1
- package/Calendar/CalendarWeekRowButton.d.ts +13 -0
- package/Calendar/CalendarWeekRowButton.js +31 -0
- package/Calendar/CalendarYearsSelector.d.ts +39 -1
- package/Calendar/CalendarYearsSelector.js +52 -16
- package/Calendar/IconChevronDown.d.ts +3 -0
- package/Calendar/IconChevronDown.js +31 -0
- package/Calendar/index.d.ts +7 -224
- package/Calendar/index.js +19 -281
- package/Calendar/use-calendar.d.ts +1 -1
- package/Color/Color.d.ts +138 -0
- package/Color/Color.js +324 -0
- package/Color/ColorGenerator.d.ts +29 -0
- package/Color/ColorGenerator.js +141 -0
- package/Color/ColorParser.d.ts +20 -0
- package/Color/ColorParser.js +284 -0
- package/Color/index.d.ts +4 -122
- package/Color/index.js +18 -473
- package/CountryFlags/SwiperOverview.d.ts +257 -0
- package/CountryFlags/SwiperOverview.js +524 -0
- package/DatePicker/index.d.ts +2 -17
- package/DatePicker/index.js +47 -61
- package/DatePicker/useDatePickerFormat.js +5 -5
- package/ErrorBoundary/Fallback.d.ts +3 -0
- package/ErrorBoundary/Fallback.js +51 -0
- package/ErrorBoundary/RenderError.d.ts +6 -0
- package/ErrorBoundary/RenderError.js +80 -0
- package/ErrorBoundary/index.d.ts +7 -11
- package/ErrorBoundary/index.js +4 -51
- package/LoadingIndicator/Spinner.d.ts +5 -3
- package/LoadingIndicator/Spinner.js +61 -32
- package/LoadingIndicator/index.d.ts +3 -3
- package/LoadingIndicator/index.js +15 -2
- package/MaskedField/index.d.ts +2 -1
- package/MaskedField/index.js +52 -43
- package/MaskedField/useMasked.js +7 -5
- package/Menu/AutoHeightWrapper.d.ts +6 -0
- package/Menu/AutoHeightWrapper.js +43 -0
- package/Menu/MeasuredItem.d.ts +10 -0
- package/Menu/MeasuredItem.js +51 -0
- package/Menu/MenuContainer.d.ts +51 -18
- package/Menu/MenuContainer.js +19 -12
- package/Menu/MenuItem.d.ts +24 -7
- package/Menu/MenuItem.js +13 -6
- package/Menu/MenuList.d.ts +4 -2
- package/Menu/MenuList.js +26 -6
- package/Menu/VirtualizedItem.d.ts +22 -0
- package/Menu/VirtualizedItem.js +69 -0
- package/Menu/VirtualizedList.d.ts +18 -0
- package/Menu/VirtualizedList.js +28 -0
- package/Menu/VirtualizedListComponent.d.ts +20 -0
- package/Menu/VirtualizedListComponent.js +305 -0
- package/Menu/index.d.ts +3 -1
- package/Menu/index.js +2 -0
- package/Popper/Popper.d.ts +7 -80
- package/Popper/Popper.js +26 -12
- package/Popper/PopperContainer.js +1 -1
- package/Popper/usePopprer.d.ts +88 -3
- package/Popper/usePopprer.js +240 -65
- package/Selectbox/SelectboxButton.d.ts +5 -0
- package/Selectbox/SelectboxButton.js +48 -8
- package/Selectbox/SelectboxButtonWrapper.d.ts +2 -0
- package/Selectbox/SelectboxButtonWrapper.js +1 -17
- package/Selectbox/SelectboxMenu.d.ts +12 -0
- package/Selectbox/SelectboxMenu.js +50 -0
- package/Selectbox/index.d.ts +5 -5
- package/Selectbox/index.js +115 -97
- package/Surface/index.js +1 -1
- package/Swiper/Swiper.d.ts +57 -0
- package/Swiper/Swiper.js +412 -0
- package/Swiper/SwiperContainer.d.ts +7 -0
- package/Swiper/SwiperContainer.js +15 -0
- package/Swiper/SwiperSlide.d.ts +12 -0
- package/Swiper/SwiperSlide.js +58 -0
- package/Swiper/SwiperSlidesRenderer.d.ts +11 -0
- package/Swiper/SwiperSlidesRenderer.js +74 -0
- package/Swiper/SwiperTrack.d.ts +18 -0
- package/Swiper/SwiperTrack.js +55 -0
- package/Swiper/SwiperWrapper.d.ts +16 -0
- package/Swiper/SwiperWrapper.js +60 -0
- package/Swiper/index.d.ts +7 -0
- package/Swiper/index.js +26 -0
- package/Switch/SwitchDot.js +1 -1
- package/Switch/SwitchTrack.js +1 -1
- package/TextField/TextFieldContainer.d.ts +2 -2
- package/TextField/TextFieldContainer.js +5 -3
- package/TextField/TextFieldErrorText.d.ts +2 -2
- package/TextField/TextFieldErrorText.js +5 -4
- package/TextField/TextFieldIconWrapper.d.ts +3 -3
- package/TextField/TextFieldIconWrapper.js +5 -3
- package/TextField/TextFieldInput.d.ts +2 -2
- package/TextField/TextFieldInput.js +6 -4
- package/TextField/TextFieldInputWrapper.d.ts +2 -2
- package/TextField/TextFieldInputWrapper.js +5 -3
- package/TextField/TextFieldLabel.d.ts +2 -2
- package/TextField/TextFieldLabel.js +5 -3
- package/TextField/TextFieldLabelAsterisk.d.ts +2 -2
- package/TextField/TextFieldLabelAsterisk.js +5 -3
- package/TextField/index.d.ts +8 -1
- package/TextField/index.js +49 -22
- package/ThemeProvider/createTheme.js +2 -2
- package/package.json +1 -1
- package/Calendar/reducer.d.ts +0 -17
- package/Calendar/reducer.js +0 -50
- /package/Calendar/{IconChevronRight.d.ts → CalendarIconNext.d.ts} +0 -0
- /package/Calendar/{IconChevronRight.js → CalendarIconNext.js} +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.VirtualizedItem = void 0;
|
|
41
|
+
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
42
|
+
const React = __importStar(require("react"));
|
|
43
|
+
const StyledVirtualizedItem = styled_1.default.div `
|
|
44
|
+
position: absolute;
|
|
45
|
+
width: 100%;
|
|
46
|
+
`;
|
|
47
|
+
exports.VirtualizedItem = React.forwardRef((props, ref) => {
|
|
48
|
+
const { children, style, index, setItemHeight, isActiveOnScroll } = props, restProps = __rest(props, ["children", "style", "index", "setItemHeight", "isActiveOnScroll"]);
|
|
49
|
+
const containerRef = React.useRef(null);
|
|
50
|
+
React.useEffect(() => {
|
|
51
|
+
const el = containerRef.current;
|
|
52
|
+
if (!el)
|
|
53
|
+
return;
|
|
54
|
+
const observer = new ResizeObserver(entries => {
|
|
55
|
+
for (const entry of entries) {
|
|
56
|
+
const { height } = entry.contentRect;
|
|
57
|
+
if (height) {
|
|
58
|
+
setItemHeight(index, height);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
observer.observe(el);
|
|
63
|
+
return () => observer.disconnect();
|
|
64
|
+
}, [index, setItemHeight]);
|
|
65
|
+
return (React.createElement(StyledVirtualizedItem, Object.assign({ style: style }, restProps, { ref: ref }),
|
|
66
|
+
React.createElement("div", { ref: containerRef }, children({ index, isActiveOnScroll }))));
|
|
67
|
+
});
|
|
68
|
+
exports.VirtualizedItem.displayName = 'VirtualizedItem';
|
|
69
|
+
exports.default = exports.VirtualizedItem;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { VirtualizedListRef, VirtualizedRenderItem } from './VirtualizedListComponent';
|
|
3
|
+
export type ScrollAlign = 'start' | 'center' | 'end' | 'auto';
|
|
4
|
+
export * from './VirtualizedListComponent';
|
|
5
|
+
export type VirtualizedListProps<T> = {
|
|
6
|
+
readonly items: readonly T[];
|
|
7
|
+
readonly renderItem: VirtualizedRenderItem<T>;
|
|
8
|
+
readonly estimatedItemHeight?: number;
|
|
9
|
+
readonly itemHeight?: number;
|
|
10
|
+
readonly overscan?: number;
|
|
11
|
+
readonly scrollToIndex?: number | null;
|
|
12
|
+
readonly scrollToAlign?: ScrollAlign;
|
|
13
|
+
readonly onEndReached?: () => void;
|
|
14
|
+
};
|
|
15
|
+
declare const _default: <T>(props: VirtualizedListProps<T> & {
|
|
16
|
+
ref?: React.Ref<VirtualizedListRef> | undefined;
|
|
17
|
+
}) => React.ReactElement;
|
|
18
|
+
export default _default;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
const react_1 = __importDefault(require("react"));
|
|
21
|
+
const AutoHeightWrapper_1 = __importDefault(require("./AutoHeightWrapper"));
|
|
22
|
+
const VirtualizedListComponent_1 = __importDefault(require("./VirtualizedListComponent"));
|
|
23
|
+
__exportStar(require("./VirtualizedListComponent"), exports);
|
|
24
|
+
const VirtualizedList = react_1.default.forwardRef((props, ref) => {
|
|
25
|
+
return (react_1.default.createElement(AutoHeightWrapper_1.default, null, height => height > 0 && react_1.default.createElement(VirtualizedListComponent_1.default, Object.assign({}, props, { height: height, ref: ref }))));
|
|
26
|
+
});
|
|
27
|
+
VirtualizedList.displayName = 'VirtualizedList';
|
|
28
|
+
exports.default = VirtualizedList;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type VirtualizedRenderItem<T> = (item: T, index: number) => React.ReactNode;
|
|
3
|
+
export type VirtualizedListComponentProp<T> = {
|
|
4
|
+
readonly items: readonly T[];
|
|
5
|
+
readonly height: number;
|
|
6
|
+
readonly renderItem: VirtualizedRenderItem<T>;
|
|
7
|
+
readonly estimatedItemHeight?: number;
|
|
8
|
+
readonly itemHeight?: number;
|
|
9
|
+
readonly overscan?: number;
|
|
10
|
+
readonly scrollToIndex?: number | null;
|
|
11
|
+
readonly scrollToAlign?: ScrollAlign;
|
|
12
|
+
readonly onEndReached?: () => void;
|
|
13
|
+
};
|
|
14
|
+
export type ScrollAlign = 'start' | 'center' | 'end' | 'auto';
|
|
15
|
+
export type VirtualizedListRef = {
|
|
16
|
+
scrollToIndex: (index: number, align?: ScrollAlign) => void;
|
|
17
|
+
getTopVisibleIndex: () => number;
|
|
18
|
+
};
|
|
19
|
+
declare const VirtualizedListComponent: React.ForwardRefExoticComponent<VirtualizedListComponentProp<unknown> & React.RefAttributes<VirtualizedListRef>>;
|
|
20
|
+
export default VirtualizedListComponent;
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const react_1 = __importStar(require("react"));
|
|
30
|
+
const MeasuredItem_1 = __importDefault(require("./MeasuredItem"));
|
|
31
|
+
const BLOCK_SIZE = 50;
|
|
32
|
+
function updateHeightWithBlocks(index, newHeight, heightsRef, offsetsRef, blockOffsetsRef, bumpVersion) {
|
|
33
|
+
const heights = heightsRef.current;
|
|
34
|
+
const offsets = offsetsRef.current;
|
|
35
|
+
const blocks = blockOffsetsRef.current;
|
|
36
|
+
const oldHeight = heights[index];
|
|
37
|
+
if (oldHeight == null || oldHeight === newHeight)
|
|
38
|
+
return;
|
|
39
|
+
const diff = newHeight - oldHeight;
|
|
40
|
+
heights[index] = newHeight;
|
|
41
|
+
// обновляем offsets начиная с index+1
|
|
42
|
+
for (let i = index + 1; i < offsets.length; i++) {
|
|
43
|
+
offsets[i] += diff;
|
|
44
|
+
}
|
|
45
|
+
// обновляем блоки, начиная с блока index
|
|
46
|
+
const blockIndex = Math.floor(index / BLOCK_SIZE);
|
|
47
|
+
for (let b = blockIndex + 1; b < blocks.length; b++) {
|
|
48
|
+
blocks[b] += diff;
|
|
49
|
+
}
|
|
50
|
+
// форсим пересчёт totalHeight
|
|
51
|
+
bumpVersion(v => v + 1);
|
|
52
|
+
}
|
|
53
|
+
const VirtualizedListComponent = react_1.default.forwardRef((props, ref) => {
|
|
54
|
+
const { items, height, renderItem, estimatedItemHeight = 40, itemHeight, overscan = 4, scrollToIndex = null, scrollToAlign = 'auto', onEndReached, } = props;
|
|
55
|
+
const containerRef = (0, react_1.useRef)(null);
|
|
56
|
+
const [scrollTop, setScrollTop] = (0, react_1.useState)(0);
|
|
57
|
+
const [renderVersion, setRenderVersion] = (0, react_1.useState)(0);
|
|
58
|
+
const heightsRef = (0, react_1.useRef)([]);
|
|
59
|
+
const offsetsRef = (0, react_1.useRef)([]);
|
|
60
|
+
const blockOffsetsRef = (0, react_1.useRef)([]);
|
|
61
|
+
const isFixed = typeof itemHeight === 'number';
|
|
62
|
+
const onEndReachedRef = react_1.default.useRef(false);
|
|
63
|
+
const threshold = Math.max(300, height * 1.5);
|
|
64
|
+
const animateScrollTop = (0, react_1.useCallback)((to, duration = 300) => {
|
|
65
|
+
const container = containerRef.current;
|
|
66
|
+
if (!container)
|
|
67
|
+
return;
|
|
68
|
+
const start = container.scrollTop;
|
|
69
|
+
const change = to - start;
|
|
70
|
+
const startTime = performance.now();
|
|
71
|
+
const easeOutCubic = (t) => 1 - Math.pow(1 - t, 3);
|
|
72
|
+
const step = (now) => {
|
|
73
|
+
const elapsed = now - startTime;
|
|
74
|
+
const progress = Math.min(1, elapsed / duration);
|
|
75
|
+
const eased = easeOutCubic(progress);
|
|
76
|
+
container.scrollTop = start + change * eased;
|
|
77
|
+
if (progress < 1) {
|
|
78
|
+
requestAnimationFrame(step);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
requestAnimationFrame(step);
|
|
82
|
+
}, []);
|
|
83
|
+
const scrollTo = (0, react_1.useCallback)((index, align = 'auto') => {
|
|
84
|
+
var _a;
|
|
85
|
+
const container = containerRef.current;
|
|
86
|
+
if (!container)
|
|
87
|
+
return;
|
|
88
|
+
const len = items.length;
|
|
89
|
+
if (index < 0 || index >= len)
|
|
90
|
+
return;
|
|
91
|
+
const offsets = offsetsRef.current;
|
|
92
|
+
const heights = heightsRef.current;
|
|
93
|
+
const itemTop = offsets[index];
|
|
94
|
+
const itemHeightValue = (_a = heights[index]) !== null && _a !== void 0 ? _a : estimatedItemHeight;
|
|
95
|
+
const viewportHeight = height;
|
|
96
|
+
const viewportTop = container.scrollTop;
|
|
97
|
+
const viewportBottom = viewportTop + viewportHeight;
|
|
98
|
+
let target = itemTop;
|
|
99
|
+
switch (align) {
|
|
100
|
+
case 'start':
|
|
101
|
+
target = itemTop;
|
|
102
|
+
break;
|
|
103
|
+
case 'center':
|
|
104
|
+
target = itemTop - viewportHeight / 2 + itemHeightValue / 2;
|
|
105
|
+
break;
|
|
106
|
+
case 'end':
|
|
107
|
+
target = itemTop - viewportHeight + itemHeightValue;
|
|
108
|
+
break;
|
|
109
|
+
case 'auto':
|
|
110
|
+
default:
|
|
111
|
+
if (itemTop < viewportTop) {
|
|
112
|
+
target = itemTop; // прокрутить вверх
|
|
113
|
+
}
|
|
114
|
+
else if (itemTop + itemHeightValue > viewportBottom) {
|
|
115
|
+
target = itemTop - viewportHeight + itemHeightValue; // прокрутить вниз
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
return; // уже видно
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
animateScrollTop(Math.max(0, target));
|
|
123
|
+
}, [items.length, estimatedItemHeight, height, animateScrollTop]);
|
|
124
|
+
// scrollToIndex без rAF
|
|
125
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
126
|
+
var _a, _b;
|
|
127
|
+
if (scrollToIndex == null)
|
|
128
|
+
return;
|
|
129
|
+
if (!containerRef.current)
|
|
130
|
+
return;
|
|
131
|
+
const idx = Math.max(0, Math.min(items.length - 1, scrollToIndex));
|
|
132
|
+
const offsets = offsetsRef.current;
|
|
133
|
+
const itemTop = offsets[idx];
|
|
134
|
+
const itemBottom = itemTop + ((_b = (_a = heightsRef.current[idx]) !== null && _a !== void 0 ? _a : itemHeight) !== null && _b !== void 0 ? _b : estimatedItemHeight);
|
|
135
|
+
const viewportTop = containerRef.current.scrollTop;
|
|
136
|
+
const viewportBottom = viewportTop + height;
|
|
137
|
+
let nextScrollTop = viewportTop;
|
|
138
|
+
if (scrollToAlign === 'start') {
|
|
139
|
+
nextScrollTop = itemTop;
|
|
140
|
+
}
|
|
141
|
+
else if (scrollToAlign === 'end') {
|
|
142
|
+
nextScrollTop = itemBottom - height;
|
|
143
|
+
}
|
|
144
|
+
else if (scrollToAlign === 'center') {
|
|
145
|
+
nextScrollTop = itemTop - height / 2 + (itemBottom - itemTop) / 2;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
// auto
|
|
149
|
+
if (itemTop < viewportTop) {
|
|
150
|
+
nextScrollTop = itemTop;
|
|
151
|
+
}
|
|
152
|
+
else if (itemBottom > viewportBottom) {
|
|
153
|
+
nextScrollTop = itemBottom - height;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
containerRef.current.scrollTop = nextScrollTop;
|
|
160
|
+
}, [scrollToIndex, scrollToAlign, items.length, height, itemHeight, estimatedItemHeight]);
|
|
161
|
+
react_1.default.useLayoutEffect(() => {
|
|
162
|
+
const totalHeight = offsetsRef.current[offsetsRef.current.length - 1] +
|
|
163
|
+
heightsRef.current[heightsRef.current.length - 1];
|
|
164
|
+
const viewportBottom = scrollTop + height;
|
|
165
|
+
const isNearEnd = viewportBottom >= totalHeight - threshold;
|
|
166
|
+
if (isNearEnd && !onEndReachedRef.current) {
|
|
167
|
+
onEndReachedRef.current = true;
|
|
168
|
+
onEndReached === null || onEndReached === void 0 ? void 0 : onEndReached();
|
|
169
|
+
}
|
|
170
|
+
if (!isNearEnd) {
|
|
171
|
+
onEndReachedRef.current = false;
|
|
172
|
+
}
|
|
173
|
+
}, [scrollTop, height, items.length, threshold, onEndReached]);
|
|
174
|
+
// ⭐ ИДЕАЛЬНАЯ ИНИЦИАЛИЗАЦИЯ offsets/heights
|
|
175
|
+
// инициализация кэша высот/offsets
|
|
176
|
+
// инициализация кэша высот/offsets
|
|
177
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
178
|
+
var _a;
|
|
179
|
+
const len = items.length;
|
|
180
|
+
const oldLen = heightsRef.current.length;
|
|
181
|
+
if (isFixed) {
|
|
182
|
+
// фиксированная высота — всё просто
|
|
183
|
+
heightsRef.current = new Array(len).fill(itemHeight);
|
|
184
|
+
offsetsRef.current = new Array(len);
|
|
185
|
+
for (let i = 0; i < len; i++) {
|
|
186
|
+
offsetsRef.current[i] = i * itemHeight;
|
|
187
|
+
}
|
|
188
|
+
const blockCount = Math.ceil(len / BLOCK_SIZE);
|
|
189
|
+
blockOffsetsRef.current = new Array(blockCount);
|
|
190
|
+
for (let b = 0; b < blockCount; b++) {
|
|
191
|
+
blockOffsetsRef.current[b] = b * BLOCK_SIZE * itemHeight;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
// динамическая высота — добавляем только новые элементы
|
|
196
|
+
const heights = heightsRef.current;
|
|
197
|
+
const offsets = offsetsRef.current;
|
|
198
|
+
// список вырос
|
|
199
|
+
if (len > oldLen) {
|
|
200
|
+
// добавляем новые элементы
|
|
201
|
+
for (let i = oldLen; i < len; i++) {
|
|
202
|
+
heights[i] = estimatedItemHeight;
|
|
203
|
+
offsets[i] = i === 0 ? 0 : offsets[i - 1] + heights[i - 1];
|
|
204
|
+
}
|
|
205
|
+
// пересчитываем блоки только для новых блоков
|
|
206
|
+
const blockCount = Math.ceil(len / BLOCK_SIZE);
|
|
207
|
+
const oldBlockCount = blockOffsetsRef.current.length;
|
|
208
|
+
for (let b = oldBlockCount; b < blockCount; b++) {
|
|
209
|
+
const start = b * BLOCK_SIZE;
|
|
210
|
+
blockOffsetsRef.current[b] = (_a = offsets[start]) !== null && _a !== void 0 ? _a : 0;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
// форсим ререндер, чтобы использовать новые offsets
|
|
215
|
+
setRenderVersion(v => v + 1);
|
|
216
|
+
}, [items.length, isFixed, itemHeight, estimatedItemHeight]);
|
|
217
|
+
const onScroll = (0, react_1.useCallback)(() => {
|
|
218
|
+
var _a, _b;
|
|
219
|
+
const top = (_b = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.scrollTop) !== null && _b !== void 0 ? _b : 0;
|
|
220
|
+
setScrollTop(top);
|
|
221
|
+
}, []);
|
|
222
|
+
// ⭐ Поиск startIndex
|
|
223
|
+
const findStartIndex = (0, react_1.useCallback)((scrollTopValue) => {
|
|
224
|
+
const len = items.length;
|
|
225
|
+
if (len === 0)
|
|
226
|
+
return 0;
|
|
227
|
+
const offsets = offsetsRef.current;
|
|
228
|
+
const blocks = blockOffsetsRef.current;
|
|
229
|
+
if (isFixed) {
|
|
230
|
+
const idx = Math.floor(scrollTopValue / (itemHeight || estimatedItemHeight));
|
|
231
|
+
return Math.max(0, Math.min(len - 1, idx));
|
|
232
|
+
}
|
|
233
|
+
// бинарный поиск по блокам
|
|
234
|
+
let low = 0;
|
|
235
|
+
let high = blocks.length - 1;
|
|
236
|
+
while (low < high) {
|
|
237
|
+
const mid = (low + high) >> 1;
|
|
238
|
+
if (blocks[mid] < scrollTopValue)
|
|
239
|
+
low = mid + 1;
|
|
240
|
+
else
|
|
241
|
+
high = mid;
|
|
242
|
+
}
|
|
243
|
+
const blockIndex = Math.max(0, low - 1);
|
|
244
|
+
const start = blockIndex * BLOCK_SIZE;
|
|
245
|
+
const end = Math.min(len - 1, start + BLOCK_SIZE * 2);
|
|
246
|
+
let i = start;
|
|
247
|
+
while (i < end && offsets[i] < scrollTopValue)
|
|
248
|
+
i++;
|
|
249
|
+
return Math.max(0, Math.min(len - 1, i));
|
|
250
|
+
}, [items.length, isFixed, itemHeight, estimatedItemHeight, renderVersion]);
|
|
251
|
+
const startIndex = (0, react_1.useMemo)(() => {
|
|
252
|
+
const idx = findStartIndex(scrollTop);
|
|
253
|
+
const _ = renderVersion;
|
|
254
|
+
return Math.max(0, idx - overscan);
|
|
255
|
+
}, [scrollTop, findStartIndex, overscan, renderVersion]);
|
|
256
|
+
// ⭐ Поиск endIndex
|
|
257
|
+
const endIndex = (0, react_1.useMemo)(() => {
|
|
258
|
+
const len = items.length;
|
|
259
|
+
if (len === 0)
|
|
260
|
+
return -1;
|
|
261
|
+
const offsets = offsetsRef.current;
|
|
262
|
+
if (offsets.length !== len)
|
|
263
|
+
return -1;
|
|
264
|
+
const totalVisibleBottom = scrollTop + height;
|
|
265
|
+
let i = startIndex;
|
|
266
|
+
while (i < len && offsets[i] < totalVisibleBottom)
|
|
267
|
+
i++;
|
|
268
|
+
const _ = renderVersion;
|
|
269
|
+
// renderVersion;
|
|
270
|
+
return Math.min(len - 1, i + overscan);
|
|
271
|
+
}, [scrollTop, height, startIndex, items.length, overscan, renderVersion]);
|
|
272
|
+
const getTopVisibleIndex = (0, react_1.useCallback)(() => startIndex, [startIndex]);
|
|
273
|
+
react_1.default.useImperativeHandle(ref, () => ({
|
|
274
|
+
scrollToIndex: (index, align = 'auto') => {
|
|
275
|
+
scrollTo(index, align);
|
|
276
|
+
},
|
|
277
|
+
getTopVisibleIndex: () => getTopVisibleIndex(),
|
|
278
|
+
}));
|
|
279
|
+
if (renderVersion === 0) {
|
|
280
|
+
return (react_1.default.createElement("div", { ref: containerRef, style: {
|
|
281
|
+
overflowY: 'auto',
|
|
282
|
+
position: 'relative',
|
|
283
|
+
height,
|
|
284
|
+
} }));
|
|
285
|
+
}
|
|
286
|
+
const visibleStart = startIndex;
|
|
287
|
+
const visibleEnd = endIndex;
|
|
288
|
+
let totalHeight = offsetsRef.current[items.length - 1] + heightsRef.current[items.length - 1];
|
|
289
|
+
if (isNaN(totalHeight)) {
|
|
290
|
+
totalHeight = 0;
|
|
291
|
+
}
|
|
292
|
+
return (react_1.default.createElement("div", { ref: containerRef, onScroll: onScroll, style: {
|
|
293
|
+
overflowY: 'auto',
|
|
294
|
+
position: 'relative',
|
|
295
|
+
height,
|
|
296
|
+
} },
|
|
297
|
+
react_1.default.createElement("div", { style: { height: totalHeight, position: 'relative' } }, Array.from({ length: visibleEnd - visibleStart + 1 }, (_, i) => {
|
|
298
|
+
const index = visibleStart + i;
|
|
299
|
+
const item = items[index];
|
|
300
|
+
const top = offsetsRef.current[index];
|
|
301
|
+
return (react_1.default.createElement(MeasuredItem_1.default, { key: index, index: index, isFixed: isFixed, top: top, updateHeight: (idx, h) => updateHeightWithBlocks(idx, h, heightsRef, offsetsRef, blockOffsetsRef, setRenderVersion) }, renderItem(item, index)));
|
|
302
|
+
}))));
|
|
303
|
+
});
|
|
304
|
+
VirtualizedListComponent.displayName = 'VirtualizedListComponent';
|
|
305
|
+
exports.default = VirtualizedListComponent;
|
package/Menu/index.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ import { MenuProps, MenuRef } from './MenuContainer';
|
|
|
3
3
|
import { AnchorPos as PopperAnchorPos } from '../Popper';
|
|
4
4
|
export type AnchorPos = PopperAnchorPos;
|
|
5
5
|
export * from './MenuContainer';
|
|
6
|
+
export * from './MenuItem';
|
|
7
|
+
export * from './MenuList';
|
|
6
8
|
declare const _default: <T, Multiple extends boolean | undefined = undefined>(props: MenuProps<T, Multiple> & {
|
|
7
9
|
ref?: React.Ref<MenuRef> | undefined;
|
|
8
|
-
}) =>
|
|
10
|
+
}) => React.ReactElement;
|
|
9
11
|
export default _default;
|
package/Menu/index.js
CHANGED
|
@@ -21,6 +21,8 @@ const react_1 = __importDefault(require("react"));
|
|
|
21
21
|
const context_1 = require("./context");
|
|
22
22
|
const MenuContainer_1 = __importDefault(require("./MenuContainer"));
|
|
23
23
|
__exportStar(require("./MenuContainer"), exports);
|
|
24
|
+
__exportStar(require("./MenuItem"), exports);
|
|
25
|
+
__exportStar(require("./MenuList"), exports);
|
|
24
26
|
const Menu = react_1.default.forwardRef((props, ref) => (react_1.default.createElement(context_1.MenuContextProvider, null,
|
|
25
27
|
react_1.default.createElement(MenuContainer_1.default, Object.assign({}, props, { ref: ref })))));
|
|
26
28
|
Menu.displayName = 'Menu';
|
package/Popper/Popper.d.ts
CHANGED
|
@@ -1,81 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { PopperContainerProps, PositionStrategy } from './PopperContainer';
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* These are the primary axes around which the popper can be placed.
|
|
6
|
-
*
|
|
7
|
-
* @default 'bottom' (when used as anchorPos)
|
|
8
|
-
* @example
|
|
9
|
-
* ```tsx
|
|
10
|
-
* type Direction = 'top' | 'bottom' | 'left' | 'right';
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
export type Direction = 'top' | 'left' | 'right' | 'bottom';
|
|
14
|
-
/**
|
|
15
|
-
* Auto placement modifiers that enable intelligent positioning.
|
|
16
|
-
* The popper will automatically choose the best placement that fits in the viewport.
|
|
17
|
-
* - `auto`: Dynamically selects the optimal direction
|
|
18
|
-
* - `auto-top`, `auto-bottom`, `auto-left`, `auto-right`: Auto placement with priority given to the specified direction
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```tsx
|
|
22
|
-
* // Will try to place on top first, but will flip if needed
|
|
23
|
-
* <Popper anchorPos="auto-top">...</Popper>
|
|
24
|
-
*
|
|
25
|
-
* // Will try all directions equally
|
|
26
|
-
* <Popper anchorPos="auto">...</Popper>
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export type AutoModifier = 'auto' | 'auto-top' | 'auto-bottom' | 'auto-left' | 'auto-right';
|
|
30
|
-
/**
|
|
31
|
-
* Precise placement modifiers for fine-tuned positioning.
|
|
32
|
-
* These combine a base direction with specific alignment options:
|
|
33
|
-
* - `start`/`end`: Aligns to the beginning or end of the anchor (useful for RTL layouts)
|
|
34
|
-
* - `left`/`right`: Horizontal alignment for vertical placements
|
|
35
|
-
* - `top`/`bottom`: Vertical alignment for horizontal placements
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```tsx
|
|
39
|
-
* // Corner placements
|
|
40
|
-
* <Popper anchorPos="top-left">Aligns to top-left corner</Popper>
|
|
41
|
-
*
|
|
42
|
-
* // Logical placements (RTL-friendly)
|
|
43
|
-
* <Popper anchorPos="bottom-start">Aligns to bottom edge, start side</Popper>
|
|
44
|
-
*
|
|
45
|
-
* // Side alignments
|
|
46
|
-
* <Popper anchorPos="left-top">Aligns to left side, top edge</Popper>
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
export type Modifier = 'top-start' | 'top-end' | 'top-left' | 'top-right' | 'bottom-end' | 'bottom-start' | 'bottom-right' | 'bottom-left' | 'left-top' | 'left-bottom' | 'right-top' | 'right-bottom';
|
|
50
|
-
/**
|
|
51
|
-
* Available placement options for the popper.
|
|
52
|
-
* Combines basic directions, precise modifiers, and auto-placement options
|
|
53
|
-
* to provide full control over popper positioning.
|
|
54
|
-
*
|
|
55
|
-
* Categories:
|
|
56
|
-
* - **Basic directions**: `top`, `bottom`, `left`, `right` - Centered placement
|
|
57
|
-
* - **Corner placements**: `top-left`, `top-right`, `bottom-left`, `bottom-right` - Aligned to corners
|
|
58
|
-
* - **Logical placements**: `top-start`, `top-end`, `bottom-start`, `bottom-end` - RTL-aware alignment
|
|
59
|
-
* - **Side alignments**: `left-top`, `left-bottom`, `right-top`, `right-bottom` - Edge-aligned
|
|
60
|
-
* - **Auto placements**: `auto`, `auto-top`, `auto-bottom`, `auto-left`, `auto-right` - Intelligent positioning
|
|
61
|
-
*
|
|
62
|
-
* @default 'bottom'
|
|
63
|
-
* @example
|
|
64
|
-
* ```tsx
|
|
65
|
-
* // Basic centered placement
|
|
66
|
-
* <Popper anchorPos="bottom">Centered below anchor</Popper>
|
|
67
|
-
*
|
|
68
|
-
* // Corner placement
|
|
69
|
-
* <Popper anchorPos="top-right">Attached to top-right corner</Popper>
|
|
70
|
-
*
|
|
71
|
-
* // Auto placement with priority
|
|
72
|
-
* <Popper anchorPos="auto-left">Try left first, then find best fit</Popper>
|
|
73
|
-
*
|
|
74
|
-
* // RTL-aware placement
|
|
75
|
-
* <Popper anchorPos="top-start">Respects text direction</Popper>
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
export type AnchorPos = Direction | Modifier | AutoModifier;
|
|
3
|
+
import { AnchorPos } from './usePopprer';
|
|
4
|
+
export * from './usePopprer';
|
|
79
5
|
export interface PopperProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
80
6
|
/**
|
|
81
7
|
* Controls the visibility of the popper.
|
|
@@ -99,7 +25,7 @@ export interface PopperProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
99
25
|
* <Popper anchorElement={anchor}>...</Popper>
|
|
100
26
|
* ```
|
|
101
27
|
*/
|
|
102
|
-
readonly anchorElement
|
|
28
|
+
readonly anchorElement: HTMLElement | null;
|
|
103
29
|
/**
|
|
104
30
|
* Determines the preferred placement of the popper relative to the anchor element.
|
|
105
31
|
* The actual placement may change if `autoFlip` is enabled and there's not enough space.
|
|
@@ -112,6 +38,7 @@ export interface PopperProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
112
38
|
* ```
|
|
113
39
|
*/
|
|
114
40
|
readonly anchorPos?: AnchorPos;
|
|
41
|
+
readonly onAnchorPosChanged?: (anchorPos: AnchorPos) => void;
|
|
115
42
|
/**
|
|
116
43
|
* The z-index value for the popper container.
|
|
117
44
|
* Used to control the stacking order of the popper relative to other elements.
|
|
@@ -154,11 +81,11 @@ export interface PopperProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
154
81
|
* - `'absolute'`: Positions relative to the nearest positioned ancestor.
|
|
155
82
|
* When using 'absolute', make sure a parent element has `position: relative`.
|
|
156
83
|
*
|
|
157
|
-
* @default '
|
|
84
|
+
* @default 'fixed'
|
|
158
85
|
* @example
|
|
159
86
|
* ```tsx
|
|
160
|
-
* <Popper positionStrategy="absolute">...</Popper> // Relative to positioned parent
|
|
161
|
-
* <Popper positionStrategy="fixed">...</Popper> // Relative to viewport
|
|
87
|
+
* <Popper positionStrategy="absolute">...</Popper> // Relative to positioned parent
|
|
88
|
+
* <Popper positionStrategy="fixed">...</Popper> // Relative to viewport (recommended)
|
|
162
89
|
* ```
|
|
163
90
|
*/
|
|
164
91
|
readonly positionStrategy?: PositionStrategy;
|
package/Popper/Popper.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
17
|
var t = {};
|
|
4
18
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -19,11 +33,12 @@ const react_1 = __importDefault(require("react"));
|
|
|
19
33
|
const react_dom_1 = __importDefault(require("react-dom"));
|
|
20
34
|
const PopperContainer_1 = __importDefault(require("./PopperContainer"));
|
|
21
35
|
const usePopprer_1 = require("./usePopprer");
|
|
36
|
+
__exportStar(require("./usePopprer"), exports);
|
|
22
37
|
exports.PORTAL_ID = 'ui-kit-portal';
|
|
23
38
|
const Popper = (props, ref) => {
|
|
24
|
-
const { isOpen, children, anchorElement, zIndex, overrides, anchorPos = 'auto', positionStrategy = '
|
|
39
|
+
const { isOpen, children, anchorElement, zIndex, overrides, anchorPos = 'auto', positionStrategy = 'fixed', viewportMargin = 30, autoFlip = true, offset = 0, onAnchorPosChanged } = props, nativeProps = __rest(props, ["isOpen", "children", "anchorElement", "zIndex", "overrides", "anchorPos", "positionStrategy", "viewportMargin", "autoFlip", "offset", "onAnchorPosChanged"]);
|
|
25
40
|
const [domLoaded, setDomLoaded] = react_1.default.useState(false);
|
|
26
|
-
const { actualPlacement, style, popperRef, isVisible
|
|
41
|
+
const { actualPlacement, style, popperRef, isVisible } = (0, usePopprer_1.usePopper)({
|
|
27
42
|
anchorElement,
|
|
28
43
|
anchorPos,
|
|
29
44
|
positionStrategy,
|
|
@@ -51,20 +66,20 @@ const Popper = (props, ref) => {
|
|
|
51
66
|
}
|
|
52
67
|
const newNode = window.document.createElement('div');
|
|
53
68
|
newNode.setAttribute('id', exports.PORTAL_ID);
|
|
54
|
-
// Важно для absolute позиционирования
|
|
55
69
|
if (positionStrategy === 'absolute') {
|
|
56
70
|
newNode.style.position = 'relative';
|
|
57
71
|
}
|
|
58
72
|
window.document.body.appendChild(newNode);
|
|
59
73
|
return newNode;
|
|
60
74
|
}, [positionStrategy]);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
75
|
+
react_1.default.useEffect(() => {
|
|
76
|
+
if (anchorPos !== actualPlacement && typeof onAnchorPosChanged === 'function') {
|
|
77
|
+
onAnchorPosChanged(actualPlacement);
|
|
78
|
+
}
|
|
79
|
+
}, [anchorPos, actualPlacement, onAnchorPosChanged]);
|
|
80
|
+
const renderNode = react_1.default.useCallback(() => (react_1.default.createElement(overridesMap.Container, Object.assign({}, nativeProps, { style: Object.assign(Object.assign(Object.assign(Object.assign({}, style), nativeProps.style), { opacity: isVisible ? 1 : 0, pointerEvents: isVisible ? 'auto' : 'none' }), (positionStrategy === 'fixed' && {
|
|
66
81
|
zIndex: zIndex,
|
|
67
|
-
})), zIndex: zIndex, "data-placement": actualPlacement, "data-popper-strategy": positionStrategy, ref: el => {
|
|
82
|
+
})), zIndex: zIndex, positionStrategy: positionStrategy, "data-popper-placement": actualPlacement, "data-popper-strategy": positionStrategy, ref: el => {
|
|
68
83
|
popperRef.current = el;
|
|
69
84
|
if (ref) {
|
|
70
85
|
if (typeof ref === 'function') {
|
|
@@ -79,13 +94,13 @@ const Popper = (props, ref) => {
|
|
|
79
94
|
nativeProps,
|
|
80
95
|
style,
|
|
81
96
|
isVisible,
|
|
82
|
-
getTransformOrigin,
|
|
97
|
+
// getTransformOrigin,
|
|
83
98
|
actualPlacement,
|
|
84
99
|
positionStrategy,
|
|
85
100
|
zIndex,
|
|
86
101
|
children,
|
|
87
|
-
ref,
|
|
88
102
|
popperRef,
|
|
103
|
+
ref,
|
|
89
104
|
]);
|
|
90
105
|
if (!isOpen) {
|
|
91
106
|
return null;
|
|
@@ -93,7 +108,6 @@ const Popper = (props, ref) => {
|
|
|
93
108
|
if (positionStrategy === 'fixed') {
|
|
94
109
|
return domLoaded && portalEl ? react_dom_1.default.createPortal(renderNode(), portalEl, exports.PORTAL_ID) : null;
|
|
95
110
|
}
|
|
96
|
-
// Для absolute стратегии - рендерим рядом с anchor (in-place)
|
|
97
111
|
return renderNode();
|
|
98
112
|
};
|
|
99
113
|
exports.default = react_1.default.forwardRef(Popper);
|