1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/frontend/src/component/context/ContextList/AddContextButton.tsx
2023-06-06 13:59:41 +03:00

42 lines
1.5 KiB
TypeScript

import { VFC } from 'react';
import { useNavigate } from 'react-router-dom';
import { useMediaQuery } from '@mui/material';
import { Add } from '@mui/icons-material';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { CREATE_CONTEXT_FIELD } from 'component/providers/AccessProvider/permissions';
import PermissionButton from 'component/common/PermissionButton/PermissionButton';
import PermissionIconButton from 'component/common/PermissionIconButton/PermissionIconButton';
interface IAddContextButtonProps {}
export const AddContextButton: VFC<IAddContextButtonProps> = () => {
const smallScreen = useMediaQuery('(max-width:700px)');
const navigate = useNavigate();
return (
<ConditionallyRender
condition={smallScreen}
show={
<PermissionIconButton
permission={CREATE_CONTEXT_FIELD}
onClick={() => navigate('/context/create')}
size="large"
tooltipProps={{ title: 'Add context type' }}
>
<Add />
</PermissionIconButton>
}
elseShow={
<PermissionButton
onClick={() => navigate('/context/create')}
permission={CREATE_CONTEXT_FIELD}
color="primary"
variant="contained"
>
New context field
</PermissionButton>
}
/>
);
};