-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalinComponent.jsx
76 lines (67 loc) · 1.66 KB
/
CalinComponent.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
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
'use strict';
import React, { Component } from 'react'
import PropTypes from 'prop-types'
const styles = {
disabled: {
pointerEvents: 'none'
}
};
export default class CalinComponent extends Component {
constructor (props) {
super(props);
this.state = {
hoverValue: props.value
}
}
render (color) {
const rating = [];
for (let i = 1; i <= this.props.max; i++) {
if (this.state.hoverValue > i) {
color = "row color-square horizontal";
} else {
color = "row square horizontal"
}
rating.push(
<div
key={i}
className={color}
disabled={this.props.disabled}
style={this.props.itemStyle}
onMouseEnter={() => this.setState({hoverValue: i})}
onMouseLeave={() => this.setState({hoverValue: this.props.value})}
onClick={() => {
if (!this.props.readOnly && this.props.onChange) {
this.props.onChange(i)
}
}}
>
<div className="col-xs-12 align-center top-16">
<span className="inner-squarer">{i}</span>
</div>
</div>
);
}
return (
<div
style={this.props.disabled || this.props.readOnly ? {...styles.disabled, ...this.props.style} : this.props.style}
>
{rating}
</div>
)
}
}
CalinComponent.defaultProps = {
disabled: false,
max: 5,
readOnly: false,
value: 0
};
CalinComponent.propTypes = {
className: PropTypes.string,
disabled: PropTypes.bool,
max: PropTypes.number,
onChange: PropTypes.func,
readOnly: PropTypes.bool,
style: PropTypes.object,
value: PropTypes.number
};