All Projects → robbevp → stimulus-transition

robbevp / stimulus-transition

Licence: MIT license
Enter/Leave transition for stimulusJS, inspired by Vue/Alpine syntax

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to stimulus-transition

stimulus-carousel
A Stimulus controller to deal with carousel.
Stars: ✭ 22 (-35.29%)
Mutual labels:  stimulus, stimulusjs
stimulus-remote-rails
A Stimulus controller to handle Rails UJS events.
Stars: ✭ 18 (-47.06%)
Mutual labels:  stimulus, stimulusjs
shotgun
Ready to go Rails App with TailwindCSS, ViewComponent, Devise, and more!
Stars: ✭ 25 (-26.47%)
Mutual labels:  stimulus, stimulusjs
Stimulus reflex
Build reactive applications with the Rails tooling you already know and love.
Stars: ✭ 1,928 (+5570.59%)
Mutual labels:  stimulus, stimulusjs
stimulus todomvc
[WIP] An implementation of TodoMVC using Ruby on Rails and StimulusJS
Stars: ✭ 14 (-58.82%)
Mutual labels:  stimulus, stimulusjs
stimulus reflex todomvc
An implementation of TodoMVC using Ruby on Rails, StimulusJS, and StimulusReflex
Stars: ✭ 50 (+47.06%)
Mutual labels:  stimulus, stimulusjs
UnityGUI
UGUI Panel Systems for navigation, animation and more
Stars: ✭ 80 (+135.29%)
Mutual labels:  transitions
denali
A simple, fast photoblogging CMS built in Ruby on Rails which features responsive, high-resolution images, a customizable posting schedule, social media management and syndication, a GraphQL API, and more.
Stars: ✭ 26 (-23.53%)
Mutual labels:  stimulus
rails 6 github template
Easy way to get a new Rails 6 project up and running.
Stars: ✭ 12 (-64.71%)
Mutual labels:  stimulusjs
Transition.css
Drop-in CSS transitions
Stars: ✭ 199 (+485.29%)
Mutual labels:  transitions
aholachek.github.io
My website
Stars: ✭ 53 (+55.88%)
Mutual labels:  transitions
CustomSegueDemo
Demonstrates encapsulation of a custom view controller transition into a UIStoryboardSegue subclass
Stars: ✭ 31 (-8.82%)
Mutual labels:  transitions
jumpstart-vite
⚡️ Jumpstart a new Rails app with Vite.js + Turbo + Stimulus, and more
Stars: ✭ 67 (+97.06%)
Mutual labels:  stimulusjs
react-component-transition
Easy animations between react component transitions.
Stars: ✭ 20 (-41.18%)
Mutual labels:  transitions
SwiftTweener
A pure Swift animation engine.
Stars: ✭ 74 (+117.65%)
Mutual labels:  transitions
Material-Design-Android
My stash for all things material, animations, typography, iconography, transitions, Animated VD, Color Palette API, UI design, and more.
Stars: ✭ 38 (+11.76%)
Mutual labels:  transitions
Just Animate
Making Animation Simple
Stars: ✭ 242 (+611.76%)
Mutual labels:  transitions
stimulus-content-loader
A Stimulus controller to asynchronously load HTML from an url.
Stars: ✭ 39 (+14.71%)
Mutual labels:  stimulusjs
hnpwa-app
An implementation of the Hacker News PWA with Rails + Stimulus
Stars: ✭ 122 (+258.82%)
Mutual labels:  stimulus
FluentTransitions
▶ Smooth UI animations & transitions for .NET
Stars: ✭ 27 (-20.59%)
Mutual labels:  transitions

Stimulus Transition

Enter/Leave transitions for Stimulus - inspired by the syntax from Vue and Alpine.
The controller watches for changes to computed display style to automatically run the transitions. This could be an added/removed class, a change in the element's style-attribute or adding/removing the hidden-attribute.

Install

Run yarn add stimulus-transition to install

Register the controller in your application

import { Application } from "stimulus"
import TransitionController from 'stimulus-transition'

const application = Application.start()
application.register("transition", TransitionController)

Usage

Add the transition controller to each element you want to transition and add classes for the transition.

<div data-controller="transition"
     data-transition-enter-active="enter-class"
     data-transition-enter-from="enter-from-class"
     data-transition-enter-to="enter-to-class"
     data-transition-leave-active="or-use multiple classes"
     data-transition-leave-from="or-use multiple classes"
     data-transition-leave-to="or-use multiple classes">
  <!-- content -->
</div>

The controller watch for changes to the computed display style on the exact element. You can trigger this by changing the classList, the element's style or with the hidden-attribute. If the change would cause the element to appear/disappear, the transition will run.

During the transition, the effect of your change will be canceled out and be reset afterwards. This controller will not change the display style itself.

All of the below should trigger a transition.

export default class extends Controller {
  static targets = ["options"]

  showOptions() {
    this.optionsTarget.hidden = false;
  }

  hideOptions() {
    this.optionsTarget.hidden = true;
  }

  addClass() {
    this.optionsTarget.classList.add("hidden")
  }

  removeClass() {
    this.optionsTarget.classList.add("hidden")
  }

  setDisplayNone() {
    this.optionsTarget.style.setProperty("display", "none")
  }
}

Optional classes

If you don't need one of the classes, you can omit the attributes. The following will just transition on enter:

<div data-controller="transition"
     data-transition-enter-active="enter-class"
     data-transition-enter-from="enter-from-class"
     data-transition-enter-to="enter-to-class">
  <!-- content -->
</div>

Initial transition

If you want to run the transition when the element in entered in the DOM, you should add the data-transition-initial-value-attribute to the element. The value you enter is not used.

<div data-controller="transition"
     data-transition-initial-value
     data-transition-enter-active="enter-class"
     data-transition-enter-from="enter-from-class"
     data-transition-enter-to="enter-to-class">
  <!-- content -->
</div>

Destroy after leave

You can also destroy the element after running the leave transition by adding data-transition-destroy-value

<div data-controller="transition"
     data-transition-destroy-value
     data-transition-enter-active="enter-class"
     data-transition-enter-from="enter-from-class"
     data-transition-enter-to="enter-to-class"
     data-transition-leave-active="or-use multiple classes"
     data-transition-leave-from="or-use multiple classes"
     data-transition-leave-to="or-use multiple classes">
</div>

Listen for transitions

If you want to run another action after the transition is completed, you can listen for the following events on the element.

  • transition:end-enter
  • transition:end-leave

This would look something like:

<div data-controller="transition"
     data-transition-enter-active="enter-class"
     data-transition-enter-from="enter-from-class"
     data-transition-enter-to="enter-to-class"
     data-action="transition:end-enter->controller#action">
  <!-- content -->
</div>

Note on using hidden

If you use the hidden attribute, you have to make sure that you set the display property correctly for all hidden items.
For example:

[hidden] {
  display: none !important
}

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/robbevp/stimulus-transition. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

This package is available as open source under the terms of the MIT License.

Credits

This implementation of the transition is inspired by the following article from Sebastian De Deyne - it's an interesting read to understand what is happening in these transitions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].