Socket
Socket
Sign inDemoInstall

vue-highlightable-input

Package Overview
Dependencies
15
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vue-highlightable-input

A Vue.js component that highlights text as you type


Version published
Weekly downloads
376
decreased by-0.27%
Maintainers
1
Install size
3.74 MB
Created
Weekly downloads
 

Readme

Source

icon npm version

Vue Highlightable Input

Highlight and style specific words as you're typing.

alt demo Try it yourself

Install

npm install vue-highlightable-input --save

Usage

In your template add this:
<highlightable-input 
  highlight-style="background-color:yellow" 
  :highlight-enabled="highlightEnabled" 
  :highlight="highlight" 
  v-model="msg"
/>
In your component add this:
import HighlightableInput from "vue-highlightable-input"
export default {
  name: 'HelloWorld',
  components : {
    HighlightableInput
  },
  data() {
    return {
      msg: '',
      highlight: [
        {text:'chicken', style:"background-color:#f37373"},
        {text:'noodle', style:"background-color:#fca88f"},
        {text:'soup', style:"background-color:#bbe4cb"},
        {text:'so', style:"background-color:#fff05e"},
        "whatever",
        {start: 2, end: 5, style:"background-color:#f330ff"}
      ],
      highlightEnabled: true
    }
  },
}

Props

NameRequiredTypeDefaultDescriptionReactive
highlightYesString or ArraynullThe string or list of words to highlight. This can be a single string value, a RegExp or you can do an array of strings or RegExp or array of Highlight Objects or array of Range Objects.Yes
highlightEnabledNoBooleantrueIf true, will highlight the textYes
highlightStyleNoString or Objectbackground-color:yellowIf no style is provided for text, this will act as the global styling for the highlight. Can also be a dictionary instead of string.Yes
highlightDelayNoNumber500Determines how long in milliseconds to wait before processing the highlights. Setting this to a low value is fine for small text but setting it higher may improve performance significantly for larger textYes
caseSensitiveNoBooleanfalseIf true, will treat highlight strings with case sensitivity. Can be overrided per highlight object.Yes
valueNoStringnullRaw text value.Yes
fireOnNoStringkeydownThe dom event on which the highlight event should be fired. This can be any event that the div content editable can handle.No (only because the listener is being added in mounted)
fireOnEnabledNoBooleantrueIf true, will process the highlights on the specified (or default) event.No (only because the value is used in the mounted function)
Highlight Object
{
    text:'chicken', // Required
    style:"background-color:#f37373" // Optional
    caseSensitive: true // Optional defaults to False
}
Range Object
{
    start:1, // Required
    end: 9,  // Required
    style:"background-color:#f37373" // Optional
}

End must be greater than start. The range end is exlusive in other words ==> [start, end)

Events

NameDescription
@inputJust like a regular input html element you can use this to react to input events

Note, that you can also use v-model

Some notes

  • This is not meant to be used for large scale text highlight because of how inefficient div contentEditable is and also the fact the algorithm I'm using is stupidly inefficient (try entering like a lot of text for highlighting)
  • Good use cases for this are something like what wit.ai does (they probably have a more efficient algorithm though) for highlighting recognized entities on the fly.
  • Let me know what other use cases you might have!

Why make this?

  • I liked the way wit.ai does highlighting and I wanted to recreate that in Vue.
  • Because I was bored and also had a similar problem at work (No, I wasn't bored at work! Quite the opposite actually.)
  • Because I still know nothing about web development and I'm still a n00b. Roast me bro.
  • Because it looks cool!

Credits

For the cool highlighter pen icon: Icons made by Freepik from Flaticon is licensed by Creative Commons BY 3.0

License

MIT

FAQs

Last updated on 03 May 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc