-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathSessionEmojiPanel.tsx
More file actions
143 lines (130 loc) · 4.4 KB
/
SessionEmojiPanel.tsx
File metadata and controls
143 lines (130 loc) · 4.4 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import Picker from '@emoji-mart/react';
import { type RefObject } from 'react';
import styled from 'styled-components';
import { usePrimaryColor } from '../../state/selectors/primaryColor';
import { useIsDarkTheme, useTheme } from '../../state/theme/selectors/theme';
import { COLORS, THEMES, ThemeStateType, type ColorsType } from '../../themes/constants/colors';
import { FixedBaseEmoji } from '../../types/Reaction';
import { i18nEmojiData } from '../../util/emoji';
import { hexColorToRGB } from '../../util/hexColorToRGB';
import { SessionFocusTrap } from '../SessionFocusTrap';
export const StyledEmojiPanel = styled.div<{
$isModal: boolean;
$primaryColor: string;
$theme: ThemeStateType;
$panelBackgroundRGB: string;
$panelTextRGB: string;
}>`
${props => (!props.$isModal ? 'padding: var(--margins-lg);' : '')}
z-index: 5;
button:focus {
outline: none;
}
em-emoji-picker {
${props => props.$panelBackgroundRGB && `background-color: rgb(${props.$panelBackgroundRGB})`};
border: var(--default-borders);
padding-bottom: var(--margins-sm);
--font-family: var(--font-default);
--font-size: var(--font-size-sm);
--shadow: none;
--border-radius: 8px;
--color-border: var(--borders-color);
--color-border-over: var(--borders-color);
--background-rgb: ${props => props.$panelBackgroundRGB};
--rgb-background: ${props => props.$panelBackgroundRGB};
--rgb-color: ${props => props.$panelTextRGB};
--rgb-input: ${props => props.$panelBackgroundRGB};
--rgb-accent: ${props => props.$primaryColor};
${props =>
!props.$isModal &&
`
&:after {
content: '';
position: absolute;
top: calc(100% - 40px);
left: calc(100% - 106px);
width: 22px;
height: 22px;
transform: rotate(45deg);
border-radius: 3px;
transform: scaleY(1.4) rotate(45deg);
border: 0.7px solid var(--borders-color);
clip-path: polygon(100% 100%, 7.2px 100%, 100% 7.2px);
${props.$panelBackgroundRGB && `background-color: rgb(${props.$panelBackgroundRGB})`};
[dir='rtl'] & {
left: 75px;
}
}
`};
}
`;
type Props = {
ref?: RefObject<HTMLDivElement | null>;
onEmojiClicked: (emoji: FixedBaseEmoji) => void;
isModal?: boolean;
onClose?: () => void;
show: boolean;
};
export const SessionEmojiPanel = (props: Props) => {
return props.show ? <EmojiPanel {...props} /> : null;
};
const EmojiPanel = ({ ref, onEmojiClicked, isModal = false, onClose }: Props) => {
const _primaryColor = usePrimaryColor();
const theme = useTheme();
const isDarkTheme = useIsDarkTheme();
let panelBackgroundRGB = hexColorToRGB(THEMES.CLASSIC_DARK.COLOR1);
let panelTextRGB = hexColorToRGB(THEMES.CLASSIC_DARK.COLOR6);
switch (theme) {
case 'ocean-dark':
panelBackgroundRGB = hexColorToRGB(THEMES.OCEAN_DARK.COLOR1);
panelTextRGB = hexColorToRGB(THEMES.OCEAN_DARK.COLOR7!);
break;
case 'ocean-light':
panelBackgroundRGB = hexColorToRGB(THEMES.OCEAN_LIGHT.COLOR7!);
panelTextRGB = hexColorToRGB(THEMES.OCEAN_LIGHT.COLOR1);
break;
case 'classic-light':
panelBackgroundRGB = hexColorToRGB(THEMES.CLASSIC_LIGHT.COLOR6);
panelTextRGB = hexColorToRGB(THEMES.CLASSIC_LIGHT.COLOR0);
break;
case 'classic-dark':
default:
panelBackgroundRGB = hexColorToRGB(THEMES.CLASSIC_DARK.COLOR1);
panelTextRGB = hexColorToRGB(THEMES.CLASSIC_DARK.COLOR6);
}
const primaryColor = !isDarkTheme
? panelTextRGB
: hexColorToRGB(
_primaryColor
? COLORS.PRIMARY[`${_primaryColor.toUpperCase() as keyof ColorsType['PRIMARY']}`]
: COLORS.PRIMARY.GREEN
);
return (
<SessionFocusTrap
focusTrapId="SessionEmojiPanel"
clickOutsideDeactivates={true}
allowNoTabbableNodes={true}
onDeactivate={onClose}
>
<StyledEmojiPanel
$isModal={isModal}
$primaryColor={primaryColor}
$theme={theme}
$panelBackgroundRGB={panelBackgroundRGB}
$panelTextRGB={panelTextRGB}
ref={ref}
>
<Picker
theme={isDarkTheme ? 'dark' : 'light'}
i18n={i18nEmojiData}
onEmojiSelect={onEmojiClicked}
onClose={onClose}
title=""
showPreview={true}
skinTonePosition={'preview'}
autoFocus={true}
/>
</StyledEmojiPanel>
</SessionFocusTrap>
);
};