All Projects → abinavseelan → react-input-trigger

abinavseelan / react-input-trigger

Licence: MIT license
React component for handling character triggers inside textareas and input fields. 🐼

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to react-input-trigger

React Adsense
📽 a simple React-component for Google AdSense / Baidu advertisement.
Stars: ✭ 210 (+138.64%)
Mutual labels:  react-component
React Sight
Visualization tool for React, with support for Fiber, Router (v4), and Redux
Stars: ✭ 2,716 (+2986.36%)
Mutual labels:  react-component
React Email Editor
Drag-n-Drop Email Editor Component for React.js
Stars: ✭ 3,131 (+3457.95%)
Mutual labels:  react-component
Yoshino
A themable React component library!Flexible Lightweight PC UI Components built on React! Anyone can generate easily all kinds of themes by it!
Stars: ✭ 216 (+145.45%)
Mutual labels:  react-component
React Kawaii
Cute SVG React Components
Stars: ✭ 2,709 (+2978.41%)
Mutual labels:  react-component
React Sweet Progress
A way to quickly add a progress bar to react app 🌈
Stars: ✭ 239 (+171.59%)
Mutual labels:  react-component
React Reorder
Drag & drop, touch enabled, reorderable / sortable list, React component
Stars: ✭ 209 (+137.5%)
Mutual labels:  react-component
react-antd-formutil
Happy to use react-formutil in the project based on ant-design ^_^
Stars: ✭ 16 (-81.82%)
Mutual labels:  react-component
Virtual List
🧾 React Virtual List Component which worked with animation
Stars: ✭ 232 (+163.64%)
Mutual labels:  react-component
Sweetalert React
Declarative SweetAlert in React
Stars: ✭ 244 (+177.27%)
Mutual labels:  react-component
React Split Pane
React split-pane component
Stars: ✭ 2,665 (+2928.41%)
Mutual labels:  react-component
React Native Htmlview
A React Native component which renders HTML content as native views
Stars: ✭ 2,546 (+2793.18%)
Mutual labels:  react-component
React Css Grid
React layout component based on CSS Grid Layout and built with styled-components
Stars: ✭ 239 (+171.59%)
Mutual labels:  react-component
React Intl Tel Input
Rewrite International Telephone Input in React.js. (Looking for maintainers, and PRs & contributors are also welcomed!)
Stars: ✭ 212 (+140.91%)
Mutual labels:  react-component
React Powerplug
🔌 Renderless Containers
Stars: ✭ 2,704 (+2972.73%)
Mutual labels:  react-component
React Code Input
React component for entering and validating PIN code.
Stars: ✭ 207 (+135.23%)
Mutual labels:  react-component
React Native demo
react-native实现网易新闻和美团,实现大部分页面。使用最新的react-navigation等组件,同时支持安卓和iOS设备。
Stars: ✭ 237 (+169.32%)
Mutual labels:  react-component
rn-markdown
basic markdown renderer for react-native using the great https://github.com/chjj/marked parser
Stars: ✭ 21 (-76.14%)
Mutual labels:  react-component
React Emoji Render
Normalize and render emoji's the way your users expect.
Stars: ✭ 250 (+184.09%)
Mutual labels:  react-component
Boundless
✨ accessible, battle-tested React components with infinite composability
Stars: ✭ 242 (+175%)
Mutual labels:  react-component

React Input Trigger

npm license downloads size

deps peer-deps

React component for handling character triggers inside textareas and input fields. 🐼

Description

Useful for building applications that need Slack-like emoji suggestions (triggered by typing :) or Github-like user mentions (triggered by typing @).

The component provides the following hooks:

  • onStart: whenever the trigger is first activated (eg. when @ is first typed).
  • onType: when something is being typed after it's been triggered.
  • onCancel: when the trigger is canceled.

The hooks pass some meta-data such as the cursor position and/or the text that has been typed since the trigger has been activated.

reactinputtrigger

Demo

A live demo of this component can be found here.

A detailed guide on using this component to build a Github-style user mentions component can be found on CampVanilla.

Usage

Getting Started

  • Install the component
$ npm install react-input-trigger
  • Import the component from the package.
import InputTrigger from 'react-input-trigger';
  • Wrap your existing <textarea /> or <input /> element with <InputTrigger />
<InputTrigger>
  <textarea />
</InputTrigger>

Or get it in the browser directly via unpkg:

<script
  src="https://unpkg.com/react-input-trigger@latest/build/lib/react-input-trigger.js"
  type="text/javascript">
</script>

Component Props

<InputTrigger> can take in the following props:

trigger

This prop takes an object that defines the trigger. The object can have the following properties

  • keyCode: This is the character code that will fire the trigger.
  • shiftKey: (Optional) Set this to true if you need the shift key to be pressed along with the keyCode to start the trigger. Ignore this property if it's not required.
  • ctrlKey: (Optional) Set this to true if you need the ctrl key to be pressed along with the keyCode to start the trigger. Ignore this property if it's not required.
  • metaKey: (Optional) Set this to true if you need the cmd key to be pressed along with the keyCode to start the trigger. Ignore this property if it's not required.
<InputTrigger
  trigger={{
    keyCode: 50,
    shiftKey: true,
  }}
>

onStart

This prop takes a function that will fire whenever trigger is activated. The function is passed some meta information about the cursor's position that you can use.

<InputTrigger
  trigger={{
    keyCode: 50,
    shiftKey: true,
  }}
  onStart={(obj) => { console.log(obj); }}
>

The parameter obj contains the following meta information

{
  "hookType": "start",
  "cursor": {
    "selectionStart",
    "selectionEnd",
    "top",
    "left",
    "height"
  }
}

onCancel

This prop takes a function that will fire everytime the user presses backspace and removes the trigger from the input section. The function is passed some meta information about the cursor's position that you can use.

<InputTrigger
  trigger={{
    keyCode: 50,
    shiftKey: true,
  }}
  onCancel={(obj) => { console.log(obj); }}
>

The parameter obj contains the following meta information

{
  "hookType": "cancel",
  "cursor": {
    "selectionStart",
    "selectionEnd",
    "top",
    "left",
    "height"
  }
}

onType

This prop takes a function that will trigger everytime the user continues typing after starting the trigger. The function is passed some meta information about the cursor's position, as well as the text that the user has typed after triggering that you can use.

<InputTrigger
  trigger={{
    keyCode: 50,
    shiftKey: true,
  }}
  onType={(obj) => { console.log(obj); }}
>

The parameter obj contains the following meta information

{
  "hookType": "typing",
  "cursor": {
    "selectionStart",
    "selectionEnd",
    "top",
    "left",
    "height"
  },
  "text"
}

endTrigger

This prop takes a function that returns a function that you need to keep in your parent component. This returned method needs to be called manually by the parent component whenever you are done using the trigger and want to end the trigger.

<InputTrigger
  endTrigger={
    endTriggerHandler => {
      this.endTriggerHandler = endTriggerHandler;

      /*
        Now you can call `this.endTriggerHandler`
        anywhere inside the parent component
        whenever you want to stop the trigger!
      */
    }
  }
>

Contributing

Want to fix something, add a new feature or raise an issue? Please read the contributing guide to get started. 😄

Contributors

Thanks goes to these wonderful people (emoji key):


Abinav Seelan

💻 📖

Aditi Mohanty

💻 📖

Adam Goldman

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].