@@ -4,44 +4,62 @@ class ColorThemes::ShowView < ApplicationView
4
4
include Phlex ::Rails ::Helpers ::FormWith
5
5
include Phlex ::Rails ::Helpers ::LinkTo
6
6
7
- def initialize ( color_scale :, curated_color_scales : [ ] )
7
+ def initialize ( color_scale :, curated_color_scales : [ ] , selected : false )
8
8
@color_scale = color_scale
9
9
@curated_color_scales = curated_color_scales
10
+ @selected = selected
10
11
end
11
12
12
13
def view_template
13
14
render Pages ::Header . new ( title : "Settings: Color Theme" )
14
15
div ( class : "section-content container py-gap" ) do
15
- h3 { @color_scale . display_name }
16
- div ( class : "color-theme color-theme:#{ @color_scale . name . parameterize } " ) do
17
- @color_scale . weights . each do |weight , color |
18
- div ( class : "color-swatch color-swatch__weight:#{ weight } " , style : "background-color: #{ color . hex } " ) do
19
- div ( class : "color-swatch__weight" ) { weight }
20
- div ( class : "color-swatch__color" ) { color . hex . delete ( "#" ) . upcase }
21
- end
22
- end
23
- end
24
-
25
16
h3 { "Want to try a different color theme?" }
17
+
26
18
p { "You can preview and save your desired color theme for this site. We have curated some options for you below." }
27
19
28
- form_with ( url : color_theme_path , method : :get ) do |f |
20
+ form_with ( url : url_for , method : :get ) do |f |
29
21
fieldset ( class : "flex items-center" ) do
30
22
f . select :id ,
31
23
@curated_color_scales . map { |cs | [ cs . display_name , cs . id ] } ,
32
24
{
33
- prompt : "Pick one!"
25
+ prompt : "Pick one!" ,
26
+ selected : ( @selected ? @color_scale . id : nil )
34
27
} ,
28
+ # requestSubmit and Turbo
35
29
# https://stackoverflow.com/questions/68624668/how-can-i-submit-a-form-on-input-change-with-turbo-streams
36
30
onchange : "this.form.requestSubmit()" ,
37
31
class : "mr-2 bg-gray-50 border border-gray-300 text-small rounded-lg focus:ring-blue-500 focus:border-blue-500 block p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
38
32
39
- whitespace
40
- span ( class : "mr-2 font-small" ) { "OR" }
41
- whitespace
42
- link_to "I feel lucky!" , color_theme_path ( id : @curated_color_scales . sample . id ) , class : "button primary"
33
+ span ( class : "mr-2 text-small" ) { "OR" }
34
+ link_to "I feel lucky!" , url_for ( id : @curated_color_scales . sample . id ) , class : "button primary mr-2"
35
+ if @selected
36
+ span ( class : "mr-2 text-small" ) { unsafe_raw "•" }
37
+ link_to "Reset to default" , url_for , class : "button secondary"
38
+ end
43
39
end
44
40
end
41
+
42
+ h3 { display_name }
43
+ div ( class : "color-theme color-theme:#{ @color_scale . name . parameterize } " ) do
44
+ @color_scale . weights . each do |weight , color |
45
+ div ( class : "color-swatch color-swatch__weight:#{ weight } " , style : "background-color: #{ color . hex } " ) do
46
+ div ( class : "color-swatch__weight" ) { weight }
47
+ div ( class : "color-swatch__color" ) { color . hex . delete ( "#" ) . upcase }
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def default_color_scale? = @color_scale . id == ColorScale . cached_default . id
57
+
58
+ def display_name
59
+ if default_color_scale?
60
+ "#{ @color_scale . display_name } (default)"
61
+ else
62
+ @color_scale . display_name
45
63
end
46
64
end
47
65
end
0 commit comments