File tree Expand file tree Collapse file tree 7 files changed +86
-10
lines changed
javascripts/hotsheet/controllers Expand file tree Collapse file tree 7 files changed +86
-10
lines changed Original file line number Diff line number Diff line change 1
1
## [ Unreleased] ( https://github.com/renuo/hotsheet/compare/v0.1.0..HEAD )
2
2
3
3
- Configure compatible Ruby/Rails versions for testing
4
+ - Improve flash messages layout
4
5
5
6
## [ 0.1.0] ( https://github.com/renuo/hotsheet/releases/tag/v0.1.0 ) (2024-11-05)
6
7
Original file line number Diff line number Diff line change 1
1
import { Application } from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js"
2
2
import EditableAttributeController from "./controllers/editable_attribute_controller"
3
+ import FlashController from "./controllers/flash_controller"
3
4
4
5
window . Stimulus = Application . start ( )
5
6
6
7
Stimulus . register ( "editable-attribute" , EditableAttributeController )
8
+ Stimulus . register ( "flash" , FlashController )
Original file line number Diff line number Diff line change
1
+ import { Controller } from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js"
2
+
3
+ export default class extends Controller {
4
+ close ( ) {
5
+ this . element . addEventListener ( "animationend" , ( ) => { this . element . remove ( ) ; } ) ;
6
+ this . element . classList . add ( "closing" ) ;
7
+ }
8
+ }
Original file line number Diff line number Diff line change 8
8
*/
9
9
10
10
: root {
11
- --bg-color : lightgray;
12
11
--sidebar-width : 12rem ;
12
+ --main-padding-x : 2rem ;
13
+ --main-padding-y : 2rem ;
14
+
15
+ --bg-color : lightgray;
16
+ --success-color : green;
17
+ --alert-color : yellow;
18
+ --notice-color : blue;
19
+ --error-color : red;
13
20
}
14
21
15
22
body {
19
26
20
27
main {
21
28
margin-left : var (--sidebar-width );
22
- padding : 1 rem ;
29
+ padding : var ( --main-padding-y ) var ( --main-padding-x ) ;
23
30
}
24
31
25
32
aside {
@@ -36,7 +43,7 @@ aside {
36
43
display : flex;
37
44
flex-direction : column;
38
45
margin : 0 ;
39
- padding : 0.25 rem ;
46
+ padding : 0.5 rem ;
40
47
41
48
a {
42
49
border-radius : 0.5rem ;
@@ -84,3 +91,58 @@ table {
84
91
width : 100% ;
85
92
}
86
93
}
94
+
95
+ .flash-container {
96
+ position : fixed;
97
+ display : flex;
98
+ flex-direction : column;
99
+ bottom : 1rem ;
100
+ right : 1rem ;
101
+ gap : 1rem ;
102
+ max-width : calc (100% - var (--sidebar-width ) - var (--main-padding-x ));
103
+
104
+ .flash {
105
+ border-radius : 0.4rem ;
106
+ padding : 0.75rem 1.25rem ;
107
+ display : flex;
108
+ justify-content : space-between;
109
+ align-items : center;
110
+ gap : 1rem ;
111
+
112
+ & .success {
113
+ background-color : rgb (from var (--success-color ) r g b / 80% );
114
+ }
115
+
116
+ & .alert {
117
+ background-color : rgb (from var (--alert-color ) r g b / 80% );
118
+ }
119
+
120
+ & .notice {
121
+ background-color : rgb (from var (--notice-color ) r g b / 80% );
122
+ }
123
+
124
+ & .error {
125
+ background-color : rgb (from var (--error-color ) r g b / 80% );
126
+ }
127
+
128
+ .btn-close {
129
+ background-color : transparent;
130
+ border : none;
131
+ cursor : pointer;
132
+ font-size : 1.5rem ;
133
+ }
134
+
135
+ & .closing {
136
+ animation : fade-out 0.5s ease-in forwards;
137
+ }
138
+ }
139
+ }
140
+
141
+ @keyframes fade-out {
142
+ from {
143
+ opacity : 1 ;
144
+ }
145
+ to {
146
+ opacity : 0 ;
147
+ }
148
+ }
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ def update # rubocop:disable Metrics/AbcSize
17
17
record = model . find params [ :id ]
18
18
19
19
if record . update model_params
20
- flash [ :notice ] = t ( "hotsheet.success" , record : model . model_name . human )
20
+ flash [ :success ] = t ( "hotsheet.success" , record : model . model_name . human )
21
21
else
22
22
flash [ :alert ] = t ( "hotsheet.error" , record : model . model_name . human ,
23
23
errors : record . errors . full_messages . join ( ", " ) )
Original file line number Diff line number Diff line change 1
1
<%# locals: () %>
2
2
3
- <% flash.each do |type, msg| %>
4
- <div class ='flash <%= type %> '>
5
- < span > <%= msg %> </ span >
6
- </ div >
7
- <% end %>
3
+ < div class ='flash-container '>
4
+ <% flash . each do |type , msg | %>
5
+ < div class ='flash <%= type %> ' data-controller ='flash '>
6
+ < span > <%= msg %> </ span >
7
+ < button class ='btn-close ' data-action ='click->flash#close '> ×</ button >
8
+ </ div >
9
+ <% end %>
10
+ </ div >
Original file line number Diff line number Diff line change 14
14
</ head >
15
15
< body >
16
16
<%= render "layouts/hotsheet/sidebar" %>
17
- <%= render "layouts/hotsheet/flash" %>
18
17
< main >
18
+ <%= render "layouts/hotsheet/flash" %>
19
19
<%= yield %>
20
20
</ main >
21
21
</ body >
You can’t perform that action at this time.
0 commit comments