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