forked from FormidableLabs/nuka-carousel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault-controls.js
124 lines (116 loc) · 2.64 KB
/
default-controls.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import React from 'react';
const defaultButtonStyles = disabled => ({
border: 0,
background: 'rgba(0,0,0,0.4)',
color: 'white',
padding: 10,
opacity: disabled ? 0.3 : 1,
cursor: disabled ? 'not-allowed' : 'pointer'
});
export class PreviousButton extends React.Component {
constructor() {
super(...arguments);
this.handleClick = this.handleClick.bind(this);
}
handleClick(event) {
event.preventDefault();
this.props.previousSlide();
}
render() {
const disabled =
(this.props.currentSlide === 0 && !this.props.wrapAround) ||
this.props.slideCount === 0;
return (
<button
style={defaultButtonStyles(disabled)}
disabled={disabled}
onClick={this.handleClick}
aria-label="previous"
>
PREV
</button>
);
}
}
export class NextButton extends React.Component {
constructor() {
super(...arguments);
this.handleClick = this.handleClick.bind(this);
}
handleClick(event) {
event.preventDefault();
this.props.nextSlide();
}
render() {
const disabled =
this.props.currentSlide + this.props.slidesToScroll >=
this.props.slideCount && !this.props.wrapAround;
return (
<button
style={defaultButtonStyles(disabled)}
disabled={disabled}
onClick={this.handleClick}
aria-label="next"
>
NEXT
</button>
);
}
}
export class PagingDots extends React.Component {
getIndexes(count, inc) {
const arr = [];
for (let i = 0; i < count; i += inc) {
arr.push(i);
}
return arr;
}
getListStyles() {
return {
position: 'relative',
margin: 0,
top: -10,
padding: 0
};
}
getListItemStyles() {
return {
listStyleType: 'none',
display: 'inline-block'
};
}
getButtonStyles(active) {
return {
border: 0,
background: 'transparent',
color: 'black',
cursor: 'pointer',
padding: 10,
fontSize: 24,
opacity: active ? 1 : 0.5
};
}
render() {
const indexes = this.getIndexes(
this.props.slideCount,
this.props.slidesToScroll
);
return (
<ul style={this.getListStyles()}>
{indexes.map(index => {
return (
<li style={this.getListItemStyles()} key={index}>
<button
style={this.getButtonStyles(this.props.currentSlide === index)}
onClick={this.props.goToSlide.bind(null, index)}
aria-label={`slide ${index + 1} bullet`}
>
•
</button>
</li>
);
})}
</ul>
);
}
}