Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 8a407c0

Browse files
authored
feat(draser): add goto top (#1113)
1 parent 3ca1740 commit 8a407c0

File tree

6 files changed

+18
-5
lines changed

6 files changed

+18
-5
lines changed

src/components/GotoTop/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@
66

77
import { FC, memo } from 'react'
88

9-
import { scrollToHeader } from '@/utils'
9+
import { scrollToHeader, scrollDrawerToTop } from '@/utils'
1010

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

1414
type TProps = {
1515
testid?: string
16+
type?: 'body' | 'drawer'
1617
}
1718

18-
const GotoTop: FC<TProps> = ({ testid }) => {
19+
const GotoTop: FC<TProps> = ({ testid = 'goto-top', type = 'body' }) => {
20+
const handler = type === 'body' ? scrollToHeader : scrollDrawerToTop
21+
1922
return (
20-
<Wrapper testid={testid} onClick={scrollToHeader}>
23+
<Wrapper testid={testid} onClick={handler}>
2124
<IconButton
2225
path="shape/air-balloon.svg"
2326
hint="回到顶部"

src/containers/tool/Drawer/AddOn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const AddOn: FC<TProps> = ({ type }) => {
7373
</SwitchArticleWrapper>
7474
<SpaceGrow />
7575
<GotoTopWrapper>
76-
<GotoTop />
76+
<GotoTop type="drawer" />
7777
</GotoTopWrapper>
7878
</Wrapper>
7979
)

src/containers/tool/Drawer/Content/DesktopView.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FC, useEffect, useRef, memo } from 'react'
22

3+
import { DRAWER_SCROLLER } from '@/constant'
34
import CustomScroller from '@/components/CustomScroller'
45

56
import renderContent from './renderContent'
@@ -28,6 +29,7 @@ const Content: FC<TProps> = ({ visible, type, attachment, attUser }) => {
2829
return (
2930
<Wrapper>
3031
<CustomScroller
32+
instanceKey={DRAWER_SCROLLER}
3133
direction="vertical"
3234
height="100vh"
3335
shadowSize="small"

utils/constant/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// a.k.a for HOME COMMUNITY NAME
22
export const HCN = 'home'
33
export const BODY_SCROLLER = 'body-scroller'
4+
export const DRAWER_SCROLLER = 'drawer-scroller'
45

56
export { default as TYPE } from './type'
67
export { default as EVENT } from './event'

utils/dom.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ANCHOR, BODY_SCROLLER } from '@/constant'
1+
import { ANCHOR, BODY_SCROLLER, DRAWER_SCROLLER } from '@/constant'
22

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

51+
export const scrollDrawerToTop = (): void => {
52+
if (typeof window === 'object') {
53+
window[DRAWER_SCROLLER]?.scroll({ top: 0 }, 300)
54+
}
55+
}
56+
5157
/**
5258
* froze page's body element
5359
* @returns {void}

utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export {
110110
scrollToHeader,
111111
scrollToTabber,
112112
scrollToTop,
113+
scrollDrawerToTop,
113114
lockPage,
114115
unlockPage,
115116
focusDoraemonBar,

0 commit comments

Comments
 (0)