-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba5f6d5
commit 4eb473b
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# edit-element | ||
|
||
A lightweight and flexible JavaScript/TypeScript library for adding in-place editing functionality to HTML elements. | ||
|
||
## Features | ||
|
||
- 🖊️ Make any HTML element in-place editable | ||
- ⚙️ CSM and ESM and TypeScript support | ||
- ⌨️ Configurable editing classname and submit shortcut key | ||
- ♿ Built-in accessibility support | ||
- 🔧 Flexible event callbacks | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install edit-element | ||
``` | ||
|
||
## Basic Usage | ||
|
||
```typescript | ||
import { EditElement } from '../dist/index.mjs'; | ||
|
||
// Make all elements with .editable class in-place editable | ||
const editableElements = new EditElement('.editable'); | ||
``` | ||
|
||
## Configuration Options | ||
|
||
### `Options` Interface | ||
|
||
| Property | Type | Required | Default | Description | | ||
|----------|------|----------|---------|-------------| | ||
| `onEnter` | `(element: HTMLElement) => void` | Optional | `undefined` | Callback function when editing starts | | ||
| `onSubmit` | `(element: HTMLElement) => void` | Optional | `undefined` | Callback function when edit is submitted | | ||
| `onLeave` | `(element: HTMLElement) => void` | Optional | `undefined` | Callback function when editing ends | | ||
| `editingElementClassName` | `string` | Optional | `undefined` | CSS class name added during editing | | ||
| `submitKey` | `string` | Optional | `'Enter'` | Key to trigger submission | | ||
|
||
## Methods | ||
|
||
### `destroyAllEditable()` | ||
Remove all editable elements. | ||
|
||
```typescript | ||
editableElements.destroyAllEditable(); | ||
``` | ||
|
||
### `destroyTargetEditable(selector: string)` | ||
Remove all editable elements by matching the specific querySelector query. | ||
|
||
```typescript | ||
editableElements.destroyTargetEditable('.specific-editable'); | ||
``` | ||
|
||
## License | ||
|
||
MIT License | ||
|
||
## Contributing | ||
|
||
Issues and pull requests are welcome! |