Skip to content

Commit 6e101c1

Browse files
committed
Extract gradients into themes
1 parent b6c5ca6 commit 6e101c1

File tree

4 files changed

+94
-26
lines changed

4 files changed

+94
-26
lines changed

apps/components_guide_web/lib/components_guide_web/controllers/web_standards_controller.ex

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,10 @@ end
1919

2020
defmodule ComponentsGuideWeb.WebStandardsView do
2121
use ComponentsGuideWeb, :view
22-
2322
use ComponentsGuideWeb.Snippets
23+
alias ComponentsGuideWeb.ThemeView
2424

2525
def header_styles() do
26-
color = {:lab, 47, 10, -44}
27-
28-
gradient = Styling.linear_gradient("150grad", [
29-
{:lab, 47, 5, -44},
30-
{:lab, 47, -24, -44},
31-
color,
32-
{:lab, 47, 53, -44}
33-
])
34-
35-
"background-color: #{color |> Styling.to_css()}; background-image: #{gradient};"
26+
ThemeView.gradient(:green)
3627
end
3728
end

apps/components_guide_web/lib/components_guide_web/templates/landing/index.html.eex

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,10 @@ subhead = "Learn about accessibility, TDD, BDD, naming, performance, and the lat
4646
</section>
4747
</div>
4848

49-
<article class="text-white py-6" style="<%= sections_styles(:blue) %>">
50-
<%= render ComponentsGuideWeb.ReactTypescriptView, "_top.html" %>
51-
</article>
52-
53-
<article class="text-white py-6" style="<%= sections_styles(:warm) %>">
54-
<%= render ComponentsGuideWeb.AccessibilityFirstView, "_top.html" %>
55-
</article>
56-
57-
<article class="text-white text-shadow py-6" style="<%= sections_styles(:other) %>">
58-
<%= render ComponentsGuideWeb.WebStandardsView, "_top.html" %>
59-
</article>
60-
61-
<article class="text-white text-shadow py-6" style="<%= sections_styles(:orange) %>">
62-
<%= render ComponentsGuideWeb.ComposableSystemsView, "_top.html" %>
63-
</article>
49+
<%= subject_banner(:accessibility_first) %>
50+
<%= subject_banner(:react_typescript) %>
51+
<%= subject_banner(:web_standards) %>
52+
<%= subject_banner(:composable_systems) %>
6453

6554
<div hidden class="text-white">
6655
<section class="pt-20 pb-20" style="<%= sections_styles(:dark) %>">

apps/components_guide_web/lib/components_guide_web/views/landing_view.ex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
defmodule ComponentsGuideWeb.LandingView do
22
use ComponentsGuideWeb, :view
3+
alias ComponentsGuideWeb.ThemeView
4+
5+
defp subject_to_module(:web_standards), do: ComponentsGuideWeb.WebStandardsView
6+
defp subject_to_module(:accessibility_first), do: ComponentsGuideWeb.AccessibilityFirstView
7+
defp subject_to_module(:composable_systems), do: ComponentsGuideWeb.ComposableSystemsView
8+
defp subject_to_module(:react_typescript), do: ComponentsGuideWeb.ReactTypescriptView
9+
10+
def subject_banner(subject) when is_atom(subject) do
11+
~E"""
12+
<article class="text-white text-shadow py-6" style="<%= ThemeView.banner_styles(subject) %>">
13+
<%= render subject_to_module(subject), "_top.html" %>
14+
</article>
15+
"""
16+
end
317

418
def stack_list(items) do
519
~E"""
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
defmodule ComponentsGuideWeb.ThemeView do
2+
use ComponentsGuideWeb, :view
3+
4+
defp gradient_styles(:green) do
5+
l = 62
6+
a = -50
7+
b = 20
8+
9+
color = {:lab, l, a, b}
10+
11+
gradient = Styling.linear_gradient("150grad", [
12+
{:lab, l * 1.5, a * 0.7, b * 2},
13+
{:lab, l * 1.3, a * 0.8, b * 1.6},
14+
{:lab, l * 1.1, a * 0.9, b * 1.2},
15+
color,
16+
{:lab, l * 0.9, a * 1.3, b * 0.7},
17+
{:lab, l * 0.8, a * 1.7, b * 0.5},
18+
])
19+
20+
"background-color: #{color |> Styling.to_css()}; background-image: #{gradient};"
21+
end
22+
23+
defp gradient_styles(:cool_pink) do
24+
color = {:lab, 47, 10, -44}
25+
26+
gradient = Styling.linear_gradient("150grad", [
27+
{:lab, 47, 5, -44},
28+
{:lab, 47, -24, -44},
29+
color,
30+
{:lab, 47, 53, -44}
31+
])
32+
33+
"background-color: #{color |> Styling.to_css()}; background-image: #{gradient};"
34+
end
35+
36+
defp gradient_styles(:blue) do
37+
l = 0
38+
a = -60
39+
b = -90
40+
color = {:lab, l, a, b}
41+
42+
gradient = Styling.linear_gradient("150grad", [
43+
{:lab, l * 1.1, a * 1.1, b * 1.4},
44+
color,
45+
{:lab, l * 1.3, a * 0.5, b * 0.5},
46+
])
47+
48+
"background-color: #{color |> Styling.to_css()}; background-image: #{gradient};"
49+
end
50+
51+
defp gradient_styles(:orange) do
52+
l = 62
53+
a = 51
54+
b = 24
55+
56+
color = {:lab, l, a, b}
57+
58+
gradient = Styling.linear_gradient("150grad", [
59+
{:lab, l * 1.5, a * 0.7, b * 2},
60+
{:lab, l * 1.3, a * 0.8, b * 1.6},
61+
{:lab, l * 1.1, a * 0.9, b * 1.2},
62+
color,
63+
{:lab, l * 0.9, a * 1.3, b * 0.7},
64+
{:lab, l * 0.8, a * 1.7, b * 0.5},
65+
])
66+
67+
"background-color: #{color |> Styling.to_css()}; background-image: #{gradient};"
68+
end
69+
70+
def banner_styles(:accessibility_first), do: gradient_styles(:cool_pink)
71+
def banner_styles(:web_standards), do: gradient_styles(:green)
72+
def banner_styles(:composable_systems), do: gradient_styles(:orange)
73+
def banner_styles(:react_typescript), do: gradient_styles(:blue)
74+
end

0 commit comments

Comments
 (0)