Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprinkles of delight with StimulusJS #138

Open
tatey opened this issue Apr 6, 2018 · 2 comments
Open

Sprinkles of delight with StimulusJS #138

tatey opened this issue Apr 6, 2018 · 2 comments

Comments

@tatey
Copy link

tatey commented Apr 6, 2018

I've been really fascinated by StimulusJS because it closely lines up with the way I've been building web applications with Rails. It gives you a great way to hook into your page and enhance it with JavaScript.

I've used it on an old side project to sprinkle animations on flash notices and form buttons. It's a got a tonne more use cases, but I could wrap a 15 minute talk around this if people are interested.

Technologies used are Rails, Turbolinks, StimulusJS, and AnimieJS.

<!-- app/views/layourts/application.html -->
<div ui-flash data-controller="flash" data-flash-height="[ui-header]">
    <%= message %>
</div>
// app/javascript/packs/controllers/flash_controller.js
import { Controller } from "stimulus";
import anime from "animejs";

export default class extends Controller {
  connect() {
    const heightElement = document.querySelector(this.data.get("height"));
    if (heightElement) {
      this.element.style.height = `${heightElement.clientHeight}px`;
    }
    const height = this.element.clientHeight;

    anime({
      targets: this.element,
      translateY: [
        {value: -height, duration: 0},
        {value: 0, duration: 500, easing: "easeOutElastic"},
        {value: -height, duration: 350, delay: 3000, easing: "easeInQuad"},
      ],
      complete: (_) => {
        this.element.parentNode.removeChild(this.element);
      },
    });
  }
}

The end result!

screenflow

@Mbuckley0
Copy link

@tatey Sounds great. Would you be able to give this talk at this months meetup on the 24th?

@tatey
Copy link
Author

tatey commented Apr 19, 2018

Hello @Mbuckley0. Lock me in for the 24th. I'll work on slides over the weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants