Giter Site home page Giter Site logo

juansebestia / animatable-component Goto Github PK

View Code? Open in Web Editor NEW

This project forked from proyecto26/animatable-component

0.0 1.0 0.0 304 KB

A WebComponent to use Web Animations API in a declarative way! ๐Ÿ’…

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

License: MIT License

TypeScript 65.21% HTML 34.79%

animatable-component's Introduction

Built With Stencil Maintenance NPM version Downloads TotalDownloads Twitter Follow

<animatable-component/>

Web Component built with Stencil.js to use Web Animations API in a declarative way.

<animatable-component
  autoPlay
  easing='ease-in-out'
  duration={800}
  delay={300}
  animation='tada'
  onFinish={() => alert('Eureka!')}
>
  <h1>Hello World</h1>
</animatable-component>

To animate things you can use the createAnimatableComponent utility:

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

const SendMessageButton = (props) =>(
  <ion-fab-button {...props}>
    <ion-icon name='send' />
  </ion-fab-button>
)
const AnimatableSendMessageButton = createAnimatableComponent(SendMessageButton)


const keyFramesSendMessage: Keyframe[] = [
  {
    opacity: '0',
    transform: 'rotate(0deg)'
  },
  {
    opacity: '1',
    transform: 'rotate(360deg)'
  }
]

const optionsSendMessage: KeyframeAnimationOptions = {
  duration: 500,
  easing: 'ease-in-out'
}

...
  render() {
    return (
       <AnimatableSendMessageButton
        keyFrames={keyFramesSendMessage}
        options={optionsSendMessage}
        onFinish={() => alert('Eureka!')}
      />
    )
  }
...

Properties

Property Attribute Description Type Default
animateId animate-id A DOMString with which to reference the animation. string undefined
animation animation Name of the animation to get the keyFrames "bounce" | "bounceIn" | "bounceInDown" | "bounceInLeft" | "bounceInRight" | "bounceInUp" | "bounceOut" | "bounceOutDown" | "bounceOutLeft" | "bounceOutRight" | "bounceOutUp" | "flash" | "heartBeat" | "jello" | "pulse" | "rotate" | "rubberBand" | "shake" | "swing" | "tada" | "wobble" undefined
autoPlay auto-play Start the animation when the component is mounted. boolean true
composite composite Determines how values are combined between this animation and other, separate animations that do not specify their own specific composite operation. Defaults to replace. "accumulate" | "add" | "replace" undefined
currentTime current-time Sets the current time value of the animation in milliseconds, whether running or paused. number undefined
delay delay The number of milliseconds to delay the start of the animation. Defaults to 0. number undefined
direction direction Direction of the animation. "alternate" | "alternate-reverse" | "normal" | "reverse" undefined
duration duration The number of milliseconds each iteration of the animation takes to complete. Defaults to 0. number undefined
easing easing The rate of the animation's change over time. custom function | "linear" | "ease" | "ease-in" | "ease-out" | "ease-in-out" | "ease-in-cubic" | "ease-out-cubic" | "ease-in-out-cubic" | "ease-in-circ" | "ease-out-circ" | "ease-in-out-circ" | "ease-in-expo" | "ease-out-expo" | "ease-in-out-expo" | "ease-in-quad" | "ease-out-quad" | "ease-in-out-quad" | "ease-in-quart" | "ease-out-quart" | "ease-in-out-quart" | "ease-in-quint" | "ease-out-quint" | "ease-in-out-quint" | "ease-in-sine" | "ease-out-sine" | "ease-in-out-sine" | "ease-in-back" | "ease-out-back" | "ease-in-out-back" undefined
endDelay end-delay The number of milliseconds to delay after the end of an animation. number undefined
fill fill Dictates whether the animation's effects should be reflected by the element(s) prior to playing ("backwards"), retained after the animation has completed playing ("forwards"), or both. Defaults to "none". "auto" | "backwards" | "both" | "forwards" | "none" undefined
iterationComposite iteration-composite Determines how values build from iteration to iteration in this animation. "accumulate" | "replace" undefined
iterationStart iteration-start Describes at what point in the iteration the animation should start. number undefined
iterations iterations The number of times the animation should repeat. Defaults to 1, and can also take a value of Infinity to make it repeat for as long as the element exists. number undefined
keyFrames -- Keyframes of the animation. Keyframe[] undefined
keyFramesData key-frames-data Keyframes of the animation in string format. string undefined
options -- Default options of the animation. KeyframeAnimationOptions undefined
optionsData options-data Default options of the animation in string format. string undefined
playbackRate playback-rate Sets the playback rate of the animation. number undefined
startTime start-time Sets the scheduled time when an animation's playback should begin. number undefined

Events

Event Description Type
cancel This event is sent when the animation is cancelled. CustomEvent<HTMLElement>
finish This event is sent when the animation finishes playing. CustomEvent<HTMLElement>

Methods

cancel() => Promise<void>

Clears all KeyframeEffects caused by this animation and aborts its playback.

Returns

Type: Promise<void>

finish() => Promise<void>

Sets the current playback time to the end of the animation corresponding to the current playback direction.

Returns

Type: Promise<void>

getCurrentTime() => Promise<number>

Returns the current time value of the animation in milliseconds, whether running or paused.

Returns

Type: Promise<number>

getPending() => Promise<boolean>

Indicates whether the animation is currently waiting for an asynchronous operation such as initiating playback or pausing a running animation.

Returns

Type: Promise<boolean>

getPlayState() => Promise<AnimationPlayState>

Returns an enumerated value describing the playback state of an animation.

Returns

Type: Promise<AnimationPlayState>

getPlaybackRate() => Promise<number>

Returns the playback rate of the animation.

Returns

Type: Promise<number>

getStartTime() => Promise<number>

Returns the scheduled time when an animation's playback should begin.

Returns

Type: Promise<number>

pause() => Promise<void>

Suspends playback of the animation.

Returns

Type: Promise<void>

play() => Promise<void>

Starts or resumes playing of an animation.

Returns

Type: Promise<void>

reverse() => Promise<void>

Reverses the playback direction, meaning the animation ends at its beginning.

Returns

Type: Promise<void>

Using this component

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

Supporting ๐Ÿป

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

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 โค๏ธ

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.