simon | 26e79f7 | 2022-10-05 22:16:08 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 Savoir-faire Linux Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Affero General Public License as |
| 6 | * published by the Free Software Foundation; either version 3 of the |
| 7 | * License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Affero General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Affero General Public |
| 15 | * License along with this program. If not, see |
| 16 | * <https://www.gnu.org/licenses/>. |
| 17 | */ |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 18 | import { QuestionMark } from '@mui/icons-material'; |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 19 | import { Box, ClickAwayListener, IconButton, IconButtonProps, Popper, SvgIconProps } from '@mui/material'; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 20 | import { styled } from '@mui/material/styles'; |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 21 | import EmojiPicker, { IEmojiData } from 'emoji-picker-react'; |
| 22 | import React, { ComponentType, MouseEvent, useCallback, useState } from 'react'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 23 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 24 | import { |
| 25 | Arrow2Icon, |
| 26 | Arrow3Icon, |
| 27 | ArrowIcon, |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 28 | CallEndIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 29 | CameraIcon, |
| 30 | CameraInBubbleIcon, |
| 31 | CancelIcon, |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 32 | ChatBubbleIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 33 | CrossedEyeIcon, |
| 34 | CrossIcon, |
| 35 | EmojiIcon, |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 36 | ExtensionIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 37 | EyeIcon, |
| 38 | FolderIcon, |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 39 | FullscreenIcon, |
| 40 | GroupAddIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 41 | InfoIcon, |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 42 | MicroIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 43 | MicroInBubbleIcon, |
| 44 | PaperClipIcon, |
| 45 | PenIcon, |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 46 | RecordingIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 47 | SaltireIcon, |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 48 | ScreenShareIcon, |
| 49 | VideoCameraIcon, |
| 50 | VolumeIcon, |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 51 | } from './SvgIcon'; |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame^] | 52 | import CustomTooltip from './Tooltip'; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 53 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 54 | type ShapedButtonProps = IconButtonProps & { |
| 55 | Icon: ComponentType<SvgIconProps>; |
| 56 | }; |
| 57 | |
| 58 | const RoundButton = styled(({ Icon, ...props }: ShapedButtonProps) => ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 59 | <IconButton {...props} disableRipple={true}> |
| 60 | <Icon fontSize="inherit" /> |
| 61 | </IconButton> |
| 62 | ))(({ theme }) => ({ |
| 63 | border: `1px solid ${theme.palette.primary.dark}`, |
| 64 | color: theme.palette.primary.dark, |
| 65 | fontSize: '15px', |
| 66 | '&:hover': { |
| 67 | background: theme.palette.primary.light, |
| 68 | }, |
| 69 | '&:active': { |
| 70 | color: '#FFF', |
| 71 | background: theme.palette.primary.dark, |
| 72 | }, |
| 73 | '&.MuiIconButton-sizeSmall': { |
| 74 | height: '15px', |
| 75 | width: '15px', |
| 76 | }, |
| 77 | '&.MuiIconButton-sizeMedium': { |
| 78 | height: '30px', |
| 79 | width: '30px', |
| 80 | }, |
| 81 | '&.MuiIconButton-sizeLarge': { |
| 82 | height: '53px', |
| 83 | width: '53px', |
| 84 | }, |
idillon-sfl | d5cc786 | 2022-08-25 11:11:34 -0400 | [diff] [blame] | 85 | })); |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 86 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 87 | export const CancelPictureButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 88 | return <RoundButton {...props} aria-label="remove picture" Icon={CancelIcon} size="large" />; |
| 89 | }; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 90 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 91 | export const EditPictureButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 92 | return <RoundButton {...props} aria-label="edit picture" Icon={PenIcon} size="large" />; |
| 93 | }; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 94 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 95 | export const UploadPictureButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 96 | return <RoundButton {...props} aria-label="upload picture" Icon={FolderIcon} size="large" />; |
| 97 | }; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 98 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 99 | export const TakePictureButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 100 | return <RoundButton {...props} aria-label="take picture" Icon={CameraIcon} size="large" />; |
| 101 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 102 | |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame^] | 103 | type InfoButtonProps = IconButtonProps & { |
| 104 | tooltipTitle: string; |
| 105 | }; |
| 106 | export const InfoButton = ({ tooltipTitle, ...props }: InfoButtonProps) => { |
| 107 | return ( |
| 108 | <CustomTooltip className="tooltip" title={tooltipTitle}> |
| 109 | <RoundButton {...props} aria-label="informations" Icon={InfoIcon} size="small" /> |
| 110 | </CustomTooltip> |
| 111 | ); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 112 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 113 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 114 | export const TipButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 115 | return <RoundButton {...props} aria-label="tip" Icon={QuestionMark} size="medium" />; |
| 116 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 117 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 118 | export const MoreButton = styled((props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 119 | return ( |
| 120 | <IconButton {...props} disableRipple={true} aria-label="more"> |
| 121 | <CrossIcon fontSize="inherit" /> |
| 122 | </IconButton> |
| 123 | ); |
| 124 | })(({ theme }) => ({ |
| 125 | border: `1px solid ${theme.palette.primary.dark}`, |
| 126 | color: theme.palette.primary.dark, |
| 127 | fontSize: '10px', |
| 128 | height: '20px', |
| 129 | width: '20px', |
| 130 | '&:hover': { |
| 131 | background: theme.palette.primary.light, |
| 132 | }, |
| 133 | '&:active': { |
| 134 | color: '#FFF', |
| 135 | background: theme.palette.primary.dark, |
| 136 | }, |
| 137 | })); |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 138 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 139 | export const BackButton = styled((props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 140 | return ( |
| 141 | <IconButton {...props} disableRipple={true} aria-label="back"> |
| 142 | <ArrowIcon fontSize="inherit" /> |
| 143 | </IconButton> |
| 144 | ); |
| 145 | })(({ theme }) => ({ |
| 146 | color: theme.palette.primary.dark, |
| 147 | fontSize: '15px', |
| 148 | height: '30px', |
| 149 | width: '51px', |
| 150 | borderRadius: '5px', |
| 151 | '&:hover': { |
| 152 | background: theme.palette.primary.light, |
| 153 | }, |
| 154 | })); |
idillon | b3788bf | 2022-08-29 15:57:57 -0400 | [diff] [blame] | 155 | |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 156 | export const CallingChatButton = (props: IconButtonProps) => { |
| 157 | return ( |
| 158 | <IconButton {...props} aria-label="chat" sx={{ color: 'white' }}> |
| 159 | <ChatBubbleIcon /> |
| 160 | </IconButton> |
| 161 | ); |
| 162 | }; |
| 163 | |
| 164 | export const CallingEndButton = (props: IconButtonProps) => { |
| 165 | return ( |
| 166 | <IconButton {...props} aria-label="end call" sx={{ color: 'white', backgroundColor: 'red' }}> |
| 167 | <CallEndIcon /> |
| 168 | </IconButton> |
| 169 | ); |
| 170 | }; |
| 171 | |
| 172 | export const CallingExtensionButton = (props: IconButtonProps) => { |
| 173 | return ( |
| 174 | <IconButton {...props} aria-label="extensions" sx={{ color: 'white' }}> |
| 175 | <ExtensionIcon /> |
| 176 | </IconButton> |
| 177 | ); |
| 178 | }; |
| 179 | |
| 180 | export const CallingFullscreenButton = (props: IconButtonProps) => { |
| 181 | return ( |
| 182 | <IconButton {...props} aria-label="fullscreen" sx={{ color: 'white' }}> |
| 183 | <FullscreenIcon /> |
| 184 | </IconButton> |
| 185 | ); |
| 186 | }; |
| 187 | |
| 188 | export const CallingGroupButton = (props: IconButtonProps) => { |
| 189 | return ( |
| 190 | <IconButton {...props} aria-label="group options" sx={{ color: 'white' }}> |
| 191 | <GroupAddIcon /> |
| 192 | </IconButton> |
| 193 | ); |
| 194 | }; |
| 195 | |
| 196 | export const CallingMicButton = (props: IconButtonProps) => { |
| 197 | return ( |
| 198 | <IconButton {...props} aria-label="microphone options" sx={{ color: 'white' }}> |
| 199 | <MicroIcon /> |
| 200 | </IconButton> |
| 201 | ); |
| 202 | }; |
| 203 | |
| 204 | export const CallingRecordButton = (props: IconButtonProps) => { |
| 205 | return ( |
| 206 | <IconButton {...props} aria-label="recording options" sx={{ color: 'white' }}> |
| 207 | <RecordingIcon /> |
| 208 | </IconButton> |
| 209 | ); |
| 210 | }; |
| 211 | |
| 212 | export const CallingScreenShareButton = (props: IconButtonProps) => { |
| 213 | return ( |
| 214 | <IconButton {...props} aria-label="screen share" sx={{ color: 'white' }}> |
| 215 | <ScreenShareIcon /> |
| 216 | </IconButton> |
| 217 | ); |
| 218 | }; |
| 219 | |
| 220 | export const CallingVideoCameraButton = (props: IconButtonProps) => { |
| 221 | return ( |
| 222 | <IconButton {...props} aria-label="camera options" sx={{ color: 'white' }}> |
| 223 | <VideoCameraIcon /> |
| 224 | </IconButton> |
| 225 | ); |
| 226 | }; |
| 227 | export const CallingVolumeButton = (props: IconButtonProps) => { |
| 228 | return ( |
| 229 | <IconButton {...props} aria-label="volume options" sx={{ color: 'white' }}> |
| 230 | <VolumeIcon /> |
| 231 | </IconButton> |
| 232 | ); |
| 233 | }; |
| 234 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 235 | export const CloseButton = styled((props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 236 | return ( |
| 237 | <IconButton {...props} disableRipple={true} aria-label="close"> |
| 238 | <SaltireIcon fontSize="inherit" /> |
| 239 | </IconButton> |
| 240 | ); |
| 241 | })(({ theme }) => ({ |
| 242 | color: theme.palette.primary.dark, |
| 243 | fontSize: '15px', |
| 244 | height: '30px', |
| 245 | width: '30px', |
| 246 | borderRadius: '5px', |
| 247 | '&:hover': { |
| 248 | background: theme.palette.primary.light, |
| 249 | }, |
| 250 | })); |
idillon | b3788bf | 2022-08-29 15:57:57 -0400 | [diff] [blame] | 251 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 252 | type ToggleVisibilityButtonProps = IconButtonProps & { |
| 253 | visible: boolean; |
| 254 | }; |
| 255 | export const ToggleVisibilityButton = styled(({ visible, ...props }: ToggleVisibilityButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 256 | const Icon = visible ? CrossedEyeIcon : EyeIcon; |
| 257 | return ( |
| 258 | <IconButton {...props} disableRipple={true}> |
| 259 | <Icon fontSize="inherit" /> |
| 260 | </IconButton> |
| 261 | ); |
| 262 | })(({ theme }) => ({ |
| 263 | color: theme.palette.primary.dark, |
| 264 | fontSize: '15px', |
| 265 | height: '15px', |
| 266 | width: '15px', |
| 267 | '&:hover': { |
| 268 | background: theme.palette.primary.light, |
| 269 | }, |
| 270 | })); |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 271 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 272 | const SquareButton = styled(({ Icon, ...props }: ShapedButtonProps) => ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 273 | <IconButton {...props} disableRipple={true}> |
| 274 | <Icon fontSize="inherit" /> |
| 275 | </IconButton> |
| 276 | ))(({ theme }) => ({ |
| 277 | color: '#7E7E7E', |
| 278 | fontSize: '25px', |
| 279 | height: '36px', |
| 280 | width: '36px', |
| 281 | borderRadius: '5px', |
| 282 | '&:hover': { |
| 283 | background: '#E5E5E5', |
| 284 | }, |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 285 | })); |
| 286 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 287 | export const RecordVideoMessageButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 288 | return <SquareButton {...props} aria-label="record video message" Icon={CameraInBubbleIcon} />; |
| 289 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 290 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 291 | export const RecordVoiceMessageButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 292 | return <SquareButton {...props} aria-label="record voice message" Icon={MicroInBubbleIcon} />; |
| 293 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 294 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 295 | export const UploadFileButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 296 | return <SquareButton {...props} aria-label="upload file" Icon={PaperClipIcon} />; |
| 297 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 298 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 299 | export const SendMessageButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 300 | return <SquareButton {...props} aria-label="send message" Icon={Arrow2Icon} />; |
| 301 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 302 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 303 | export const ReplyMessageButton = styled((props: IconButtonProps) => ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 304 | <IconButton {...props} disableRipple={true} aria-label="send message"> |
| 305 | <Arrow3Icon fontSize="inherit" /> |
| 306 | </IconButton> |
| 307 | ))(({ theme }) => ({ |
| 308 | color: theme.palette.primary.dark, |
| 309 | fontSize: '20px', |
| 310 | height: '20px', |
| 311 | width: '20px', |
| 312 | borderRadius: '5px', |
| 313 | '&:hover': { |
| 314 | background: '#E5E5E5', |
| 315 | }, |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 316 | })); |
| 317 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 318 | type EmojiButtonProps = IconButtonProps & { |
| 319 | emoji: string; |
| 320 | }; |
| 321 | export const EmojiButton = styled(({ emoji, ...props }: EmojiButtonProps) => ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 322 | <IconButton {...props} disableRipple={true}> |
| 323 | {emoji} |
| 324 | </IconButton> |
| 325 | ))(({ theme }) => ({ |
| 326 | color: 'white', |
| 327 | fontSize: '20px', |
| 328 | height: '20px', |
| 329 | width: '20px', |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 330 | })); |
| 331 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 332 | type SelectEmojiButtonProps = { |
| 333 | onEmojiSelected: (emoji: string) => void; |
| 334 | }; |
| 335 | export const SelectEmojiButton = ({ onEmojiSelected, ...props }: SelectEmojiButtonProps) => { |
| 336 | const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null); |
idillon | 1664bb2 | 2022-09-14 17:18:15 -0400 | [diff] [blame] | 337 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 338 | const handleOpenEmojiPicker = useCallback( |
| 339 | (e: MouseEvent<HTMLButtonElement>) => setAnchorEl(anchorEl ? null : e.currentTarget), |
| 340 | [anchorEl] |
| 341 | ); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 342 | |
| 343 | const handleClose = useCallback(() => setAnchorEl(null), [setAnchorEl]); |
| 344 | |
| 345 | const onEmojiClick = useCallback( |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 346 | (e: MouseEvent, emojiObject: IEmojiData) => { |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 347 | onEmojiSelected(emojiObject.emoji); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 348 | handleClose(); |
| 349 | }, |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 350 | [handleClose, onEmojiSelected] |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 351 | ); |
| 352 | |
| 353 | const open = Boolean(anchorEl); |
| 354 | const id = open ? 'simple-popover' : undefined; |
| 355 | |
| 356 | return ( |
| 357 | <ClickAwayListener onClickAway={handleClose}> |
| 358 | <Box> |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 359 | <SquareButton aria-describedby={id} aria-label="select emoji" Icon={EmojiIcon} onClick={(e) => {}} /> |
| 360 | <Popper id={id} open={open} anchorEl={anchorEl}> |
| 361 | <EmojiPicker onEmojiClick={onEmojiClick} disableAutoFocus={true} disableSkinTonePicker={true} native /> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 362 | </Popper> |
| 363 | </Box> |
| 364 | </ClickAwayListener> |
| 365 | ); |
| 366 | }; |