]> git.openstreetmap.org Git - rails.git/blob - app/helpers/numbered_pagination_helper.rb
Prepare to split element version pagination into multiple lists
[rails.git] / app / helpers / numbered_pagination_helper.rb
1 module NumberedPaginationHelper
2   def element_versions_pagination(top_version, active_version: 0, &)
3     lists = []
4
5     lists << tag.ul(:class => [
6                       "pagination pagination-sm",
7                       "overflow-x-scroll pb-3", # horizontal scrollbar with reserved space below
8                       "pt-1" # space reserved for focus outlines
9                     ]) do
10       (1..top_version).each do |v|
11         concat element_versions_pagination_item(v, **yield(v), :active => v == active_version)
12       end
13     end
14
15     tag.div safe_join(lists), :class => "d-flex align-items-start"
16   end
17
18   private
19
20   def element_versions_pagination_item(body, href: nil, title: nil, active: false)
21     link_class = "page-link"
22     link = link_to body, href, :class => link_class, :title => title
23     tag.li link, :class => ["page-item", { "active" => active }]
24   end
25 end