2020-05-20 08:25:31 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-11-15 08:37:54 +00:00
|
|
|
import { withStyles } from '@material-ui/styles';
|
|
|
|
import clsx from 'clsx';
|
2021-06-10 12:48:44 +00:00
|
|
|
import React, { useCallback } from 'react';
|
2020-05-20 08:25:31 +00:00
|
|
|
|
|
|
|
import { Icon, IconArrowDown } from '../../../icons';
|
2021-11-15 08:37:54 +00:00
|
|
|
import { withPixelLineHeight } from '../../../styles/functions.web';
|
2020-05-20 08:25:31 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Text of the button.
|
|
|
|
*/
|
|
|
|
children: React$Node,
|
|
|
|
|
2021-11-15 08:37:54 +00:00
|
|
|
/**
|
|
|
|
* An object containing the CSS classes.
|
|
|
|
*/
|
|
|
|
classes: Object,
|
|
|
|
|
2020-05-20 08:25:31 +00:00
|
|
|
/**
|
|
|
|
* Text css class of the button.
|
|
|
|
*/
|
|
|
|
className?: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the button is disabled or not.
|
|
|
|
*/
|
|
|
|
disabled?: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the button has options.
|
|
|
|
*/
|
|
|
|
hasOptions?: boolean,
|
|
|
|
|
2020-09-29 11:00:30 +00:00
|
|
|
/**
|
|
|
|
* Icon to display in the options section.
|
|
|
|
*/
|
|
|
|
OptionsIcon?: React$Node,
|
|
|
|
|
2020-07-10 15:28:57 +00:00
|
|
|
/**
|
|
|
|
* TestId of the button. Can be used to locate element when testing UI.
|
|
|
|
*/
|
|
|
|
testId?: string,
|
|
|
|
|
2020-05-20 08:25:31 +00:00
|
|
|
/**
|
|
|
|
* The type of th button: primary, secondary, text.
|
|
|
|
*/
|
|
|
|
type: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* OnClick button handler.
|
|
|
|
*/
|
|
|
|
onClick: Function,
|
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
|
2020-05-20 08:25:31 +00:00
|
|
|
/**
|
|
|
|
* Click handler for options.
|
|
|
|
*/
|
2021-06-10 12:48:44 +00:00
|
|
|
onOptionsClick?: Function,
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* To navigate with the keyboard.
|
2021-06-10 12:48:44 +00:00
|
|
|
*/
|
|
|
|
tabIndex?: number,
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* To give a role to the icon.
|
2021-06-10 12:48:44 +00:00
|
|
|
*/
|
|
|
|
role?: string,
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* To give a aria-pressed to the icon.
|
2021-06-10 12:48:44 +00:00
|
|
|
*/
|
|
|
|
ariaPressed?: boolean,
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* The Label of the current element.
|
2021-06-10 12:48:44 +00:00
|
|
|
*/
|
|
|
|
ariaLabel?: string,
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* The Label of the child element.
|
2021-06-10 12:48:44 +00:00
|
|
|
*/
|
|
|
|
ariaDropDownLabel?: string
|
2020-05-20 08:25:31 +00:00
|
|
|
};
|
|
|
|
|
2021-11-15 08:37:54 +00:00
|
|
|
/**
|
|
|
|
* Creates the styles for the component.
|
|
|
|
*
|
|
|
|
* @param {Object} theme - The current UI theme.
|
|
|
|
*
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
const styles = theme => {
|
|
|
|
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',
|
|
|
|
position: 'relative',
|
|
|
|
textAlign: 'center',
|
|
|
|
width: '100%',
|
|
|
|
|
|
|
|
'&.primary': {
|
|
|
|
background: theme.palette.action01,
|
|
|
|
border: '1px solid #0376DA',
|
|
|
|
|
|
|
|
'&:hover': {
|
|
|
|
backgroundColor: theme.palette.action01Hover
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'&.secondary': {
|
|
|
|
background: theme.palette.action02,
|
|
|
|
border: '1px solid transparent'
|
|
|
|
},
|
|
|
|
|
|
|
|
'&.text': {
|
|
|
|
width: 'auto',
|
|
|
|
fontSize: '13px',
|
|
|
|
margin: '0',
|
|
|
|
padding: '0'
|
|
|
|
},
|
|
|
|
|
|
|
|
'&.disabled': {
|
|
|
|
background: theme.palette.action01Disabled,
|
|
|
|
border: '1px solid #5E6D7A',
|
|
|
|
color: '#AFB6BC',
|
|
|
|
cursor: 'initial',
|
|
|
|
|
|
|
|
'.icon': {
|
|
|
|
'& > svg': {
|
|
|
|
fill: '#AFB6BC'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
[theme.breakpoints.down('400')]: {
|
|
|
|
fontSize: 16,
|
|
|
|
marginBottom: 8,
|
|
|
|
padding: '11px 16px'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
borderRadius: theme.shape.borderRadius / 2,
|
|
|
|
alignItems: 'center',
|
|
|
|
display: 'flex',
|
|
|
|
height: '100%',
|
|
|
|
justifyContent: 'center',
|
|
|
|
position: 'absolute',
|
|
|
|
right: 0,
|
|
|
|
top: 0,
|
|
|
|
width: 36,
|
|
|
|
|
|
|
|
'&:hover': {
|
|
|
|
backgroundColor: '#0262B6'
|
|
|
|
},
|
|
|
|
|
|
|
|
'& svg': {
|
|
|
|
pointerEvents: 'none'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-05-20 08:25:31 +00:00
|
|
|
/**
|
|
|
|
* Button used for pre meeting actions.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
function ActionButton({
|
|
|
|
children,
|
2021-11-15 08:37:54 +00:00
|
|
|
classes,
|
2020-05-20 08:25:31 +00:00
|
|
|
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) {
|
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 ]);
|
|
|
|
|
2021-11-15 08:37:54 +00:00
|
|
|
const containerClasses = clsx(
|
|
|
|
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
|
|
|
|
&& <div
|
|
|
|
aria-disabled = { disabled }
|
|
|
|
aria-haspopup = 'true'
|
|
|
|
aria-label = { ariaDropDownLabel }
|
|
|
|
aria-pressed = { ariaPressed }
|
2021-11-15 08:37:54 +00:00
|
|
|
className = { classes.options }
|
2021-06-10 12:48:44 +00:00
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-11-15 08:37:54 +00:00
|
|
|
export default withStyles(styles)(ActionButton);
|