-
Notifications
You must be signed in to change notification settings - Fork 0
/
range-input.js
86 lines (65 loc) · 1.89 KB
/
range-input.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
/* global requestAnimationFrame, cancelAnimationFrame */
import React, {useEffect, useState} from 'react';
import {styled, withStyles} from '@material-ui/core/styles';
import Slider from '@material-ui/core/Slider';
import Button from '@material-ui/core/IconButton';
import PlayIcon from '@material-ui/icons/PlayArrow';
import PauseIcon from '@material-ui/icons/Pause';
import App, {goToAmericas} from "./app.js";
import Carousel from 'react-bootstrap/Carousel';
const PositionContainer = styled('div')({
position: 'absolute',
zIndex: 1,
bottom: '40px',
width: '100%',
display: 'flex',
opacity: .2,
justifyContent: 'center',
alignItems: 'center'
});
const SliderInput = withStyles({
root: {
marginLeft: 12,
opacity: 0,
width: '40%'
},
valueLabel: {
'& span': {
whiteSpace: 'nowrap',
background: 'none',
color: '#fff'
}
}
})(Slider);
export default function RangeInput({min, max, value, animationSpeed, onChange, formatLabel}) {
const [isPlaying, setIsPlaying] = useState(false);
// prettier-ignore
useEffect(() => {
let animation;
if (isPlaying) {
animation = requestAnimationFrame(() => {
let nextValue = value + animationSpeed;
// if (nextValue > max) {
// nextValue = min;
// }
onChange(nextValue);
});
}
return () => animation && cancelAnimationFrame(animation);
});
return (
<PositionContainer>
<Button color='primary' onClick={() => setIsPlaying(!isPlaying)}>
{isPlaying ? <PauseIcon title="Stop" /> : <PlayIcon title="Animate" />}
</Button>
// <SliderInput
// min={min}
// max={max}
// value={value}
// onChange={(event, newValue) => onChange(newValue)}
// valueLabelDisplay="off"
// valueLabelFormat={formatLabel}
/>
</PositionContainer>
);
}