-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Highlight): add support for Highlight component (#3810)
* feat(Highlight): add support for Highlight component * feat(AutoComplete): use Highlight to highlight the matching part of the option text * fix: fix redundant less dependency * docs(Highlight): update docs * fix: update --rs-text-highlight-bg
- Loading branch information
Showing
39 changed files
with
644 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Highlight | ||
|
||
Used to mark or highlight matched text content. For example, used to highlight search results. | ||
|
||
## Import | ||
|
||
<!--{include:<import-guide>}--> | ||
|
||
## Examples | ||
|
||
### Default | ||
|
||
<!--{include:`basic.md`}--> | ||
|
||
### Highlight with multiple words | ||
|
||
<!--{include:`multiple-words.md`}--> | ||
|
||
### Custom Highlight | ||
|
||
<!--{include:`custom.md`}--> | ||
|
||
### Combine with search | ||
|
||
<!--{include:`search.md`}--> | ||
|
||
## Props | ||
|
||
### `<Highlight>` | ||
|
||
| Property | Type`(Default)` | Description | | ||
| ----------- | ------------------------------------------- | -------------------------------------- | | ||
| children | ReactNode | The content to highlight. | | ||
| classPrefix | string `('highlight')` | The prefix of the component CSS class. | | ||
| query | string \| string[] | The keyword to highlight. | | ||
| renderMark | (match: string, index: number) => ReactNode | Custom render the highlight mark. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!--start-code--> | ||
|
||
```js | ||
import { Highlight } from 'rsuite'; | ||
|
||
const App = () => { | ||
return ( | ||
<Highlight query="react"> | ||
React Suite is a set of react components that have high quality and high performance. | ||
</Highlight> | ||
); | ||
}; | ||
ReactDOM.render(<App />, document.getElementById('root')); | ||
``` | ||
|
||
<!--end-code--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!--start-code--> | ||
|
||
```js | ||
import { Highlight } from 'rsuite'; | ||
|
||
const App = () => { | ||
return ( | ||
<Highlight | ||
query={['high quality', 'high performance']} | ||
renderMark={(match, index) => ( | ||
<mark key={index} style={{ backgroundColor: '#f4f4f4', color: '#f00' }}> | ||
{match} | ||
</mark> | ||
)} | ||
> | ||
React Suite is a set of react components that have high quality and high performance. | ||
</Highlight> | ||
); | ||
}; | ||
ReactDOM.render(<App />, document.getElementById('root')); | ||
``` | ||
|
||
<!--end-code--> |
16 changes: 16 additions & 0 deletions
16
docs/pages/components/highlight/fragments/multiple-words.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!--start-code--> | ||
|
||
```js | ||
import { Highlight } from 'rsuite'; | ||
|
||
const App = () => { | ||
return ( | ||
<Highlight query={['high quality', 'high performance']}> | ||
React Suite is a set of react components that have high quality and high performance. | ||
</Highlight> | ||
); | ||
}; | ||
ReactDOM.render(<App />, document.getElementById('root')); | ||
``` | ||
|
||
<!--end-code--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<!--start-code--> | ||
|
||
```js | ||
import { Highlight, List, Input } from 'rsuite'; | ||
|
||
const App = () => { | ||
const [query, setQuery] = React.useState('react'); | ||
|
||
const filteredData = data.filter(item => { | ||
return ( | ||
item.name.toLowerCase().includes(query.toLowerCase()) || | ||
item.description.toLowerCase().includes(query.toLowerCase()) | ||
); | ||
}); | ||
|
||
return ( | ||
<div> | ||
<Input placeholder="Search" value={query} onChange={setQuery} /> | ||
<hr /> | ||
<List> | ||
{filteredData.map(item => ( | ||
<List.Item key={item.name}> | ||
<Highlight query={query}>{item.name}</Highlight> | ||
<p> | ||
<Highlight query={query}>{item.description}</Highlight> | ||
</p> | ||
</List.Item> | ||
))} | ||
</List> | ||
</div> | ||
); | ||
}; | ||
ReactDOM.render(<App />, document.getElementById('root')); | ||
|
||
const data = [ | ||
{ | ||
name: 'React', | ||
description: | ||
'React is a declarative, efficient, and flexible JavaScript library for building user interfaces.' | ||
}, | ||
{ | ||
name: 'React Router', | ||
description: | ||
'React Router is a collection of navigational components that compose declaratively with your application.' | ||
}, | ||
{ | ||
name: 'React Suite', | ||
description: | ||
'React Suite is a set of react components that have high quality and high performance.' | ||
}, | ||
{ | ||
name: 'React Virtualized', | ||
description: 'React components for efficiently rendering large lists and tabular data.' | ||
}, | ||
{ | ||
name: 'React DnD', | ||
description: 'Drag and Drop for React.' | ||
}, | ||
{ | ||
name: 'React Bootstrap', | ||
description: | ||
'React-Bootstrap replaces the Bootstrap JavaScript. Each component has been built from scratch as a true React component, without unneeded dependencies like jQuery.' | ||
}, | ||
{ | ||
name: 'Ant Design', | ||
description: 'An enterprise-class UI design language and React UI library.' | ||
}, | ||
{ | ||
name: 'Material-UI', | ||
description: "React components that implement Google's Material Design." | ||
} | ||
]; | ||
``` | ||
|
||
<!--end-code--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import { Highlight, Input, List } from 'rsuite'; | ||
import DefaultPage from '@/components/Page'; | ||
import ImportGuide from '@/components/ImportGuide'; | ||
|
||
const inDocsComponents = { | ||
'import-guide': () => <ImportGuide components={['Highlight']} /> | ||
}; | ||
|
||
export default function Page() { | ||
return ( | ||
<DefaultPage inDocsComponents={inDocsComponents} dependencies={{ Highlight, Input, List }} /> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Highlight 高亮 | ||
|
||
用于标记或突出显示匹配的文本内容。例如,用于高亮搜索结果。 | ||
|
||
## 获取组件 | ||
|
||
<!--{include:<import-guide>}--> | ||
|
||
## 示例 | ||
|
||
### 默认 | ||
|
||
<!--{include:`basic.md`}--> | ||
|
||
### 高亮多个词 | ||
|
||
<!--{include:`multiple-words.md`}--> | ||
|
||
### 自定义高亮 | ||
|
||
<!--{include:`custom.md`}--> | ||
|
||
### 与搜索结合 | ||
|
||
<!--{include:`search.md`}--> | ||
|
||
## Props | ||
|
||
### `<Highlight>` | ||
|
||
| 属性 | 类型`(默认值)` | 描述 | | ||
| ----------- | ------------------------------------------- | -------------------------- | | ||
| children | ReactNode | 需要高亮的内容。 | | ||
| classPrefix | string `('highlight')` | 组件 CSS 类名的前缀。 | | ||
| query | string \| string[] | 需要高亮的关键词。 | | ||
| renderMark | (match: string, index: number) => ReactNode | 自定义高亮标记的渲染函数。 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.