|
1 | 1 | # A simple React inline editing component.
|
| 2 | + |
| 3 | +## Reasoning |
| 4 | + |
| 5 | +This npm package is originally adapted from https://github.com/bfischer/react-inline-editing. I found the package a few days ago and is super useful but un-maintained? Mainly needed it to work with TypeScript + ReactJS. The below README desc is adapted from the originator's README. |
| 6 | + |
| 7 | +This is an inline, editable text/label component built in React + TypeScript. |
| 8 | + |
| 9 | +The `<InlineInputEdit />` allows the user to simply click and edit text inline. It consists of a `<label>` element to display the unedited text and an `<input />` element to allow editing. |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +- `npm install --save react-inline-input-edit` |
| 16 | +- `yarn add react-inline-input-edit` |
| 17 | + |
| 18 | +## Component `props` |
| 19 | +_* Required_ |
| 20 | + |
| 21 | +| Prop | Type | Description | |
| 22 | +| ---------------- | -------- | ------------------------------------------------------------------------------------ | |
| 23 | +| text (*) | string | Text to be displayed on both the label and initially in the editor | |
| 24 | +| isEditing | boolean | Flags whether the label should be in editor mode | |
| 25 | +| emptyEdit | boolean | Flags whether the label should be in editor mode when text is empty('' or undefined) | |
| 26 | +| labelPlaceHolder | string | Label value to display when text is not present | |
| 27 | +| labelClassName | string | Class name for the text styling | |
| 28 | +| labelFontSize | string | Font size for the text | |
| 29 | +| labelFontWeight | string | Font weight for the text | |
| 30 | +| inputMaxLength | number | Max length for the input in editing mode | |
| 31 | +| inputPlaceHolder | string | Placeholder for the input in editing mode | |
| 32 | +| inputWidth | string | Width of the input in editing mode | |
| 33 | +| inputHeight | string | Height of the input in editing mode | |
| 34 | +| inputFontSize | string | Font size for the input in editing mode | |
| 35 | +| inputFontWeight | string | Font weight for the input in editing mode | |
| 36 | +| inputClassName | string | Class name for the input editor's styling | |
| 37 | +| inputBorderWidth | string | Border width for the input in editing mode | |
| 38 | +| onFocus | function | Callback for text focusing. Parameter(s): `text` | |
| 39 | +| onFocusOut | function | Callback for focus leaving editor. Parameter(s): `text` | |
| 40 | + |
| 41 | + |
| 42 | +## An example |
| 43 | +```javascript |
| 44 | +import React, { FC } from 'react'; |
| 45 | +import { InlineInputEdit } from 'react-inline-input-edit'; |
| 46 | + |
| 47 | +interface Props {} |
| 48 | + |
| 49 | +export const SomeAwesomeComponent: FC<Props> = () => { |
| 50 | + |
| 51 | + const _handleFocus = (text: any) => { |
| 52 | + console.log('Focused with text: ' + text); |
| 53 | + }; |
| 54 | + |
| 55 | + const _handleFocusOut = (text: any) => { |
| 56 | + console.log('Left editor with text: ' + text); |
| 57 | + }; |
| 58 | + |
| 59 | + return ( |
| 60 | + <> |
| 61 | + <InlineInputEdit |
| 62 | + text={`Chuck Norris’ tears cure cancer. Too bad he has never cried.`} |
| 63 | + inputWidth="200px" |
| 64 | + inputHeight="25px" |
| 65 | + inputMaxLength={50} |
| 66 | + labelFontWeight="bold" |
| 67 | + inputFontWeight="bold" |
| 68 | + onFocus={_handleFocus} |
| 69 | + onFocusOut={_handleFocusOut} |
| 70 | + /> |
| 71 | + </> |
| 72 | + ) |
| 73 | +}; |
| 74 | +``` |
0 commit comments