forked from NebraskaJS/speaker-signup
/
Reaction.js
82 lines (76 loc) · 1.92 KB
/
Reaction.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import React from 'react';
import styled from 'react-emotion';
import { Tooltip } from 'react-tippy';
import 'react-tippy/dist/tippy.css';
import { Authentication } from '..';
import { Trigger } from './Trigger';
import { Emoji } from '..';
const Container = styled.div({
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
minHeight: 60,
padding: '0.25rem 0',
border: '1px solid #EEE',
borderLeftWidth: 0,
borderRightWidth: 0,
marginTop: 'auto',
marginBottom: '1rem',
});
const ReactionContainer = styled.div({
display: 'flex',
});
const Reactions = ({ list, onReaction }) => (
<ReactionContainer>
{list.map(name => (
<Emoji
ariaLabel="Emoji reaction"
key={name}
name={name}
interactive
onClick={() => onReaction(name)}
/>
))}
</ReactionContainer>
);
export function Reaction({ children, list }) {
return (
<Authentication>
{({ authenticate, authenticated, token }) => (
<Container>
{children}
<Tooltip
position="bottom"
trigger="click"
html={
<Reactions
list={list}
onReaction={reaction => {
if (!authenticated) {
const shouldAuthenticate = confirm(
'Adding a reaction requires logging in. Log in?'
);
if (shouldAuthenticate) {
authenticate();
}
}
}}
/>
}
animation="scale"
duration={150}
theme="light"
interactive
arrow
arrowSize="big"
>
<Trigger />
</Tooltip>
</Container>
)}
</Authentication>
);
}
Reaction.defaultProps = {
list: ['THUMBS_UP', 'THUMBS_DOWN', 'LAUGH', 'HOORAY', 'CONFUSED', 'HEART'],
};