-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
3 changed files
with
157 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { useState } from 'react'; | ||
import './styles.scss'; | ||
|
||
interface IUser { | ||
id: string | number; | ||
name: string; | ||
score: number; | ||
} | ||
|
||
interface IProps { | ||
data: IUser[]; | ||
curId: number; | ||
} | ||
|
||
const Rank = (props: IProps) => { | ||
|
||
const { data, curId } = props; | ||
const curIndex = data.findIndex(item => item.id === curId); | ||
const [visible, setVisible] = useState(false); | ||
|
||
const toggleVisible = () => { | ||
setVisible(!visible); | ||
} | ||
|
||
return ( | ||
<div className={`mi-c-rank ${visible ? '' : 'hidden'}`}> | ||
<div className="rank-title">Rank</div> | ||
<ul className="rank-list"> | ||
{ | ||
data.map((item, index) => { | ||
return ( | ||
<li className="rank-info"> | ||
<div className="rank-index">{index + 1}</div> | ||
<div className="name">{item.name}</div> | ||
<div className="score">{item.score}</div> | ||
</li> | ||
) | ||
}) | ||
} | ||
</ul> | ||
<div className="rank-info my-rank-info"> | ||
<div className="rank-index">{curIndex + 1}</div> | ||
<div className="name">ME</div> | ||
<div className="score">{data[curIndex].score}</div> | ||
</div> | ||
<div className="opt"> | ||
<div className="toggle-visible" onClick={toggleVisible}/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Rank; |
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,77 @@ | ||
.mi-c-rank { | ||
position: absolute; | ||
left: 0; | ||
padding: 16px; | ||
width: 160px; | ||
height: 500px; | ||
background: #eee; | ||
top: 50%; | ||
transform: translate3d(0, -50%, 0); | ||
transition: transform 0.3s; | ||
|
||
.rank-title { | ||
border-bottom: 2px solid; | ||
line-height: 2; | ||
text-align: center; | ||
} | ||
|
||
.rank-list { | ||
padding: 8px 0; | ||
} | ||
|
||
.my-rank-info { | ||
border-top: 2px solid; | ||
padding-top: 8px; | ||
} | ||
|
||
.rank-index { | ||
width: 30px; | ||
} | ||
|
||
.name { | ||
flex: 1; | ||
} | ||
|
||
.score { | ||
width: 50px; | ||
} | ||
|
||
.rank-info { | ||
display: flex; | ||
|
||
& > div { | ||
padding: 0 6px; | ||
} | ||
} | ||
|
||
.opt { | ||
position: absolute; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 24px; | ||
height: 60px; | ||
left: 100%; | ||
top: 50%; | ||
transform: translateY(-50%); | ||
background: #eee; | ||
cursor: pointer; | ||
|
||
.toggle-visible{ | ||
content: ''; | ||
display: block; | ||
border-width: 28px 16px 28px 0; | ||
border-color: transparent blue transparent transparent; | ||
border-style: solid; | ||
} | ||
} | ||
|
||
&.hidden { | ||
transform: translate3d(-100%, -50%, 0); | ||
|
||
.opt .toggle-visible { | ||
border-width: 28px 0 28px 16px; | ||
border-color: transparent transparent transparent blue; | ||
} | ||
} | ||
} |
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