# mithril-transition

> A lightweight library for MithrilJS to create your own custom transitions based on the lifecycle of your components.

Latest version **4.0.0** (published 2017-03-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install mithril-transition
pnpm add mithril-transition
yarn add mithril-transition
bun add mithril-transition
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2017-03-22 |
| First published | 2015-09-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 39 |
| Author | Geut |
| Maintainers | geut, tinchoz49 |
| Keywords | mithriljs, css, velocityjs, transitions, animations |

## Links

- npm: https://www.npmjs.com/package/mithril-transition
- Repository: https://github.com/geut/mithril-transition
- Homepage: https://github.com/geut/mithril-transition#readme
- Issues: https://github.com/geut/mithril-transition/issues
- npm.io page: https://npm.io/package/mithril-transition

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2017-03-22
- 3.1.0 — 2016-04-22
- 3.0.0 — 2016-04-20
- 2.4.1 — 2016-04-05
- 2.4.0 — 2016-04-05
- 2.3.1 — 2016-02-20
- 2.2.6 — 2016-02-12
- 2.2.5 — 2016-02-11
- 2.2.4 — 2016-02-11
- 2.2.3 — 2016-02-11
- 2.2.1 — 2016-02-10
- 2.2.0 — 2015-11-19
- 2.1.1 — 2015-11-07
- 2.0.2 — 2015-10-16
- 2.0.1 — 2015-09-28
- … 7 more at https://npm.io/package/mithril-transition/versions

## README

# mithril-transition
[![Build Status](https://travis-ci.org/geut/mithril-transition.svg?branch=master)](https://travis-ci.org/geut/mithril-transition)
> A lightweight library for MithrilJS to create your own custom transitions based on the lifecycle of your components.

**NOTE:** This package was updated for the rewrite of Mithril, if you are looking
for the old and unmaintained package can be found it
[here](https://github.com/geut/mithril-transition/tree/v0.2)

## Install

With [npm](https://npmjs.com/package/mithril-transition) and [browserify](https://www.npmjs.com/package/browserify)/[webpack](https://www.npmjs.com/package/webpack) do:

```
npm install --save mithril-transition
```

Or you can use the UMD bundle

```html
<script src="/lib/mithril-transition/dist/mithril-transition.min.js" type="text/javascript"></script>
```

## How to use it

**mithril-transition** is a function factory that returns an `object` with an `oncreate` and `onremove` hooks to add in the vnode lifecycle (where you want animate it) of mithril.

Check our live **[example](https://geut.github.io/mithril-transition/example)**

## Functions

#### createTransition(options = {}) -> {transition}
Factory function to create a new transition. The options are defined below.

#### transition.oncreate(vnode)
Function that you need hook up to the lifecycle of the vnode

#### transition.onremove(vnode)
Function that you need hook up to the lifecycle of the vnode

#### transition.enable()
Method to enable the animation. **By default is enabled.**

#### transition.disable()
Method to disable the animation.

## Options

#### animation (required)
Callback function where you define the animation for the next/prev component.

The callback has an object argument {} with the next properties:

**lastElm**: The last DOM element that is removing.

**nextElm**: The new DOM element that is inserting.

**direction**: This option allow to you define differents animations based of next/prev direction of the lifecycle components. Is required have at least ```useHistory``` in true.

**cbLast**: Callback to complete the remove of the lastElm. (is required call it)

**cbNext**: Callback to complete the insert of the nextElm. (is required call it)

#### useHistory (default = true)
When is enabled the library keep the history of your components, to know if the next element in the transition is really the next element or a prev element.

#### persistHistoryAs ({string} default = null)
Save the history in the sessionStorage identified by a key.

#### classList ({object})
Before that the transition begin, the library set a list of classes for each parent|element and remove it when the transition is finished.
```javascript
default = {
    parent: 'm-transition-parent',
    lastElem: 'm-transition-last-element',
    newElem: 'm-transition-next-element',
    direction: 'm-transition-<direction>'
}
```

## On roadmap

- Add unit tests

## Credits

* Thanks to @dpaez to work with me the last year in a mobile project using [Mithril](http://mithril.js.org/) and exploring how to make transitions and animations with this excellent "MVC" framework.

## License

MIT

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