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

https://github.com/nju33/context-modal

Display related elements with axis of trigger element
https://github.com/nju33/context-modal

context dropdown library menu modal pure-javascript

Last synced: over 1 year ago
JSON representation

Display related elements with axis of trigger element

Awesome Lists containing this project

README

          

# ContextModal

Display related elements with axis of trigger element. I made it to make it easy to make things like context-menu and dropdown, etc.

![screenshot](https://github.com/nju33/context-modal/raw/master/images/screenshot.gif?raw=true)

## Install or Download

```sh
yarn add context-modal
npm i -S context-modal
```

Or access to [releases page](https://github.com/nju33/context-modal/releases).
Then, download the latest version.

## Usage

First, if you read as a separate file

```html

```

Markup is like this. (`test/fixtures/index.html`)

```html

Button




```

`data-context-modal-for` works like ``, `data-context-modal-id` works as ``.
That is, `[data-context-modal-id=foo]` will be shown using something of `[data-context-modal-for=foo]` as a trigger.

The trigger is `click` by default, but you can change only that element by adding `data-context-modal-event-type`.

Also, by default, the top left of the modal comes to the position you clicked. If you want to fix this somewhere else (eg bottom-left), add `data-context-menu-offset` to `[data-context-menu-for]` element. The following values can be specified for this.

- `left-top`
- `left-bottom`
- `right-top`
- `right-bottom`

```js
// For es
import ContextModal from 'context-modal';
const ctxModal = new ContextModal(document.querySelectorAll('[data-context-modal-for]'), {
// This is global opts

// Elements to prevent scrolling while displaying
//
// Use `data-context-modal-scrollable`
// if you want to change only certain elements
scrollable: document.body, // default

// Transition values at `onshow` and `onhide`
//
// Use `data-context-modal-transition-for-onshow` or `data-context-modal-transition-for-onhide`
// if you want to change only certain elements
transition: ['opacity .2s linear', 'none'] // defaults
});
ctxModal.init();
```

After `ctxModal.init`, `[data-context-modal-id]` will be able to use the following events.

- `contextmodalwillshow`
Just before being shown
- `contextmodaldidshow`
After being shown (after transition)
- `contextmodalwillhide`
Just before hiding
- `contextmodaldidhide`
After hiding (after transition)

### Example

- `test/fixtures/index.js`
- `example/webpack/index.js`

## LICENSE

The MIT License (MIT)

Copyright (c) 2017 nju33