Skip to content

Commit 90e4523

Browse files
authored
Created FullscreenModal component (#670)
1 parent 2fe932d commit 90e4523

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Styles } from '@monkvision/types';
2+
3+
export const styles: Styles = {
4+
container: {
5+
width: '100%',
6+
height: '100%',
7+
top: '0',
8+
left: '0',
9+
position: 'fixed',
10+
zIndex: '999',
11+
backgroundColor: 'black',
12+
},
13+
title: {
14+
position: 'absolute',
15+
top: '8px',
16+
left: '50%',
17+
transform: 'translate(-50%)',
18+
padding: '8px',
19+
margin: '8px',
20+
fontWeight: '500',
21+
fontSize: '20px',
22+
color: 'white',
23+
},
24+
closeButton: {
25+
cursor: 'pointer',
26+
position: 'absolute',
27+
padding: '8px',
28+
top: '8px',
29+
right: '8px',
30+
},
31+
content: {
32+
display: 'flex',
33+
alignItems: 'center',
34+
justifyContent: 'center',
35+
height: '100%',
36+
},
37+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { JSX } from 'react';
2+
import { Button } from '../Button';
3+
import { styles } from './FullscreenModal.styles';
4+
5+
/**
6+
* Props that can be passed to the Fullscreen Modal component.
7+
*/
8+
export interface FullscreenModalProps {
9+
show: boolean;
10+
onClose?: () => void;
11+
title?: string;
12+
children?: string | JSX.Element | JSX.Element[];
13+
}
14+
15+
/**
16+
* Generic Fullscreen Modal component used to display a full screen modal on top of the screen.
17+
*/
18+
export function FullscreenModal({ show, onClose, title = '', children }: FullscreenModalProps) {
19+
return show ? (
20+
<div style={styles['container']} data-testid='container'>
21+
<div style={styles['content']}> {children}</div>
22+
<div style={styles['title']}>{title}</div>
23+
<Button
24+
style={styles['closeButton']}
25+
icon='close'
26+
variant='text'
27+
primaryColor={'text-white'}
28+
onClick={onClose}
29+
/>
30+
</div>
31+
) : null;
32+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { FullscreenModal } from './FullscreenModal';

packages/public/common-ui-web/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './TakePictureButton';
44
export * from './DynamicSVG';
55
export * from './SightOverlay';
66
export * from './SwitchButton';
7+
export * from './FullscreenModal';
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import '@testing-library/jest-dom';
2+
import { render, screen } from '@testing-library/react';
3+
import { FullscreenModal } from '../../src';
4+
5+
describe('FullsreenModal component', () => {
6+
afterEach(() => {
7+
jest.clearAllMocks();
8+
});
9+
10+
const mockOnClose = jest.fn();
11+
const title = 'test title';
12+
const content = 'test content';
13+
14+
it('should not render modal when show is false', () => {
15+
const { unmount } = render(<FullscreenModal show={false}></FullscreenModal>);
16+
expect(screen.queryByText(title)).toBeNull();
17+
expect(screen.queryByText(content)).toBeNull();
18+
19+
unmount();
20+
});
21+
22+
it('renders modal with title and content when show is true', () => {
23+
const { unmount } = render(
24+
<FullscreenModal show={true} onClose={mockOnClose} title={title}>
25+
{content}
26+
</FullscreenModal>,
27+
);
28+
expect(screen.getByText(title)).toBeInTheDocument();
29+
expect(screen.getByText(content)).toBeInTheDocument();
30+
31+
unmount();
32+
});
33+
});

0 commit comments

Comments
 (0)