Animatable Component

Animatable Component

Animate once, use Everywhere!

$0.00

Juan David Nicholls

Juan David Nicholls

Member since 2014

Details

Version:
1.0
Ionic:
4.x  
Platforms:
iOS, Android  
Released:
9 months ago
Updated:
9 months ago
Category:
Plugins
Tags:
,

Built With StencilMaintenanceNPM versionDownloadsTotalDownloadsTwitter Follow

<animatable/>

Web Component built with Stencil.js to use Web Animations API in a declarative way. You can animate any HTML element easily:

```

Hello World

```

With the largest list of Keyframes/Easing Functions that can also be used with other animation tools or Platforms! 🧚

Demo 🎮

Do you want to see this web component in action? Visit https://codepen.io/jdnichollsc/full/rNNYBbe yay! 🎉

Animatable

Includes a PWA demo for debugging animations! ▶

Usage 🎉

Proof that Tony Stark has a heart ✵

- [animatable-cube](./src/components/animatable-cube/readme.md)

Front
Back
Right
Left
Top
Bottom

```

With other animation libraries:

``` import { ANIMATIONS, EASING_FUNCTIONS, EASING, KEYFRAMES } from '@proyecto26/animatable-component';

const bounceKeyFrames = KEYFRAMES[ANIMATIONS.BOUNCE]; const easingOutCubic = EASINGFUNCTIONS[EASING.EASEOUT_CUBIC];

// Use here any other animation tool :) ```

Getting Started 📖

Packages

ProjectPackageVersionLinks
**Core**[`@proyecto26/animatable-component`](https://www.npmjs.com/package/@proyecto26/animatable-component)[![version](https://img.shields.io/npm/v/@proyecto26/animatable-component/latest.svg)](https://www.npmjs.com/package/@proyecto26/animatable-component)[`README.md`](./README.md)
**React**[`@proyecto26/animatable-component-react`](https://www.npmjs.com/package/@proyecto26/animatable-component-react)[![version](https://img.shields.io/npm/v/@proyecto26/animatable-component-react/latest.svg)](https://www.npmjs.com/package/@proyecto26/animatable-component-react)[`README.md`](react/README.md)

Script tag

  • Put a script tag similar to this <script src='https://unpkg.com/[email protected]/dist/animatable-component.js'></script> in the head of your index.html
  • Then you can use the element anywhere in your template, JSX, html etc

Node Modules

  • Run npm install @proyecto26/animatable-component --save
  • Put a script tag similar to this <script src='node_modules/@proyecto26/animatable-component/dist/animatable-component.js'></script> in the head of your index.html
  • Then you can use the element anywhere in your template, JSX, html etc

In a stencil-starter app

  • Run npm install @proyecto26/animatable-component --save
  • Add an import to the npm packages import @proyecto26/animatable-component;
  • Then you can use the element anywhere in your template, JSX, html etc

Framework integrations 👨‍💻

Angular

Using animatable-component component within an Angular project:

Including the Custom Elements Schema

Including the CUSTOM_ELEMENTS_SCHEMA in the module allows the use of Web Components in the HTML files. Here is an example of adding it to AppModule:

``` import { BrowserModule } from '@angular/platform-browser'; import { CUSTOMELEMENTSSCHEMA, NgModule } from '@angular/core'; import { AppComponent } from './app.component';

@NgModule({ declarations: [AppComponent], imports: [BrowserModule], bootstrap: [AppComponent], schemas: [CUSTOMELEMENTSSCHEMA] }) export class AppModule {} ```

The CUSTOM_ELEMENTS_SCHEMA needs to be included in any module that uses Animatable.

Calling defineCustomElements

Animatable component includes a function used to load itself in the application window object. That function is called defineCustomElements() and needs to be executed once during the bootstrapping of your application. One convenient place to add it is in the main.ts file as follows:

``` import { enableProdMode } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { defineCustomElements as defineAnimatable } from '@proyecto26/animatable-component/loader';

import { AppModule } from './app/app.module'; import { environment } from './environments/environment';

if (environment.production) { enableProdMode(); }

platformBrowserDynamic().bootstrapModule(AppModule) .catch(err => console.log(err)); defineAnimatable(window); ```

from stencil documentation

React

  • Specific Wrapper

When using a wrapper component, It's not necessary to access the reference directly to attach events, etc. More details here.

``` import React from 'react'; import { AnimatableComponent, ANIMATIONS, EASING } from '@proyecto26/animatable-component-react';

const App = () => { return ( console.log('Starting animation')} onFinish={() => console.log('Finished animation')} onCancel={() => console.log('Cancelled animation')} >

HELLO WORLD

); }; export default App; ```

  • Web Component

Other option is using the web component directly:

``` import React from 'react' import ReactDOM from 'react-dom' import { defineCustomElements as defineAnimatable } from '@proyecto26/animatable-component/loader' import App from './App';

ReactDOM.render(, document.getElementById('root'));

defineAnimatable(window); ```

from stencil documentation

Vue

In order to use the animatable-component Web Component inside of a Vue application, it should be modified to define the custom elements and to inform the Vue compiler which elements to ignore during compilation. This can all be done within the main.js file as follows:

``` import Vue from 'vue'; import { defineCustomElements as defineAnimatable } from '@proyecto26/animatable-component/loader'

import App from './App.vue';

Vue.config.productionTip = false; Vue.config.ignoredElements = [/animatable-\w*/];

// Bind the custom element to the window object defineAnimatable(window);

new Vue({ render: h => h(App) }).$mount('#app'); ```

from stencil documentation

Stencil

To animate Functional Components you can use the createAnimatableComponent utility, e.g:

  • utils.tsx:

``` import { createAnimatableComponent } from '@proyecto26/animatable-component';

const SendMessageButton = (props) => ( ); export const AnimatableSendMessageButton = createAnimatableComponent(SendMessageButton); export const keyFramesSendMessage: Keyframe[] = [ { opacity: '0', transform: 'rotate(0deg)' }, { opacity: '1', transform: 'rotate(360deg)' } ]; export const optionsSendMessage: KeyframeAnimationOptions = { duration: 500, easing: 'ease-in-out' }; ```

  • my-component.tsx:

``` import { Component, Host, h } from '@stencil/core'; import { AnimatableSendMessageButton, keyFramesSendMessage, optionsSendMessage } from './utils'

@Component({ tag: 'my-component', shadow: false }) export class MyComponent { render() { return ( alert('Eureka!')} /> ) } } ```

Credits 👍

Supporting 🍻

I believe in Unicorns 🦄 Support me, if you do too.

Enterprise 💼

Available as part of the Tidelift Subscription.

The maintainers of <animatable/> and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

Security contact information 🚨

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

Happy coding 💯

Made with ❤️