-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c04e580
commit e8e3ac5
Showing
7 changed files
with
100 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,70 @@ | ||
import { useEffect } from 'react'; | ||
import { alphabet } from '../../helpers/variables'; | ||
|
||
const Keyboard = ({ keyboardLettersColors, onEnter, addLetter, deleteLetter, state}) => { | ||
import { useEffect } from "react"; | ||
import { | ||
alphabet, | ||
firstRow, | ||
secondRow, | ||
thirdRow, | ||
} from "../../helpers/variables"; | ||
import KeyboardRow from "../KeyboardRow/KeyboardRow"; | ||
|
||
const Keyboard = ({ | ||
keyboardLettersColors, | ||
onEnter, | ||
addLetter, | ||
deleteLetter, | ||
state, | ||
}) => { | ||
useEffect(() => { | ||
function handler(e) { | ||
if (e.key === 'Enter') { | ||
if (e.key === "Enter") { | ||
onEnter(); | ||
} else if (e.key === 'Backspace') { | ||
} else if (e.key === "Backspace") { | ||
deleteLetter(); | ||
} else { | ||
} else if (alphabet.includes(e.key)) { | ||
addLetter(e.key.toUpperCase()); | ||
} | ||
|
||
} | ||
|
||
window.addEventListener('keydown', handler) | ||
window.addEventListener("keydown", handler); | ||
|
||
return () => { | ||
window.removeEventListener('keydown', handler) | ||
} | ||
}, [state, onEnter, addLetter, deleteLetter]); | ||
window.removeEventListener("keydown", handler); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<div className="wrapper-keyboard"> | ||
<div className='keyboard'> | ||
{alphabet.map((letter, i) => { | ||
return <button | ||
key={i} | ||
style={{ backgroundColor: keyboardLettersColors[letter.toUpperCase()] }} | ||
name={letter.toUpperCase()} | ||
onClick={(e) => addLetter(e.target.name)} | ||
> | ||
{letter.toUpperCase()} | ||
<div className="keyboard"> | ||
<div className="wrapper-keyboard-button"> | ||
<KeyboardRow | ||
row={firstRow} | ||
addLetter={addLetter} | ||
keyboardLettersColors={keyboardLettersColors} | ||
/> | ||
</div> | ||
<div className="wrapper-keyboard-button"> | ||
<KeyboardRow | ||
row={secondRow} | ||
addLetter={addLetter} | ||
keyboardLettersColors={keyboardLettersColors} | ||
/> | ||
</div> | ||
<div className="wrapper-keyboard-button"> | ||
<button className="keyboard-button" onClick={onEnter}> | ||
Enter | ||
</button> | ||
<KeyboardRow | ||
row={thirdRow} | ||
addLetter={addLetter} | ||
keyboardLettersColors={keyboardLettersColors} | ||
/> | ||
<button className="keyboard-button" onClick={deleteLetter}> | ||
Delete | ||
</button> | ||
})} | ||
<button | ||
className='keyboard-button' | ||
onClick={onEnter} | ||
> | ||
Enter | ||
</button> | ||
<button | ||
className='keyboard-button' | ||
onClick={deleteLetter} | ||
> | ||
Delete | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
}; | ||
|
||
export default Keyboard; | ||
export default Keyboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const KeyboardRow = ({row, addLetter, keyboardLettersColors}) => { | ||
return row.map((letter, i) => { | ||
return <button | ||
key={i} | ||
style={{ backgroundColor: keyboardLettersColors[letter.toUpperCase()]}} | ||
name={letter.toUpperCase()} | ||
onClick={(e) => addLetter(e.target.name)} | ||
> | ||
{letter.toUpperCase()} | ||
</button> | ||
}) | ||
} | ||
|
||
export default KeyboardRow; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters