@@ -7,6 +7,10 @@ import Dial from './Dial';
7
7
import LArrow from '../../../../../assets/images/arrow-prev.svg' ;
8
8
import RArrow from '../../../../../assets/images/arrow-next.svg' ;
9
9
10
+ import './style.scss' ;
11
+
12
+ /* global window */
13
+
10
14
/**
11
15
* Transforms stats object to a more convenient array representation.
12
16
* @param {Object } stats
@@ -63,19 +67,26 @@ export default class Records extends React.Component {
63
67
constructor ( props ) {
64
68
super ( props ) ;
65
69
this . state = { } ;
70
+ this . check = this . check . bind ( this ) ;
71
+ this . width = 0 ;
72
+ }
73
+
74
+ componentDidMount ( ) {
75
+ window . addEventListener ( 'resize' , this . check ) ;
76
+ }
77
+
78
+ componentWillUnmount ( ) {
79
+ window . removeEventListener ( 'resize' , this . check ) ;
66
80
}
67
81
68
82
check ( ) {
69
83
if ( ! this . carousel ) return ;
70
84
const st = this . carousel . state ;
71
- const showLeft = Boolean ( st . currentSlide ) ;
85
+ const showLeft = st . left < 0 ;
72
86
const showRight = st . currentSlide < st . slideCount - st . slidesToScroll ;
73
- const align = st . slideCount === 'auto'
74
- || st . slidesToScroll >= st . slideCount ;
75
87
if ( showLeft === this . state . showLeft
76
- && showRight === this . state . showRight
77
- && align === this . state . align ) return ;
78
- this . setState ( { align, showLeft, showRight } ) ;
88
+ && showRight === this . state . showRight ) return ;
89
+ this . setState ( { showLeft, showRight } ) ;
79
90
}
80
91
81
92
render ( ) {
@@ -113,9 +124,7 @@ export default class Records extends React.Component {
113
124
}
114
125
115
126
return (
116
- < div
117
- style = { { display : this . state . align ? 'inline-block' : 'block' } }
118
- >
127
+ < div >
119
128
< Carousel
120
129
afterSlide = { ( ) => setImmediate ( ( ) => this . check ( ) ) }
121
130
decorators = { decorators }
@@ -126,11 +135,10 @@ export default class Records extends React.Component {
126
135
} }
127
136
slidesToScroll = "auto"
128
137
slideWidth = "200px"
129
- width = {
130
- this . state . align ? (
131
- ( 200 * this . carousel . state . slideCount ) + 200
132
- ) : '100%'
133
- }
138
+ style = { {
139
+ display : 'flex' ,
140
+ justifyContent : 'center' ,
141
+ } }
134
142
>
135
143
{
136
144
transformStats ( stats ) . map ( item => (
0 commit comments