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 | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame^] | 18 | import { QuestionMark, RadioButtonChecked, RadioButtonUnchecked } 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'; |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 22 | import { 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, |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 28 | AudioCallIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 29 | CameraIcon, |
| 30 | CameraInBubbleIcon, |
| 31 | CancelIcon, |
| 32 | CrossedEyeIcon, |
| 33 | CrossIcon, |
| 34 | EmojiIcon, |
| 35 | EyeIcon, |
| 36 | FolderIcon, |
| 37 | InfoIcon, |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 38 | ListIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 39 | MicroInBubbleIcon, |
| 40 | PaperClipIcon, |
| 41 | PenIcon, |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 42 | PeopleWithPlusSignIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 43 | SaltireIcon, |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 44 | VideoCallIcon, |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 45 | } from './SvgIcon'; |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 46 | import CustomTooltip from './Tooltip'; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 47 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 48 | type ShapedButtonProps = IconButtonProps & { |
| 49 | Icon: ComponentType<SvgIconProps>; |
| 50 | }; |
| 51 | |
| 52 | const RoundButton = styled(({ Icon, ...props }: ShapedButtonProps) => ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 53 | <IconButton {...props} disableRipple={true}> |
| 54 | <Icon fontSize="inherit" /> |
| 55 | </IconButton> |
| 56 | ))(({ theme }) => ({ |
| 57 | border: `1px solid ${theme.palette.primary.dark}`, |
| 58 | color: theme.palette.primary.dark, |
| 59 | fontSize: '15px', |
| 60 | '&:hover': { |
| 61 | background: theme.palette.primary.light, |
| 62 | }, |
| 63 | '&:active': { |
| 64 | color: '#FFF', |
| 65 | background: theme.palette.primary.dark, |
| 66 | }, |
| 67 | '&.MuiIconButton-sizeSmall': { |
| 68 | height: '15px', |
| 69 | width: '15px', |
| 70 | }, |
| 71 | '&.MuiIconButton-sizeMedium': { |
| 72 | height: '30px', |
| 73 | width: '30px', |
| 74 | }, |
| 75 | '&.MuiIconButton-sizeLarge': { |
| 76 | height: '53px', |
| 77 | width: '53px', |
| 78 | }, |
idillon-sfl | d5cc786 | 2022-08-25 11:11:34 -0400 | [diff] [blame] | 79 | })); |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 80 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 81 | export const CancelPictureButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 82 | return <RoundButton {...props} aria-label="remove picture" Icon={CancelIcon} size="large" />; |
| 83 | }; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 84 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 85 | export const EditPictureButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 86 | return <RoundButton {...props} aria-label="edit picture" Icon={PenIcon} size="large" />; |
| 87 | }; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 88 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 89 | export const UploadPictureButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 90 | return <RoundButton {...props} aria-label="upload picture" Icon={FolderIcon} size="large" />; |
| 91 | }; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 92 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 93 | export const TakePictureButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 94 | return <RoundButton {...props} aria-label="take picture" Icon={CameraIcon} size="large" />; |
| 95 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 96 | |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 97 | type InfoButtonProps = IconButtonProps & { |
| 98 | tooltipTitle: string; |
| 99 | }; |
| 100 | export const InfoButton = ({ tooltipTitle, ...props }: InfoButtonProps) => { |
| 101 | return ( |
| 102 | <CustomTooltip className="tooltip" title={tooltipTitle}> |
| 103 | <RoundButton {...props} aria-label="informations" Icon={InfoIcon} size="small" /> |
| 104 | </CustomTooltip> |
| 105 | ); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 106 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 107 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 108 | export const TipButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 109 | return <RoundButton {...props} aria-label="tip" Icon={QuestionMark} size="medium" />; |
| 110 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 111 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 112 | export const MoreButton = styled((props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 113 | return ( |
| 114 | <IconButton {...props} disableRipple={true} aria-label="more"> |
| 115 | <CrossIcon fontSize="inherit" /> |
| 116 | </IconButton> |
| 117 | ); |
| 118 | })(({ theme }) => ({ |
| 119 | border: `1px solid ${theme.palette.primary.dark}`, |
| 120 | color: theme.palette.primary.dark, |
| 121 | fontSize: '10px', |
| 122 | height: '20px', |
| 123 | width: '20px', |
| 124 | '&:hover': { |
| 125 | background: theme.palette.primary.light, |
| 126 | }, |
| 127 | '&:active': { |
| 128 | color: '#FFF', |
| 129 | background: theme.palette.primary.dark, |
| 130 | }, |
| 131 | })); |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 132 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 133 | export const BackButton = styled((props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 134 | return ( |
| 135 | <IconButton {...props} disableRipple={true} aria-label="back"> |
| 136 | <ArrowIcon fontSize="inherit" /> |
| 137 | </IconButton> |
| 138 | ); |
| 139 | })(({ theme }) => ({ |
| 140 | color: theme.palette.primary.dark, |
| 141 | fontSize: '15px', |
| 142 | height: '30px', |
| 143 | width: '51px', |
| 144 | borderRadius: '5px', |
| 145 | '&:hover': { |
| 146 | background: theme.palette.primary.light, |
| 147 | }, |
| 148 | })); |
idillon | b3788bf | 2022-08-29 15:57:57 -0400 | [diff] [blame] | 149 | |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame^] | 150 | export type ToggleIconButtonProps = IconButtonProps & { |
| 151 | selected: boolean; |
| 152 | toggle: () => void; |
| 153 | IconOn?: ComponentType<SvgIconProps>; |
| 154 | IconOff?: ComponentType<SvgIconProps>; |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 155 | }; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame^] | 156 | export const ToggleIconButton = ({ |
| 157 | IconOn = RadioButtonChecked, |
| 158 | IconOff = RadioButtonUnchecked, |
| 159 | selected, |
| 160 | toggle, |
| 161 | ...props |
| 162 | }: ToggleIconButtonProps) => { |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 163 | return ( |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame^] | 164 | <IconButton |
| 165 | {...props} |
| 166 | onClick={() => { |
| 167 | toggle(); |
| 168 | }} |
| 169 | > |
| 170 | {selected ? <IconOn /> : <IconOff />} |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 171 | </IconButton> |
| 172 | ); |
| 173 | }; |
| 174 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 175 | export const CloseButton = styled((props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 176 | return ( |
| 177 | <IconButton {...props} disableRipple={true} aria-label="close"> |
| 178 | <SaltireIcon fontSize="inherit" /> |
| 179 | </IconButton> |
| 180 | ); |
| 181 | })(({ theme }) => ({ |
| 182 | color: theme.palette.primary.dark, |
| 183 | fontSize: '15px', |
| 184 | height: '30px', |
| 185 | width: '30px', |
| 186 | borderRadius: '5px', |
| 187 | '&:hover': { |
| 188 | background: theme.palette.primary.light, |
| 189 | }, |
| 190 | })); |
idillon | b3788bf | 2022-08-29 15:57:57 -0400 | [diff] [blame] | 191 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 192 | type ToggleVisibilityButtonProps = IconButtonProps & { |
| 193 | visible: boolean; |
| 194 | }; |
| 195 | export const ToggleVisibilityButton = styled(({ visible, ...props }: ToggleVisibilityButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 196 | const Icon = visible ? CrossedEyeIcon : EyeIcon; |
| 197 | return ( |
| 198 | <IconButton {...props} disableRipple={true}> |
| 199 | <Icon fontSize="inherit" /> |
| 200 | </IconButton> |
| 201 | ); |
| 202 | })(({ theme }) => ({ |
| 203 | color: theme.palette.primary.dark, |
| 204 | fontSize: '15px', |
| 205 | height: '15px', |
| 206 | width: '15px', |
| 207 | '&:hover': { |
| 208 | background: theme.palette.primary.light, |
| 209 | }, |
| 210 | })); |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 211 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 212 | const SquareButton = styled(({ Icon, ...props }: ShapedButtonProps) => ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 213 | <IconButton {...props} disableRipple={true}> |
| 214 | <Icon fontSize="inherit" /> |
| 215 | </IconButton> |
| 216 | ))(({ theme }) => ({ |
| 217 | color: '#7E7E7E', |
| 218 | fontSize: '25px', |
| 219 | height: '36px', |
| 220 | width: '36px', |
| 221 | borderRadius: '5px', |
| 222 | '&:hover': { |
| 223 | background: '#E5E5E5', |
| 224 | }, |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 225 | })); |
| 226 | |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 227 | export const AddParticipantButton = (props: IconButtonProps) => { |
| 228 | return <SquareButton {...props} aria-label="add participant" Icon={PeopleWithPlusSignIcon} />; |
| 229 | }; |
| 230 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 231 | export const RecordVideoMessageButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 232 | return <SquareButton {...props} aria-label="record video message" Icon={CameraInBubbleIcon} />; |
| 233 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 234 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 235 | export const RecordVoiceMessageButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 236 | return <SquareButton {...props} aria-label="record voice message" Icon={MicroInBubbleIcon} />; |
| 237 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 238 | |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 239 | export const ShowOptionsMenuButton = (props: IconButtonProps) => { |
| 240 | return <SquareButton {...props} aria-label="show options menu" Icon={ListIcon} />; |
| 241 | }; |
| 242 | |
| 243 | export const StartVideoCallButton = (props: IconButtonProps) => { |
| 244 | return <SquareButton {...props} aria-label="start audio call" Icon={AudioCallIcon} />; |
| 245 | }; |
| 246 | |
| 247 | export const StartAudioCallButton = (props: IconButtonProps) => { |
| 248 | return <SquareButton {...props} aria-label="start video call" Icon={VideoCallIcon} />; |
| 249 | }; |
| 250 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 251 | export const UploadFileButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 252 | return <SquareButton {...props} aria-label="upload file" Icon={PaperClipIcon} />; |
| 253 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 254 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 255 | export const SendMessageButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 256 | return <SquareButton {...props} aria-label="send message" Icon={Arrow2Icon} />; |
| 257 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 258 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 259 | export const ReplyMessageButton = styled((props: IconButtonProps) => ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 260 | <IconButton {...props} disableRipple={true} aria-label="send message"> |
| 261 | <Arrow3Icon fontSize="inherit" /> |
| 262 | </IconButton> |
| 263 | ))(({ theme }) => ({ |
| 264 | color: theme.palette.primary.dark, |
| 265 | fontSize: '20px', |
| 266 | height: '20px', |
| 267 | width: '20px', |
| 268 | borderRadius: '5px', |
| 269 | '&:hover': { |
| 270 | background: '#E5E5E5', |
| 271 | }, |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 272 | })); |
| 273 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 274 | type EmojiButtonProps = IconButtonProps & { |
| 275 | emoji: string; |
| 276 | }; |
| 277 | export const EmojiButton = styled(({ emoji, ...props }: EmojiButtonProps) => ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 278 | <IconButton {...props} disableRipple={true}> |
| 279 | {emoji} |
| 280 | </IconButton> |
| 281 | ))(({ theme }) => ({ |
| 282 | color: 'white', |
| 283 | fontSize: '20px', |
| 284 | height: '20px', |
| 285 | width: '20px', |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 286 | })); |
| 287 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 288 | type SelectEmojiButtonProps = { |
| 289 | onEmojiSelected: (emoji: string) => void; |
| 290 | }; |
| 291 | export const SelectEmojiButton = ({ onEmojiSelected, ...props }: SelectEmojiButtonProps) => { |
| 292 | const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null); |
idillon | 1664bb2 | 2022-09-14 17:18:15 -0400 | [diff] [blame] | 293 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 294 | const handleOpenEmojiPicker = useCallback( |
| 295 | (e: MouseEvent<HTMLButtonElement>) => setAnchorEl(anchorEl ? null : e.currentTarget), |
| 296 | [anchorEl] |
| 297 | ); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 298 | |
| 299 | const handleClose = useCallback(() => setAnchorEl(null), [setAnchorEl]); |
| 300 | |
| 301 | const onEmojiClick = useCallback( |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 302 | (e: MouseEvent, emojiObject: IEmojiData) => { |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 303 | onEmojiSelected(emojiObject.emoji); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 304 | handleClose(); |
| 305 | }, |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 306 | [handleClose, onEmojiSelected] |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 307 | ); |
| 308 | |
| 309 | const open = Boolean(anchorEl); |
| 310 | const id = open ? 'simple-popover' : undefined; |
| 311 | |
| 312 | return ( |
| 313 | <ClickAwayListener onClickAway={handleClose}> |
| 314 | <Box> |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 315 | <SquareButton |
| 316 | aria-describedby={id} |
| 317 | aria-label="select emoji" |
| 318 | Icon={EmojiIcon} |
| 319 | onClick={handleOpenEmojiPicker} |
| 320 | /> |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 321 | <Popper id={id} open={open} anchorEl={anchorEl}> |
| 322 | <EmojiPicker onEmojiClick={onEmojiClick} disableAutoFocus={true} disableSkinTonePicker={true} native /> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 323 | </Popper> |
| 324 | </Box> |
| 325 | </ClickAwayListener> |
| 326 | ); |
| 327 | }; |