1.1.2 • Published 6 years ago

react-cursor-dropdown v1.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

react-cursor-dropdown

A React HOC for adding cursor dropdown menus to textareas and inputs - Try it out!

NPM JavaScript Style Guide

Install

npm install --save react-cursor-dropdown

Usage

import React, { Component } from "react";

import { WithCursorDropdown, CursorDropdown } from "react-cursor-dropdown";

// Import the component you want to dropdown from the cursor
import SomeListComponent from "SomeListComponent";

const Input = props => <input {...props} />;
const InputWithCursorDropdown = WithCursorDropdown(Input);

class App extends Component {
  constructor(props) {
    super(props);

    this.state = {
      value: ""
    };

    this.handleChange = ({ target }) => {
      this.setState({
        value: target.value
      });
    };

    this.handleCursorDropdownChange = ({ value, cursor }) => {
      // Do something with the value from the dropdown
    };
  }

  render() {
    return (
      <InputWithCursorDropdown
        value={this.state.value}
        onChange={this.handleChange}
        onCursorDropdownChange={this.handleCursorDropdownChange}
      >
        // Specify the regex to match against the current word (capture group
        required)
        <CursorDropdown pattern={/^:(\w*)$/} component={SomeListComponent} />
      </InputWithCursorDropdown>
    );
  }
}

License

MIT © danrpts