@sima-land/ui-nucleons 44.2.7 → 44.2.8
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/carousel/draggable.d.ts +6 -0
- package/carousel/draggable.js +8 -0
- package/carousel/index.d.ts +13 -2
- package/carousel/index.js +31 -13
- package/package.json +1 -1
package/carousel/draggable.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface Control {
|
|
|
6
6
|
isGrabbed: () => boolean;
|
|
7
7
|
setOffset: typeof Draggable.prototype.setOffset;
|
|
8
8
|
toggleTransition: typeof Draggable.prototype.toggleTransition;
|
|
9
|
+
isTransitionEnabled: () => boolean;
|
|
9
10
|
}
|
|
10
11
|
export declare type Delta2d = {
|
|
11
12
|
dx: number;
|
|
@@ -92,6 +93,11 @@ export default class Draggable extends Component<DraggableProps> {
|
|
|
92
93
|
* @param active Нужен ли плавный переход.
|
|
93
94
|
*/
|
|
94
95
|
toggleTransition(active: boolean): void;
|
|
96
|
+
/**
|
|
97
|
+
* Возвращает true, если css свойство transition активно, false в противном случае.
|
|
98
|
+
* @return Активно ли css свойство transition.
|
|
99
|
+
*/
|
|
100
|
+
isTransitionEnabled(): boolean;
|
|
95
101
|
/**
|
|
96
102
|
* Сохраняет данные позиции на экземпляре.
|
|
97
103
|
* @param event Событие.
|
package/carousel/draggable.js
CHANGED
|
@@ -90,6 +90,7 @@ class Draggable extends react_1.Component {
|
|
|
90
90
|
isGrabbed: () => this.isGrabbed,
|
|
91
91
|
setOffset: this.setOffset.bind(this),
|
|
92
92
|
toggleTransition: this.toggleTransition.bind(this),
|
|
93
|
+
isTransitionEnabled: this.isTransitionEnabled.bind(this),
|
|
93
94
|
});
|
|
94
95
|
}
|
|
95
96
|
/**
|
|
@@ -207,6 +208,13 @@ class Draggable extends react_1.Component {
|
|
|
207
208
|
draggableEl.style.transition = active ? (0, styles_1.getTransitionStyle)(duration, 'transform') : '';
|
|
208
209
|
}
|
|
209
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Возвращает true, если css свойство transition активно, false в противном случае.
|
|
213
|
+
* @return Активно ли css свойство transition.
|
|
214
|
+
*/
|
|
215
|
+
isTransitionEnabled() {
|
|
216
|
+
return this.hasTransition;
|
|
217
|
+
}
|
|
210
218
|
/**
|
|
211
219
|
* Сохраняет данные позиции на экземпляре.
|
|
212
220
|
* @param event Событие.
|
package/carousel/index.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export declare class Carousel extends Component<CarouselProps, State> {
|
|
|
61
61
|
dragStartOffset: IPoint;
|
|
62
62
|
currentIndex: number;
|
|
63
63
|
containerRef: React.RefObject<HTMLDivElement>;
|
|
64
|
+
rootElementRef: React.RefObject<HTMLDivElement>;
|
|
64
65
|
wrapperRef: React.RefObject<HTMLDivElement>;
|
|
65
66
|
timerId?: number;
|
|
66
67
|
canAutoMove?: boolean;
|
|
@@ -69,6 +70,7 @@ export declare class Carousel extends Component<CarouselProps, State> {
|
|
|
69
70
|
toggleDragTransition: Control['toggleTransition'];
|
|
70
71
|
setDragOffset: Control['setOffset'];
|
|
71
72
|
isGrabbed: Control['isGrabbed'];
|
|
73
|
+
isTransitionEnabled: Control['isTransitionEnabled'];
|
|
72
74
|
/**
|
|
73
75
|
* Конструктор.
|
|
74
76
|
* @param props Свойства.
|
|
@@ -125,6 +127,15 @@ export declare class Carousel extends Component<CarouselProps, State> {
|
|
|
125
127
|
* Обновляет информацию о состоянии отображения элементов.
|
|
126
128
|
*/
|
|
127
129
|
componentDidMount(): void;
|
|
130
|
+
/**
|
|
131
|
+
* Подписывается на изменение размера корневого элемента.
|
|
132
|
+
* @param Observer Класс ResizeObserver.
|
|
133
|
+
*/
|
|
134
|
+
observeResize(Observer?: typeof ResizeObserver): void;
|
|
135
|
+
/**
|
|
136
|
+
* Корректирует смещение при изменении размеров.
|
|
137
|
+
*/
|
|
138
|
+
handleResize(): void;
|
|
128
139
|
/**
|
|
129
140
|
* По необходимости обновляет индекс текущего элемента.
|
|
130
141
|
* Обновляет информацию о состоянии отображения элементов.
|
|
@@ -286,9 +297,9 @@ export declare class Carousel extends Component<CarouselProps, State> {
|
|
|
286
297
|
}): void;
|
|
287
298
|
/**
|
|
288
299
|
* Получает управление от Draggable.
|
|
289
|
-
* @param
|
|
300
|
+
* @param control Функции управления Draggable.
|
|
290
301
|
*/
|
|
291
|
-
takeDragControl(
|
|
302
|
+
takeDragControl(control: Control): void;
|
|
292
303
|
/** @inheritdoc */
|
|
293
304
|
render(): JSX.Element;
|
|
294
305
|
/**
|
package/carousel/index.js
CHANGED
|
@@ -37,7 +37,6 @@ const max_index_of_1 = __importDefault(require("../helpers/max-index-of"));
|
|
|
37
37
|
const get_relative_pos_1 = __importDefault(require("../helpers/get-relative-pos"));
|
|
38
38
|
const find_child_element_1 = __importDefault(require("../helpers/find-child-element"));
|
|
39
39
|
const arrow_button_1 = require("../arrow-button");
|
|
40
|
-
const on_1 = __importDefault(require("../helpers/on"));
|
|
41
40
|
const bind_1 = __importDefault(require("classnames/bind"));
|
|
42
41
|
const carousel_module_scss_1 = __importDefault(require("./carousel.module.scss"));
|
|
43
42
|
const is_browser_1 = __importDefault(require("../helpers/is-browser"));
|
|
@@ -66,6 +65,7 @@ class Carousel extends react_1.Component {
|
|
|
66
65
|
isAllItemsVisible: false,
|
|
67
66
|
};
|
|
68
67
|
// refs
|
|
68
|
+
this.rootElementRef = (0, react_1.createRef)(); // для слежки за изменением размера
|
|
69
69
|
this.containerRef = (0, react_1.createRef)(); // для определения размеров списка элементов
|
|
70
70
|
this.wrapperRef = (0, react_1.createRef)(); // для определения viewport'а карусели
|
|
71
71
|
// bound methods
|
|
@@ -80,6 +80,7 @@ class Carousel extends react_1.Component {
|
|
|
80
80
|
this.toggleDragTransition = lodash_1.noop;
|
|
81
81
|
this.setDragOffset = lodash_1.noop;
|
|
82
82
|
this.isGrabbed = lodash_1.stubFalse;
|
|
83
|
+
this.isTransitionEnabled = lodash_1.stubFalse;
|
|
83
84
|
}
|
|
84
85
|
/**
|
|
85
86
|
* Возвращает элемент списка.
|
|
@@ -154,12 +155,7 @@ class Carousel extends react_1.Component {
|
|
|
154
155
|
*/
|
|
155
156
|
componentDidMount() {
|
|
156
157
|
const { autoplay, onReady } = this.props;
|
|
157
|
-
this.
|
|
158
|
-
this.toggleDragTransition(false);
|
|
159
|
-
this.scrollToItem({ needTransition: false });
|
|
160
|
-
this.updateItemsVisibility();
|
|
161
|
-
this.toggleDragTransition(true);
|
|
162
|
-
});
|
|
158
|
+
this.observeResize(window.ResizeObserver);
|
|
163
159
|
this.toggleMounted(true);
|
|
164
160
|
this.forceUpdate(() => {
|
|
165
161
|
this.scrollToItem({ needTransition: false });
|
|
@@ -168,6 +164,27 @@ class Carousel extends react_1.Component {
|
|
|
168
164
|
autoplay && this.enableAutoplay();
|
|
169
165
|
onReady && onReady(this.currentIndex);
|
|
170
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Подписывается на изменение размера корневого элемента.
|
|
169
|
+
* @param Observer Класс ResizeObserver.
|
|
170
|
+
*/
|
|
171
|
+
observeResize(Observer) {
|
|
172
|
+
if (Observer && this.rootElementRef.current) {
|
|
173
|
+
const observer = new Observer(() => this.handleResize());
|
|
174
|
+
observer.observe(this.rootElementRef.current);
|
|
175
|
+
this.offWindowResize = () => observer.disconnect();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Корректирует смещение при изменении размеров.
|
|
180
|
+
*/
|
|
181
|
+
handleResize() {
|
|
182
|
+
const wasEnabled = this.isTransitionEnabled();
|
|
183
|
+
wasEnabled && this.toggleDragTransition(false);
|
|
184
|
+
this.scrollToItem({ needTransition: false });
|
|
185
|
+
this.updateItemsVisibility();
|
|
186
|
+
wasEnabled && this.toggleDragTransition(true);
|
|
187
|
+
}
|
|
171
188
|
/**
|
|
172
189
|
* По необходимости обновляет индекс текущего элемента.
|
|
173
190
|
* Обновляет информацию о состоянии отображения элементов.
|
|
@@ -560,19 +577,20 @@ class Carousel extends react_1.Component {
|
|
|
560
577
|
}
|
|
561
578
|
/**
|
|
562
579
|
* Получает управление от Draggable.
|
|
563
|
-
* @param
|
|
580
|
+
* @param control Функции управления Draggable.
|
|
564
581
|
*/
|
|
565
|
-
takeDragControl(
|
|
566
|
-
this.toggleDragTransition = toggleTransition;
|
|
567
|
-
this.setDragOffset = setOffset;
|
|
568
|
-
this.isGrabbed = isGrabbed;
|
|
582
|
+
takeDragControl(control) {
|
|
583
|
+
this.toggleDragTransition = control.toggleTransition;
|
|
584
|
+
this.setDragOffset = control.setOffset;
|
|
585
|
+
this.isGrabbed = control.isGrabbed;
|
|
586
|
+
this.isTransitionEnabled = control.isTransitionEnabled;
|
|
569
587
|
}
|
|
570
588
|
/** @inheritdoc */
|
|
571
589
|
render() {
|
|
572
590
|
const { currentOffset, isAllItemsVisible } = this.state;
|
|
573
591
|
const { autoplay, autoplayHoverPause, vertical, containerProps = {}, viewportElementProps = {}, withControls = 'auto', renderControl = Carousel.defaultRenderControl, controlProps, } = this.props;
|
|
574
592
|
const needShowControls = (isAuto(withControls) && !isAllItemsVisible) || withControls === true;
|
|
575
|
-
return (react_1.default.createElement("div", Object.assign({}, containerProps, { className: cx('carousel-wrapper', containerProps.className), onMouseEnter: () => {
|
|
593
|
+
return (react_1.default.createElement("div", Object.assign({ ref: this.rootElementRef }, containerProps, { className: cx('carousel-wrapper', containerProps.className), onMouseEnter: () => {
|
|
576
594
|
autoplay && autoplayHoverPause && this.toggleAutoMove(false);
|
|
577
595
|
}, onMouseLeave: () => {
|
|
578
596
|
autoplay && autoplayHoverPause && !this.isGrabbed() && this.toggleAutoMove(true);
|