Skip to content

Commit 2bb4135

Browse files
committed
Fix: Viewport-size responsiveness of the member metrics carousel
1 parent 0f6f0a3 commit 2bb4135

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

src/shared/components/Dashboard/MemberMetrics/Records/index.jsx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import Dial from './Dial';
77
import LArrow from '../../../../../assets/images/arrow-prev.svg';
88
import RArrow from '../../../../../assets/images/arrow-next.svg';
99

10+
import './style.scss';
11+
12+
/* global window */
13+
1014
/**
1115
* Transforms stats object to a more convenient array representation.
1216
* @param {Object} stats
@@ -63,19 +67,26 @@ export default class Records extends React.Component {
6367
constructor(props) {
6468
super(props);
6569
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);
6680
}
6781

6882
check() {
6983
if (!this.carousel) return;
7084
const st = this.carousel.state;
71-
const showLeft = Boolean(st.currentSlide);
85+
const showLeft = st.left < 0;
7286
const showRight = st.currentSlide < st.slideCount - st.slidesToScroll;
73-
const align = st.slideCount === 'auto'
74-
|| st.slidesToScroll >= st.slideCount;
7587
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 });
7990
}
8091

8192
render() {
@@ -113,9 +124,7 @@ export default class Records extends React.Component {
113124
}
114125

115126
return (
116-
<div
117-
style={{ display: this.state.align ? 'inline-block' : 'block' }}
118-
>
127+
<div>
119128
<Carousel
120129
afterSlide={() => setImmediate(() => this.check())}
121130
decorators={decorators}
@@ -126,11 +135,10 @@ export default class Records extends React.Component {
126135
}}
127136
slidesToScroll="auto"
128137
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+
}}
134142
>
135143
{
136144
transformStats(stats).map(item => (
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.container {
2+
display: flex;
3+
justify-content: center;
4+
}

src/shared/components/Dashboard/MemberMetrics/style.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@
5252

5353
position: absolute;
5454
right: 25px;
55-
top: 30px;
55+
top: 10px;
5656
}

src/shared/components/Dashboard/style.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
background: $tc-gray-neutral-dark;
55
flex: 1;
66
padding: 20px 30px;
7+
width: 100%;
78

89
@include xs-to-sm {
910
padding: 0;

0 commit comments

Comments
 (0)