-
Notifications
You must be signed in to change notification settings - Fork 30
/
star.js
33 lines (29 loc) · 804 Bytes
/
star.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
import React from 'react'
import PropTypes from 'prop-types'
const Star = (props) => {
const starProps = Object.assign({}, props)
const nameMap = {
isDisabled: 'is-disabled',
isActive: 'is-active',
isActiveHalf: 'is-active-half',
willBeActive: 'will-be-active'
}
const className = Object.keys(nameMap)
.filter(prop => (delete starProps[prop], props[prop]))
.map(prop => nameMap[prop])
.join(' ')
return <div className={`react-rater-star ${className}`} {...starProps}>★</div>
}
Star.defaultProps = {
willBeActive: false,
isActive: false,
isActiveHalf: false,
isDisabled: false
}
Star.propTypes = {
isActive: PropTypes.bool,
isActiveHalf: PropTypes.bool,
willBeActive: PropTypes.bool,
isDisabled: PropTypes.bool
}
export default Star