# @dile/dile-overlay-mixin

> Mixin function to esaily create overlay web components

Latest version **3.0.2** (published 2023-01-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @dile/dile-overlay-mixin
pnpm add @dile/dile-overlay-mixin
yarn add @dile/dile-overlay-mixin
bun add @dile/dile-overlay-mixin
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2023-01-22 |
| First published | 2020-07-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 107 |
| Author | midesweb |
| Maintainers | midesweb |
| Keywords | overlay, components, animation, effect, mixin |

## Links

- npm: https://www.npmjs.com/package/@dile/dile-overlay-mixin
- Repository: https://github.com/Polydile/dile-components
- Issues: https://github.com/Polydile/dile-components/issues
- npm.io page: https://npm.io/package/@dile/dile-overlay-mixin

## Alternatives

- [react-native-root-siblings](https://npm.io/package/react-native-root-siblings.md) — 102.9K weekly downloads
- [post-robot](https://npm.io/package/post-robot.md) — 93.7K weekly downloads
- [@praxisui/dialog](https://npm.io/package/@praxisui/dialog.md) — 2.0K weekly downloads
- [easy-toggle-state](https://npm.io/package/easy-toggle-state.md) — 350 weekly downloads
- [ngx-lightbox-evp](https://npm.io/package/ngx-lightbox-evp.md) — 19 weekly downloads

## Recent versions

- 3.0.2 (latest) — 2023-01-22
- 3.0.1 — 2023-01-20
- 3.0.0 — 2022-12-29
- 2.0.1 — 2022-06-12
- 2.0.0 — 2022-05-18
- 1.1.3 — 2022-05-16
- 1.1.2 — 2022-05-12
- 1.1.1 — 2022-05-12
- 1.1.0 — 2022-03-18
- 1.0.0 — 2020-07-08

## README

# @dile/dile-overlay-mixin

Mixin to create overlay elements. It has the functionality to position custom elements in a various ways, and open or close the elements with a smooth animation.

## Requirements

This mixin need two elements in the web component to make its work:
- Overlay layer, to show / hide some content
- Trigger element, to click and toggle the overlay state

Both elements should be in the shadow DOM of the element and need to have this ids:
- #overlay for the overlay layer content
- #trigger for the element to asign the close / hide functions

Also is necessary to asign some styles to the overlay element:

```css
#overlay {
  display: none;
  position: absolute;
  opacity: 0;
}
```

Usually you may also prefer to asign some additional styles, to make a transition between hide / show states:

```css
#overlay {
  display: none;
  position: absolute;
  opacity: 0;
  transition: ease 0.5s;
  transition-property: transform, opacity;
  transform: translateY(-10px);
}
```

To create the smooth animation there is also necessary to create a "opened" CSS class, to asing styles to the open state of the overlay layer.

```css
#overlay.opened {
  opacity: 1;
  transform: translateY(0);
}
```

Of course, you can customize your own styles to create your preferred animations.

## Usage

Install

```
npm install @dile/dile-overlay-mixin
```

Use the mixin

```
import { LitElement, html, css } from 'lit';
import { DileOverlayMixin } from '@dile/dile-overlay-mixin';

class NewComponent  extends DileOverlayMixin(LitElement) {

}
```

## Properties

The mixin offers several properties to customize the the way it shows the overlay.

- **horizontalAlign**: String property to set the horizontal position of the menu. Valid values are "under_left", "under_right", "left", "right" or "center". Default to "under_left".
- **verticalAlign**: String property to set the vertical position of the menu. Valid values are "bottom", "center" or "top". Default to "bottom".
- **moveTop**: Number of pixels to modify the default vertical position of the overlay. Accepts positive (move down) an negative (move up) values. Default 0.
- **moveLeft**: Number of pixels to modify the default horizontal position of the overlay. Accepts positive (move right) an negative (move left) values. Default 0.

## Overlay state

This mixin also includes a "state" property called "_overlayClass". In order to have the opened/closed state in the overlay layer you should assign the property into the class attribute.

```html
<div id="overlay" class="${this._overlayClass}">
  I am the overlay layer
</div>
```

## Methods

- **open()**: Use it to open the menu overlay box
- **close()**: Use it to close the menu overlay box
- **toggle()**: Toggles the menu-overlay box

**Important note**: the trigger does not opens the menu by itself. You must call the ```open()``` or ```toggle()``` method to open the menu when you need. The trigger is used by default only for positioning the menu overlay.

For example, you can use the the ```toogle()``` method as a click handler on the trigger.

```html
<span id="trigger" @click=${this.toggle}>This is the trigger</span>
```

## Custom events

- **overlay-opened**: dispatched when the overlay opens.
- **overlay-closed**: dispatched when the overlay closes.

---
_Source: https://npm.io/package/@dile/dile-overlay-mixin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
