Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/components/GotoTop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@

import { FC, memo } from 'react'

import { scrollToHeader } from '@/utils'
import { scrollToHeader, scrollDrawerToTop } from '@/utils'

import { IconButton } from '@/components/Buttons'
import { Wrapper } from './styles'

type TProps = {
testid?: string
type?: 'body' | 'drawer'
}

const GotoTop: FC<TProps> = ({ testid }) => {
const GotoTop: FC<TProps> = ({ testid = 'goto-top', type = 'body' }) => {
const handler = type === 'body' ? scrollToHeader : scrollDrawerToTop

return (
<Wrapper testid={testid} onClick={scrollToHeader}>
<Wrapper testid={testid} onClick={handler}>
<IconButton
path="shape/air-balloon.svg"
hint="回到顶部"
Expand Down
2 changes: 1 addition & 1 deletion src/containers/tool/Drawer/AddOn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const AddOn: FC<TProps> = ({ type }) => {
</SwitchArticleWrapper>
<SpaceGrow />
<GotoTopWrapper>
<GotoTop />
<GotoTop type="drawer" />
</GotoTopWrapper>
</Wrapper>
)
Expand Down
2 changes: 2 additions & 0 deletions src/containers/tool/Drawer/Content/DesktopView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FC, useEffect, useRef, memo } from 'react'

import { DRAWER_SCROLLER } from '@/constant'
import CustomScroller from '@/components/CustomScroller'

import renderContent from './renderContent'
Expand Down Expand Up @@ -28,6 +29,7 @@ const Content: FC<TProps> = ({ visible, type, attachment, attUser }) => {
return (
<Wrapper>
<CustomScroller
instanceKey={DRAWER_SCROLLER}
direction="vertical"
height="100vh"
shadowSize="small"
Expand Down
1 change: 1 addition & 0 deletions utils/constant/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// a.k.a for HOME COMMUNITY NAME
export const HCN = 'home'
export const BODY_SCROLLER = 'body-scroller'
export const DRAWER_SCROLLER = 'drawer-scroller'

export { default as TYPE } from './type'
export { default as EVENT } from './event'
Expand Down
8 changes: 7 additions & 1 deletion utils/dom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ANCHOR, BODY_SCROLLER } from '@/constant'
import { ANCHOR, BODY_SCROLLER, DRAWER_SCROLLER } from '@/constant'

// side effects, need refactor
/* eslint-disable no-undef */
Expand Down Expand Up @@ -48,6 +48,12 @@ export const scrollIntoEle = (eleID: string): void => {
export const scrollToHeader = (): void => scrollIntoEle(ANCHOR.GLOBAL_HEADER_ID)
export const scrollToTabber = (): void => scrollIntoEle(ANCHOR.GLOBAL_TABBER_ID)

export const scrollDrawerToTop = (): void => {
if (typeof window === 'object') {
window[DRAWER_SCROLLER]?.scroll({ top: 0 }, 300)
}
}

/**
* froze page's body element
* @returns {void}
Expand Down
1 change: 1 addition & 0 deletions utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export {
scrollToHeader,
scrollToTabber,
scrollToTop,
scrollDrawerToTop,
lockPage,
unlockPage,
focusDoraemonBar,
Expand Down