Skip to content

Commit 35fc4ee

Browse files
committed
flash messages can now be closed
Signed-off-by: Kai Wagner <kai.wagner@percona.com>
1 parent f30f1f7 commit 35fc4ee

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

app/assets/stylesheets/components/form.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,27 @@ input[type=submit], input[type=button] {
3131
gap: var(--spacing-2);
3232
}
3333

34+
.flash-message {
35+
flex: 1;
36+
}
37+
38+
.flash-close {
39+
margin-left: auto;
40+
border: 0;
41+
background: transparent;
42+
color: inherit;
43+
font: inherit;
44+
cursor: pointer;
45+
padding: 0;
46+
line-height: 1;
47+
opacity: 0.8;
48+
49+
&:hover,
50+
&:focus-visible {
51+
opacity: 1;
52+
}
53+
}
54+
3455
.flash.alert {
3556
background-color: var(--color-danger-soft);
3657
color: var(--color-danger);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Controller } from "@hotwired/stimulus"
2+
3+
export default class extends Controller {
4+
dismiss() {
5+
this.element.remove()
6+
}
7+
}

app/views/layouts/application.html.slim

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,16 @@ 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-controller="flash"
138138
= flash_icon(type)
139-
= message
139+
span.flash-message = message
140+
button.flash-close type="button" aria-label="Dismiss message" data-action="flash#dismiss" x
140141
= yield
141142
- else
142143
main.container
143144
- flash.each do |type, message|
144-
.flash class=type
145+
.flash class=type data-controller="flash"
145146
= flash_icon(type)
146-
= message
147+
span.flash-message = message
148+
button.flash-close type="button" aria-label="Dismiss message" data-action="flash#dismiss" x
147149
= yield

0 commit comments

Comments
 (0)