1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-28 17:55:15 +02:00
unleash.unleash/frontend/src/component/common/ResponsiveButton/ResponsiveButton.tsx
olav ab4efe0837 refactor: remove unused tooltip prop (#769)
* refactor: remove unused tooltip prop

* refactor: fix PermissionButton base props

* refactor: sync yarn.lock

* refactor: fix unused ts-expect-error
2022-03-09 10:13:50 +01:00

67 lines
1.8 KiB
TypeScript

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