Skip to content

Commit 9bbab54

Browse files
committed
Allow select color scale for preview
1 parent fe1f6e2 commit 9bbab54

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

app/controllers/color_themes_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class ColorThemesController < ApplicationController
22
def show
33
@color_scale = params[:id] ? ColorScale.find(params[:id]) : ColorScale.find_or_create_default
4-
curated_color_scales = Rails.cache.fetch("curated_color_scales") { ColorScale.curated }
4+
curated_color_scales = ColorScale.cached_curated
55

66
render ColorThemes::ShowView.new(
7-
color_scale: color_scale,
7+
color_scale: @color_scale,
88
curated_color_scales: curated_color_scales
99
)
1010
end

app/views/application/theme/_color.html.erb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<%
2-
my_color = 'cerulean-blue'
3-
ui_colors_color_increments = [50, *1.upto(9).map { |n| n*100}, 950 ]
4-
5-
color_scale = ColorScale.find_or_create_default
2+
color_scale = @color_scale || ColorScale.find_or_create_default
63
%>
74
<style>
85
:root {

app/views/color_themes/show_view.rb

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
class ColorThemes::ShowView < ApplicationView
44
include Phlex::Rails::Helpers::FormWith
5+
include Phlex::Rails::Helpers::LinkTo
56

67
def initialize(color_scale:, curated_color_scales: [])
78
@color_scale = color_scale
@@ -11,8 +12,6 @@ def initialize(color_scale:, curated_color_scales: [])
1112
def view_template
1213
render Pages::Header.new(title: "Settings: Color Theme")
1314
div(class: "section-content container py-gap") do
14-
p { "You can preview and save your desired color theme for this site. We have curated some options for you below." }
15-
1615
h3 { @color_scale.display_name }
1716
div(class: "color-theme color-theme:#{@color_scale.name.parameterize}") do
1817
@color_scale.weights.each do |weight, color|
@@ -24,12 +23,23 @@ def view_template
2423
end
2524

2625
h3 { "Want to try a different color theme?" }
26+
p { "You can preview and save your desired color theme for this site. We have curated some options for you below." }
27+
2728
form_with(url: color_theme_path, method: :get) do |f|
28-
fieldset do
29-
f.select :id, @curated_color_scales.map { |cs| [cs.display_name, cs.id] }, include_blank: "Pick one!"
30-
end
31-
fieldset do
32-
f.submit "Show me!", class: "button primary"
29+
fieldset(class: "flex items-center") do
30+
f.select :id,
31+
@curated_color_scales.map { |cs| [cs.display_name, cs.id] },
32+
{
33+
prompt: "Pick one!"
34+
},
35+
# https://stackoverflow.com/questions/68624668/how-can-i-submit-a-form-on-input-change-with-turbo-streams
36+
onchange: "this.form.requestSubmit()",
37+
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+
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"
3343
end
3444
end
3545
end

0 commit comments

Comments
 (0)