-
Notifications
You must be signed in to change notification settings - Fork 3k
/
index.js
67 lines (57 loc) · 2.16 KB
/
index.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
import React, {forwardRef, useImperativeHandle, useRef, useState} from 'react';
import PropTypes from 'prop-types';
import BasePopoverReactionList from './BasePopoverReactionList';
const propTypes = {
innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
};
const defaultProps = {
innerRef: () => {},
};
function PopoverReactionList(props) {
const innerReactionListRef = useRef();
const [reactionListReportActionID, setReactionListReportActionID] = useState('');
const [reactionListEmojiName, setReactionListEmojiName] = useState('');
/**
* Show the ReactionList modal popover.
*
* @param {Object} [event] - A press event.
* @param {Element} reactionListAnchor - reactionListAnchor
* @param {String} emojiName - Name of emoji
* @param {String} reportActionID - ID of the report action
*/
const showReactionList = (event, reactionListAnchor, emojiName, reportActionID) => {
setReactionListReportActionID(reportActionID);
setReactionListEmojiName(emojiName);
innerReactionListRef.current.showReactionList(event, reactionListAnchor);
};
const hideReactionList = () => {
innerReactionListRef.current.hideReactionList();
};
/**
* Whether PopoverReactionList is active for the Report Action.
*
* @param {Number|String} actionID
* @return {Boolean}
*/
const isActiveReportAction = (actionID) => Boolean(actionID) && reactionListReportActionID === actionID;
useImperativeHandle(props.innerRef, () => ({showReactionList, hideReactionList, isActiveReportAction}));
return (
<BasePopoverReactionList
ref={innerReactionListRef}
reportActionID={reactionListReportActionID}
emojiName={reactionListEmojiName}
/>
);
}
PopoverReactionList.propTypes = propTypes;
PopoverReactionList.defaultProps = defaultProps;
PopoverReactionList.displayName = 'PopoverReactionList';
export default React.memo(
forwardRef((props, ref) => (
<PopoverReactionList
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
innerRef={ref}
/>
)),
);