Skip to content

Commit 34b4988

Browse files
authored
Migrate the home components to align with Phlex conversions (#169)
1 parent 635d9c4 commit 34b4988

File tree

8 files changed

+188
-172
lines changed

8 files changed

+188
-172
lines changed

app/components/home_view/banner.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
module Components
4+
module HomeView
5+
class Banner < Components::Base
6+
include DeferredRender
7+
8+
def view_template(&block)
9+
div(class: "relative overflow-hidden") do
10+
render Shared::GridPattern.new(spacing: :md)
11+
render HomeView::Shapes.new(size: :xl, color: :pink, class: "hidden sm:block absolute right-0 top-1/2 transform -translate-y-1/2 sm:translate-x-2/3 md:translate-x-1/2")
12+
div(class: "relative container mx-auto max-w-3xl py-24 lg:py-32 px-4 sm:text-center flex flex-col sm:items-center gap-y-6") do
13+
Heading(level: 1) do
14+
plain "A UI component library, crafted precisely for Ruby devs"
15+
span(class: "text-foreground opacity-30") { " who want to stay organised and build modern apps, fast." }
16+
end
17+
if @cta
18+
div(class: "grid grid-cols-1 sm:grid-cols-2 gap-4", &@cta)
19+
end
20+
end
21+
end
22+
end
23+
24+
def cta(&block)
25+
@cta = block
26+
end
27+
end
28+
end
29+
end

app/components/home_view/card.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# frozen_string_literal: true
2+
3+
module Components
4+
module HomeView
5+
class Card < Components::Base
6+
include DeferredRender
7+
8+
def initialize(attributes = {})
9+
@attributes = attributes
10+
@title = attributes.delete(:title)
11+
@subtitle = attributes.delete(:subtitle) || nil
12+
@color = attributes.delete(:color) || :card
13+
14+
@color_classes = {
15+
card: "bg-background border",
16+
primary: "bg-primary text-white",
17+
secondary: "bg-accent text-accent-foreground",
18+
# Add sky, violet, amber, lime, pink
19+
sky: "bg-sky-100 text-sky-950",
20+
violet: "bg-violet-100 text-violet-950",
21+
amber: "bg-amber-100 text-amber-950",
22+
lime: "bg-lime-100 text-lime-950",
23+
pink: "bg-pink-100 text-pink-950"
24+
}
25+
end
26+
27+
def view_template(&block)
28+
div(**@attributes, class: ["relative flex flex-col p-6 md:p-10 rounded-2xl space-y-8 overflow-hidden", @attributes[:class], @color_classes[@color.to_sym]]) do
29+
if @icon
30+
div(&@icon)
31+
end
32+
if @title || @subtitle
33+
div(class: "space-y-2") do
34+
h3(class: "font-semibold leading-none tracking-tight") { @title } if @title
35+
p { @subtitle } if @subtitle
36+
end
37+
end
38+
39+
@content&.call
40+
end
41+
end
42+
43+
def icon(&block)
44+
@icon = block
45+
end
46+
47+
def content(&block)
48+
@content = block
49+
end
50+
end
51+
end
52+
end

app/components/home_view/shapes.rb

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# frozen_string_literal: true
2+
3+
module Components
4+
module HomeView
5+
class Shapes < Components::Base
6+
def initialize(size: :md, **attributes)
7+
@attributes = attributes
8+
@circle_sizes = {
9+
xs: "w-8 h-8",
10+
sm: "w-12 h-12",
11+
md: "w-16 h-16",
12+
lg: "w-24 h-24",
13+
xl: "w-32 h-32"
14+
}
15+
16+
@square_sizes = {
17+
xs: "w-16 h-16 rounde-md",
18+
sm: "w-24 h-24 rounded-md",
19+
md: "w-32 h-32 rounded-lg",
20+
lg: "w-48 h-48 rounded-lg",
21+
xl: "w-64 h-64 rounded-xl"
22+
}
23+
24+
@size = size
25+
@colors = %w[sky violet pink amber lime]
26+
@color = @attributes.delete(:color) || @colors.sample
27+
end
28+
29+
def view_template
30+
# Create one square and one circle of different colors
31+
# The square will be on a rotation of 15deg
32+
# the circle will be a solid color
33+
# The shapes will be slightly overlapping
34+
div(**@attributes) do
35+
div(class: "relative") do
36+
circle
37+
square
38+
end
39+
end
40+
end
41+
42+
def square
43+
color_classes = {
44+
sky: "bg-sky-500/10 backdrop-blur-3xl ring-1 ring-sky-600/20 saturate-150",
45+
violet: "bg-violet-500/10 backdrop-blur-3xl ring-1 ring-violet-600/20 saturate-150",
46+
pink: "bg-pink-500/10 backdrop-blur-3xl ring-1 ring-pink-600/20 saturate-150",
47+
amber: "bg-amber-500/10 backdrop-blur-3xl ring-1 ring-amber-600/20 saturate-150",
48+
lime: "bg-lime-500/10 backdrop-blur-3xl ring-1 ring-lime-600/20 saturate-150"
49+
}
50+
51+
sample_color = color_classes[@color.to_sym]
52+
53+
div(class: "#{@square_sizes[@size]} #{sample_color} -rotate-12")
54+
end
55+
56+
def circle
57+
color_classes = {
58+
sky: "bg-sky-400",
59+
violet: "bg-violet-400",
60+
pink: "bg-pink-400",
61+
amber: "bg-amber-400",
62+
lime: "bg-lime-400"
63+
}
64+
65+
sample_color = color_classes[@color.to_sym]
66+
67+
div(class: "#{@circle_sizes[@size]} #{sample_color} rounded-full absolute top-0 left-0 transform -translate-x-1/2 -translate-y-1/2")
68+
end
69+
end
70+
end
71+
end

app/components/home_view/steps.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
module Components
4+
module HomeView
5+
class Steps < Components::Base
6+
def initialize(attributes = {})
7+
@attributes = attributes
8+
@steps = attributes.delete(:steps) || []
9+
end
10+
11+
def view_template(&block)
12+
div(**@attributes) do
13+
@steps.each_with_index do |step, index|
14+
render_step(step, index: index, last: index == @steps.length - 1)
15+
end
16+
end
17+
end
18+
19+
def render_step(step, index:, last: false)
20+
div(class: "relative flex space-x-8") do
21+
div(class: "flex-shrink-0 h-full") do
22+
div(class: "flex-0 flex items-center justify-center h-6 w-6 rounded-full border bg-background") do
23+
p(class: "font-medium") { index + 1 }
24+
end
25+
# vertical line unless last
26+
hr(class: "absolute left-3 top-6 -ml-px h-full w-px bg-border") unless last
27+
end
28+
div(class: "flex-grow space-y-2 pb-10 pt-1") do
29+
h3(class: "font-semibold leading-none tracking-tight") { step[:title] } if step[:title]
30+
p { step[:description] } if step[:description]
31+
end
32+
end
33+
end
34+
end
35+
end
36+
end

app/views/home_view/banner.rb

Lines changed: 0 additions & 25 deletions
This file was deleted.

app/views/home_view/card.rb

Lines changed: 0 additions & 48 deletions
This file was deleted.

app/views/home_view/shapes.rb

Lines changed: 0 additions & 67 deletions
This file was deleted.

app/views/home_view/steps.rb

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)