Skip to content

Commit

Permalink
feat: add hover for blog sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
kuizuo committed Dec 26, 2023
1 parent 310a6a0 commit 4831dd8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/theme/BlogPostPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function BlogPostPageContent({

return (
<BlogLayout
// sidebar={sidebar}
sidebar={sidebar}
toc={
!hideTableOfContents && toc.length > 0 ? (
<TOC
Expand Down
10 changes: 8 additions & 2 deletions src/theme/BlogSidebar/Desktop/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useState } from 'react'
import clsx from 'clsx'
import Link from '@docusaurus/Link'
import { Icon } from '@iconify/react'
Expand All @@ -10,20 +10,26 @@ import styles from './styles.module.scss'

export default function BlogSidebarDesktop({ sidebar }: Props): JSX.Element {
const { isBlogPostPage } = useBlogPost()
const [isHovered, setIsHovered] = useState(false)

const handleBack = () => {
window.history.back()
}

return (
<aside className="col col--2">
<aside
className="col col--2"
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
>
<nav
className={clsx(styles.sidebar, 'thin-scrollbar')}
aria-label={translate({
id: 'theme.blog.sidebar.navAriaLabel',
message: 'Blog recent posts navigation',
description: 'The ARIA label for recent posts in the blog sidebar',
})}
style={{ opacity: isHovered ? 1 : 0 }}
>
{isBlogPostPage && (
<div className={styles.backButton} onClick={handleBack}>
Expand Down
25 changes: 15 additions & 10 deletions src/theme/BlogSidebar/Desktop/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
overflow-y: auto;
position: sticky;
top: calc(var(--ifm-navbar-height) + 2rem);

transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 0.5s;
}

.sidebarItemTitle {
Expand Down Expand Up @@ -50,6 +53,16 @@
}
}

:root {
--back-btn-bg-color: #fafaf9;
--back-btn-bg-color-hover: #f1f5f9;
}

html[data-theme='dark'] {
--back-btn-bg-color: #18181b;
--back-btn-bg-color-hover: #334155;
}

.backButton {
width: 32px;
height: 32px;
Expand All @@ -64,18 +77,10 @@
transition: all 0.3s ease-in-out;
cursor: pointer;

background-color: #fafaf9;
background-color: var(--back-btn-bg-color);

&:hover {
color: var(--ifm-link-color);
background-color: #f1f5f9;
}
}

html[data-theme='dark'] .backButton {
background-color: #1e293b;

&:hover {
background-color: #334155;
background-color: var(--back-btn-bg-color-hover);
}
}

1 comment on commit 4831dd8

@vercel
Copy link

@vercel vercel bot commented on 4831dd8 Dec 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blog – ./

blog-git-main-kuizuo1.vercel.app
blog-kuizuo1.vercel.app
kuizuo.cn
blog-kuizuo.vercel.app

Please sign in to comment.