Skip to content

Commit

Permalink
Document delayed topbar
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Feb 3, 2022
1 parent 907e7e8 commit 22ac99b
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions guides/introduction/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,34 @@ $ npm install --prefix assets --save topbar
Then customize LiveView to use it in your `assets/js/app.js`, right before the `liveSocket.connect()` call:

```js
import topbar from "topbar"

// Show progress bar on live navigation and form submits
import topbar from "topbar"
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
window.addEventListener("phx:page-loading-start", info => topbar.show())
window.addEventListener("phx:page-loading-stop", info => topbar.hide())
```

Alternatively, you can also delay showing the `topbar` and wait if the results do not appear within 200ms:

```js
// Show progress bar on live navigation and form submits
import topbar from "topbar"
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
let topBarScheduled = undefined;

window.addEventListener("phx:page-loading-start", () => {
if(!topBarScheduled) {
topBarScheduled = setTimeout(() => topbar.show(), 200);
};
});

window.addEventListener("phx:page-loading-stop", () => {
clearTimeout(topBarScheduled);
topBarScheduled = undefined;
topbar.hide();
});
```

## Location for LiveView modules

By convention your LiveView modules and `heex` templates should be placed in `lib/my_app_web/live/` directory.

0 comments on commit 22ac99b

Please sign in to comment.