1
- import React , {
2
- Fragment ,
3
- useCallback ,
4
- useContext ,
5
- useEffect ,
6
- useMemo ,
7
- useRef ,
8
- useState ,
9
- } from 'react' ;
1
+ import * as React from 'react' ;
10
2
11
3
import { useUniqId } from '@gravity-ui/uikit' ;
12
4
import debounce from 'lodash/debounce' ;
@@ -93,19 +85,19 @@ export const SliderOldBlock = (props: React.PropsWithChildren<SliderOldProps>) =
93
85
initialIndex = 0 ,
94
86
} = props ;
95
87
96
- const { isServer} = useContext ( SSRContext ) ;
97
- const isMobile = useContext ( MobileContext ) ;
98
- const [ breakpoint , setBreakpoint ] = useState < number > ( BREAKPOINTS . xl ) ;
88
+ const { isServer} = React . useContext ( SSRContext ) ;
89
+ const isMobile = React . useContext ( MobileContext ) ;
90
+ const [ breakpoint , setBreakpoint ] = React . useState < number > ( BREAKPOINTS . xl ) ;
99
91
const sliderId = useUniqId ( ) ;
100
- const disclosedChildren = useMemo < React . ReactElement [ ] > (
92
+ const disclosedChildren = React . useMemo < React . ReactElement [ ] > (
101
93
( ) => discloseAllNestedChildren ( children as React . ReactElement [ ] , sliderId ) ,
102
94
[ children , sliderId ] ,
103
95
) ;
104
96
const childrenCount = disclosedChildren . length ;
105
97
const isAutoplayEnabled = autoplaySpeed !== undefined && autoplaySpeed > 0 ;
106
- const isUserInteractionRef = useRef ( false ) ;
98
+ const isUserInteractionRef = React . useRef ( false ) ;
107
99
108
- const [ slidesToShow ] = useState < SliderBreakpointParams > (
100
+ const [ slidesToShow ] = React . useState < SliderBreakpointParams > (
109
101
getSlidesToShowWithDefaults ( {
110
102
contentLength : childrenCount ,
111
103
breakpoints : props . slidesToShow ,
@@ -118,11 +110,11 @@ export const SliderOldBlock = (props: React.PropsWithChildren<SliderOldProps>) =
118
110
const slidesToShowCount = getSlidesToShowCount ( slidesToShow ) ;
119
111
const slidesCountByBreakpoint = getSlidesCountByBreakpoint ( breakpoint , slidesToShow ) ;
120
112
121
- const [ currentIndex , setCurrentIndex ] = useState < number > ( initialIndex ) ;
122
- const [ childStyles , setChildStyles ] = useState < Object > ( { } ) ;
123
- const [ slider , setSlider ] = useState < SlickSlider > ( ) ;
124
- const prevIndexRef = useRef < number > ( 0 ) ;
125
- const autoplayTimeId = useRef < Timeout > ( ) ;
113
+ const [ currentIndex , setCurrentIndex ] = React . useState < number > ( initialIndex ) ;
114
+ const [ childStyles , setChildStyles ] = React . useState < Object > ( { } ) ;
115
+ const [ slider , setSlider ] = React . useState < SlickSlider > ( ) ;
116
+ const prevIndexRef = React . useRef < number > ( 0 ) ;
117
+ const autoplayTimeId = React . useRef < Timeout > ( ) ;
126
118
const { hasFocus, unsetFocus} = useFocus ( slider ?. innerSlider ?. list ) ;
127
119
128
120
const asUserInteraction =
@@ -133,7 +125,7 @@ export const SliderOldBlock = (props: React.PropsWithChildren<SliderOldProps>) =
133
125
} ;
134
126
135
127
// eslint-disable-next-line react-hooks/exhaustive-deps
136
- const onResize = useCallback (
128
+ const onResize = React . useCallback (
137
129
debounce ( ( ) => {
138
130
if ( ! slider ) {
139
131
return ;
@@ -151,7 +143,7 @@ export const SliderOldBlock = (props: React.PropsWithChildren<SliderOldProps>) =
151
143
[ slider , breakpoint ] ,
152
144
) ;
153
145
154
- const scrollLastSlide = useCallback (
146
+ const scrollLastSlide = React . useCallback (
155
147
( current : number ) => {
156
148
const lastSlide = childrenCount - slidesToShowCount ;
157
149
@@ -173,15 +165,15 @@ export const SliderOldBlock = (props: React.PropsWithChildren<SliderOldProps>) =
173
165
[ autoplaySpeed , childrenCount , isAutoplayEnabled , slider , slidesToShowCount ] ,
174
166
) ;
175
167
176
- useEffect ( ( ) => {
168
+ React . useEffect ( ( ) => {
177
169
if ( hasFocus && autoplayTimeId . current ) {
178
170
clearTimeout ( autoplayTimeId . current ) ;
179
171
} else {
180
172
scrollLastSlide ( currentIndex ) ;
181
173
}
182
174
} , [ currentIndex , hasFocus , scrollLastSlide ] ) ;
183
175
184
- useEffect ( ( ) => {
176
+ React . useEffect ( ( ) => {
185
177
onResize ( ) ;
186
178
187
179
window . addEventListener ( 'resize' , onResize , { passive : true } ) ;
@@ -205,7 +197,7 @@ export const SliderOldBlock = (props: React.PropsWithChildren<SliderOldProps>) =
205
197
}
206
198
} ;
207
199
208
- const onBeforeChange = useCallback (
200
+ const onBeforeChange = React . useCallback (
209
201
( current : number , next : number ) => {
210
202
if ( handleBeforeChange ) {
211
203
handleBeforeChange ( current , next ) ;
@@ -218,7 +210,7 @@ export const SliderOldBlock = (props: React.PropsWithChildren<SliderOldProps>) =
218
210
[ handleBeforeChange ] ,
219
211
) ;
220
212
221
- const onAfterChange = useCallback (
213
+ const onAfterChange = React . useCallback (
222
214
( current : number ) => {
223
215
if ( handleAfterChange ) {
224
216
handleAfterChange ( current ) ;
@@ -289,7 +281,7 @@ export const SliderOldBlock = (props: React.PropsWithChildren<SliderOldProps>) =
289
281
const renderAccessibleBar = ( index : number ) => {
290
282
return (
291
283
// To have this key differ from keys used in renderDot function, added `-accessible-bar` part
292
- < Fragment key = { `${ index } -accessible-bar` } >
284
+ < React . Fragment key = { `${ index } -accessible-bar` } >
293
285
{ slidesCountByBreakpoint > 0 && (
294
286
< li
295
287
className = { b ( 'accessible-bar' ) }
@@ -306,7 +298,7 @@ export const SliderOldBlock = (props: React.PropsWithChildren<SliderOldProps>) =
306
298
{ ...getRovingItemProps ( currentIndex + 1 ) }
307
299
/>
308
300
) }
309
- </ Fragment >
301
+ </ React . Fragment >
310
302
) ;
311
303
} ;
312
304
0 commit comments