/
indicator-dots.js
45 lines (41 loc) · 987 Bytes
/
indicator-dots.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import React from 'react'
import PropTypes from 'prop-types'
function Dot (props) {
return (
<span style={{
display: 'inline-block',
height: '8px',
width: '8px',
borderRadius: '4px',
backgroundColor: 'white',
margin: '7px 5px',
opacity: props.selected ? '1' : '0.3',
transitionDuration: '300ms'
}} />
)
}
export default function IndicatorDots (props) {
const wrapperStyle = {
position: 'absolute',
width: '100%',
zIndex: '100',
bottom: '0px',
textAlign: 'center'
}
if (props.total < 2) {
// Hide dots when there is only one dot.
return <div style={wrapperStyle} />
} else {
return (
<div style={wrapperStyle}>{
Array.apply(null, Array(props.total)).map((x, i) => {
return <Dot key={i} selected={props.index === i} />
})
}</div>
)
}
}
IndicatorDots.propTypes = {
index: PropTypes.number.isRequired,
total: PropTypes.number.isRequired
}