This repository was archived by the owner on Jun 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 372
Expand file tree
/
Copy pathindex.js
More file actions
64 lines (55 loc) · 1.37 KB
/
index.js
File metadata and controls
64 lines (55 loc) · 1.37 KB
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
/* eslint-disable jsx-a11y/no-static-element-interactions */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
const Container = styled.div`
height: 6px;
width: 100%;
background-color: #f7f7f7;
cursor: pointer;
margin-bottom: 5px;
`;
const Progress = styled.div`
height: 100%;
background-color: ${props => props.theme.brandPrimary};
position: relative;
padding-left: 12px;
&:after {
content: '';
height: 12px;
width: 12px;
border-radius: 10px;
position: absolute;
right: 0;
display: block;
background: #fff;
top: -3px;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
transition: height 0.5s;
}
`;
export default class Track extends Component {
static propTypes = {
progress: PropTypes.number.isRequired,
onTrackChange: PropTypes.func.isRequired
};
handleClick = (event) => {
const { onTrackChange } = this.props;
const fraction =
event.nativeEvent.offsetX / this.container.getBoundingClientRect().width;
return onTrackChange(fraction);
};
render() {
const { progress } = this.props;
return (
<Container
ref={(container) => {
this.container = container;
}}
onClick={this.handleClick}
>
<Progress style={{ width: `${progress}%` }} />
</Container>
);
}
}