-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
liuyichang
committed
Jul 23, 2018
1 parent
0911fde
commit 0724a71
Showing
19 changed files
with
3,289 additions
and
82 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.DS_Store | ||
node_modules | ||
/dist | ||
/dist/demo.html | ||
/demo | ||
|
||
# local env files | ||
.env.local | ||
|
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,4 @@ | ||
module.exports = { | ||
singleQuote: true, | ||
semi: false | ||
}; |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Yichang Liu | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,100 @@ | ||
# vue-highlight-words | ||
|
||
> A simple port from [`react-highlight-words`](https://github.com/bvaughn/react-highlight-words) | ||
> | ||
> Vue component to highlight words within a larger body of text. | ||
## Usage | ||
|
||
To use it, just provide it with an array of search terms and a body of text to highlight. | ||
|
||
```html | ||
<template> | ||
<div id="app"> | ||
<Highlighter highlightClassName="highlight" | ||
:searchWords="keywords" | ||
:autoEscape="true" | ||
:textToHighlight="text"/> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import Highlighter from 'vue-highlight-words' | ||
export default { | ||
name: 'app', | ||
components: { | ||
Highlighter | ||
}, | ||
data() { | ||
return { | ||
text: 'The dog is chasing the cat. Or perhaps they\'re just playing?', | ||
words: 'and or the' | ||
} | ||
}, | ||
computed: { | ||
keywords() { | ||
return this.words.split(' ') | ||
} | ||
} | ||
} | ||
</script> | ||
``` | ||
|
||
And the `Highlighter` will mark all occurrences of search terms within the text: | ||
|
||
<img width="368" alt="screen shot 2015-12-19 at 8 23 43 am" src="https://cloud.githubusercontent.com/assets/29597/11914033/e3c319f6-a629-11e5-896d-1a5ce22c9ea2.png"> | ||
|
||
## Props | ||
|
||
| Property | Type | Required? | Description | | ||
| :------------------- | :------------ | :-------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| activeClassName | String | | The class name to be applied to an active match. Use along with `activeIndex` | | ||
| activeIndex | String | | Specify the match index that should be actively highlighted. Use along with `activeClassName` | | ||
| activeStyle | Object | | The inline style to be applied to an active match. Use along with `activeIndex` | | ||
| autoEscape | Boolean | | Escape characters in `searchWords` which are meaningful in regular expressions | | ||
| className | String | | CSS class name applied to the outer/wrapper `<span>` | | ||
| caseSensitive | Boolean | | Search should be case sensitive; defaults to `false` | | ||
| findChunks | Function | | Use a custom function to search for matching chunks. This makes it possible to use arbitrary logic when looking for matches. See the default `findChunks` function in [highlight-words-core](https://github.com/bvaughn/highlight-words-core) for signature. Have a look at the [custom findChunks example](https://codesandbox.io/s/k20x3ox31o) on how to use it. | | ||
| highlightClassName | String | | CSS class name applied to highlighted text | | ||
| highlightStyle | Object | | Inline styles applied to highlighted text | | ||
| highlightTag | Node | | Type of tag to wrap around highlighted matches; defaults to `mark` but can also be a React element (class or functional) | | ||
| sanitize | Function | | Process each search word and text to highlight before comparing (eg remove accents); signature `(text: string): string` | | ||
| searchWords | Array<String> | ✓ | Array of search words. The search terms are treated as RegExps unless `autoEscape` is set. | | ||
| textToHighlight | String | ✓ | Text to highlight matches in | | ||
| unhighlightClassName | String | | CSS class name applied to unhighlighted text | | ||
| unhighlightStyle | Object | | Inline styles applied to unhighlighted text | | ||
|
||
|
||
## Installation | ||
|
||
``` | ||
npm i --save react-highlight-words | ||
``` | ||
|
||
## Project setup | ||
|
||
``` | ||
npm install | ||
``` | ||
|
||
### Compiles and hot-reloads for development | ||
|
||
``` | ||
npm run serve | ||
``` | ||
|
||
### Compiles and minifies for production | ||
|
||
``` | ||
npm run build | ||
``` | ||
|
||
### Lints and fixes files | ||
|
||
``` | ||
npm run lint | ||
``` | ||
|
||
## License | ||
MIT License - fork, modify and use however you want. |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = { | ||
presets: ["@vue/app"] | ||
}; | ||
presets: ['@vue/app'] | ||
} |
Oops, something went wrong.