added Overlay component
This commit is contained in:
parent
e9cb2e4de9
commit
aa6c03ebcb
640
package-lock.json
generated
640
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -6,8 +6,6 @@
|
||||
"@emotion/react": "^11.11.1",
|
||||
"@emotion/styled": "^11.11.0",
|
||||
"@mui/material": "^5.14.20",
|
||||
"@testing-library/jest-dom": "^6.1.5",
|
||||
"@testing-library/react": "^14.1.2",
|
||||
"@testing-library/user-event": "^14.5.1",
|
||||
"axios": "^1.6.2",
|
||||
"prop-types": "^15.8.1",
|
||||
@ -50,5 +48,9 @@
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"proxy": "http://localhost:5000"
|
||||
"proxy": "http://localhost:5000",
|
||||
"devDependencies": {
|
||||
"@testing-library/jest-dom": "^6.1.5",
|
||||
"@testing-library/react": "^14.1.2"
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
border: 1px solid white;
|
||||
border-radius: 8px;
|
||||
margin: 20px;
|
||||
z-index: 2;
|
||||
}
|
||||
.name-input-container > button {
|
||||
margin-top: 5px;
|
||||
@ -17,18 +18,6 @@
|
||||
.name-input-container > input {
|
||||
margin-top: 10px;
|
||||
}
|
||||
.name-overlay {
|
||||
position: absolute;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
z-index: 1;
|
||||
}
|
||||
input,
|
||||
button {
|
||||
padding: 0;
|
||||
|
||||
@ -22,7 +22,6 @@ const NameInput = ({ isRoomPrivate, roomId }) => {
|
||||
}, [socket]);
|
||||
|
||||
return (
|
||||
<div className='name-overlay'>
|
||||
<div className='name-input-container' style={{ height: isRoomPrivate ? '100px' : '50px' }}>
|
||||
<input placeholder='Nickname' type='text' onChange={nickname.onChange} />
|
||||
{isRoomPrivate ? (
|
||||
@ -35,7 +34,6 @@ const NameInput = ({ isRoomPrivate, roomId }) => {
|
||||
) : null}
|
||||
<button onClick={handleButtonClick}>JOIN</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ import ReactLoading from 'react-loading';
|
||||
|
||||
import './ServerList.css';
|
||||
import NameInput from '../NameInput/NameInput';
|
||||
import Overlay from '../../Overlay/Overlay';
|
||||
|
||||
const ServerList = () => {
|
||||
const socket = useContext(SocketContext);
|
||||
@ -70,7 +71,11 @@ const ServerList = () => {
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{joining ? <NameInput roomId={clickedRoom._id} isRoomPrivate={clickedRoom.private} /> : null}
|
||||
{joining ? (
|
||||
<Overlay handleOverlayClose={() => setJoining(false)}>
|
||||
<NameInput roomId={clickedRoom._id} isRoomPrivate={clickedRoom.private} />
|
||||
</Overlay>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
9
src/components/Overlay/Overlay.jsx
Normal file
9
src/components/Overlay/Overlay.jsx
Normal file
@ -0,0 +1,9 @@
|
||||
import styles from './Overlay.module.css';
|
||||
import useKeyPress from '../../hooks/useKeyPress';
|
||||
|
||||
const Overlay = ({ children, handleOverlayClose }) => {
|
||||
useKeyPress('Escape', handleOverlayClose);
|
||||
|
||||
return <div className={styles.container}>{children}</div>;
|
||||
};
|
||||
export default Overlay;
|
||||
13
src/components/Overlay/Overlay.module.css
Normal file
13
src/components/Overlay/Overlay.module.css
Normal file
@ -0,0 +1,13 @@
|
||||
.container {
|
||||
position: absolute;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
z-index: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
34
src/components/Overlay/Overlay.test.js
Normal file
34
src/components/Overlay/Overlay.test.js
Normal file
@ -0,0 +1,34 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
import Overlay from './Overlay';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
describe('Overlay component', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('renders Overlay component', () => {
|
||||
const { container } = render(<Overlay handleOverlayClose={() => {}} />);
|
||||
expect(container).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders children inside Overlay', () => {
|
||||
const { getByTestId } = render(
|
||||
<Overlay handleOverlayClose={() => {}}>
|
||||
<div data-testid='test-child' />
|
||||
</Overlay>
|
||||
);
|
||||
expect(getByTestId('test-child')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls handleOverlayClose on Escape key press', async () => {
|
||||
const handleOverlayCloseMock = jest.fn();
|
||||
render(<Overlay handleOverlayClose={handleOverlayCloseMock} />);
|
||||
|
||||
await userEvent.type(document.body, '{Escape}');
|
||||
|
||||
expect(handleOverlayCloseMock).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user