-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add menu nav logic, favicon etc
- Loading branch information
Showing
24 changed files
with
397 additions
and
76 deletions.
There are no files selected for viewing
Binary file not shown.
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 @@ | ||
import React from 'react' | ||
import { useHistory, useLocation } from 'react-router-dom' | ||
import cn from 'classnames' | ||
import ROUTES from 'constants/routes' | ||
|
||
import styles from './style.module.css' | ||
|
||
const NAVBAR = { | ||
[ROUTES.DISCOVERY]: [ | ||
{ | ||
label: '个性推荐', | ||
route: ROUTES.RECOMMENDATION | ||
}, | ||
{ | ||
label: '歌单', | ||
route: ROUTES.SONG_LIST | ||
}, | ||
{ | ||
label: '排行榜', | ||
route: ROUTES.LEADER_BOARD | ||
}, | ||
{ | ||
label: '歌手', | ||
route: ROUTES.SINGERS | ||
}, | ||
{ | ||
label: '最新音乐', | ||
route: ROUTES.LATEST_MUSIC | ||
} | ||
], | ||
[ROUTES.VIDEOS]: [ | ||
{ | ||
label: '视频', | ||
route: ROUTES.VIDEO | ||
}, | ||
{ | ||
label: 'MV', | ||
route: ROUTES.MV | ||
} | ||
] | ||
} | ||
|
||
const Navbar = () => { | ||
const history = useHistory() | ||
const { pathname } = useLocation() | ||
|
||
const matchPathPrefix = Object.keys(NAVBAR).find((key) => pathname.startsWith(key)) || ROUTES.DISCOVERY | ||
const items = NAVBAR[matchPathPrefix] | ||
|
||
const hasMatchRoute = items.find(({ route }) => route === pathname) | ||
|
||
const handleItemClick = (route: string) => { | ||
history.push(route) | ||
} | ||
|
||
return ( | ||
<div className={styles.root}> | ||
{ | ||
items.map(({ label, route }, index) => { | ||
const isActive = hasMatchRoute ? route === pathname : index === 0 | ||
|
||
return ( | ||
<div | ||
key={label} | ||
className={cn(styles.item, isActive ? styles.active : '')} | ||
onClick={() => handleItemClick(route)} | ||
> | ||
{label} | ||
</div> | ||
) | ||
}) | ||
} | ||
</div> | ||
) | ||
} | ||
|
||
export default Navbar |
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,21 @@ | ||
@value colors: "~styles/colors.module.css"; | ||
@value grey, black from colors; | ||
|
||
.root { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.item { | ||
margin-right: 2em; | ||
cursor: pointer; | ||
color: grey; | ||
|
||
&:hover { | ||
color: black; | ||
} | ||
} | ||
|
||
.active { | ||
color: black; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import React from 'react' | ||
import { Icon, IconName } from '@blueprintjs/core' | ||
import { useHistory, useLocation } from 'react-router-dom' | ||
import cn from 'classnames' | ||
|
||
import ROUTES from 'constants/routes' | ||
import styles from './style.module.css' | ||
|
||
interface IMenuItem { | ||
icon: IconName, | ||
label: string, | ||
active?: boolean, | ||
route: string | ||
} | ||
|
||
interface IMenu { | ||
title?: string, | ||
items: IMenuItem[] | ||
} | ||
|
||
const MENU: IMenu[] = [ | ||
{ | ||
items: [ | ||
{ | ||
icon: 'music', | ||
label: '发现音乐', | ||
route: ROUTES.DISCOVERY | ||
}, | ||
{ | ||
icon: 'mobile-video', | ||
label: '视频', | ||
route: ROUTES.VIDEOS | ||
} | ||
] | ||
}, | ||
{ | ||
title: '我的音乐', | ||
items: [ | ||
{ | ||
icon: 'import', | ||
label: '下载管理', | ||
route: ROUTES.DOWNLOAD | ||
}, | ||
{ | ||
icon: 'cloud', | ||
label: '我的音乐云盘', | ||
route: ROUTES.CLOUD | ||
}, | ||
{ | ||
icon: 'star-empty', | ||
label: '我的收藏', | ||
route: ROUTES.COLLECTION | ||
} | ||
] | ||
} | ||
] | ||
|
||
const Menus = () => { | ||
const history = useHistory() | ||
const { pathname } = useLocation() | ||
|
||
const handleMenuItemClick = (route: string) => { | ||
history.push(route) | ||
} | ||
|
||
return ( | ||
<> | ||
{MENU.map(({ title, items }, index) => { | ||
return ( | ||
<div className={styles.block} key={index}> | ||
{title && <div className={styles.title}>{title}</div>} | ||
<div className={styles.tabs}> | ||
{items.map(({ icon, label, route }) => { | ||
const isActive = pathname.startsWith(route) || (pathname === ROUTES.ROOT && route === ROUTES.DISCOVERY) | ||
return ( | ||
<div | ||
key={label} | ||
className={isActive ? cn(styles.tab, styles.active) : styles.tab} | ||
onClick={() => handleMenuItemClick(route)} | ||
> | ||
<Icon icon={icon} /> | ||
{label} | ||
</div> | ||
) | ||
})} | ||
</div> | ||
</div> | ||
) | ||
})} | ||
</> | ||
) | ||
} | ||
|
||
export default Menus |
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,33 @@ | ||
@value colors: "~styles/colors.module.css"; | ||
@value grey from colors; | ||
|
||
.tabs { | ||
color: rgb(77, 77, 77); | ||
cursor: default; | ||
|
||
.tab { | ||
padding: 10px 20px; | ||
|
||
span { | ||
margin-right: 10px; | ||
} | ||
} | ||
|
||
.tab:hover { | ||
background-color: rgb(227, 227, 227); | ||
} | ||
|
||
.active { | ||
color: rgb(208, 58, 54); | ||
} | ||
} | ||
|
||
.block { | ||
margin-bottom: 25px; | ||
|
||
.title { | ||
padding-left: 20px; | ||
font-size: 0.8em; | ||
color: grey; | ||
} | ||
} |
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
Oops, something went wrong.