Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #94 from EmileCalixte/room-code-hover
Browse files Browse the repository at this point in the history
Timeout and animation for room code reveal
  • Loading branch information
EmileCalixte authored Jan 7, 2021
2 parents 5beb893 + 32e04f8 commit 18e15ba
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 12 deletions.
34 changes: 22 additions & 12 deletions frontend/src/components/pages/Room/views/Lobby.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,37 @@ class Lobby extends React.Component {

constructor(props) {
super(props);
this.state = {
hover: false
};

this.roomCodeHoverTimeout = null;
}

onMouseEnter = () => {
this.setState({hover: true});
onRoomCodeMouseEnter = () => {
const hiddenCodeMessage = document.getElementById('lobby-hidden-code-message');
const codeSpan = document.getElementById('lobby-room-code');

hiddenCodeMessage.classList.add('is-hover');
this.roomCodeHoverTimeout = setTimeout(() => {
codeSpan.classList.add('visible');
hiddenCodeMessage.classList.remove('visible');
}, 300);
};

onMouseLeave = () => {
this.setState({hover: false});
onRoomCodeMouseLeave = () => {
const hiddenCodeMessage = document.getElementById('lobby-hidden-code-message');
const codeSpan = document.getElementById('lobby-room-code');

clearTimeout(this.roomCodeHoverTimeout);
hiddenCodeMessage.classList.remove('is-hover');
codeSpan.classList.remove('visible');
hiddenCodeMessage.classList.add('visible');
}

render() {
const { roomData, gameConfiguration, currentPlayer, isHost, startQuiz, changeOptions, leaveRoom } = this.props;
const { hover } = this.state;

let displayClass = 'hidden';
if(isHost) displayClass = 'visible';

const roomCodeText = hover ? roomData.id : 'Survolez pour afficher le code du salon';

return (
<div className="lobby-container">
<div className="lobby-title">
Expand Down Expand Up @@ -68,8 +77,9 @@ class Lobby extends React.Component {
</div>
<div>
<p className="lobby-room-code">
<span onMouseEnter={() => this.onMouseEnter()} onMouseLeave={() => this.onMouseLeave()}>
{roomCodeText}
<span id="lobby-hover-to-show-code" onMouseEnter={this.onRoomCodeMouseEnter} onMouseLeave={this.onRoomCodeMouseLeave}>
<span id="lobby-hidden-code-message" className="visible">Survolez pour afficher le code du salon</span>
<span id="lobby-room-code">{roomData.id}</span>
</span>
</p>
</div>
Expand Down
41 changes: 41 additions & 0 deletions frontend/src/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,47 @@ button:disabled {
text-align: center;
}

#lobby-hover-to-show-code {
position: relative;
}

#lobby-hover-to-show-code #lobby-hidden-code-message,
#lobby-hover-to-show-code #lobby-room-code {
display: inline-block;
cursor: default;
}

#lobby-hover-to-show-code #lobby-hidden-code-message {
transition: transform 0.1s;
user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
}

#lobby-hover-to-show-code #lobby-hidden-code-message.is-hover {
transform: scale(0.95);
transition: transform 0.4s ease-in;
}

/*#hover-to-show-code #hidden-code-message,*/
#lobby-hover-to-show-code #lobby-room-code {
position: absolute;
left: 50%;
transform: translateX(-50%);

transition: opacity 0s;
}

#lobby-hover-to-show-code #lobby-room-code.visible {
transition: opacity 0.2s ease-in;
}

#lobby-hidden-code-message:not(.visible),
#lobby-room-code:not(.visible) {
opacity: 0;
}

.leave-button {
color: white;
background-color: #DE2D48;
Expand Down

0 comments on commit 18e15ba

Please sign in to comment.