Skip to content

Commit

Permalink
Add support for content as first argument for TitleComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
diegotoral committed Feb 7, 2024
1 parent ca05398 commit f1cbde7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 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 specify content as first arggument to `Bulma::TitleComponent`
- Drop supoort for Ruby 2,7
- Updated capybara to latest version 3.40.0
- Updated `ImageComponentPreview` to include sizes exemple
Expand Down
5 changes: 3 additions & 2 deletions app/components/bulma/title_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

module Bulma
class TitleComponent < Component
def initialize(as: :h1, size: 1)
def initialize(title = nil, as: :h1, size: 1)
raise ArgumentError, "invalid value to size" if size > 6

@title = title
@as = as
@size = size
end

def call
content_tag @as, content, class: class_names(
content_tag @as, @title || content, class: class_names(
"title",
"is-#{@size}"
)
Expand Down
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 @@ -7,6 +7,12 @@
expect(page).to have_css "h1.title", text: "Title 1"
end

it "accepts content as first argument" do
render_inline(described_class.new("Title"))

expect(page).to have_content "Title"
end

it "renders content within another tag as specified" do
render_inline(described_class.new(as: :h2)) { "Title 1" }

Expand Down

0 comments on commit f1cbde7

Please sign in to comment.