Skip to content

Commit

Permalink
docs: Create README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
riceball-tw authored Dec 7, 2024
1 parent ba5f6d5 commit 4eb473b
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions README.md
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!

0 comments on commit 4eb473b

Please sign in to comment.