Skip to content

Commit

Permalink
🧹 Add title to CollapsableSectionPresenter (#6657)
Browse files Browse the repository at this point in the history
* 🧹 Add title to CollapsableSectionPresenter

This is a back-port of Hyku functionality, while preserving method
signature compatibility.

* Amending to reflect observed Hyku changes
  • Loading branch information
jeremyf authored Feb 7, 2024
1 parent 4169c5d commit 5d2152d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
10 changes: 7 additions & 3 deletions app/presenters/hyrax/collapsable_section_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
module Hyrax
# Draws a collapsable list widget using the Bootstrap 3 / Collapse.js plugin
class CollapsableSectionPresenter
def initialize(view_context:, text:, id:, icon_class:, open:)
# rubocop:disable Metrics/ParameterLists
def initialize(view_context:, text:, id:, icon_class:, open:, title: nil)
@view_context = view_context
@text = text
@id = id
@icon_class = icon_class
@open = open
@title = title
end
# rubocop:enable Metrics/ParameterLists

attr_reader :view_context, :text, :id, :icon_class, :open
attr_reader :view_context, :text, :id, :icon_class, :open, :title
delegate :content_tag, :safe_join, :tag, to: :view_context

def render(&block)
Expand All @@ -26,7 +29,8 @@ def button_tag
href: "##{id}",
onclick: "toggleCollapse(this)",
'aria-expanded' => open,
'aria-controls' => id) do
'aria-controls' => id,
title: title) do
safe_join([tag.span('', class: icon_class, 'aria-hidden': true),
tag.span(text)], ' ')
end
Expand Down
16 changes: 14 additions & 2 deletions app/presenters/hyrax/menu_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@ def initialize(view_context)
delegate :controller, :controller_name, :action_name, :content_tag,
:current_page?, :link_to, :can?, :tag, to: :view_context

##
# @!group Class Attributes
#
# @!attribute section_controller_names [r|w]
# @return [Array<String>]
# @see #settings_section?
class_attribute :section_controller_names, default: %w[appearances content_blocks features pages collection_types]
# @!endgroup Class Attributes
##

# Returns true if the current controller happens to be one of the controllers that deals
# with settings. This is used to keep the parent section on the sidebar open.
def settings_section?
%w[appearances content_blocks features pages collection_types].include?(controller_name)
section_controller_names.include?(controller_name)
end

# @param options [Hash, String] a hash or string representing the path. Hash is prefered as it
Expand Down Expand Up @@ -47,12 +57,14 @@ def analytics_reporting_section?
%w[work_reports collection_reports].include?(controller_name)
end

##
# Draw a collaspable menu section. The passed block should contain <li> items.
def collapsable_section(text, id:, icon_class:, open:, &block)
def collapsable_section(text, id:, icon_class:, open:, title: nil, &block)
CollapsableSectionPresenter.new(view_context: view_context,
text: text,
id: id,
icon_class: icon_class,
title: title,
open: open).render(&block)
end

Expand Down

0 comments on commit 5d2152d

Please sign in to comment.