diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index 40049b853d..cf63f18e95 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb @@ -153,11 +153,10 @@ def panel_block(**args, &block) **args.except(:class, :inner_class, :inner_id, :heading, :heading_links) ) do concat(heading) - if content.present? - concat(tag.div(class: class_names("panel-body", args[:inner_class]), - id: args[:inner_id]) do - concat(content) - end) + if args[:collapse].present? + concat(panel_collapse_body(args, content)) + else + concat(panel_block_body(args, content)) end concat(footer) end @@ -170,6 +169,8 @@ def panel_block_heading(args) els = [args[:heading]] if args[:heading_links].present? els << tag.span(args[:heading_links], class: "float-right") + elsif args[:collapse].present? + els << panel_collapse_trigger(args) end els.safe_join end @@ -179,6 +180,29 @@ def panel_block_heading(args) end end + def panel_body(args, content) + return "" if content.blank? + + tag.div(class: class_names("panel-body", args[:inner_class]), + id: args[:inner_id]) do + concat(content) + end + end + + def panel_collapse_trigger(args) + link_to(link_icon(:chevron_down), "##{args[:collapse]}", + class: "panel-collapse-trigger", + role: "button", data: { toggle: "collapse" }, + aria: { expanded: "false", controls: args } ) + end + + def panel_collapse_body(args, content) + tag.div(class: class_names("panel-collapse collapse", args[:collapsed]), + id: args[:collapse]) do + concat(panel_body(args, content)) + end + end + def panel_block_footer(args) if args[:footer] tag.div(class: "panel-footer") do diff --git a/app/helpers/link_helper.rb b/app/helpers/link_helper.rb index 8048896771..3ca7578549 100644 --- a/app/helpers/link_helper.rb +++ b/app/helpers/link_helper.rb @@ -181,7 +181,11 @@ def link_icon(type, **args) print: "print", globe: "globe", find_on_map: "screenshot", - apply: "check" + apply: "check", + chevron_down: "chevron-down", + chevron_up: "chevron-up", + chevron_left: "chevron-left", + chevron_right: "chevron-right" }.freeze # button to destroy object