2022-09-13 07:36:00 +00:00
|
|
|
import { Theme } from '@mui/material';
|
2022-08-26 09:54:03 +00:00
|
|
|
import React, { ReactNode, useCallback } from 'react';
|
2022-10-17 09:28:04 +00:00
|
|
|
import { makeStyles } from 'tss-react/mui';
|
2020-05-20 08:25:31 +00:00
|
|
|
|
2022-08-26 09:54:03 +00:00
|
|
|
import Icon from '../../../icons/components/Icon';
|
2022-09-06 17:32:20 +00:00
|
|
|
import { IconArrowDown } from '../../../icons/svg';
|
2021-11-15 08:37:54 +00:00
|
|
|
import { withPixelLineHeight } from '../../../styles/functions.web';
|
2020-05-20 08:25:31 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
2022-08-26 09:54:03 +00:00
|
|
|
* Icon to display in the options section.
|
2020-05-20 08:25:31 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
OptionsIcon?: Function;
|
2020-05-20 08:25:31 +00:00
|
|
|
|
2021-11-15 08:37:54 +00:00
|
|
|
/**
|
2022-08-26 09:54:03 +00:00
|
|
|
* The Label of the child element.
|
2021-11-15 08:37:54 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
ariaDropDownLabel?: string;
|
2021-11-15 08:37:54 +00:00
|
|
|
|
2020-05-20 08:25:31 +00:00
|
|
|
/**
|
2022-08-26 09:54:03 +00:00
|
|
|
* The Label of the current element.
|
2020-05-20 08:25:31 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
ariaLabel?: string;
|
2020-05-20 08:25:31 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-26 09:54:03 +00:00
|
|
|
* To give a aria-pressed to the icon.
|
2020-05-20 08:25:31 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
ariaPressed?: boolean;
|
2020-05-20 08:25:31 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-26 09:54:03 +00:00
|
|
|
* Text of the button.
|
2020-05-20 08:25:31 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
children: ReactNode;
|
2020-05-20 08:25:31 +00:00
|
|
|
|
2020-09-29 11:00:30 +00:00
|
|
|
/**
|
2022-08-26 09:54:03 +00:00
|
|
|
* Text css class of the button.
|
2020-09-29 11:00:30 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
className?: string;
|
2020-09-29 11:00:30 +00:00
|
|
|
|
2020-05-20 08:25:31 +00:00
|
|
|
/**
|
2022-08-26 09:54:03 +00:00
|
|
|
* If the button is disabled or not.
|
2020-05-20 08:25:31 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
disabled?: boolean;
|
2020-05-20 08:25:31 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-26 09:54:03 +00:00
|
|
|
* If the button has options.
|
2020-05-20 08:25:31 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
hasOptions?: boolean;
|
2020-05-20 08:25:31 +00:00
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
|
2020-05-20 08:25:31 +00:00
|
|
|
/**
|
2022-08-26 09:54:03 +00:00
|
|
|
* OnClick button handler.
|
2020-05-20 08:25:31 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
onClick?: (e?: React.MouseEvent) => void;
|
2021-06-10 12:48:44 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-26 09:54:03 +00:00
|
|
|
* Click handler for options.
|
2021-06-10 12:48:44 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
onOptionsClick?: (e?: React.KeyboardEvent | React.MouseEvent) => void;
|
2021-06-10 12:48:44 +00:00
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* To give a role to the icon.
|
2021-06-10 12:48:44 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
role?: string;
|
2021-06-10 12:48:44 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-26 09:54:03 +00:00
|
|
|
* To navigate with the keyboard.
|
2021-06-10 12:48:44 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
tabIndex?: number;
|
2021-06-10 12:48:44 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-26 09:54:03 +00:00
|
|
|
* TestId of the button. Can be used to locate element when testing UI.
|
2021-06-10 12:48:44 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
testId?: string;
|
2021-06-10 12:48:44 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-26 09:54:03 +00:00
|
|
|
* The type of th button: primary, secondary, text.
|
2021-06-10 12:48:44 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
type: string;
|
2020-05-20 08:25:31 +00:00
|
|
|
};
|
|
|
|
|
2022-10-17 09:28:04 +00:00
|
|
|
const useStyles = makeStyles()((theme: Theme) => {
|
2021-11-15 08:37:54 +00:00
|
|
|
return {
|
|
|
|
actionButton: {
|
|
|
|
...withPixelLineHeight(theme.typography.bodyLongBold),
|
|
|
|
borderRadius: theme.shape.borderRadius,
|
|
|
|
boxSizing: 'border-box',
|
|
|
|
color: theme.palette.text01,
|
|
|
|
cursor: 'pointer',
|
|
|
|
display: 'inline-block',
|
|
|
|
marginBottom: '16px',
|
|
|
|
padding: '7px 16px',
|
2022-09-13 07:36:00 +00:00
|
|
|
position: 'relative' as const,
|
2021-11-15 08:37:54 +00:00
|
|
|
textAlign: 'center',
|
|
|
|
width: '100%',
|
2022-07-18 08:40:16 +00:00
|
|
|
border: 0,
|
2021-11-15 08:37:54 +00:00
|
|
|
|
|
|
|
'&.primary': {
|
|
|
|
background: theme.palette.action01,
|
2022-07-18 08:40:16 +00:00
|
|
|
color: theme.palette.text01,
|
2021-11-15 08:37:54 +00:00
|
|
|
|
|
|
|
'&:hover': {
|
|
|
|
backgroundColor: theme.palette.action01Hover
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'&.secondary': {
|
|
|
|
background: theme.palette.action02,
|
2022-07-18 08:40:16 +00:00
|
|
|
color: theme.palette.text04,
|
|
|
|
|
|
|
|
'&:hover': {
|
|
|
|
backgroundColor: theme.palette.action02Hover
|
|
|
|
}
|
2021-11-15 08:37:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
'&.text': {
|
|
|
|
width: 'auto',
|
|
|
|
fontSize: '13px',
|
|
|
|
margin: '0',
|
|
|
|
padding: '0'
|
|
|
|
},
|
|
|
|
|
|
|
|
'&.disabled': {
|
2022-07-12 12:28:20 +00:00
|
|
|
background: theme.palette.disabled01,
|
2021-11-15 08:37:54 +00:00
|
|
|
border: '1px solid #5E6D7A',
|
|
|
|
color: '#AFB6BC',
|
|
|
|
cursor: 'initial',
|
|
|
|
|
|
|
|
'.icon': {
|
|
|
|
'& > svg': {
|
|
|
|
fill: '#AFB6BC'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2022-09-13 07:36:00 +00:00
|
|
|
[theme.breakpoints.down(400)]: {
|
2021-11-15 08:37:54 +00:00
|
|
|
fontSize: 16,
|
|
|
|
marginBottom: 8,
|
|
|
|
padding: '11px 16px'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
options: {
|
2022-09-13 07:36:00 +00:00
|
|
|
borderRadius: Number(theme.shape.borderRadius) / 2,
|
2021-11-15 08:37:54 +00:00
|
|
|
alignItems: 'center',
|
|
|
|
display: 'flex',
|
|
|
|
height: '100%',
|
|
|
|
justifyContent: 'center',
|
2022-09-13 07:36:00 +00:00
|
|
|
position: 'absolute' as const,
|
2021-11-15 08:37:54 +00:00
|
|
|
right: 0,
|
|
|
|
top: 0,
|
|
|
|
width: 36,
|
|
|
|
|
|
|
|
'&:hover': {
|
|
|
|
backgroundColor: '#0262B6'
|
|
|
|
},
|
|
|
|
|
|
|
|
'& svg': {
|
|
|
|
pointerEvents: 'none'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-10-17 09:28:04 +00:00
|
|
|
});
|
2021-11-15 08:37:54 +00:00
|
|
|
|
2020-05-20 08:25:31 +00:00
|
|
|
/**
|
|
|
|
* Button used for pre meeting actions.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
function ActionButton({
|
|
|
|
children,
|
|
|
|
className = '',
|
|
|
|
disabled,
|
|
|
|
hasOptions,
|
2020-09-29 11:00:30 +00:00
|
|
|
OptionsIcon = IconArrowDown,
|
2020-07-10 15:28:57 +00:00
|
|
|
testId,
|
2020-05-20 08:25:31 +00:00
|
|
|
type = 'primary',
|
|
|
|
onClick,
|
2021-06-10 12:48:44 +00:00
|
|
|
onOptionsClick,
|
|
|
|
tabIndex,
|
|
|
|
role,
|
|
|
|
ariaPressed,
|
|
|
|
ariaLabel,
|
|
|
|
ariaDropDownLabel
|
2020-05-20 08:25:31 +00:00
|
|
|
}: Props) {
|
2022-10-17 09:28:04 +00:00
|
|
|
const { classes, cx } = useStyles();
|
2021-06-10 12:48:44 +00:00
|
|
|
|
|
|
|
const onKeyPressHandler = useCallback(e => {
|
|
|
|
if (onClick && !disabled && (e.key === ' ' || e.key === 'Enter')) {
|
|
|
|
e.preventDefault();
|
|
|
|
onClick(e);
|
|
|
|
}
|
|
|
|
}, [ onClick, disabled ]);
|
|
|
|
|
|
|
|
const onOptionsKeyPressHandler = useCallback(e => {
|
|
|
|
if (onOptionsClick && !disabled && (e.key === ' ' || e.key === 'Enter')) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
onOptionsClick(e);
|
|
|
|
}
|
|
|
|
}, [ onOptionsClick, disabled ]);
|
|
|
|
|
2022-10-17 09:28:04 +00:00
|
|
|
const containerClasses = cx(
|
2021-11-15 08:37:54 +00:00
|
|
|
classes.actionButton,
|
|
|
|
className && className,
|
|
|
|
type,
|
|
|
|
disabled && 'disabled'
|
|
|
|
);
|
|
|
|
|
2020-05-20 08:25:31 +00:00
|
|
|
return (
|
|
|
|
<div
|
2021-06-10 12:48:44 +00:00
|
|
|
aria-disabled = { disabled }
|
|
|
|
aria-label = { ariaLabel }
|
2021-11-15 08:37:54 +00:00
|
|
|
className = { containerClasses }
|
2020-07-10 15:28:57 +00:00
|
|
|
data-testid = { testId ? testId : undefined }
|
2021-06-10 12:48:44 +00:00
|
|
|
onClick = { disabled ? undefined : onClick }
|
|
|
|
onKeyPress = { onKeyPressHandler }
|
|
|
|
role = 'button'
|
|
|
|
tabIndex = { 0 } >
|
2020-05-20 08:25:31 +00:00
|
|
|
{children}
|
2021-06-10 12:48:44 +00:00
|
|
|
{ hasOptions
|
2022-10-17 09:28:04 +00:00
|
|
|
&& <div
|
|
|
|
aria-disabled = { disabled }
|
|
|
|
aria-haspopup = 'true'
|
|
|
|
aria-label = { ariaDropDownLabel }
|
|
|
|
aria-pressed = { ariaPressed }
|
|
|
|
className = { classes.options }
|
|
|
|
data-testid = 'prejoin.joinOptions'
|
|
|
|
onClick = { disabled ? undefined : onOptionsClick }
|
|
|
|
onKeyPress = { onOptionsKeyPressHandler }
|
|
|
|
role = { role }
|
|
|
|
tabIndex = { tabIndex }>
|
|
|
|
<Icon
|
|
|
|
className = 'icon'
|
|
|
|
size = { 14 }
|
|
|
|
src = { OptionsIcon } />
|
|
|
|
</div>
|
2020-05-20 08:25:31 +00:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-17 09:28:04 +00:00
|
|
|
export default ActionButton;
|