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