2022-09-13 07:36:00 +00:00
|
|
|
import { Theme } from '@mui/material';
|
2022-08-05 12:07:44 +00:00
|
|
|
import React from 'react';
|
2022-09-13 07:36:00 +00:00
|
|
|
import { makeStyles } from 'tss-react/mui';
|
2022-08-05 12:07:44 +00:00
|
|
|
|
|
|
|
import { isMobileBrowser } from '../../../environment/utils';
|
|
|
|
import Icon from '../../../icons/components/Icon';
|
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
accessibilityLabel: string;
|
|
|
|
icon: Function;
|
2022-10-11 08:24:11 +00:00
|
|
|
id?: string;
|
2022-08-05 12:07:44 +00:00
|
|
|
onClick: () => void;
|
|
|
|
}
|
|
|
|
|
2022-09-13 07:36:00 +00:00
|
|
|
const useStyles = makeStyles()((theme: Theme) => {
|
2022-08-05 12:07:44 +00:00
|
|
|
return {
|
|
|
|
button: {
|
|
|
|
padding: '2px',
|
|
|
|
backgroundColor: theme.palette.action03,
|
|
|
|
border: 0,
|
|
|
|
outline: 0,
|
|
|
|
borderRadius: `${theme.shape.borderRadius}px`,
|
|
|
|
|
|
|
|
'&:hover': {
|
|
|
|
backgroundColor: theme.palette.ui02
|
|
|
|
},
|
|
|
|
|
2022-09-29 10:26:34 +00:00
|
|
|
'&:focus': {
|
|
|
|
outline: 0,
|
|
|
|
boxShadow: `0px 0px 0px 2px ${theme.palette.focus01}`
|
|
|
|
},
|
|
|
|
|
2022-08-05 12:07:44 +00:00
|
|
|
'&:active': {
|
|
|
|
backgroundColor: theme.palette.ui03
|
|
|
|
},
|
|
|
|
|
|
|
|
'&.is-mobile': {
|
|
|
|
padding: '10px'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2022-10-11 08:24:11 +00:00
|
|
|
const ClickableIcon = ({ accessibilityLabel, icon, id, onClick }: IProps) => {
|
2022-09-13 07:36:00 +00:00
|
|
|
const { classes: styles, cx } = useStyles();
|
2022-08-05 12:07:44 +00:00
|
|
|
const isMobile = isMobileBrowser();
|
|
|
|
|
2022-09-13 07:36:00 +00:00
|
|
|
return (
|
|
|
|
<button
|
|
|
|
aria-label = { accessibilityLabel }
|
|
|
|
className = { cx(styles.button, isMobile && 'is-mobile') }
|
2022-10-11 08:24:11 +00:00
|
|
|
id = { id }
|
2022-09-13 07:36:00 +00:00
|
|
|
onClick = { onClick }>
|
|
|
|
<Icon
|
|
|
|
size = { 24 }
|
|
|
|
src = { icon } />
|
|
|
|
</button>
|
|
|
|
);
|
2022-08-05 12:07:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ClickableIcon;
|