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 | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 19 | import { |
| 20 | Box, |
| 21 | ClickAwayListener, |
simon | 492e840 | 2022-11-29 16:48:37 -0500 | [diff] [blame] | 22 | FormControlLabel, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 23 | IconButton, |
| 24 | IconButtonProps, |
| 25 | ListItemIcon, |
| 26 | ListItemText, |
| 27 | Menu, |
| 28 | MenuItem, |
| 29 | Popper, |
| 30 | Radio, |
| 31 | RadioGroup, |
simon | 492e840 | 2022-11-29 16:48:37 -0500 | [diff] [blame] | 32 | RadioGroupProps, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 33 | SvgIconProps, |
| 34 | } from '@mui/material'; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 35 | import { styled } from '@mui/material/styles'; |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 36 | import EmojiPicker, { IEmojiData } from 'emoji-picker-react'; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 37 | import React, { ComponentType, MouseEvent, ReactNode, useCallback, useState } from 'react'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 38 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 39 | import { |
| 40 | Arrow2Icon, |
| 41 | Arrow3Icon, |
| 42 | ArrowIcon, |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 43 | AudioCallIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 44 | CameraIcon, |
| 45 | CameraInBubbleIcon, |
| 46 | CancelIcon, |
| 47 | CrossedEyeIcon, |
| 48 | CrossIcon, |
| 49 | EmojiIcon, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 50 | ExpandLessIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 51 | EyeIcon, |
| 52 | FolderIcon, |
| 53 | InfoIcon, |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 54 | ListIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 55 | MicroInBubbleIcon, |
| 56 | PaperClipIcon, |
| 57 | PenIcon, |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 58 | PeopleWithPlusSignIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 59 | SaltireIcon, |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 60 | VideoCallIcon, |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 61 | } from './SvgIcon'; |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 62 | import CustomTooltip from './Tooltip'; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 63 | |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 64 | export type ShapedButtonProps = IconButtonProps & { |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 65 | Icon: ComponentType<SvgIconProps>; |
| 66 | }; |
| 67 | |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 68 | export const RoundButton = styled(({ Icon, ...props }: ShapedButtonProps) => ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 69 | <IconButton {...props} disableRipple={true}> |
| 70 | <Icon fontSize="inherit" /> |
| 71 | </IconButton> |
| 72 | ))(({ theme }) => ({ |
| 73 | border: `1px solid ${theme.palette.primary.dark}`, |
| 74 | color: theme.palette.primary.dark, |
| 75 | fontSize: '15px', |
| 76 | '&:hover': { |
| 77 | background: theme.palette.primary.light, |
| 78 | }, |
| 79 | '&:active': { |
| 80 | color: '#FFF', |
| 81 | background: theme.palette.primary.dark, |
| 82 | }, |
| 83 | '&.MuiIconButton-sizeSmall': { |
| 84 | height: '15px', |
| 85 | width: '15px', |
| 86 | }, |
| 87 | '&.MuiIconButton-sizeMedium': { |
| 88 | height: '30px', |
| 89 | width: '30px', |
| 90 | }, |
| 91 | '&.MuiIconButton-sizeLarge': { |
| 92 | height: '53px', |
| 93 | width: '53px', |
| 94 | }, |
idillon-sfl | d5cc786 | 2022-08-25 11:11:34 -0400 | [diff] [blame] | 95 | })); |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 96 | |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 97 | type ExpandMenuOption = { |
| 98 | description: ReactNode; |
| 99 | icon?: ReactNode; |
| 100 | }; |
| 101 | |
simon | 492e840 | 2022-11-29 16:48:37 -0500 | [diff] [blame] | 102 | export type ExpandMenuRadioOption = RadioGroupProps & { |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 103 | options: { |
| 104 | key: string; |
| 105 | description: ReactNode; |
| 106 | }[]; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | export type ExpandableButtonProps = IconButtonProps & { |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 110 | isVertical?: boolean; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 111 | Icon?: ComponentType<SvgIconProps>; |
| 112 | expandMenuOptions?: (ExpandMenuOption | ExpandMenuRadioOption)[]; |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 113 | IconButtonComp?: ComponentType<IconButtonProps>; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 114 | }; |
| 115 | |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 116 | export const ExpandableButton = ({ |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 117 | isVertical, |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 118 | Icon, |
| 119 | expandMenuOptions = undefined, |
| 120 | IconButtonComp = IconButton, |
| 121 | ...props |
| 122 | }: ExpandableButtonProps) => { |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 123 | const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); |
| 124 | const handleClose = () => { |
| 125 | setAnchorEl(null); |
| 126 | }; |
| 127 | |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 128 | return ( |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 129 | <> |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 130 | {expandMenuOptions && ( |
| 131 | <Menu |
| 132 | anchorEl={anchorEl} |
| 133 | open={!!anchorEl} |
| 134 | onClose={handleClose} |
| 135 | anchorOrigin={{ |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 136 | vertical: !isVertical ? 'top' : 'center', |
| 137 | horizontal: !isVertical ? 'center' : 'left', |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 138 | }} |
| 139 | transformOrigin={{ |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 140 | vertical: !isVertical ? 'bottom' : 'center', |
| 141 | horizontal: !isVertical ? 'center' : 'right', |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 142 | }} |
| 143 | > |
| 144 | {expandMenuOptions?.map((option, id) => { |
| 145 | if ('options' in option) { |
simon | 492e840 | 2022-11-29 16:48:37 -0500 | [diff] [blame] | 146 | const { options, ...radioGroupProps } = option; |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 147 | return ( |
simon | 492e840 | 2022-11-29 16:48:37 -0500 | [diff] [blame] | 148 | <RadioGroup key={id} {...radioGroupProps}> |
| 149 | {options.map(({ description, key }, i) => ( |
| 150 | <MenuItem key={i}> |
| 151 | <FormControlLabel |
| 152 | value={key} |
| 153 | control={<Radio value={key} />} |
| 154 | label={<ListItemText>{description}</ListItemText>} |
| 155 | sx={{ |
| 156 | width: '100%', |
| 157 | }} |
| 158 | /> |
| 159 | </MenuItem> |
| 160 | ))} |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 161 | </RadioGroup> |
| 162 | ); |
| 163 | } |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 164 | |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 165 | return ( |
| 166 | <MenuItem key={id} onClick={handleClose}> |
| 167 | <ListItemIcon>{option.icon}</ListItemIcon> |
| 168 | <ListItemText>{option.description}</ListItemText> |
| 169 | </MenuItem> |
| 170 | ); |
| 171 | })} |
| 172 | </Menu> |
| 173 | )} |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 174 | <Box position="relative" display="flex" justifyContent="center" alignItems="center"> |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 175 | {expandMenuOptions && ( |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 176 | <IconButton |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 177 | aria-label="expand options" |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 178 | onClick={(e) => setAnchorEl(e.currentTarget)} |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 179 | sx={{ |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 180 | rotate: !isVertical ? '' : '-90deg', |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 181 | position: 'absolute', |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 182 | top: !isVertical ? '-55%' : 'auto', |
| 183 | left: !isVertical ? 'auto' : '-55%', |
| 184 | zIndex: 1, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 185 | }} |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 186 | className={props.className} |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 187 | > |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 188 | <ExpandLessIcon |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 189 | fontSize="small" |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 190 | sx={{ |
| 191 | backgroundColor: '#444444', |
| 192 | borderRadius: '5px', |
| 193 | }} |
| 194 | /> |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 195 | </IconButton> |
| 196 | )} |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 197 | <IconButtonComp {...props}>{Icon && <Icon />}</IconButtonComp> |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 198 | </Box> |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 199 | </> |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 200 | ); |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 201 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 202 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 203 | export const CancelPictureButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 204 | return <RoundButton {...props} aria-label="remove picture" Icon={CancelIcon} size="large" />; |
| 205 | }; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 206 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 207 | export const EditPictureButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 208 | return <RoundButton {...props} aria-label="edit picture" Icon={PenIcon} size="large" />; |
| 209 | }; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 210 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 211 | export const UploadPictureButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 212 | return <RoundButton {...props} aria-label="upload picture" Icon={FolderIcon} size="large" />; |
| 213 | }; |
idillon-sfl | 44b0534 | 2022-08-24 15:46:42 -0400 | [diff] [blame] | 214 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 215 | export const TakePictureButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 216 | return <RoundButton {...props} aria-label="take picture" Icon={CameraIcon} size="large" />; |
| 217 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 218 | |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 219 | type InfoButtonProps = IconButtonProps & { |
| 220 | tooltipTitle: string; |
| 221 | }; |
| 222 | export const InfoButton = ({ tooltipTitle, ...props }: InfoButtonProps) => { |
| 223 | return ( |
| 224 | <CustomTooltip className="tooltip" title={tooltipTitle}> |
| 225 | <RoundButton {...props} aria-label="informations" Icon={InfoIcon} size="small" /> |
| 226 | </CustomTooltip> |
| 227 | ); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 228 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 229 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 230 | export const TipButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 231 | return <RoundButton {...props} aria-label="tip" Icon={QuestionMark} size="medium" />; |
| 232 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 233 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 234 | export const MoreButton = styled((props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 235 | return ( |
| 236 | <IconButton {...props} disableRipple={true} aria-label="more"> |
| 237 | <CrossIcon fontSize="inherit" /> |
| 238 | </IconButton> |
| 239 | ); |
| 240 | })(({ theme }) => ({ |
| 241 | border: `1px solid ${theme.palette.primary.dark}`, |
| 242 | color: theme.palette.primary.dark, |
| 243 | fontSize: '10px', |
| 244 | height: '20px', |
| 245 | width: '20px', |
| 246 | '&:hover': { |
| 247 | background: theme.palette.primary.light, |
| 248 | }, |
| 249 | '&:active': { |
| 250 | color: '#FFF', |
| 251 | background: theme.palette.primary.dark, |
| 252 | }, |
| 253 | })); |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 254 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 255 | export const BackButton = styled((props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 256 | return ( |
| 257 | <IconButton {...props} disableRipple={true} aria-label="back"> |
| 258 | <ArrowIcon fontSize="inherit" /> |
| 259 | </IconButton> |
| 260 | ); |
| 261 | })(({ theme }) => ({ |
| 262 | color: theme.palette.primary.dark, |
| 263 | fontSize: '15px', |
| 264 | height: '30px', |
| 265 | width: '51px', |
| 266 | borderRadius: '5px', |
| 267 | '&:hover': { |
| 268 | background: theme.palette.primary.light, |
| 269 | }, |
| 270 | })); |
idillon | b3788bf | 2022-08-29 15:57:57 -0400 | [diff] [blame] | 271 | |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 272 | export type ToggleIconButtonProps = IconButtonProps & { |
| 273 | selected: boolean; |
| 274 | toggle: () => void; |
| 275 | IconOn?: ComponentType<SvgIconProps>; |
| 276 | IconOff?: ComponentType<SvgIconProps>; |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 277 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 278 | |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 279 | export const ToggleIconButton = ({ |
| 280 | IconOn = RadioButtonChecked, |
| 281 | IconOff = RadioButtonUnchecked, |
| 282 | selected, |
| 283 | toggle, |
| 284 | ...props |
| 285 | }: ToggleIconButtonProps) => { |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 286 | return ( |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 287 | <IconButton |
| 288 | {...props} |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 289 | sx={{ |
| 290 | color: selected ? 'white' : 'red', |
| 291 | ...props.sx, |
| 292 | }} |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 293 | onClick={() => { |
| 294 | toggle(); |
| 295 | }} |
| 296 | > |
| 297 | {selected ? <IconOn /> : <IconOff />} |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 298 | </IconButton> |
| 299 | ); |
| 300 | }; |
| 301 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 302 | export const CloseButton = styled((props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 303 | return ( |
| 304 | <IconButton {...props} disableRipple={true} aria-label="close"> |
| 305 | <SaltireIcon fontSize="inherit" /> |
| 306 | </IconButton> |
| 307 | ); |
| 308 | })(({ theme }) => ({ |
| 309 | color: theme.palette.primary.dark, |
| 310 | fontSize: '15px', |
| 311 | height: '30px', |
| 312 | width: '30px', |
| 313 | borderRadius: '5px', |
| 314 | '&:hover': { |
| 315 | background: theme.palette.primary.light, |
| 316 | }, |
| 317 | })); |
idillon | b3788bf | 2022-08-29 15:57:57 -0400 | [diff] [blame] | 318 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 319 | type ToggleVisibilityButtonProps = IconButtonProps & { |
| 320 | visible: boolean; |
| 321 | }; |
| 322 | export const ToggleVisibilityButton = styled(({ visible, ...props }: ToggleVisibilityButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 323 | const Icon = visible ? CrossedEyeIcon : EyeIcon; |
| 324 | return ( |
| 325 | <IconButton {...props} disableRipple={true}> |
| 326 | <Icon fontSize="inherit" /> |
| 327 | </IconButton> |
| 328 | ); |
| 329 | })(({ theme }) => ({ |
| 330 | color: theme.palette.primary.dark, |
| 331 | fontSize: '15px', |
| 332 | height: '15px', |
| 333 | width: '15px', |
| 334 | '&:hover': { |
| 335 | background: theme.palette.primary.light, |
| 336 | }, |
| 337 | })); |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 338 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 339 | const SquareButton = styled(({ Icon, ...props }: ShapedButtonProps) => ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 340 | <IconButton {...props} disableRipple={true}> |
| 341 | <Icon fontSize="inherit" /> |
| 342 | </IconButton> |
simon | 416d079 | 2022-11-03 02:46:18 -0400 | [diff] [blame] | 343 | ))(() => ({ |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 344 | color: '#7E7E7E', |
| 345 | fontSize: '25px', |
| 346 | height: '36px', |
| 347 | width: '36px', |
| 348 | borderRadius: '5px', |
| 349 | '&:hover': { |
| 350 | background: '#E5E5E5', |
| 351 | }, |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 352 | })); |
| 353 | |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 354 | export const AddParticipantButton = (props: IconButtonProps) => { |
| 355 | return <SquareButton {...props} aria-label="add participant" Icon={PeopleWithPlusSignIcon} />; |
| 356 | }; |
| 357 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 358 | export const RecordVideoMessageButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 359 | return <SquareButton {...props} aria-label="record video message" Icon={CameraInBubbleIcon} />; |
| 360 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 361 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 362 | export const RecordVoiceMessageButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 363 | return <SquareButton {...props} aria-label="record voice message" Icon={MicroInBubbleIcon} />; |
| 364 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 365 | |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 366 | export const ShowOptionsMenuButton = (props: IconButtonProps) => { |
| 367 | return <SquareButton {...props} aria-label="show options menu" Icon={ListIcon} />; |
| 368 | }; |
| 369 | |
| 370 | export const StartVideoCallButton = (props: IconButtonProps) => { |
simon | cd698c5 | 2022-11-08 19:21:38 -0500 | [diff] [blame] | 371 | return <SquareButton {...props} aria-label="start audio call" Icon={VideoCallIcon} />; |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 372 | }; |
| 373 | |
| 374 | export const StartAudioCallButton = (props: IconButtonProps) => { |
simon | cd698c5 | 2022-11-08 19:21:38 -0500 | [diff] [blame] | 375 | return <SquareButton {...props} aria-label="start video call" Icon={AudioCallIcon} />; |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 376 | }; |
| 377 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 378 | export const UploadFileButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 379 | return <SquareButton {...props} aria-label="upload file" Icon={PaperClipIcon} />; |
| 380 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 381 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 382 | export const SendMessageButton = (props: IconButtonProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 383 | return <SquareButton {...props} aria-label="send message" Icon={Arrow2Icon} />; |
| 384 | }; |
idillon | aedab94 | 2022-09-01 14:29:43 -0400 | [diff] [blame] | 385 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 386 | export const ReplyMessageButton = styled((props: IconButtonProps) => ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 387 | <IconButton {...props} disableRipple={true} aria-label="send message"> |
| 388 | <Arrow3Icon fontSize="inherit" /> |
| 389 | </IconButton> |
| 390 | ))(({ theme }) => ({ |
| 391 | color: theme.palette.primary.dark, |
| 392 | fontSize: '20px', |
| 393 | height: '20px', |
| 394 | width: '20px', |
| 395 | borderRadius: '5px', |
| 396 | '&:hover': { |
| 397 | background: '#E5E5E5', |
| 398 | }, |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 399 | })); |
| 400 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 401 | type EmojiButtonProps = IconButtonProps & { |
| 402 | emoji: string; |
| 403 | }; |
| 404 | export const EmojiButton = styled(({ emoji, ...props }: EmojiButtonProps) => ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 405 | <IconButton {...props} disableRipple={true}> |
| 406 | {emoji} |
| 407 | </IconButton> |
simon | 416d079 | 2022-11-03 02:46:18 -0400 | [diff] [blame] | 408 | ))(() => ({ |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 409 | color: 'white', |
| 410 | fontSize: '20px', |
| 411 | height: '20px', |
| 412 | width: '20px', |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 413 | })); |
| 414 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 415 | type SelectEmojiButtonProps = { |
| 416 | onEmojiSelected: (emoji: string) => void; |
| 417 | }; |
simon | 416d079 | 2022-11-03 02:46:18 -0400 | [diff] [blame] | 418 | export const SelectEmojiButton = ({ onEmojiSelected }: SelectEmojiButtonProps) => { |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 419 | const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null); |
idillon | 1664bb2 | 2022-09-14 17:18:15 -0400 | [diff] [blame] | 420 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 421 | const handleOpenEmojiPicker = useCallback( |
| 422 | (e: MouseEvent<HTMLButtonElement>) => setAnchorEl(anchorEl ? null : e.currentTarget), |
| 423 | [anchorEl] |
| 424 | ); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 425 | |
| 426 | const handleClose = useCallback(() => setAnchorEl(null), [setAnchorEl]); |
| 427 | |
| 428 | const onEmojiClick = useCallback( |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 429 | (e: MouseEvent, emojiObject: IEmojiData) => { |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 430 | onEmojiSelected(emojiObject.emoji); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 431 | handleClose(); |
| 432 | }, |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 433 | [handleClose, onEmojiSelected] |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 434 | ); |
| 435 | |
| 436 | const open = Boolean(anchorEl); |
| 437 | const id = open ? 'simple-popover' : undefined; |
| 438 | |
| 439 | return ( |
| 440 | <ClickAwayListener onClickAway={handleClose}> |
| 441 | <Box> |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 442 | <SquareButton |
| 443 | aria-describedby={id} |
| 444 | aria-label="select emoji" |
| 445 | Icon={EmojiIcon} |
| 446 | onClick={handleOpenEmojiPicker} |
| 447 | /> |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 448 | <Popper id={id} open={open} anchorEl={anchorEl}> |
| 449 | <EmojiPicker onEmojiClick={onEmojiClick} disableAutoFocus={true} disableSkinTonePicker={true} native /> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 450 | </Popper> |
| 451 | </Box> |
| 452 | </ClickAwayListener> |
| 453 | ); |
| 454 | }; |