Skip to content

Commit 6e173d0

Browse files
authored
Migrate the steps components to app/components to align with Phlex conversions (#166)
1 parent 071b0a7 commit 6e173d0

File tree

6 files changed

+69
-63
lines changed

6 files changed

+69
-63
lines changed

app/components/steps/builder.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
module Components
4+
module Steps
5+
class Builder < Components::Base
6+
include DeferredRender
7+
8+
def initialize(**attrs)
9+
@attrs = attrs
10+
@step_number = 0
11+
@steps = []
12+
end
13+
14+
def view_template
15+
div(**@attrs) do
16+
@steps.each do |step|
17+
render step
18+
end
19+
end
20+
end
21+
22+
def add_step(&)
23+
@step_number += 1
24+
step = Step.new(number: @step_number, last: true, &)
25+
@steps << step
26+
# Last false for all steps except the last one
27+
@steps[0..-2].each { |s| s.last = false }
28+
end
29+
end
30+
end
31+
end

app/components/steps/container.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module Components
4+
module Steps
5+
class Container < Components::Base
6+
def view_template(&)
7+
div(class: "space-y-4", &)
8+
end
9+
end
10+
end
11+
end

app/components/steps/step.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
module Components
4+
module Steps
5+
class Step < Components::Base
6+
def initialize(number: 1, last: false)
7+
@number = number
8+
@last = last
9+
end
10+
11+
attr_writer :last
12+
13+
def view_template(&block)
14+
div(class: "relative flex space-x-4 md:space-x-8") do
15+
div(class: "flex-shrink-0 h-full") do
16+
div(class: "flex-0 flex items-center justify-center h-6 w-6 rounded-md border border-amber-500/20 bg-amber-100 dark:bg-amber-100/20 text-amber-700 dark:text-amber-200") do
17+
p(class: "font-medium text-sm") { @number }
18+
end
19+
# vertical line unless last
20+
hr(class: "absolute left-3 top-6 -ml-px h-full w-px bg-amber-500/20") unless @last
21+
end
22+
div(class: "flex-1 space-y-2 pb-10 overflow-hidden -mt-0.5", &block)
23+
end
24+
end
25+
end
26+
end
27+
end

app/views/components/steps/builder.rb

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

app/views/components/steps/container.rb

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

app/views/components/steps/step.rb

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

0 commit comments

Comments
 (0)