Skip to content

Commit

Permalink
Mock up collapsible panel helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Aug 13, 2024
1 parent 2cb2c1d commit 94c0e9e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
34 changes: 29 additions & 5 deletions app/helpers/content_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion app/helpers/link_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 94c0e9e

Please sign in to comment.