Skip to content

Commit

Permalink
Add support to render subtitle as slot from title component
Browse files Browse the repository at this point in the history
  • Loading branch information
diegotoral committed Aug 30, 2024
1 parent d431546 commit bab8c02
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [Unreleased]

- Added support to render subtitle as slot from `Bulma::TitleComponent`
- Added support to specify HTML tag to use for `Bulma::SubtitleComponent`
- Updated `Bulma::TitleComponent` previews to use helper method
- Updated `Bulma::ImageComponent` previews to use Ruby logo
Expand Down
8 changes: 4 additions & 4 deletions app/components/bulma/title_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module Bulma
class TitleComponent < Component
renders_one :subtitle, SubtitleComponent

def initialize(title = nil, as: :h1, size: 1)
raise ArgumentError, "invalid value to size" if size > 6

Expand All @@ -11,10 +13,8 @@ def initialize(title = nil, as: :h1, size: 1)
end

def call
content_tag @as, @title || content, class: class_names(
"title",
"is-#{@size}"
)
concat content_tag(@as, @title || content, class: class_names("title", "is-#{@size}"))
concat subtitle
end
end
end
6 changes: 6 additions & 0 deletions spec/components/bulma/title_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@
described_class.new(size: 999)
}.to raise_error ArgumentError, /invalid value to size/
end

it "allows to render a subtitle" do
render_inline(described_class.new("Title")) { _1.with_subtitle "Subtitle" }

expect(page).to have_css "p.subtitle", text: "Subtitle"
end
end

0 comments on commit bab8c02

Please sign in to comment.