Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kanety/stimulus-dialog


https://github.com/kanety/stimulus-dialog

Last synced: 2 months ago
JSON representation

Awesome Lists containing this project

README

        

# stimulus-dialog

A stimulus controller for simple dialog.

## Dependencies

* @hotwired/stimulus 3.0+

## Installation

Install from npm:

$ npm install @kanety/stimulus-dialog --save

## Usage

Register controller:

```javascript
import { Application } from '@hotwired/stimulus';
import DialogController from '@kanety/stimulus-dialog';

const application = Application.start();
application.register('dialog', DialogController);
```

Import css:

```css
@import '@kanety/stimulus-dialog';
```

Build html as follows:

```html



Title


content1


content2




OK
Cancel

Open

```

### Options

#### focus

Set element focused when dialog is opened:

```html
OK
```

#### drag

Make dialog draggable:

```html



Title




```

#### modal

You can use modal dialog by wrapping dialog element as follows:

```html







```

### Callbacks

Run callbacks when dialog is opened or closed:

```javascript
let element = document.querySelector('[data-controller="dialog"]');
element.addEventListener('dialog:opend', e => {
console.log("opened by " + e.detail.target);
});
element.addEventListener('dialog:closed', e => {
console.log("closed by " + e.detail.target);
});
```

### Event operations

Open, close or toggle dialog via event:

```html



```

```javascript
let element = document.querySelector('[data-controller="dialog"]');
element.dispatchEvent(new CustomEvent('dialog:open'));
element.dispatchEvent(new CustomEvent('dialog:close'));
element.dispatchEvent(new CustomEvent('dialog:toggle'));
```

## License

The library is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).