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

Commit df176a7

Browse files
committed
refactor(doramon): use react version of custom-scrollbar
1 parent a609f1e commit df176a7

File tree

4 files changed

+47
-56
lines changed

4 files changed

+47
-56
lines changed
+43-37
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import React from 'react'
22
import R from 'ramda'
33
import Highlighter from 'react-highlight-words'
4+
import { OverlayScrollbarsComponent } from 'overlayscrollbars-react'
45

6+
// eslint-disable-next-line import/named
57
import { ICON_CMD } from '@config'
68
import { THREAD } from '@constant'
79

@@ -30,43 +32,47 @@ const HintIcon = ({ index, active, cur, length }) => {
3032
}
3133

3234
const ResultsList = ({ searchValue, searchThread, suggestions, activeRaw }) => (
33-
<Wrapper id="suggestion-scroller">
34-
<SuggestionWrapper empty={suggestions.length === 0}>
35-
{suggestions.map((suggestion, i) => (
36-
<InfoBar
37-
active={activeRaw === suggestion.raw}
38-
key={suggestion.raw}
39-
id={suggestion.raw}
40-
onMouseEnter={navToSuggestion.bind(this, suggestion)}
41-
onClick={suggestionOnSelect}
42-
>
43-
<SuggestIcon
44-
raw={suggestion.raw}
45-
suggestion={suggestion}
46-
round={R.contains(searchThread, [THREAD.POST, THREAD.USER])}
47-
searchThread={searchThread}
48-
/>
49-
<ContentWraper>
50-
<Title>
51-
<Highlighter
52-
highlightClassName="doramon-search-highlighter"
53-
searchWords={[searchValue]}
54-
autoEscape
55-
textToHighlight={suggestion.title}
56-
/>
57-
</Title>
58-
<Desc>{suggestion.desc}</Desc>
59-
</ContentWraper>
60-
<HintIcon
61-
index={i}
62-
active={activeRaw}
63-
cur={suggestion.raw}
64-
length={suggestions.length}
65-
/>
66-
</InfoBar>
67-
))}
68-
</SuggestionWrapper>
69-
</Wrapper>
35+
<OverlayScrollbarsComponent
36+
options={{ scrollbars: { autoHide: 'scroll', autoHideDelay: 200 } }}
37+
>
38+
<Wrapper>
39+
<SuggestionWrapper empty={suggestions.length === 0}>
40+
{suggestions.map((suggestion, i) => (
41+
<InfoBar
42+
active={activeRaw === suggestion.raw}
43+
key={suggestion.raw}
44+
id={suggestion.raw}
45+
onMouseEnter={navToSuggestion.bind(this, suggestion)}
46+
onClick={suggestionOnSelect}
47+
>
48+
<SuggestIcon
49+
raw={suggestion.raw}
50+
suggestion={suggestion}
51+
round={R.contains(searchThread, [THREAD.POST, THREAD.USER])}
52+
searchThread={searchThread}
53+
/>
54+
<ContentWraper>
55+
<Title>
56+
<Highlighter
57+
highlightClassName="doramon-search-highlighter"
58+
searchWords={[searchValue]}
59+
autoEscape
60+
textToHighlight={suggestion.title}
61+
/>
62+
</Title>
63+
<Desc>{suggestion.desc}</Desc>
64+
</ContentWraper>
65+
<HintIcon
66+
index={i}
67+
active={activeRaw}
68+
cur={suggestion.raw}
69+
length={suggestions.length}
70+
/>
71+
</InfoBar>
72+
))}
73+
</SuggestionWrapper>
74+
</Wrapper>
75+
</OverlayScrollbarsComponent>
7076
)
7177

7278
export default ResultsList

src/containers/Doraemon/index.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
import React from 'react'
88

99
import { connectStore, buildLog } from '@utils'
10-
import { usePlatform } from '@hooks'
11-
12-
import { PageOverlay, PanelContainer } from './styles'
1310

1411
import InputEditor from './InputEditor'
1512
import ResultsList from './ResultsList'
@@ -18,15 +15,14 @@ import ThreadSelectBar from './ThreadSelectBar'
1815
import AlertBar from './AlertBar'
1916
import UtilsBar from './UtilsBar'
2017

21-
import { useInit, useScrollbar, hidePanel } from './logic'
18+
import { PageOverlay, PanelContainer } from './styles'
19+
import { useInit, hidePanel } from './logic'
2220

2321
/* eslint-disable-next-line */
2422
const log = buildLog('C:Doraemon')
2523

2624
const DoraemonContainer = ({ doraemon }) => {
2725
useInit(doraemon)
28-
const { isMacOS } = usePlatform()
29-
useScrollbar(isMacOS)
3026

3127
const {
3228
inputValue,

src/containers/Doraemon/logic/index.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import R from 'ramda'
22
import { useEffect } from 'react'
33
import Router from 'next/router'
44

5+
// eslint-disable-next-line import/named
56
import { ISSUE_ADDR } from '@config'
67
import { TYPE, EVENT, ERR, THREAD } from '@constant'
78
import {
@@ -496,15 +497,6 @@ const initSpecCmdResolver = () => {
496497
// ###############################
497498
// init & uninit handlers
498499
// ###############################
499-
export const useScrollbar = isMacOS => {
500-
useEffect(() => {
501-
if (isMacOS) {
502-
/* eslint-disable no-undef */
503-
OverlayScrollbars(document.getElementById('suggestion-scroller'), {})
504-
}
505-
}, [isMacOS])
506-
}
507-
508500
export const useInit = _store => {
509501
useEffect(() => {
510502
store = _store

src/containers/Doraemon/styles/results_list.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ import styled from 'styled-components'
33
import Img from '@components/Img'
44
import { theme, animate, cs } from '@utils'
55

6-
export const Wrapper = styled.div.attrs(({ id }) => ({
7-
id,
8-
}))`
6+
export const Wrapper = styled.div`
97
width: 100%;
10-
overflow: hidden;
118
max-height: 400px;
129
`
1310
export const LoadingIcon = styled(Img)`

0 commit comments

Comments
 (0)