-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarousel.jsx
48 lines (45 loc) · 1.42 KB
/
carousel.jsx
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
46
47
48
"use strict";
class Carousel extends React.Component {
render(){
let slides = this.props.image_urls.map(function(source, index){
let props = {
key: index,
index: index,
imgSrc: source
}
return <Slide {...props}/>;
});
return (
<div id="myCarousel" className="carousel slide" data-ride="carousel">
<div className="carousel-inner" role="listbox">
{ [] }
{ slides }
</div>
<a className="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span className="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
</a>
<a className="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span className="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
</a>
</div>
);
}
}
Carousel.propTypes = { image_urls: React.PropTypes.array };
Carousel.defaultProps = { image_urls: [] };
class Slide extends React.Component {
render(){
let className = this.props.index == 0? 'item active' : 'item';
return(
<div className={ className }>
<img src={ this.props.imgSrc } alt="..." width="100%"/>
</div>
);
}
}
function renderCarouselatNode(images, node){
return ReactDOM.render(
<Carousel image_urls={ images }/>,
document.getElementById(node)
);
}