Skip to content

Commit

Permalink
feat: change all the scrollbars to overlay style
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiteMinds committed Dec 7, 2023
1 parent a97c688 commit 2b71649
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 57 deletions.
1 change: 0 additions & 1 deletion packages/neuron/src/components/Header/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ $desktopHeaderContentHeight: 88px;

.content {
margin: 64px 0;
overflow: auto;
}

.close {
Expand Down
73 changes: 38 additions & 35 deletions packages/neuron/src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Link from 'next/link'
import * as Dialog from '@radix-ui/react-dialog'
import { useRouter } from 'next/router'
import { useTranslation } from 'react-i18next'
import { OverlayScrollbarsComponent } from 'overlayscrollbars-react'
import styles from './index.module.scss'
import IconLogo from './logo.svg'
import IconGithub from './github.svg'
Expand Down Expand Up @@ -98,43 +99,45 @@ const MenuDialog: FC = () => {
</Dialog.Close>
</div>

<div className={styles.content}>
<LinkWithEffect className={styles.title} href="/">
{t('Home')}
</LinkWithEffect>

<div className={styles.title}>{t('Services')}</div>
<div className={styles.links}>
<LinkWithEffect href="https://neuron.magickbase.com/">{t('Neuron Wallet')}</LinkWithEffect>
<span title="Coming soon">{t('CKB Explorer')}</span>
<span title="Coming soon">{t('Godwoke Explorer')}</span>
<span title="Coming soon">{t('Axon Explorer')}</span>
<span title="Coming soon">{t('Kuai')}</span>
</div>
<OverlayScrollbarsComponent options={{ scrollbars: { autoHide: 'never' } }}>
<div className={styles.content}>
<LinkWithEffect className={styles.title} href="/">
{t('Home')}
</LinkWithEffect>

<div className={styles.title}>{t('Services')}</div>
<div className={styles.links}>
<LinkWithEffect href="https://neuron.magickbase.com/">{t('Neuron Wallet')}</LinkWithEffect>
<span title="Coming soon">{t('CKB Explorer')}</span>
<span title="Coming soon">{t('Godwoke Explorer')}</span>
<span title="Coming soon">{t('Axon Explorer')}</span>
<span title="Coming soon">{t('Kuai')}</span>
</div>

<LinkWithEffect
className={styles.title}
href="https://github.com/nervosnetwork/ckb/wiki/Public-JSON-RPC-nodes"
>
{t('Public Node')}
</LinkWithEffect>

<div className={styles.title}>{t('Language')}</div>
<div className={clsx(styles.links, styles.languages)}>
{languages.map(language => (
<LinkWithEffect
key={language.name}
className={clsx(styles.languageItem, {
[styles.selected ?? '']: language.localeName === router.locale,
})}
href={{ pathname, query }}
locale={language.localeName}
>
{language.name}
</LinkWithEffect>
))}
<LinkWithEffect
className={styles.title}
href="https://github.com/nervosnetwork/ckb/wiki/Public-JSON-RPC-nodes"
>
{t('Public Node')}
</LinkWithEffect>

<div className={styles.title}>{t('Language')}</div>
<div className={clsx(styles.links, styles.languages)}>
{languages.map(language => (
<LinkWithEffect
key={language.name}
className={clsx(styles.languageItem, {
[styles.selected ?? '']: language.localeName === router.locale,
})}
href={{ pathname, query }}
locale={language.localeName}
>
{language.name}
</LinkWithEffect>
))}
</div>
</div>
</div>
</OverlayScrollbarsComponent>

<Contacts className={styles.contacts} />
</Dialog.Content>
Expand Down
7 changes: 4 additions & 3 deletions packages/neuron/src/hooks/useMarkdownProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import remarkGfm from 'remark-gfm'
import rehypeRaw from 'rehype-raw'
import rehypeSanitize from 'rehype-sanitize'
import clsx from 'clsx'
import { OverlayScrollbarsComponent } from 'overlayscrollbars-react'
import { TOCItem } from '../components/TableOfContents'
import { UpsideDownEffect } from '../components/UpsideDownEffect'

Expand Down Expand Up @@ -40,10 +41,10 @@ export function useMarkdownProps({
<img {...tagProps} alt={tagProps.alt ?? 'image'} className={clsx(tagProps.className, imgClass)} />
),
table: ({ node, ...tagProps }) => (
// The table is too wide, so we need to wrap it in a container with `overflow: auto`.
<div style={{ width: 'min-content', maxWidth: '100%', overflow: 'auto' }}>
// The table is too wide, so we need to wrap it in the OverlayScrollbarsComponent.
<OverlayScrollbarsComponent options={{ scrollbars: { autoHide: 'never' } }}>
<table {...tagProps} />
</div>
</OverlayScrollbarsComponent>
),
}),
[imgClass, supportToc],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
}

.accordionContent {
min-height: 0;

&[data-state='open'] {
animation: slideDown 300ms cubic-bezier(0.87, 0, 0.13, 1);
}
Expand Down
25 changes: 14 additions & 11 deletions packages/neuron/src/pages/posts/ClassifiedPosts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FC } from 'react'
import * as Accordion from '@radix-ui/react-accordion'
import clsx from 'clsx'
import { useTranslation } from 'react-i18next'
import { OverlayScrollbarsComponent } from 'overlayscrollbars-react'
import { Post, TopLevelMenu, getPostURL } from '../../../utils'
import IconArrow from './arrow.svg'
import styles from './index.module.scss'
Expand Down Expand Up @@ -48,17 +49,19 @@ export const ClassifiedPosts: FC<
</Accordion.Header>

<Accordion.Content className={clsx(styles.accordionContent, postsClass)}>
{menu.posts?.map(post => (
<LinkWithEffect
key={post.key}
data-selected={post.key === viewingPost.key}
className={clsx(styles.post, postClass)}
href={getPostURL(post)}
fullWidth
>
{post.title}
</LinkWithEffect>
))}
<OverlayScrollbarsComponent style={{ maxHeight: '100%' }}>
{menu.posts?.map(post => (
<LinkWithEffect
key={post.key}
data-selected={post.key === viewingPost.key}
className={clsx(styles.post, postClass)}
href={getPostURL(post)}
fullWidth
>
{post.title}
</LinkWithEffect>
))}
</OverlayScrollbarsComponent>
</Accordion.Content>
</Accordion.Item>
))}
Expand Down
4 changes: 0 additions & 4 deletions packages/neuron/src/pages/posts/Sidebar/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ $accordionTriggerHeight: 48px;
}

.posts {
&[data-state='open'] {
overflow: auto;
}

.post {
display: flex;
align-items: center;
Expand Down
11 changes: 9 additions & 2 deletions packages/neuron/src/pages/posts/[...slug].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import clsx from 'clsx'
import { FC, useMemo } from 'react'
import { useObservableState } from 'observable-hooks'
import { useTranslation } from 'react-i18next'
import { OverlayScrollbarsComponent } from 'overlayscrollbars-react'
import { TOCContextProvider, TOCItem } from '../../components/TableOfContents'
import {
Post,
Expand Down Expand Up @@ -87,13 +88,19 @@ export const PostPage$Desktop: FC<PageProps> = ({ post, menusWithPosts, menuWith
<div className={styles.item}>{post.title}</div>
</div>

<div ref={scrollContainerRef} className={clsx(CrawlableContentClassname, styles.postContent)}>
<OverlayScrollbarsComponent
ref={obj => {
const scrollContainer = obj?.osInstance()?.elements().viewport
scrollContainer && scrollContainerRef(scrollContainer)
}}
className={clsx(CrawlableContentClassname, styles.postContent)}
>
<TOCItem id={post.title} titleInTOC={post.title}>
<h1 className={styles.title}>{post.title}</h1>
</TOCItem>

<ReactMarkdown {...mdProps}>{post.body ?? ''}</ReactMarkdown>
</div>
</OverlayScrollbarsComponent>

<TOC className={styles.toc} />
</div>
Expand Down
1 change: 0 additions & 1 deletion packages/neuron/src/pages/posts/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

.postContent {
padding: 0 24px 16px;
overflow: auto;

.img {
max-width: 100%;
Expand Down

0 comments on commit 2b71649

Please sign in to comment.