1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/frontend/src/component/common/ResponsiveButton/ResponsiveButton.tsx

59 lines
1.6 KiB
TypeScript
Raw Normal View History

import { useMediaQuery } from '@material-ui/core';
import ConditionallyRender from '../ConditionallyRender';
import PermissionButton from '../PermissionButton/PermissionButton';
import PermissionIconButton from '../PermissionIconButton/PermissionIconButton';
interface IResponsiveButtonProps {
Icon: React.ElementType;
onClick: () => void;
tooltip?: string;
disabled?: boolean;
permission?: string;
maxWidth: string;
}
const ResponsiveButton: React.FC<IResponsiveButtonProps> = ({
Icon,
onClick,
maxWidth,
tooltip,
disabled = false,
children,
permission,
...rest
}) => {
const smallScreen = useMediaQuery(`(max-width:${maxWidth})`);
return (
<ConditionallyRender
condition={smallScreen}
show={
<PermissionIconButton
disabled={disabled}
onClick={onClick}
permission={permission}
data-loading
{...rest}
>
<Icon />
</PermissionIconButton>
}
elseShow={
<PermissionButton
onClick={onClick}
permission={permission}
color="primary"
variant="contained"
disabled={disabled}
data-loading
{...rest}
>
{children}
</PermissionButton>
}
/>
);
};
export default ResponsiveButton;