2017-09-26 07:45:44 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2016-06-30 06:00:06 +08:00
|
|
|
import Button from '/imports/ui/components/button/component';
|
2017-04-25 10:08:18 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-09-26 07:45:44 +08:00
|
|
|
import injectWbResizeEvent from '/imports/ui/components/presentation/resize-wrapper/component';
|
2018-01-08 14:17:18 +08:00
|
|
|
import { styles } from './styles.scss';
|
2016-05-06 02:50:18 +08:00
|
|
|
|
2017-04-25 10:08:18 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
pollingTitleLabel: {
|
|
|
|
id: 'app.polling.pollingTitle',
|
|
|
|
description: 'Title label for polling options',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-09-26 07:45:44 +08:00
|
|
|
class PollingComponent extends Component {
|
2017-03-24 05:52:36 +08:00
|
|
|
|
2016-07-01 06:21:46 +08:00
|
|
|
getStyles() {
|
|
|
|
const number = this.props.poll.answers.length + 1;
|
|
|
|
const buttonStyle =
|
|
|
|
{
|
|
|
|
width: `calc(75%/ ${number} )`,
|
|
|
|
marginLeft: `calc(25%/${number * 2})`,
|
|
|
|
marginRight: `calc(25%/${number * 2})`,
|
|
|
|
};
|
|
|
|
|
|
|
|
return buttonStyle;
|
|
|
|
}
|
|
|
|
|
2016-05-06 02:50:18 +08:00
|
|
|
render() {
|
|
|
|
const poll = this.props.poll;
|
2016-07-01 06:21:46 +08:00
|
|
|
const calculatedStyles = this.getStyles();
|
2017-04-25 10:08:18 +08:00
|
|
|
const { intl } = this.props;
|
2016-07-01 06:21:46 +08:00
|
|
|
|
2016-05-06 02:50:18 +08:00
|
|
|
return (
|
2016-06-30 06:00:06 +08:00
|
|
|
<div className={styles.pollingContainer}>
|
2016-07-01 06:21:46 +08:00
|
|
|
<div className={styles.pollingTitle}>
|
|
|
|
<p>
|
2017-04-25 10:08:18 +08:00
|
|
|
{intl.formatMessage(intlMessages.pollingTitleLabel)}
|
2016-07-01 06:21:46 +08:00
|
|
|
</p>
|
|
|
|
</div>
|
2017-09-26 07:45:44 +08:00
|
|
|
{poll.answers.map(pollAnswer =>
|
2017-06-03 03:25:02 +08:00
|
|
|
(<div
|
2017-09-26 07:45:44 +08:00
|
|
|
key={pollAnswer.id}
|
2017-03-02 06:15:44 +08:00
|
|
|
style={calculatedStyles}
|
|
|
|
className={styles.pollButtonWrapper}
|
|
|
|
>
|
2016-07-01 06:21:46 +08:00
|
|
|
<Button
|
2016-07-06 05:49:31 +08:00
|
|
|
className={styles.pollingButton}
|
|
|
|
label={pollAnswer.key}
|
2016-07-01 06:21:46 +08:00
|
|
|
size="lg"
|
|
|
|
color="primary"
|
|
|
|
onClick={() => this.props.handleVote(poll.pollId, pollAnswer)}
|
2016-07-06 05:49:31 +08:00
|
|
|
aria-labelledby={`pollAnswerLabel${pollAnswer.key}`}
|
|
|
|
aria-describedby={`pollAnswerDesc${pollAnswer.key}`}
|
|
|
|
/>
|
|
|
|
<div
|
|
|
|
className={styles.hidden}
|
|
|
|
id={`pollAnswerLabel${pollAnswer.key}`}
|
|
|
|
>
|
|
|
|
{`Poll answer ${pollAnswer.key}`}
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
className={styles.hidden}
|
|
|
|
id={`pollAnswerDesc${pollAnswer.key}`}
|
2016-07-01 06:21:46 +08:00
|
|
|
>
|
2016-07-06 05:49:31 +08:00
|
|
|
{`Select this option to vote for ${pollAnswer.key}`}
|
|
|
|
</div>
|
2017-06-03 03:25:02 +08:00
|
|
|
</div>),
|
2016-06-28 02:24:37 +08:00
|
|
|
)}
|
2016-05-06 02:50:18 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|
2017-04-25 10:08:18 +08:00
|
|
|
|
2017-09-26 07:45:44 +08:00
|
|
|
export default injectWbResizeEvent(injectIntl(PollingComponent));
|
|
|
|
|
|
|
|
PollingComponent.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,
|
|
|
|
};
|