2022-11-28 16:13:45 +01:00
|
|
|
import React from 'react';
|
2022-05-02 15:52:41 +02:00
|
|
|
import { useMediaQuery } from '@mui/material';
|
2022-05-02 12:52:33 +02:00
|
|
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
2023-03-17 19:21:13 +01:00
|
|
|
import PermissionButton from 'component/common/PermissionButton/PermissionButton';
|
|
|
|
import PermissionIconButton from 'component/common/PermissionIconButton/PermissionIconButton';
|
2022-11-28 16:13:45 +01:00
|
|
|
import { ITooltipResolverProps } from '../TooltipResolver/TooltipResolver';
|
2021-07-07 11:04:36 +02:00
|
|
|
|
|
|
|
interface IResponsiveButtonProps {
|
|
|
|
Icon: React.ElementType;
|
2022-11-28 16:13:45 +01:00
|
|
|
endIcon?: React.ReactNode;
|
|
|
|
tooltipProps?: Omit<ITooltipResolverProps, 'children'>;
|
2021-07-07 11:04:36 +02:00
|
|
|
onClick: () => void;
|
2021-10-01 12:15:02 +02:00
|
|
|
disabled?: boolean;
|
2023-06-23 10:57:08 +02:00
|
|
|
permission: string | string[];
|
2021-10-20 12:05:44 +02:00
|
|
|
projectId?: string;
|
2022-01-14 15:50:02 +01:00
|
|
|
environmentId?: string;
|
2021-07-07 11:04:36 +02:00
|
|
|
maxWidth: string;
|
2022-03-01 13:22:47 +01:00
|
|
|
className?: string;
|
2021-07-07 11:04:36 +02:00
|
|
|
}
|
|
|
|
|
2021-07-16 15:41:54 +02:00
|
|
|
const ResponsiveButton: React.FC<IResponsiveButtonProps> = ({
|
2021-07-07 11:04:36 +02:00
|
|
|
Icon,
|
|
|
|
onClick,
|
|
|
|
maxWidth,
|
2021-10-01 12:15:02 +02:00
|
|
|
disabled = false,
|
2021-07-16 15:41:54 +02:00
|
|
|
children,
|
2021-10-08 11:23:29 +02:00
|
|
|
permission,
|
2022-01-14 15:50:02 +01:00
|
|
|
environmentId,
|
2021-10-20 12:05:44 +02:00
|
|
|
projectId,
|
2023-05-25 19:28:08 +02:00
|
|
|
endIcon,
|
2021-09-30 11:44:30 +02:00
|
|
|
...rest
|
2021-07-16 15:41:54 +02:00
|
|
|
}) => {
|
2021-07-07 11:04:36 +02:00
|
|
|
const smallScreen = useMediaQuery(`(max-width:${maxWidth})`);
|
|
|
|
|
|
|
|
return (
|
2021-10-08 11:23:29 +02:00
|
|
|
<ConditionallyRender
|
|
|
|
condition={smallScreen}
|
|
|
|
show={
|
|
|
|
<PermissionIconButton
|
|
|
|
disabled={disabled}
|
|
|
|
onClick={onClick}
|
|
|
|
permission={permission}
|
2021-10-20 12:05:44 +02:00
|
|
|
projectId={projectId}
|
2022-01-14 15:50:02 +01:00
|
|
|
environmentId={environmentId}
|
2021-10-08 11:23:29 +02:00
|
|
|
data-loading
|
|
|
|
{...rest}
|
|
|
|
>
|
|
|
|
<Icon />
|
|
|
|
</PermissionIconButton>
|
|
|
|
}
|
|
|
|
elseShow={
|
|
|
|
<PermissionButton
|
|
|
|
onClick={onClick}
|
|
|
|
permission={permission}
|
2021-10-20 12:05:44 +02:00
|
|
|
projectId={projectId}
|
2021-10-08 11:23:29 +02:00
|
|
|
color="primary"
|
|
|
|
variant="contained"
|
|
|
|
disabled={disabled}
|
2022-01-14 15:50:02 +01:00
|
|
|
environmentId={environmentId}
|
2023-05-25 19:28:08 +02:00
|
|
|
endIcon={endIcon}
|
2021-10-08 11:23:29 +02:00
|
|
|
data-loading
|
|
|
|
{...rest}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</PermissionButton>
|
|
|
|
}
|
|
|
|
/>
|
2021-07-07 11:04:36 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ResponsiveButton;
|