bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/meeting-ended/rating/component.jsx

92 lines
2.1 KiB
React
Raw Normal View History

2018-05-09 00:30:00 +08:00
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { range } from '/imports/utils/array-utils';
import { defineMessages, injectIntl } from 'react-intl';
2021-10-30 02:51:42 +08:00
import Styled from './styles';
2023-02-23 22:23:51 +08:00
import { uniqueId } from '/imports/utils/string-utils';
2018-05-09 00:30:00 +08:00
2019-05-09 23:00:17 +08:00
const intlMessages = defineMessages({
legendTitle: {
id: 'app.meeting-ended.rating.legendLabel',
description: 'label for star feedback legend',
},
2019-05-09 23:35:52 +08:00
starLabel: {
id: 'app.meeting-ended.rating.starLabel',
description: 'label for feedback stars',
},
2019-05-09 23:00:17 +08:00
});
const propTypes = {
intl: PropTypes.object.isRequired,
onRate: PropTypes.func.isRequired,
total: PropTypes.string.isRequired,
};
2018-05-09 00:30:00 +08:00
class Rating extends Component {
constructor(props) {
super(props);
this.clickStar = this.clickStar.bind(this);
}
shouldComponentUpdate() {
// when component re render lost checked item
return false;
}
clickStar(e) {
const { onRate } = this.props;
onRate(e);
2018-05-09 00:30:00 +08:00
}
renderStars(num) {
2019-05-09 23:00:17 +08:00
const { intl } = this.props;
2018-05-09 00:30:00 +08:00
return (
2021-10-30 02:51:42 +08:00
<Styled.StarRating>
2018-05-09 00:30:00 +08:00
<fieldset>
2021-10-30 02:51:42 +08:00
<Styled.Legend>{intl.formatMessage(intlMessages.legendTitle)}</Styled.Legend>
2018-05-09 00:30:00 +08:00
{
2023-06-28 21:50:02 +08:00
range(0, num)
2019-05-09 23:35:52 +08:00
.map(i => [
(
<input
type="radio"
id={`${i + 1}star`}
name="rating"
value={i + 1}
2023-02-23 22:23:51 +08:00
key={uniqueId('star-')}
2019-05-09 23:35:52 +08:00
onChange={() => this.clickStar(i + 1)}
/>
),
(
<label
htmlFor={`${i + 1}star`}
2023-02-23 22:23:51 +08:00
key={uniqueId('star-')}
aria-label={`${i + 1} ${intl.formatMessage(intlMessages.starLabel)}`}
/>
2019-05-09 23:35:52 +08:00
),
]).reverse()
2018-05-09 00:30:00 +08:00
}
</fieldset>
2021-10-30 02:51:42 +08:00
</Styled.StarRating>
2018-05-09 00:30:00 +08:00
);
}
render() {
const {
total,
} = this.props;
return (
2021-10-30 02:51:42 +08:00
<div>
2018-05-09 00:30:00 +08:00
{
this.renderStars(total)
}
</div>
);
}
}
2019-05-09 23:00:17 +08:00
export default injectIntl(Rating);
Rating.propTypes = propTypes;