Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: Add credits button and modal functionality in App.tsx #26

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function App() {
Modal.setAppElement('#root');
const [isModalOpen, setModalOpen] = useState(false);
const [isRuleModalOpen, setRuleModalOpen] = useState(false);

const [isLeaderBoardModalOpen, setLeaderBoardModalOpen] = useState(false);
const [isMusicPlaying, setMusicPlaying] = useState(false);

Expand Down Expand Up @@ -53,23 +54,6 @@ function App() {
setRuleModalOpen(!isRuleModalOpen);
};

const modalStyle = {
content: {
top: '50%',
left: '50%',
width: '80%',
height: '57%',
right: 'auto',
bottom: 'auto',
marginRight: '-50%',
transform: 'translate(-50%, -50%)',
fontSize: '16px',
border: '4px solid #000',
boxShadow: '5px 5px #000',
textColor: 'red',
},
};

const credits = async () => {
toggleModal();
};
Expand Down Expand Up @@ -101,7 +85,6 @@ function App() {
>
Rules
</button>
<CreditsButton onClick={credits}></CreditsButton>
<button
onClick={toggleMusic}
className="p-2 mr-2 text-2xl w-6 "
Expand All @@ -115,7 +98,7 @@ function App() {
<Canvas setMusicPlaying={setMusicPlaying} />
</div>

<Modal isOpen={isModalOpen} onRequestClose={toggleModal} style={modalStyle} ariaHideApp={false}>
<Modal isOpen={isModalOpen} onRequestClose={toggleModal} className="modal-base modal-medium" ariaHideApp={false}>
<div className="relative">
<button onClick={toggleModal} className="absolute top-[-10px] right-0 p-2">
<div className="relative w-6 h-6">
Expand All @@ -127,7 +110,7 @@ function App() {
</div>
</Modal>

<Modal isOpen={isRuleModalOpen} onRequestClose={toggleRuleModal} style={modalStyle}>
<Modal isOpen={isRuleModalOpen} onRequestClose={toggleRuleModal} className="modal-base modal-large">
<div className="relative">
<button onClick={toggleRuleModal} className="absolute top-[-10px] right-0 p-2">
<div className="relative w-6 h-6">
Expand All @@ -142,7 +125,7 @@ function App() {
<Modal
isOpen={isLeaderBoardModalOpen}
onRequestClose={toggleLeaderBoardModal}
style={modalStyle}
className="modal-base modal-large"
ariaHideApp={false}
>
<div className="relative">
Expand Down
32 changes: 29 additions & 3 deletions client/src/index.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
Expand Down Expand Up @@ -28,3 +28,29 @@ body {
canvas {
display: block;
}

@layer components {
.modal-base {
@apply relative p-4 border-4 border-black rounded shadow-lg bg-white w-[80%] top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 text-base;
}

.modal-header-close-btn {
@apply absolute top-[-10px] right-0 p-2;
}

.close-line {
@apply absolute inset-0 w-1 h-full bg-black origin-center;
}

.modal-small {
@apply h-48;
}

.modal-medium {
@apply h-[57%];
}

.modal-large {
@apply h-[85%];
}
}
6 changes: 1 addition & 5 deletions client/src/ui/CreditsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ interface NewGameButtonProps {

const CreditsButton: React.FC<NewGameButtonProps> = ({ onClick }) => {
return (
<button
className="bg-blue-500 hover:bg-blue-700 mx-10 my-10 text-white font-bold py-2 px-4 rounded"
style={{ width: '210px' }}
onClick={onClick}
>
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded w-full" onClick={onClick}>
Credits
</button>
);
Expand Down
15 changes: 14 additions & 1 deletion client/src/ui/NewGame.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useState } from 'react';
import NewGameButton from './NewGameButton';
import Modal from 'react-modal';
import RulesModal from './RulesModal';
import Credits from './Credits';
import CreditsButton from './CreditsButton';

interface NewGameProps {
onClick: () => void;
Expand Down Expand Up @@ -40,6 +41,18 @@ const NewGame: React.FC<NewGameProps> = ({ onClick, onPseudoChange }) => {
maxLength={18} // Limit the input to 30 characters
/>
<NewGameButton onClick={onClick} disabled={!username.trim()}></NewGameButton>
<CreditsButton onClick={toggleModal}></CreditsButton>
<Modal isOpen={isModalOpen} onRequestClose={toggleModal} className="modal-base modal-medium" ariaHideApp={false}>
<div className="relative">
<button onClick={toggleModal} className="absolute top-[-10px] right-0 p-2">
<div className="relative w-6 h-6">
<div className="absolute inset-0 w-1 h-full bg-black transform rotate-45 origin-center"></div>
<div className="absolute inset-0 w-1 h-full bg-black transform -rotate-45 origin-center"></div>
</div>
</button>
<Credits />
</div>
</Modal>
</div>
);
};
Expand Down
3 changes: 1 addition & 2 deletions client/src/ui/NewGameButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const NewGameButton: React.FC<NewGameButtonProps> = ({ onClick, disabled }) => {
<button
className={`bg-blue-500 ${
disabled ? 'opacity-50 cursor-not-allowed' : 'hover:bg-blue-700'
} my-10 text-white font-bold py-2 px-4 rounded`}
style={{ width: '100%' }}
} my-10 text-white font-bold py-2 px-4 rounded w-full`}
onClick={onClick}
disabled={disabled}
>
Expand Down
Loading