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

Commit 18c1f50

Browse files
committed
feat(doraemon): support hightlight keywords
1 parent 057aefd commit 18c1f50

File tree

6 files changed

+139
-52
lines changed

6 files changed

+139
-52
lines changed

containers/Doraemon/ResultsList.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import R from 'ramda'
3+
import Highlighter from 'react-highlight-words'
34

45
import { ICON_CMD } from 'config'
56

@@ -29,7 +30,7 @@ const HintIcon = ({ index, active, cur, length }) => {
2930
return null
3031
}
3132

32-
const ResultsList = ({ searchThread, suggestions, activeRaw }) => (
33+
const ResultsList = ({ searchValue, searchThread, suggestions, activeRaw }) => (
3334
<Wrapper>
3435
<SuggestionWrapper empty={suggestions.length === 0}>
3536
{suggestions.map((suggestion, i) => (
@@ -47,7 +48,14 @@ const ResultsList = ({ searchThread, suggestions, activeRaw }) => (
4748
searchThread={searchThread}
4849
/>
4950
<ContentWraper>
50-
<Title>{suggestion.title}</Title>
51+
<Title>
52+
<Highlighter
53+
highlightClassName="YourHighlightClass"
54+
searchWords={[searchValue]}
55+
autoEscape
56+
textToHighlight={suggestion.title}
57+
/>
58+
</Title>
5159
<Desc>{suggestion.desc}</Desc>
5260
</ContentWraper>
5361
<HintIcon

containers/Doraemon/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class DoraemonContainer extends React.Component {
6464
<AlertBar value={inputValue} searchThread={searchThread} />
6565
)}
6666
<ResultsList
67+
searchValue={inputValue}
6768
suggestions={suggestions}
6869
activeRaw={activeRaw}
6970
searchThread={searchThread}

containers/Doraemon/styles/results_list.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ export const Title = styled.div`
112112
> a {
113113
color: ${theme('shell.link')};
114114
}
115+
116+
${cs.truncate('400px')};
117+
${cs.media.mobile`
118+
${cs.truncate('200px')};
119+
`};
115120
`
116121
export const Desc = styled.div`
117122
color: ${theme('shell.desc')};

package-docker.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"react-calendar-heatmap": "^1.6.3",
6060
"react-content-loader": "3.1.2",
6161
"react-dom": "16.6.0",
62+
"react-highlight-words": "^0.16.0",
6263
"react-intl": "2.4.0",
6364
"react-json-view": "1.19.1",
6465
"react-keydown": "1.9.7",

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"react-calendar-heatmap": "^1.6.3",
100100
"react-content-loader": "3.1.2",
101101
"react-dom": "16.6.0",
102+
"react-highlight-words": "^0.16.0",
102103
"react-intl": "2.4.0",
103104
"react-json-view": "1.19.1",
104105
"react-keydown": "1.9.7",

0 commit comments

Comments
 (0)