forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreaction-picker-view.js
More file actions
66 lines (52 loc) · 1.81 KB
/
Copy pathreaction-picker-view.js
File metadata and controls
66 lines (52 loc) · 1.81 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import {reactionTypeToEmoji} from '../helpers';
const CONTENT_TYPES = Object.keys(reactionTypeToEmoji);
const EMOJI_COUNT = CONTENT_TYPES.length;
const EMOJI_PER_ROW = 4;
const EMOJI_ROWS = Math.ceil(EMOJI_COUNT / EMOJI_PER_ROW);
export default class ReactionPickerView extends React.Component {
static propTypes = {
viewerReacted: PropTypes.arrayOf(
PropTypes.oneOf(Object.keys(reactionTypeToEmoji)),
),
// Action methods
addReactionAndClose: PropTypes.func.isRequired,
removeReactionAndClose: PropTypes.func.isRequired,
}
render() {
const viewerReactedSet = new Set(this.props.viewerReacted);
const emojiRows = [];
for (let row = 0; row < EMOJI_ROWS; row++) {
const emojiButtons = [];
for (let column = 0; column < EMOJI_PER_ROW; column++) {
const emojiIndex = row * EMOJI_PER_ROW + column;
/* istanbul ignore if */
if (emojiIndex >= CONTENT_TYPES.length) {
break;
}
const content = CONTENT_TYPES[emojiIndex];
const toggle = !viewerReactedSet.has(content)
? () => this.props.addReactionAndClose(content)
: () => this.props.removeReactionAndClose(content);
const className = cx(
'github-ReactionPicker-reaction',
'btn',
{selected: viewerReactedSet.has(content)},
);
emojiButtons.push(
<button key={content} className={className} onClick={toggle}>
{reactionTypeToEmoji[content]}
</button>,
);
}
emojiRows.push(<p key={row} className="github-ReactionPicker-row inline-block-tight">{emojiButtons}</p>);
}
return (
<div className="github-ReactionPicker">
{emojiRows}
</div>
);
}
}