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