1.0.2 • Published 5 years ago

react-edit-button v1.0.2

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

react-edit-button

A React wrapper component for making any html element's text editable

NPM Build Status JavaScript Style Guide GitHub

Example animation gif

Install

npm install --save react-edit-button

or

yarn add react-edit-button

Usage

The basic usage of React Edit Button only requires two props - an onAccept function and an html element child that has text as it's child.

import React, { Component } from 'react'
import EditButton from 'react-edit-button'

class Example extends Component {
  state = {
    text: 'edit me'
  }
  onAccept = (text) => {
    this.setState({ text })
  }
  render () {
    return (
      <EditButton onAccept={handleOnAccept}>
        <span>{ this.state.text }</span>
      </EditButton>
    )
  }
}

Props

PropTypeRequiredDefaultNote
containerPropsobjectNoundefinedProps applied to the container element.
editButtonPropsobjectNo{}Props applied to the edit button.
editButtonProps.textstringNo'Edit'Replace the edit button text.
editButtonProps.iconanyNoReplace the default edit button icon with anything.
editModebooleanNoundefinedManually control edit mode.
hideEditButtonbooleanNoundefinedManually control showing and hiding the edit button.
hoverToShowEditButtonbooleanNofalseWill hide the edit button by default and show it on hover of the wrapped element.
inputPropsobjectNo{}Props for the input element.
inputProps.onChangefunctionNoundefinedFunction fired on input change.
inputProps.placeholderstringNoundefinedInput placeholder text.
inputProps.valuestringnumberNoundefinedValue shown in the input (can be different than displayed text in wrapped elelent)
onAcceptfunctionYesundefinedFunction that is fired when the accept button is clicked.
onContainerClickfunctionNoundefinedFunction that is fired when the content container is clicked.
onEditButtonClickfunctionNoundefinedFunction that fires when the edit button is clicked.
onRejectfunctionNoundefinedFunction that is fired when the reject button is clicked.

License

MIT © stackfive