@sima-land/moleculas 16.0.0-alpha.0 → 16.0.0-alpha.1
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/desktop/components/modifiers/group/modifiers-group.module.scss +2 -0
- package/desktop/components/product-carousel/index.d.ts +1 -1
- package/desktop/components/product-carousel/index.js +36 -27
- package/desktop/components/product-carousel/utils.d.ts +2 -3
- package/desktop/components/product-carousel/utils.js +17 -20
- package/package.json +1 -1
|
@@ -27,5 +27,5 @@ export interface ProductCarouselProps {
|
|
|
27
27
|
* @param props Свойства.
|
|
28
28
|
* @return Элемент.
|
|
29
29
|
*/
|
|
30
|
-
export declare
|
|
30
|
+
export declare function ProductCarousel({ className, itemSize, onInViewport, onNeedRequest, withHoverCard, children, }: ProductCarouselProps): JSX.Element;
|
|
31
31
|
export {};
|
|
@@ -51,7 +51,7 @@ const getSizeClasses = (size = {}) => [
|
|
|
51
51
|
* @param props Свойства.
|
|
52
52
|
* @return Элемент.
|
|
53
53
|
*/
|
|
54
|
-
|
|
54
|
+
function ProductCarousel({ className, itemSize, onInViewport, onNeedRequest, withHoverCard, children, }) {
|
|
55
55
|
const layer = (0, layer_1.useLayer)();
|
|
56
56
|
const [activeItemIndex, setActiveItemIndex] = (0, react_1.useState)(null);
|
|
57
57
|
const cardShow = (0, utils_1.useAllowFlag)();
|
|
@@ -66,7 +66,8 @@ const ProductCarousel = ({ className, itemSize, onInViewport, onNeedRequest, wit
|
|
|
66
66
|
items = children ? [children] : [];
|
|
67
67
|
}
|
|
68
68
|
// вычисляем ширину элемента карусели для позиционирования стрелок
|
|
69
|
-
const
|
|
69
|
+
const firstItemRef = (0, react_1.useRef)(null);
|
|
70
|
+
const itemWidth = (0, utils_1.useClientWidth)(firstItemRef, [items.length]);
|
|
70
71
|
// инициируем загрузку данных, когда компонент почти попал в зону видимости
|
|
71
72
|
const options = (0, react_1.useMemo)(() => ({ rootMargin: '200px 0px 200px 0px' }), []);
|
|
72
73
|
(0, intersection_1.useIntersection)(rootRef, entry => {
|
|
@@ -88,34 +89,12 @@ const ProductCarousel = ({ className, itemSize, onInViewport, onNeedRequest, wit
|
|
|
88
89
|
top: `${itemWidth / 2}px`,
|
|
89
90
|
},
|
|
90
91
|
},
|
|
91
|
-
}), { renderItem: ([item, index]) => (react_1.default.createElement(
|
|
92
|
+
}), { renderItem: ([item, index], realIndex) => (react_1.default.createElement(ProductCarouselItem, { rootRef: realIndex === 0 ? firstItemRef : undefined, withHoverCard: withHoverCard, className: cx(getSizeClasses(itemSize)), onMouseEnter: e => {
|
|
92
93
|
if (cardShow.allowed()) {
|
|
93
94
|
targetItemRef.current = e.currentTarget;
|
|
94
95
|
setActiveItemIndex(index);
|
|
95
96
|
}
|
|
96
|
-
} },
|
|
97
|
-
children: react_1.Children.toArray(item.props.children).reduce((list, child) => {
|
|
98
|
-
if ((0, react_1.isValidElement)(child)) {
|
|
99
|
-
switch (child.type) {
|
|
100
|
-
case product_info_1.Parts.Image: {
|
|
101
|
-
// иконки у картинки скрываем если есть HoverCard
|
|
102
|
-
list.push(withHoverCard ? (0, react_1.cloneElement)(child, { children: undefined }) : child);
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
case product_info_1.Parts.Footer:
|
|
106
|
-
// футер не выводим если есть HoverCard
|
|
107
|
-
!withHoverCard && list.push(child);
|
|
108
|
-
break;
|
|
109
|
-
default: {
|
|
110
|
-
// остальное выводим как есть
|
|
111
|
-
list.push(child);
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return list;
|
|
117
|
-
}, []),
|
|
118
|
-
}))),
|
|
97
|
+
} }, item)),
|
|
119
98
|
// длительность прокрутки в Carousel - 320, делаем слегка с запасом
|
|
120
99
|
// @todo после восстановления проверить позицию курсора чтобы показать карточку (если будет критично)
|
|
121
100
|
onChangeTargetIndex: () => cardShow.disallowFor(360) }))),
|
|
@@ -123,5 +102,35 @@ const ProductCarousel = ({ className, itemSize, onInViewport, onNeedRequest, wit
|
|
|
123
102
|
activeItemIndex !== null &&
|
|
124
103
|
items[activeItemIndex] &&
|
|
125
104
|
[items[activeItemIndex]].map(item => (react_1.default.createElement(hover_card_1.HoverCard, Object.assign({ key: activeItemIndex, targetRef: targetItemRef, onMouseLeave: () => setActiveItemIndex(null) }, item.props))))));
|
|
126
|
-
}
|
|
105
|
+
}
|
|
127
106
|
exports.ProductCarousel = ProductCarousel;
|
|
107
|
+
/**
|
|
108
|
+
* Элемент карусели. Выведет базовый контент.
|
|
109
|
+
* Полное содержимое будет выведено во всплывающей карточке.
|
|
110
|
+
* @inheritdoc
|
|
111
|
+
*/
|
|
112
|
+
function ProductCarouselItem({ rootRef, className, onMouseEnter, withHoverCard, children, }) {
|
|
113
|
+
return (react_1.default.createElement("div", { ref: rootRef, "data-testid": 'product-carousel:item', className: cx('item', className), onMouseEnter: onMouseEnter }, (0, react_1.cloneElement)(children, {
|
|
114
|
+
children: react_1.Children.toArray(children.props.children).reduce((list, child) => {
|
|
115
|
+
if ((0, react_1.isValidElement)(child)) {
|
|
116
|
+
switch (child.type) {
|
|
117
|
+
case product_info_1.Parts.Image: {
|
|
118
|
+
// иконки у картинки скрываем если есть HoverCard
|
|
119
|
+
list.push(withHoverCard ? (0, react_1.cloneElement)(child, { children: undefined }) : child);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case product_info_1.Parts.Footer:
|
|
123
|
+
// футер не выводим если есть HoverCard
|
|
124
|
+
!withHoverCard && list.push(child);
|
|
125
|
+
break;
|
|
126
|
+
default: {
|
|
127
|
+
// остальное выводим как есть
|
|
128
|
+
list.push(child);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return list;
|
|
134
|
+
}, []),
|
|
135
|
+
})));
|
|
136
|
+
}
|
|
@@ -9,9 +9,8 @@ export declare const useAllowFlag: () => {
|
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
11
|
* Возвращает ширину дочернего элемента.
|
|
12
|
-
* @param ref Ref элемента.
|
|
13
|
-
* @param selector CSS-селектор дочернего элемента.
|
|
12
|
+
* @param ref Ref дочернего элемента.
|
|
14
13
|
* @param deps Массив зависимостей от которых зависит пересчет.
|
|
15
14
|
* @return Ширина.
|
|
16
15
|
*/
|
|
17
|
-
export declare const
|
|
16
|
+
export declare const useClientWidth: (ref: React.RefObject<HTMLElement | null>, deps?: React.DependencyList) => number | null;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
3
|
+
exports.useClientWidth = exports.useAllowFlag = void 0;
|
|
7
4
|
const react_1 = require("react");
|
|
8
|
-
const on_1 = __importDefault(require("@sima-land/ui-nucleons/helpers/on"));
|
|
9
5
|
/**
|
|
10
6
|
* Возвращает объект работы с флагом, который автоматически возвращается в true через заданный промежуток времени.
|
|
11
7
|
* @return Объект работы с флагом.
|
|
@@ -25,23 +21,24 @@ const useAllowFlag = () => {
|
|
|
25
21
|
exports.useAllowFlag = useAllowFlag;
|
|
26
22
|
/**
|
|
27
23
|
* Возвращает ширину дочернего элемента.
|
|
28
|
-
* @param ref Ref элемента.
|
|
29
|
-
* @param selector CSS-селектор дочернего элемента.
|
|
24
|
+
* @param ref Ref дочернего элемента.
|
|
30
25
|
* @param deps Массив зависимостей от которых зависит пересчет.
|
|
31
26
|
* @return Ширина.
|
|
32
27
|
*/
|
|
33
|
-
const
|
|
34
|
-
const [
|
|
35
|
-
const update = (0, react_1.useCallback)(() => {
|
|
36
|
-
if (ref.current) {
|
|
37
|
-
const child = ref.current.querySelector(selector);
|
|
38
|
-
child && setItemWidth(child.clientWidth);
|
|
39
|
-
}
|
|
40
|
-
}, [ref]);
|
|
28
|
+
const useClientWidth = (ref, deps = []) => {
|
|
29
|
+
const [width, setWidth] = (0, react_1.useState)(null);
|
|
41
30
|
(0, react_1.useEffect)(() => {
|
|
42
|
-
ref.current
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
if (!ref.current) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const element = ref.current;
|
|
35
|
+
const observer = new ResizeObserver(() => {
|
|
36
|
+
setWidth(element.clientWidth);
|
|
37
|
+
});
|
|
38
|
+
observer.observe(ref.current);
|
|
39
|
+
setWidth(element.clientWidth);
|
|
40
|
+
return observer.disconnect();
|
|
41
|
+
}, [ref, ...deps]);
|
|
42
|
+
return width;
|
|
46
43
|
};
|
|
47
|
-
exports.
|
|
44
|
+
exports.useClientWidth = useClientWidth;
|