Skip to content

Commit

Permalink
Allow passing attributes to navbar sections
Browse files Browse the repository at this point in the history
  • Loading branch information
davidalejandroaguilar committed Oct 1, 2024
1 parent 817d0f4 commit e20c4c7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
27 changes: 21 additions & 6 deletions lib/phlexy_ui/navbar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,31 @@ def view_template(&)
end
end

def start(&)
div(class: :"navbar-start", &)
def start(*, as: :div, **options, &)
generate_classes!(
component_html_class: :"navbar-start",
options:
).then do |classes|
public_send(as, class: classes, **options, &)
end
end

def center(&)
div(class: :"navbar-center", &)
def center(*, as: :div, **options, &)
generate_classes!(
component_html_class: :"navbar-center",
options:
).then do |classes|
public_send(as, class: classes, **options, &)
end
end

def end(&)
div(class: :"navbar-end", &)
def end(*, as: :div, **options, &)
generate_classes!(
component_html_class: :"navbar-end",
options:
).then do |classes|
public_send(as, class: classes, **options, &)
end
end

register_modifiers(
Expand Down
12 changes: 6 additions & 6 deletions spec/lib/phlexy_ui/navbar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
Class.new(Phlex::HTML) do
def view_template(&)
render PhlexyUI::Navbar.new do |navbar|
navbar.start do
navbar.start class: "start", data: {my: :start} do
end

navbar.center do
navbar.center class: "center", data: {my: :center} do
end

navbar.end do
navbar.end class: "end", data: {my: :end} do
end
end
end
Expand All @@ -75,9 +75,9 @@ def view_template(&)
it "is expected to match the formatted HTML" do
expected_html = html <<~HTML
<nav class="navbar">
<div class="navbar-start"></div>
<div class="navbar-center"></div>
<div class="navbar-end"></div>
<div class="navbar-start start" data-my="start"></div>
<div class="navbar-center center" data-my="center"></div>
<div class="navbar-end end" data-my="end"></div>
</nav>
HTML

Expand Down

0 comments on commit e20c4c7

Please sign in to comment.