From bab8c02951b77f44135f3288bed26234babdea5c Mon Sep 17 00:00:00 2001 From: Diego Toral Date: Fri, 30 Aug 2024 16:05:30 -0700 Subject: [PATCH] Add support to render subtitle as slot from title component --- CHANGELOG.md | 1 + app/components/bulma/title_component.rb | 8 ++++---- spec/components/bulma/title_component_spec.rb | 6 ++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f24d78..b2686ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/app/components/bulma/title_component.rb b/app/components/bulma/title_component.rb index f9c8019..16d3d90 100644 --- a/app/components/bulma/title_component.rb +++ b/app/components/bulma/title_component.rb @@ -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 @@ -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 diff --git a/spec/components/bulma/title_component_spec.rb b/spec/components/bulma/title_component_spec.rb index 266ca60..8dcf2ec 100644 --- a/spec/components/bulma/title_component_spec.rb +++ b/spec/components/bulma/title_component_spec.rb @@ -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