Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract a TitleComponent #3372

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/components/spotlight/title_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="container site-title-container">
<div class="site-title-wrapper">
<%= title %>
<%= subtitle %>
</div>
</div>
22 changes: 22 additions & 0 deletions app/components/spotlight/title_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module Spotlight
# Draws the title in the masthead
class TitleComponent < ViewComponent::Base
def initialize(title:, subtitle:)
@title = title
@subtitle = subtitle
super
end

def title
tag.h1 @title, class: 'site-title h2'
end

def subtitle
return unless @subtitle

tag.small(@subtitle, class: 'd-none d-md-block py-2 fs-4')
end
end
end
19 changes: 1 addition & 18 deletions app/views/shared/_masthead.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,7 @@
<% end %>

<%= masthead_navbar if resource_masthead? %>

<div class="container site-title-container">
<div class="site-title-wrapper">
<% if content_for? :masthead %>
<h1 class="site-title h2">
<%= content_for :masthead %>
</h1>
<% else %>
<h1 class="site-title h2">
<%= masthead_heading_content %>
</h1>
<% if masthead_subheading_content %>
<small class="d-none d-md-block py-2 fs-4"><%= masthead_subheading_content %></small>
<% end %>
<% end %>
</div>
</div>

<%= render Spotlight::Engine.config.spotlight.title_component.new(title: content_for(:masthead) || masthead_heading_content, subtitle: masthead_subheading_content) %>
<%= masthead_navbar unless resource_masthead? %>
</header>

Expand Down
1 change: 1 addition & 0 deletions lib/spotlight/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def self.blacklight_config
ActiveSupport::Reloader.to_prepare do
Spotlight::Engine.config.spotlight = OpenStruct.new
Spotlight::Engine.config.spotlight.header_navigation_link_component = Spotlight::HeaderNavigationLinkComponent
Spotlight::Engine.config.spotlight.title_component = Spotlight::TitleComponent
end
end

Expand Down
Loading