项目作者: danrpts

项目描述 :
A React HOC for adding cursor dropdown menus to textareas and text inputs.
高级语言: JavaScript
项目地址: git://github.com/danrpts/react-cursor-dropdown.git
创建时间: 2018-10-07T04:24:13Z
项目社区:https://github.com/danrpts/react-cursor-dropdown

开源协议:MIT License

下载


react-cursor-dropdown

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

NPM JavaScript Style Guide

Install

  1. npm install --save react-cursor-dropdown

Usage

  1. import React, { Component } from "react";
  2. import { WithCursorDropdown, CursorDropdown } from "react-cursor-dropdown";
  3. // Import the component you want to dropdown from the cursor
  4. import SomeListComponent from "SomeListComponent";
  5. const Input = props => <input {...props} />;
  6. const InputWithCursorDropdown = WithCursorDropdown(Input);
  7. class App extends Component {
  8. constructor(props) {
  9. super(props);
  10. this.state = {
  11. value: ""
  12. };
  13. this.handleChange = ({ target }) => {
  14. this.setState({
  15. value: target.value
  16. });
  17. };
  18. this.handleCursorDropdownChange = ({ value, cursor }) => {
  19. // Do something with the value from the dropdown
  20. };
  21. }
  22. render() {
  23. return (
  24. <InputWithCursorDropdown
  25. value={this.state.value}
  26. onChange={this.handleChange}
  27. onCursorDropdownChange={this.handleCursorDropdownChange}
  28. >
  29. // Specify the regex to match against the current word (capture group
  30. required)
  31. <CursorDropdown pattern={/^:(\w*)$/} component={SomeListComponent} ></CursorDropdown>
  32. </InputWithCursorDropdown>
  33. );
  34. }
  35. }

License

MIT © danrpts