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