bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/polling/component.jsx
2018-04-13 15:56:21 -03:00

74 lines
2.3 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import Button from '/imports/ui/components/button/component';
import injectWbResizeEvent from '/imports/ui/components/presentation/resize-wrapper/component';
import { defineMessages, injectIntl } from 'react-intl';
import Tooltip from '/imports/ui/components/tooltip/component';
import { styles } from './styles.scss';
const intlMessages = defineMessages({
pollingTitleLabel: {
id: 'app.polling.pollingTitle',
description: 'Title label for polling options',
},
});
const Polling = ({ intl, poll, handleVote }) => (
<div className={styles.pollingContainer} role="alert">
<div className={styles.pollingTitle}>
{intl.formatMessage(intlMessages.pollingTitleLabel)}
</div>
<div className={styles.pollingAnswers}>
{poll.answers.map(pollAnswer => (
<div
key={pollAnswer.id}
className={styles.pollButtonWrapper}
>
<Tooltip
key={pollAnswer.id}
title={pollAnswer.key}
>
<Button
className={styles.pollingButton}
color="default"
size="lg"
label={pollAnswer.key}
onClick={() => handleVote(poll.pollId, pollAnswer)}
aria-labelledby={`pollAnswerLabel${pollAnswer.key}`}
aria-describedby={`pollAnswerDesc${pollAnswer.key}`}
/>
</Tooltip>
<div
className={styles.hidden}
id={`pollAnswerLabel${pollAnswer.key}`}
>
{`Poll answer ${pollAnswer.key}`}
</div>
<div
className={styles.hidden}
id={`pollAnswerDesc${pollAnswer.key}`}
>
{`Select this option to vote for ${pollAnswer.key}`}
</div>
</div>
))}
</div>
</div>
);
export default injectIntl(injectWbResizeEvent(Polling));
Polling.propTypes = {
intl: PropTypes.shape({
formatMessage: PropTypes.func.isRequired,
}).isRequired,
handleVote: PropTypes.func.isRequired,
poll: PropTypes.shape({
pollId: PropTypes.string.isRequired,
answers: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.number.isRequired,
key: PropTypes.string.isRequired,
}).isRequired).isRequired,
}).isRequired,
};