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/react": "^11.11.1",
|
||||||
"@emotion/styled": "^11.11.0",
|
"@emotion/styled": "^11.11.0",
|
||||||
"@mui/material": "^5.14.20",
|
"@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",
|
"@testing-library/user-event": "^14.5.1",
|
||||||
"axios": "^1.6.2",
|
"axios": "^1.6.2",
|
||||||
"prop-types": "^15.8.1",
|
"prop-types": "^15.8.1",
|
||||||
@ -50,5 +48,9 @@
|
|||||||
"last 1 safari version"
|
"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: 1px solid white;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
margin: 20px;
|
margin: 20px;
|
||||||
|
z-index: 2;
|
||||||
}
|
}
|
||||||
.name-input-container > button {
|
.name-input-container > button {
|
||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
@ -17,18 +18,6 @@
|
|||||||
.name-input-container > input {
|
.name-input-container > input {
|
||||||
margin-top: 10px;
|
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,
|
input,
|
||||||
button {
|
button {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|||||||
@ -22,19 +22,17 @@ const NameInput = ({ isRoomPrivate, roomId }) => {
|
|||||||
}, [socket]);
|
}, [socket]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='name-overlay'>
|
<div className='name-input-container' style={{ height: isRoomPrivate ? '100px' : '50px' }}>
|
||||||
<div className='name-input-container' style={{ height: isRoomPrivate ? '100px' : '50px' }}>
|
<input placeholder='Nickname' type='text' onChange={nickname.onChange} />
|
||||||
<input placeholder='Nickname' type='text' onChange={nickname.onChange} />
|
{isRoomPrivate ? (
|
||||||
{isRoomPrivate ? (
|
<input
|
||||||
<input
|
placeholder='Room password'
|
||||||
placeholder='Room password'
|
type='text'
|
||||||
type='text'
|
onChange={password.onChange}
|
||||||
onChange={password.onChange}
|
style={{ backgroundColor: isPasswordWrong ? 'red' : null }}
|
||||||
style={{ backgroundColor: isPasswordWrong ? 'red' : null }}
|
/>
|
||||||
/>
|
) : null}
|
||||||
) : null}
|
<button onClick={handleButtonClick}>JOIN</button>
|
||||||
<button onClick={handleButtonClick}>JOIN</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import ReactLoading from 'react-loading';
|
|||||||
|
|
||||||
import './ServerList.css';
|
import './ServerList.css';
|
||||||
import NameInput from '../NameInput/NameInput';
|
import NameInput from '../NameInput/NameInput';
|
||||||
|
import Overlay from '../../Overlay/Overlay';
|
||||||
|
|
||||||
const ServerList = () => {
|
const ServerList = () => {
|
||||||
const socket = useContext(SocketContext);
|
const socket = useContext(SocketContext);
|
||||||
@ -70,7 +71,11 @@ const ServerList = () => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</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>
|
</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