|
1 |
| -# react-basic-contenteditable |
2 |
| -React 18 contenteditable component. Super-customizable! |
| 1 | +# React Basic Contenteditable |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +A React component that allows you to create an editable area in your application. It's perfect for situations where you need to provide a user-friendly, in-place editing functionality. |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +Install via npm |
| 10 | + |
| 11 | +```sh |
| 12 | +npm install --save react-basic-contenteditable |
| 13 | +``` |
| 14 | + |
| 15 | +or yarn |
| 16 | + |
| 17 | +```sh |
| 18 | +yarn add react-basic-contenteditable |
| 19 | +``` |
| 20 | + |
| 21 | +## Usage |
| 22 | + |
| 23 | +<!-- Live **demo** at: [https://chrisuser.github.io/react-basic-contenteditable/](https://chrisuser.github.io/react-basic-contenteditable/) --> |
| 24 | + |
| 25 | +### Example |
| 26 | + |
| 27 | +```javascript |
| 28 | +import ContentEditable from "react-basic-contenteditable" |
| 29 | + |
| 30 | +const App = () => { |
| 31 | + const [content, setContent] = useState("") |
| 32 | + |
| 33 | + return ( |
| 34 | + <div> |
| 35 | + <div>{content}</div> |
| 36 | + <ContentEditable |
| 37 | + placeholder="Type here" |
| 38 | + containerClassName="container-class" |
| 39 | + contentEditableClassName="contenteditable-class" |
| 40 | + placeholderClassName="placeholder-class" |
| 41 | + onChange={(content) => setContent(content)} |
| 42 | + /> |
| 43 | + </div> |
| 44 | + ) |
| 45 | +} |
| 46 | + |
| 47 | +export default App |
| 48 | +``` |
| 49 | + |
| 50 | +### Props |
| 51 | + |
| 52 | +> All props except `onChange` are optional. |
| 53 | +
|
| 54 | +| Name | Optional | Type | Description | |
| 55 | +| ------------------------ | -------- | ------------------- | --------------------------------------------------------------------- | |
| 56 | +| containerClassName | ✔️ | `string` | Custom classes for the wrapper div | |
| 57 | +| contentEditableClassName | ✔️ | `string` | Custom classes for the input element | |
| 58 | +| placeholderClassName | ✔️ | `string` | Custom classes for the placeholder text | |
| 59 | +| placeholder | ✔️ | `string` | Input placeholder text | |
| 60 | +| disabled | ✔️ | `boolean` | Flag that disables the input element | |
| 61 | +| updatedContent | ✔️ | `string` | Text injected from parent element into the input as the current value | |
| 62 | +| onContentExternalUpdate | ✔️ | `(content) => void` | Method that emits the injected content by the `updatedContent` prop | |
| 63 | +| onChange | ❌ | `(content) => void` | Method that emits the current content as a string | |
| 64 | +| onKeyUp | ✔️ | `(e) => void` | Method that emits the keyUp keyboard event | |
| 65 | +| onKeyDown | ✔️ | `(e) => void` | Method that emits the keyDown keyboard event | |
| 66 | +| onFocus | ✔️ | `(e) => void` | Method that emits the focus event | |
| 67 | +| onBlur | ✔️ | `(e) => void` | Method that emits the blur event | |
| 68 | + |
| 69 | +## Contribution |
| 70 | + |
| 71 | +If you have a suggestion that would make this component better feel free to fork the project and open a pull request or create an issue for any idea or bug you find.\ |
| 72 | +Remeber to follow the [Contributing Guidelines](https://github.com/ChrisUser/.github/blob/main/CONTRIBUTING.md). |
| 73 | + |
| 74 | +## Licence |
| 75 | + |
| 76 | +React Basic Contenteditable is [MIT licensed](https://github.com/ChrisUser/react-basic-contenteditable/blob/master/LICENSE). |
0 commit comments