1.2.1 • Published 5 years ago

react-editable-text v1.2.1

Weekly downloads
18
License
MIT
Repository
github
Last release
5 years ago

react-editable-text

Editable text line or box component for facebook react.Box use textarea element, Line use input[type=text] element.

I recommend using with Bootstrap.

Install

npm install react-editable-text --save-dev

How to use

import React from 'react';
import Box from 'react-editable-text/Box';
import Line from 'react-editable-text/Line';

export default class GuestEditView extends React.Component
{
  constructor(props) {
    super(props);
  }

  onSaveMemo(memo, textarea){
    setTimeout(() => {
      console.log(memo);
      textarea.fix();
    }, 600);
  }

  render() {
    return (
      <div>
        <Line
          label='<i class="fa fa-user"></i>'
          onSave={(value, editable) => this.onSave(value, editable)}
          editLabel='<i class="fa fa-pencil"></i>'
          saveLabel='<i class="fa fa-floppy-o"></i>'
          cancelLabel='<i class="fa fa-ban"></i>'
          value='Initial line value'
          needsSaveOnKeyPress = {(e) => this.needsSaveOnKeyPressInInputText(e)}
        />
        <Box
          label='<i class="fa fa-list-alt"></i>&nbsp;Memo'
          onSave={(value, editable) => this.onSave(value, editable)}
          editLabel='<i class="fa fa-pencil"></i>'
          saveLabel='<i class="fa fa-floppy-o"></i>'
          cancelLabel='<i class="fa fa-ban"></i>'
          value='Initial box value'
          needsSaveOnKeyPress = {(e) => this.needsSaveOnKeyPressInTextarea(e)}
        />
      </div>
    );
  }
}

onSave sample is here. Second arg editable is this component.

  onSave(value, editable){
    $.ajax({
      url: '/ajax/save',
      data:{value: value}
    }).done(() => {
      // change to fix mode
      editable.success();
    }).fail(() => {
      // back to edit mode
      editable.fail();
    });
  }

If you want save when some key press in the element, Set callback to needsSaveOnKeyPress props, and return true.The arg is keypress event.

  needsSaveOnKeyPressInInputText(e){
    if(e.charCode == 13){
      return true;
    }

    return false;
  }

  needsSaveOnKeyPressInTextarea(e){
    if(e.charCode == 13 && e.shiftKey){
      return true;
    }

    return false;
  }

All labels are set to dangerouslySetInnerHTML.Please note the "cross-site scripting".

All props list is here

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago