Skip to content

Commit f6008f5

Browse files
committed
notice flash messages now auto-dismiss after 3 seconds
Signed-off-by: Kai Wagner <kai.wagner@percona.com>
1 parent f30f1f7 commit f6008f5

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

app/assets/stylesheets/components/form.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ input[type=submit], input[type=button] {
2929
display: flex;
3030
align-items: center;
3131
gap: var(--spacing-2);
32+
transition: opacity 0.25s ease;
33+
}
34+
35+
.flash.is-hiding {
36+
opacity: 0;
3237
}
3338

3439
.flash.alert {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Controller } from "@hotwired/stimulus"
2+
3+
export default class extends Controller {
4+
static values = { delay: { type: Number, default: 3000 } }
5+
6+
connect() {
7+
this.timeout = setTimeout(() => this.dismiss(), this.delayValue)
8+
}
9+
10+
disconnect() {
11+
if (this.timeout) clearTimeout(this.timeout)
12+
if (this.removeTimeout) clearTimeout(this.removeTimeout)
13+
}
14+
15+
dismiss() {
16+
this.element.classList.add("is-hiding")
17+
this.removeTimeout = setTimeout(() => this.element.remove(), 250)
18+
}
19+
}

app/views/layouts/application.html.slim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ html data-theme="light"
134134
.layout-sidebar-overlay data-sidebar-target="overlay" data-action="click->sidebar#closeMobile"
135135
main.container
136136
- flash.each do |type, message|
137-
.flash class=type
137+
.flash class=type data=(type.to_s == "notice" ? { controller: "flash", "flash-delay-value": 3000 } : {})
138138
= flash_icon(type)
139139
= message
140140
= yield
141141
- else
142142
main.container
143143
- flash.each do |type, message|
144-
.flash class=type
144+
.flash class=type data=(type.to_s == "notice" ? { controller: "flash", "flash-delay-value": 3000 } : {})
145145
= flash_icon(type)
146146
= message
147147
= yield

0 commit comments

Comments
 (0)