|
3 | 3 | class ColorThemes::ShowView < ApplicationView
|
4 | 4 | include Phlex::Rails::Helpers::FormWith
|
5 | 5 | include Phlex::Rails::Helpers::LinkTo
|
| 6 | + include Phlex::Rails::Helpers::ButtonTo |
| 7 | + include Phlex::Rails::Helpers::ContentFor |
6 | 8 |
|
7 |
| - def initialize(color_theme:, curated_color_scales: [], selected: false) |
| 9 | + def initialize(color_theme:, fallback_color_scale: nil, curated_color_scales: [], selected: false, saved: false) |
8 | 10 | @color_theme = color_theme
|
9 | 11 | @color_scale = color_theme.color_scale
|
| 12 | + @fallback_color_scale = fallback_color_scale |
10 | 13 | @curated_color_scales = curated_color_scales
|
11 | 14 | @selected = selected
|
| 15 | + @saved = saved |
12 | 16 | end
|
13 | 17 |
|
14 | 18 | def view_template
|
15 |
| - render Pages::Header.new(title: "Settings: Color Theme") |
| 19 | + content_for :head do |
| 20 | + render("application/theme/color") |
| 21 | + end |
| 22 | + render Pages::Header.new(title: "Theme") |
16 | 23 | div(class: "section-content container py-gap") do
|
17 |
| - h3 { "Want to try a different color theme?" } |
18 |
| - |
19 |
| - p { "You can preview and save your desired color theme for this site. We have curated some options for you below." } |
20 |
| - |
21 |
| - form_with(model: @color_theme, url: url_for, method: :get) do |f| |
22 |
| - fieldset(class: "flex items-center") do |
23 |
| - f.select( |
24 |
| - :color_scale_id, |
25 |
| - @curated_color_scales.map { |cs| [cs.display_name, cs.id] }, |
26 |
| - { |
27 |
| - prompt: "Pick one!", |
28 |
| - selected: (@selected ? @color_scale.id : nil) |
29 |
| - }, |
30 |
| - # requestSubmit and Turbo |
31 |
| - # https://stackoverflow.com/questions/68624668/how-can-i-submit-a-form-on-input-change-with-turbo-streams |
32 |
| - onchange: "this.form.requestSubmit()", |
33 |
| - 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" |
34 |
| - ) |
| 24 | + if @saved || @selected |
| 25 | + h3 do |
| 26 | + plain "You are now #{@saved ? "using" : "previewing"} the" |
| 27 | + whitespace |
| 28 | + span(class: "emphasis") { @color_scale.display_name } |
| 29 | + whitespace |
| 30 | + plain "color scheme" |
| 31 | + end |
| 32 | + else |
| 33 | + h3 { "Want to try a different color scheme?" } |
| 34 | + end |
35 | 35 |
|
36 |
| - span(class: "mr-2 text-small") { "OR" } |
37 |
| - link_to "I feel lucky!", url_for(color_theme: {color_scale_id: @curated_color_scales.sample.id}), class: "button primary mr-2" |
38 |
| - if @selected |
39 |
| - span(class: "mr-2 text-small") { unsafe_raw "•" } |
40 |
| - link_to "Reset to default", url_for, class: "button secondary" |
| 36 | + p { "You can preview and save your desired color scheme for this site. We have curated some options for you below." } |
| 37 | + |
| 38 | + div(class: "flex items-center") do |
| 39 | + span(class: "mr-2 text-small") { "Preview" } |
| 40 | + |
| 41 | + form_with(model: @color_theme, url: url_for, method: :get) do |f| |
| 42 | + fieldset do |
| 43 | + f.select( |
| 44 | + :color_scale_id, |
| 45 | + @curated_color_scales.map { |cs| [cs.display_name, cs.id] }, |
| 46 | + { |
| 47 | + prompt: "Pick one!", |
| 48 | + selected: @selected && @color_scale.id |
| 49 | + }, |
| 50 | + # requestSubmit and Turbo |
| 51 | + # https://stackoverflow.com/questions/68624668/how-can-i-submit-a-form-on-input-change-with-turbo-streams |
| 52 | + onchange: "this.form.requestSubmit()", |
| 53 | + class: "mr-2" |
| 54 | + ) |
41 | 55 | end
|
42 | 56 | end
|
| 57 | + |
| 58 | + span(class: "mr-2 text-small") { "OR" } |
| 59 | + |
| 60 | + link_to "I feel lucky!", |
| 61 | + color_theme_path(color_theme: {color_scale_id: @curated_color_scales.sample.id}), |
| 62 | + class: "button secondary mr-2" |
| 63 | + |
| 64 | + if @selected && @color_scale != @fallback_color_scale |
| 65 | + span(class: "mr-2 text-small") { "OR" } |
| 66 | + |
| 67 | + button_to "Reset preview", |
| 68 | + color_theme_path(color_theme: {color_scale_id: @fallback_color_scale.id}), |
| 69 | + method: :patch, |
| 70 | + class: "button tertiary mr-2" |
| 71 | + end |
| 72 | + end |
| 73 | + |
| 74 | + if @selected |
| 75 | + div(class: "flex items-center") do |
| 76 | + span(class: "mr-2 text-small") { plain "Save" } |
| 77 | + |
| 78 | + button_to "Save this color scheme", |
| 79 | + color_theme_path(color_theme: {color_scale_id: @color_scale.id}), |
| 80 | + method: :patch, |
| 81 | + class: "button primary mr-2" |
| 82 | + |
| 83 | + span(class: "mr-2 text-small") { unsafe_raw "•" } |
| 84 | + |
| 85 | + button_to "Reset to default", |
| 86 | + color_theme_path(color_theme: {color_scale_id: ColorScale.cached_default.id}), |
| 87 | + method: :patch, |
| 88 | + class: "button tertiary mr-2" |
| 89 | + end |
43 | 90 | end
|
44 | 91 |
|
45 | 92 | h3 { display_name }
|
46 |
| - div(class: "color-theme color-theme:#{@color_scale.name.parameterize}") do |
| 93 | + |
| 94 | + div(class: "color-scheme color-scheme__#{@color_scale.name.parameterize}") do |
47 | 95 | @color_scale.weights.each do |weight, color|
|
48 | 96 | div(class: "color-swatch color-swatch__weight:#{weight}", style: "background-color: #{color.hex}") do
|
49 | 97 | div(class: "color-swatch__weight") { weight }
|
|
0 commit comments