-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathEmojiPickerButtonDropdown.tsx
105 lines (98 loc) · 4.15 KB
/
EmojiPickerButtonDropdown.tsx
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import React, {useEffect, useRef} from 'react';
import type {ForwardedRef} from 'react';
import {View} from 'react-native';
import type {StyleProp, ViewStyle} from 'react-native';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
import type {AnimatedTextInputRef} from '@components/RNTextInput';
import Text from '@components/Text';
import Tooltip from '@components/Tooltip/PopoverAnchorTooltip';
import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import getButtonState from '@libs/getButtonState';
import * as EmojiPickerAction from '@userActions/EmojiPickerAction';
import CONST from '@src/CONST';
type EmojiPickerButtonDropdownProps = {
/** Flag to disable the emoji picker button */
isDisabled?: boolean;
accessibilityLabel?: string;
role?: string;
onModalHide: EmojiPickerAction.OnModalHideValue;
onInputChange: (emoji: string) => void;
value?: string;
disabled?: boolean;
style: StyleProp<ViewStyle>;
};
function EmojiPickerButtonDropdown(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
{isDisabled = false, onModalHide, onInputChange, value, disabled, style, ...otherProps}: EmojiPickerButtonDropdownProps,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
ref: ForwardedRef<AnimatedTextInputRef>,
) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const emojiPopoverAnchor = useRef(null);
const {translate} = useLocalize();
useEffect(() => EmojiPickerAction.resetEmojiPopoverAnchor, []);
const onPress = () => {
if (EmojiPickerAction.isEmojiPickerVisible()) {
EmojiPickerAction.hideEmojiPicker();
return;
}
EmojiPickerAction.showEmojiPicker(
onModalHide,
(emoji) => onInputChange(emoji),
emojiPopoverAnchor,
{
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP,
shiftVertical: 4,
},
() => {},
undefined,
value,
);
};
return (
<Tooltip text={translate('reportActionCompose.emoji')}>
<PressableWithoutFeedback
ref={emojiPopoverAnchor}
style={[styles.emojiPickerButtonDropdown, style]}
disabled={isDisabled}
onPress={onPress}
id="emojiDropdownButton"
accessibilityLabel="statusEmoji"
role={CONST.ROLE.BUTTON}
>
{({hovered, pressed}) => (
<View style={styles.emojiPickerButtonDropdownContainer}>
<Text
style={styles.emojiPickerButtonDropdownIcon}
numberOfLines={1}
>
{
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
value || (
<Icon
src={Expensicons.Emoji}
fill={StyleUtils.getIconFillColor(CONST.BUTTON_STATES.DISABLED)}
/>
)
}
</Text>
<View style={[styles.popoverMenuIcon, styles.pointerEventsAuto, disabled && styles.cursorDisabled, styles.rotate90]}>
<Icon
src={Expensicons.ArrowRight}
fill={StyleUtils.getIconFillColor(getButtonState(hovered, pressed))}
/>
</View>
</View>
)}
</PressableWithoutFeedback>
</Tooltip>
);
}
EmojiPickerButtonDropdown.displayName = 'EmojiPickerButtonDropdown';
export default React.forwardRef(EmojiPickerButtonDropdown);