summaryrefslogtreecommitdiff
path: root/lib/sidebars/concerns/container_with_html_options.rb
blob: 79dddd309b5d8134c0f00ad205b55cf4c8590942 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# frozen_string_literal: true

module Sidebars
  module Concerns
    module ContainerWithHtmlOptions
      # The attributes returned from this method
      # will be applied to helper methods like
      # `link_to` or the div containing the container.
      def container_html_options
        {
          aria: { label: title }
        }.merge(extra_container_html_options)
      end

      # Classes will override mostly this method
      # and not `container_html_options`.
      def extra_container_html_options
        {}
      end

      # The attributes returned from this method
      # will be applied to helper methods like
      # `link_to` or the div containing the container
      # when it is collapsed.
      def collapsed_container_html_options
        {
          aria: { label: title }
        }.merge(extra_collapsed_container_html_options)
      end

      # Classes should mostly override this method
      # and not `collapsed_container_html_options`.
      def extra_collapsed_container_html_options
        {}
      end

      # Attributes to pass to the html_options attribute
      # in the helper method that sets the active class
      # on each element.
      def nav_link_html_options
        {
          data: {
            track_label: self.class.name.demodulize.underscore
          }
        }.deep_merge(extra_nav_link_html_options)
      end

      # Classes should mostly override this method
      # and not `nav_link_html_options`.
      def extra_nav_link_html_options
        {}
      end

      def title
        raise NotImplementedError
      end

      # The attributes returned from this method
      # will be applied right next to the title,
      # for example in the span that renders the title.
      def title_html_options
        {}
      end

      def link
        raise NotImplementedError
      end
    end
  end
end