-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1221 from tangly1024/gitbook-collapse
gitbook-collapse
- Loading branch information
Showing
13 changed files
with
107 additions
and
65 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
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
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 was deleted.
Oops, something went wrong.
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,39 @@ | ||
import BlogPostCard from './BlogPostCard' | ||
import React, { useState } from 'react' | ||
import Collapse from '@/components/Collapse' | ||
|
||
/** | ||
* 导航列表 | ||
* @param posts 所有文章 | ||
* @param tags 所有标签 | ||
* @returns {JSX.Element} | ||
* @constructor | ||
*/ | ||
const NavPostItem = (props) => { | ||
const { group } = props | ||
const [isOpen, changeIsOpen] = useState(group?.selected) | ||
|
||
const toggleOpenSubMenu = () => { | ||
changeIsOpen(!isOpen) | ||
} | ||
|
||
if (group.category) { | ||
return <> | ||
<div | ||
onClick={toggleOpenSubMenu} | ||
className='flex justify-between text-sm font-sans cursor-pointer p-2 hover:bg-gray-50 rounded-md dark:hover:bg-gray-600' key={group.category}> | ||
<span>{group.category}</span> | ||
<div className='inline-flex items-center select-none pointer-events-none '><i className={`px-2 fas fa-chevron-left transition-all duration-200 ${isOpen ? '-rotate-90' : ''}`}></i></div> | ||
</div> | ||
<Collapse isOpen={isOpen} onHeightChange={props.onHeightChange}> | ||
{group.items?.map(post => (<div key={post.id} className='ml-3 border-l'> | ||
<BlogPostCard className='text-sm ml-3' post={post} /></div>)) | ||
} | ||
</Collapse> | ||
</> | ||
} else { | ||
return <div> {group.items?.map(post => (<BlogPostCard key={post.id} post={post} className='text-sm' />))}</div> | ||
} | ||
} | ||
|
||
export default NavPostItem |
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,46 @@ | ||
import NavPostListEmpty from './NavPostListEmpty' | ||
import { useRouter } from 'next/router' | ||
import NavPostItem from './NavPostItem' | ||
|
||
/** | ||
* 博客列表滚动分页 | ||
* @param posts 所有文章 | ||
* @param tags 所有标签 | ||
* @returns {JSX.Element} | ||
* @constructor | ||
*/ | ||
const NavPostList = (props) => { | ||
const { posts = [], currentSearch } = props | ||
const filteredPosts = Object.assign(posts) | ||
const router = useRouter() | ||
let selectedSth = false | ||
|
||
// 处理是否选中 | ||
filteredPosts.map((group) => { | ||
let groupSelected = false | ||
for (const post of group?.items) { | ||
if (router.asPath.split('?')[0] === '/' + post.slug) { | ||
groupSelected = true | ||
selectedSth = true | ||
} | ||
} | ||
group.selected = groupSelected | ||
return null | ||
}) | ||
|
||
// 如果都没有选中默认打开第一个 | ||
if (!selectedSth && filteredPosts && filteredPosts.length > 0) { | ||
filteredPosts[0].selected = true | ||
} | ||
|
||
if (!filteredPosts || filteredPosts.length === 0) { | ||
return <NavPostListEmpty currentSearch={currentSearch} /> | ||
} else { | ||
return <div className='w-full'> | ||
{/* 文章列表 */} | ||
{filteredPosts?.map((group, index) => <NavPostItem key={index} group={group} onHeightChange={props.onHeightChange}/>)} | ||
</div> | ||
} | ||
} | ||
|
||
export default NavPostList |
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