2021-07-07 11:04:36 +02:00
|
|
|
import { IconButton, Tooltip, Button, useMediaQuery } from '@material-ui/core';
|
|
|
|
import ConditionallyRender from '../ConditionallyRender';
|
|
|
|
|
|
|
|
interface IResponsiveButtonProps {
|
|
|
|
Icon: React.ElementType;
|
|
|
|
onClick: () => void;
|
|
|
|
tooltip?: string;
|
|
|
|
maxWidth: string;
|
|
|
|
}
|
|
|
|
|
2021-07-16 15:41:54 +02:00
|
|
|
const ResponsiveButton: React.FC<IResponsiveButtonProps> = ({
|
2021-07-07 11:04:36 +02:00
|
|
|
Icon,
|
|
|
|
onClick,
|
|
|
|
maxWidth,
|
|
|
|
tooltip,
|
2021-07-16 15:41:54 +02:00
|
|
|
children,
|
|
|
|
}) => {
|
2021-07-07 11:04:36 +02:00
|
|
|
const smallScreen = useMediaQuery(`(max-width:${maxWidth})`);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={smallScreen}
|
|
|
|
show={
|
|
|
|
<Tooltip title={tooltip ? tooltip : ''}>
|
2021-07-16 15:41:54 +02:00
|
|
|
<IconButton onClick={onClick} data-loading>
|
2021-07-07 11:04:36 +02:00
|
|
|
<Icon />
|
|
|
|
</IconButton>
|
|
|
|
</Tooltip>
|
|
|
|
}
|
|
|
|
elseShow={
|
2021-07-16 15:41:54 +02:00
|
|
|
<Button
|
|
|
|
onClick={onClick}
|
|
|
|
color="primary"
|
|
|
|
variant="contained"
|
|
|
|
data-loading
|
|
|
|
>
|
|
|
|
{children}
|
2021-07-07 11:04:36 +02:00
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ResponsiveButton;
|