Giter Site home page Giter Site logo

proyecto26 / animatable-component Goto Github PK

View Code? Open in Web Editor NEW
252.0 12.0 16.0 2 MB

Animate once, use Everywhere! ๐Ÿ’ซ

Home Page: https://proyecto26.github.io/animatable-component

License: MIT License

TypeScript 79.11% HTML 17.00% CSS 3.70% JavaScript 0.19%
web-animations-api web-animations web-animation animation animation-library animations transitions declarative web-components stenciljs stencil stenciljs-components stencil-components pwa web ux ux-experience waapi designers designer-website

animatable-component's Introduction

Built With Stencil Maintenance NPM version Downloads TotalDownloads Twitter Follow

<animatable/>

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

<animatable-component
  autoplay
  easing="ease-in-out"
  duration="800"
  delay="300"
  animation="tada"
>
  <h1>Hello World</h1>
</animatable-component>

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 ๐ŸŽ‰

<animatable-component autoplay iterations="3" animation="heartBeat" easing="ease-in" duration="1000">
  <h1>Proof that Tony Stark has a heart โœต</h1>
</animatable-component>
<animatable-cube
  autoplay
  fill="forwards"
  composite="add"
  duration="2600"
  easing="linear"
  iterations="Infinity"
  fromClassName="playing"
  toClassName="finished"
  animation="rotate-90-vertical-bck"
>
  <div slot="front-face">Front</div>
  <div slot="back-face">Back</div>
  <div slot="right-face">Right</div>
  <div slot="left-face">Left</div>
  <div slot="top-face">Top</div>
  <div slot="bottom-face">Bottom</div>
</animatable-cube>

With other animation libraries:

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

const bounceKeyFrames = KEYFRAMES[ANIMATIONS.BOUNCE];
const easingOutCubic = EASING_FUNCTIONS[EASING.EASE_OUT_CUBIC];

// Use here any other animation tool like Ionic Animations, AnimeJS, GSAP, etc! :)

Getting Started ๐Ÿ“–

Packages

Project Package Version Links
Core @proyecto26/animatable-component version README.md
React @proyecto26/animatable-component-react version README.md

Script tag

  • Put a script tag similar to this <script src='https://cdn.jsdelivr.net/npm/@proyecto26/[email protected]/dist/animatable-component/animatable-component.esm.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/animatable-component.esm.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 { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  bootstrap: [AppComponent],
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
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 (
    <AnimatableComponent
      autoPlay
      delay={300}
      duration={800}
      composite='add'
      direction='alternate'
      iterations={Infinity}
      animation={ANIMATIONS.TADA}
      easing={EASING.EASE_IN_OUT_BACK}
      onStart={() => console.log('Starting animation')}
      onFinish={() => console.log('Finished animation')}
      onCancel={() => console.log('Cancelled animation')}
    >
      <div>
        <p>HELLO WORLD</p>
      </div>
    </AnimatableComponent>
  );
};
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(<App />, 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) => (
  <ion-fab-button {...props}>
    <ion-icon name='send' />
  </ion-fab-button>
);
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 (
       <AnimatableSendMessageButton
        autoPlay
        keyFrames={keyFramesSendMessage}
        options={optionsSendMessage}
        onFinish={() => alert('Eureka!')}
      />
    )
  }
}

Credits ๐Ÿ‘

Contributing โœจ

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated โค๏ธ.
You can learn more about how you can contribute to this project in the contribution guide.

Supporting ๐Ÿป

I believe in Unicorns ๐Ÿฆ„ Support me, if you do too.

Donate Ethereum, ADA, BNB, SHIBA, USDT, DOGE:

Wallet address

Wallet address: 0x3F9fA8021B43ACe578C2352861Cf335449F33427

Please let us know your contributions! ๐Ÿ™

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.

License โš–๏ธ

This repository is available under the MIT License.

Happy coding ๐Ÿ’ฏ

Made with โค๏ธ

animatable-component's People

Contributors

jdnichollsc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

animatable-component's Issues

Can't run two animations at once

I have to animations I try to run, and both start according to events, but only one finishes. I'm not getting any errors back.

if(self.animatePlayerTo != null)
      {
        var animatePlayerTo = document.getElementById("animate"+self.animatePlayerTo);
        console.log(animatePlayerTo);
        animatePlayerTo.addEventListener("start", function(event) {
          console.log('ANIMATION START', event)
        });
        animatePlayerTo.addEventListener("finish", function(event) {
          console.log('ANIMATION FINISH', event)
        });
        await animatePlayerTo.play();
        //self.animatePlayerTo = null;
      }
      if(self.animatePlayerFrom != null)
      {
        var animatePlayerFrom = document.getElementById("animate"+self.animatePlayerFrom);
        console.log(animatePlayerFrom);
        animatePlayerFrom.addEventListener("start", function(event2) {
          console.log('ANIMATION START', event2)
        });
        animatePlayerFrom.addEventListener("finish", function(event2) {
          console.log('ANIMATION FINISH', event2)
        });
        await animatePlayerFrom.play();
        //self.animatePlayerFrom = null;
      }

Console proof...
https://imgur.com/hOjGct7

Add more animations

Can't find module './animations/animations' when used with stenciljs ionic-pwa starter project.

Explained in the title, './animations/animations' module is not found.
I'm using the latest stenciljs verstion: 1.8.1 with node 12.13

           Cannot find module './animations/animations'.

     L11:    AnimationsType,
     L12:  } from './animations/animations';

[ WARN  ]  TypeScript: node_modules/@proyecto26/animatable-component/dist/types/index.d.ts:3:28
           Cannot find module './animations/animations'.

      L2:  export * from './easing/easing';
      L3:  export { ANIMATIONS } from './animations/animations';
      L4:  export { createAnimatableComponent } from './utils/utils';

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.