Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/suzukiryuichiro/loading-animation


https://github.com/suzukiryuichiro/loading-animation

Last synced: 1 day ago
JSON representation

Awesome Lists containing this project

README

        

## Steps to add a loading animation (with Font Awesome)

1. Add an application wide spinner div in the layout html (initially invisible)

```html



<%= yield %>

```

2. Add a stimulus controller that handles showing the spinner

```sh
rails g stimulus spinner
```

3. mount the controller to the body and set the spinner as a target

```html



<%= yield %>

```

4. code the spinner controller's show action

```js
// spinner_controller.js
import { Controller } from "@hotwired/stimulus";

// Connects to data-controller="spinner"
export default class extends Controller {
static targets = ["spinner"];

show() {
// Simply make the spinner that is initially hidden visible when the form starts submitting
this.spinnerTarget.classList.remove("invisible");
}
}
```

5. add an action trigger to the form. trigger will be [`turbo:submit-start`](https://turbo.hotwired.dev/reference/events)

```erb


<%= simple_form_for @recipe, data: { action: 'turbo:submit-start->spinner#show' } do |f| %>
<%= f.input :title %>
<%= f.submit %>
<% end %>

```