New: Add Star Rating to Album table (#365)
parent
73157534e0
commit
18b29f8208
@ -0,0 +1,19 @@
|
||||
.starRating {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.backStar {
|
||||
position: relative;
|
||||
display: flex;
|
||||
color: #515253;
|
||||
}
|
||||
|
||||
.frontStar {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
color: #ffbc0b;
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React from 'react';
|
||||
import { icons } from 'Helpers/Props';
|
||||
import Icon from 'Components/Icon';
|
||||
import styles from './StarRating.css';
|
||||
|
||||
function StarRating({ rating, votes, iconSize }) {
|
||||
const starWidth = {
|
||||
width: `${rating * 10}%`
|
||||
};
|
||||
|
||||
const helpText = `${rating/2} (${votes} Votes)`;
|
||||
|
||||
return (
|
||||
<span className={styles.starRating} title={helpText}>
|
||||
<div className={styles.backStar}>
|
||||
<Icon name={icons.STAR_FULL} size={iconSize} />
|
||||
<Icon name={icons.STAR_FULL} size={iconSize} />
|
||||
<Icon name={icons.STAR_FULL} size={iconSize} />
|
||||
<Icon name={icons.STAR_FULL} size={iconSize} />
|
||||
<Icon name={icons.STAR_FULL} size={iconSize} />
|
||||
<div className={styles.frontStar} style={starWidth}>
|
||||
<Icon name={icons.STAR_FULL} size={iconSize} />
|
||||
<Icon name={icons.STAR_FULL} size={iconSize} />
|
||||
<Icon name={icons.STAR_FULL} size={iconSize} />
|
||||
<Icon name={icons.STAR_FULL} size={iconSize} />
|
||||
<Icon name={icons.STAR_FULL} size={iconSize} />
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
StarRating.propTypes = {
|
||||
rating: PropTypes.number.isRequired,
|
||||
votes: PropTypes.number.isRequired,
|
||||
iconSize: PropTypes.number.isRequired
|
||||
};
|
||||
|
||||
StarRating.defaultProps = {
|
||||
iconSize: 14
|
||||
};
|
||||
|
||||
export default StarRating;
|
Loading…
Reference in new issue