primer_view_components 0.0.41 → 0.0.46

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +265 -1
  3. data/app/assets/javascripts/primer_view_components.js +1 -1
  4. data/app/assets/javascripts/primer_view_components.js.map +1 -1
  5. data/app/components/primer/alpha/button_marketing.rb +70 -0
  6. data/app/components/primer/auto_complete.rb +99 -42
  7. data/app/components/primer/auto_complete/auto_complete.html.erb +1 -0
  8. data/app/components/primer/avatar_stack_component.rb +7 -1
  9. data/app/components/primer/base_component.rb +62 -26
  10. data/app/components/primer/beta/text.rb +27 -0
  11. data/app/components/primer/blankslate_component.html.erb +1 -0
  12. data/app/components/primer/blankslate_component.rb +64 -45
  13. data/app/components/primer/border_box_component.rb +3 -0
  14. data/app/components/primer/button_component.rb +3 -2
  15. data/app/components/primer/button_group.rb +1 -1
  16. data/app/components/primer/clipboard_copy.rb +25 -7
  17. data/app/components/primer/component.rb +5 -1
  18. data/app/components/primer/details_component.rb +18 -3
  19. data/app/components/primer/dropdown.d.ts +1 -0
  20. data/app/components/primer/{dropdown_component.html.erb → dropdown.html.erb} +2 -1
  21. data/app/components/primer/dropdown.js +1 -0
  22. data/app/components/primer/dropdown.rb +149 -0
  23. data/app/components/primer/dropdown.ts +1 -0
  24. data/app/components/primer/dropdown/menu.d.ts +1 -0
  25. data/app/components/primer/dropdown/menu.html.erb +25 -0
  26. data/app/components/primer/dropdown/menu.js +1 -0
  27. data/app/components/primer/dropdown/menu.rb +99 -0
  28. data/app/components/primer/dropdown/menu.ts +1 -0
  29. data/app/components/primer/heading_component.rb +1 -1
  30. data/app/components/primer/hidden_text_expander.rb +2 -2
  31. data/app/components/primer/icon_button.rb +1 -1
  32. data/app/components/primer/image_crop.rb +2 -2
  33. data/app/components/primer/markdown.rb +6 -2
  34. data/app/components/primer/menu_component.rb +7 -3
  35. data/app/components/primer/navigation/tab_component.rb +6 -6
  36. data/app/components/primer/octicon_component.rb +4 -3
  37. data/app/components/primer/popover_component.rb +2 -2
  38. data/app/components/primer/primer.d.ts +1 -0
  39. data/app/components/primer/primer.js +1 -0
  40. data/app/components/primer/primer.ts +1 -0
  41. data/app/components/primer/spinner_component.rb +2 -0
  42. data/app/components/primer/tab_nav_component.html.erb +4 -2
  43. data/app/components/primer/tab_nav_component.rb +48 -6
  44. data/app/components/primer/tooltip.rb +1 -1
  45. data/app/components/primer/truncate.rb +6 -2
  46. data/app/components/primer/underline_nav_component.html.erb +1 -1
  47. data/app/components/primer/underline_nav_component.rb +27 -5
  48. data/app/lib/primer/tabbed_component_helper.rb +2 -2
  49. data/{app/lib → lib}/primer/classify.rb +41 -35
  50. data/{app/lib → lib}/primer/classify/cache.rb +16 -35
  51. data/{app/lib → lib}/primer/classify/flex.rb +0 -0
  52. data/{app/lib → lib}/primer/classify/functional_background_colors.rb +2 -0
  53. data/{app/lib → lib}/primer/classify/functional_border_colors.rb +2 -0
  54. data/{app/lib → lib}/primer/classify/functional_colors.rb +0 -0
  55. data/{app/lib → lib}/primer/classify/functional_text_colors.rb +2 -0
  56. data/lib/primer/classify/grid.rb +45 -0
  57. data/lib/primer/classify/utilities.rb +137 -0
  58. data/lib/primer/classify/utilities.yml +1271 -0
  59. data/lib/primer/view_components.rb +1 -0
  60. data/lib/primer/view_components/engine.rb +2 -0
  61. data/lib/primer/view_components/linters.rb +3 -0
  62. data/lib/primer/view_components/linters/argument_mappers/button.rb +82 -0
  63. data/lib/primer/view_components/linters/argument_mappers/conversion_error.rb +10 -0
  64. data/lib/primer/view_components/linters/argument_mappers/system_arguments.rb +47 -0
  65. data/lib/primer/view_components/linters/button_component_migration_counter.rb +39 -0
  66. data/lib/primer/view_components/linters/flash_component_migration_counter.rb +16 -0
  67. data/lib/primer/view_components/linters/helpers.rb +191 -0
  68. data/lib/primer/view_components/version.rb +1 -1
  69. data/lib/tasks/docs.rake +180 -108
  70. data/lib/tasks/utilities.rake +105 -0
  71. data/lib/yard/docs_helper.rb +12 -2
  72. data/static/statuses.json +7 -5
  73. metadata +50 -20
  74. data/app/components/primer/button_marketing_component.rb +0 -68
  75. data/app/components/primer/dropdown/menu_component.html.erb +0 -12
  76. data/app/components/primer/dropdown/menu_component.rb +0 -46
  77. data/app/components/primer/dropdown_component.rb +0 -73
  78. data/app/components/primer/text_component.rb +0 -25
  79. data/app/lib/primer/classify/spacing.rb +0 -63
@@ -5,6 +5,8 @@ module Primer
5
5
  class DetailsComponent < Primer::Component
6
6
  status :beta
7
7
 
8
+ BODY_TAG_DEFAULT = :div
9
+ BODY_TAG_OPTIONS = [:ul, :"details-menu", :"details-dialog", BODY_TAG_DEFAULT].freeze
8
10
  NO_OVERLAY = :none
9
11
  OVERLAY_MAPPINGS = {
10
12
  NO_OVERLAY => "",
@@ -14,7 +16,7 @@ module Primer
14
16
 
15
17
  # Use the Summary slot as a trigger to reveal the content.
16
18
  #
17
- # @param button [Boolean] Whether to render the Summary as a button or not.
19
+ # @param button [Boolean] (true) Whether to render the Summary as a button or not.
18
20
  # @param kwargs [Hash] The same arguments as <%= link_to_system_arguments_docs %>.
19
21
  renders_one :summary, lambda { |button: true, **system_arguments|
20
22
  system_arguments[:tag] = :summary
@@ -27,12 +29,25 @@ module Primer
27
29
 
28
30
  # Use the Body slot as the main content to be shown when triggered by the Summary.
29
31
  #
32
+ # @param tag [String] (Primer::DetailsComponent::BODY_TAG_DEFAULT) <%= one_of(Primer::DetailsComponent::BODY_TAG_OPTIONS) %>
30
33
  # @param kwargs [Hash] The same arguments as <%= link_to_system_arguments_docs %>.
31
- renders_one :body, lambda { |**system_arguments|
32
- system_arguments[:tag] ||= :div
34
+ renders_one :body, lambda { |tag: BODY_TAG_DEFAULT, **system_arguments|
35
+ system_arguments[:tag] = fetch_or_fallback(BODY_TAG_OPTIONS, tag, BODY_TAG_DEFAULT)
36
+
33
37
  Primer::BaseComponent.new(**system_arguments)
34
38
  }
35
39
 
40
+ # @example Default
41
+ #
42
+ # <%= render Primer::DetailsComponent.new do |c| %>
43
+ # component.summary do
44
+ # "Summary"
45
+ # end
46
+ # component.body do
47
+ # "Body"
48
+ # end
49
+ # <% end %>
50
+ #
36
51
  # @param overlay [Symbol] Dictates the type of overlay to render with. <%= one_of(Primer::DetailsComponent::OVERLAY_MAPPINGS.keys) %>
37
52
  # @param reset [Boolean] Defatuls to false. If set to true, it will remove the default caret and remove style from the summary element
38
53
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
@@ -0,0 +1 @@
1
+ import './dropdown/menu';
@@ -1,6 +1,7 @@
1
1
  <%= render(Primer::DetailsComponent.new(**@system_arguments)) do |c| %>
2
- <% c.summary(classes: @summary_classes) do %>
2
+ <% c.summary(**@button_arguments) do %>
3
3
  <%= button %>
4
+ <% if @with_caret %><div class="dropdown-caret"></div><% end %>
4
5
  <% end %>
5
6
 
6
7
  <% c.body do %>
@@ -0,0 +1 @@
1
+ import './dropdown/menu';
@@ -0,0 +1,149 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ # `Dropdown` is a lightweight context menu for housing navigation and actions.
5
+ # They're great for instances where you don't need the full power (and code) of the SelectMenu.
6
+ class Dropdown < Primer::Component
7
+ # Required trigger for the dropdown. Has the same arguments as <%= link_to_component(Primer::ButtonComponent) %>,
8
+ # but it is locked as a `summary` tag.
9
+ renders_one :button, lambda { |**system_arguments, &block|
10
+ @button_arguments = system_arguments
11
+ @button_arguments[:button] = true
12
+
13
+ view_context.capture { block&.call }
14
+ }
15
+
16
+ # Required context menu for the dropdown.
17
+ #
18
+ # @param as [Symbol] When `as` is `:list`, wraps the menu in a `<ul>` with a `<li>` for each item.
19
+ # @param direction [Symbol] <%= one_of(Primer::Dropdown::Menu::DIRECTION_OPTIONS) %>
20
+ # @param scheme [Symbol] Pass `:dark` for dark mode theming
21
+ # @param header [String] Optional string to display as the header
22
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
23
+ renders_one :menu, "Primer::Dropdown::Menu"
24
+
25
+ # @example Default
26
+ # <%= render(Primer::Dropdown.new) do |c| %>
27
+ # <% c.button do %>
28
+ # Dropdown
29
+ # <% end %>
30
+ #
31
+ # <%= c.menu(header: "Options") do |menu|
32
+ # menu.item { "Item 1" }
33
+ # menu.item { "Item 2" }
34
+ # menu.item { "Item 3" }
35
+ # end %>
36
+ # <% end %>
37
+ #
38
+ # @example With dividers
39
+ #
40
+ # @description
41
+ # Dividers can be used to separate a group of items. They don't have any content.
42
+ # @code
43
+ # <%= render(Primer::Dropdown.new) do |c| %>
44
+ # <% c.button do %>
45
+ # Dropdown
46
+ # <% end %>
47
+ #
48
+ # <%= c.menu(header: "Options") do |menu|
49
+ # menu.item { "Item 1" }
50
+ # menu.item { "Item 2" }
51
+ # menu.item(divider: true)
52
+ # menu.item { "Item 3" }
53
+ # menu.item { "Item 4" }
54
+ # menu.item(divider: true)
55
+ # menu.item { "Item 5" }
56
+ # menu.item { "Item 6" }
57
+ # end %>
58
+ # <% end %>
59
+ #
60
+ # @example With direction
61
+ # <%= render(Primer::Dropdown.new(display: :inline_block)) do |c| %>
62
+ # <% c.button do %>
63
+ # Dropdown
64
+ # <% end %>
65
+ #
66
+ # <%= c.menu(header: "Options", direction: :s) do |menu|
67
+ # menu.item { "Item 1" }
68
+ # menu.item { "Item 2" }
69
+ # menu.item { "Item 3" }
70
+ # menu.item { "Item 4" }
71
+ # end %>
72
+ # <% end %>
73
+ #
74
+ # @example With caret
75
+ # <%= render(Primer::Dropdown.new(with_caret: true)) do |c| %>
76
+ # <% c.button do %>
77
+ # Dropdown
78
+ # <% end %>
79
+ #
80
+ # <%= c.menu(header: "Options") do |menu|
81
+ # menu.item { "Item 1" }
82
+ # menu.item { "Item 2" }
83
+ # menu.item { "Item 3" }
84
+ # menu.item { "Item 4" }
85
+ # end %>
86
+ # <% end %>
87
+ #
88
+ # @example Customizing the button
89
+ # <%= render(Primer::Dropdown.new) do |c| %>
90
+ # <% c.button(scheme: :primary, variant: :small) do %>
91
+ # Dropdown
92
+ # <% end %>
93
+ #
94
+ # <%= c.menu(header: "Options") do |menu|
95
+ # menu.item { "Item 1" }
96
+ # menu.item { "Item 2" }
97
+ # menu.item { "Item 3" }
98
+ # menu.item { "Item 4" }
99
+ # end %>
100
+ # <% end %>
101
+ #
102
+ # @example Menu as list
103
+ # <%= render(Primer::Dropdown.new) do |c| %>
104
+ # <% c.button do %>
105
+ # Dropdown
106
+ # <% end %>
107
+ #
108
+ # <%= c.menu(as: :list, header: "Options") do |menu|
109
+ # menu.item { "Item 1" }
110
+ # menu.item { "Item 2" }
111
+ # menu.item(divider: true)
112
+ # menu.item { "Item 3" }
113
+ # menu.item { "Item 4" }
114
+ # end %>
115
+ # <% end %>
116
+ #
117
+ # @example Customizing menu items
118
+ # <%= render(Primer::Dropdown.new) do |c| %>
119
+ # <% c.button do %>
120
+ # Dropdown
121
+ # <% end %>
122
+ #
123
+ # <%= c.menu(header: "Options") do |menu|
124
+ # menu.item(tag: :button) { "Item 1" }
125
+ # menu.item(classes: "custom-class") { "Item 2" }
126
+ # menu.item { "Item 3" }
127
+ # end %>
128
+ # <% end %>
129
+ #
130
+ # @param overlay [Symbol] <%= one_of(Primer::DetailsComponent::OVERLAY_MAPPINGS.keys) %>
131
+ # @param with_caret [Boolean] Whether or not a caret should be rendered in the button.
132
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
133
+ def initialize(overlay: :default, with_caret: false, **system_arguments)
134
+ @with_caret = with_caret
135
+
136
+ @system_arguments = system_arguments
137
+ @system_arguments[:overlay] = overlay
138
+ @system_arguments[:reset] = true
139
+ @system_arguments[:classes] = class_names(
140
+ @system_arguments[:classes],
141
+ "dropdown"
142
+ )
143
+ end
144
+
145
+ def render?
146
+ button.present? && menu.present?
147
+ end
148
+ end
149
+ end
@@ -0,0 +1 @@
1
+ import './dropdown/menu'
@@ -0,0 +1 @@
1
+ import '@github/details-menu-element';
@@ -0,0 +1,25 @@
1
+ <%= render Primer::BaseComponent.new(**@system_arguments) do %>
2
+ <% if @header.present? %>
3
+ <div class="dropdown-header">
4
+ <%= @header %>
5
+ </div>
6
+ <% end %>
7
+
8
+ <% if list? %>
9
+ <ul>
10
+ <% items.each do |item| %>
11
+ <% if item.divider? %>
12
+ <%= item %>
13
+ <% else %>
14
+ <li>
15
+ <%= item %>
16
+ </li>
17
+ <% end %>
18
+ <% end %>
19
+ </ul>
20
+ <% else %>
21
+ <% items.each do |item| %>
22
+ <%= item %>
23
+ <% end %>
24
+ <% end %>
25
+ <% end %>
@@ -0,0 +1 @@
1
+ import '@github/details-menu-element';
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ class Dropdown
5
+ # This component is part of `Dropdown` and should not be
6
+ # used as a standalone component.
7
+ class Menu < Primer::Component
8
+ AS_DEFAULT = :default
9
+ AS_OPTIONS = [AS_DEFAULT, :list].freeze
10
+
11
+ SCHEME_DEFAULT = :default
12
+ SCHEME_MAPPINGS = {
13
+ SCHEME_DEFAULT => "",
14
+ :dark => "dropdown-menu-dark"
15
+ }.freeze
16
+
17
+ DIRECTION_DEFAULT = :se
18
+ DIRECTION_OPTIONS = [DIRECTION_DEFAULT, :sw, :w, :e, :ne, :s].freeze
19
+
20
+ # @param tag [Symbol] <%= one_of(Primer::Dropdown::Menu::Item::TAG_OPTIONS) %>.
21
+ # @param divider [Boolean] Whether the item is a divider without any function.
22
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
23
+ renders_many :items, lambda { |divider: false, **system_arguments|
24
+ Primer::Dropdown::Menu::Item.new(as: @as, divider: divider, **system_arguments)
25
+ }
26
+
27
+ # @param as [Symbol] When `as` is `:list`, wraps the menu in a `<ul>` with a `<li>` for each item.
28
+ # @param direction [Symbol] <%= one_of(Primer::Dropdown::Menu::DIRECTION_OPTIONS) %>.
29
+ # @param header [String] Header to be displayed above the menu.
30
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
31
+ def initialize(as: AS_DEFAULT, direction: DIRECTION_DEFAULT, scheme: SCHEME_DEFAULT, header: nil, **system_arguments)
32
+ @header = header
33
+ @direction = direction
34
+ @as = fetch_or_fallback(AS_OPTIONS, as, AS_DEFAULT)
35
+
36
+ @system_arguments = system_arguments
37
+ @system_arguments[:tag] = "details-menu"
38
+ @system_arguments[:role] = "menu"
39
+
40
+ @system_arguments[:classes] = class_names(
41
+ @system_arguments[:classes],
42
+ "dropdown-menu",
43
+ "dropdown-menu-#{fetch_or_fallback(DIRECTION_OPTIONS, direction, DIRECTION_DEFAULT)}",
44
+ SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_MAPPINGS.keys, scheme, SCHEME_DEFAULT)]
45
+ )
46
+ end
47
+
48
+ private
49
+
50
+ def list?
51
+ @as == :list
52
+ end
53
+
54
+ # Items to be rendered in the `Dropdown` menu.
55
+ class Item < Primer::Component
56
+ TAG_DEFAULT = :a
57
+ BUTTON_TAGS = [:button, :summary].freeze
58
+ TAG_OPTIONS = [TAG_DEFAULT, *BUTTON_TAGS].freeze
59
+
60
+ def initialize(as:, tag: TAG_DEFAULT, divider: false, **system_arguments)
61
+ @divider = divider
62
+ @as = as
63
+
64
+ @system_arguments = system_arguments
65
+ @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, TAG_DEFAULT)
66
+ @system_arguments[:tag] = :li if list? && divider?
67
+ @system_arguments[:role] ||= :menuitem
68
+ @system_arguments[:role] = :separator if divider
69
+ @system_arguments[:classes] = class_names(
70
+ @system_arguments[:classes],
71
+ "dropdown-item" => !divider,
72
+ "dropdown-divider" => divider
73
+ )
74
+ end
75
+
76
+ def call
77
+ component = if BUTTON_TAGS.include?(@system_arguments[:tag])
78
+ Primer::ButtonComponent.new(scheme: :link, **@system_arguments)
79
+ else
80
+ Primer::BaseComponent.new(**@system_arguments)
81
+ end
82
+
83
+ # divider has no content
84
+ render(component) if divider?
85
+
86
+ render(component) { content }
87
+ end
88
+
89
+ def divider?
90
+ @divider
91
+ end
92
+
93
+ def list?
94
+ @as == :list
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1 @@
1
+ import '@github/details-menu-element'
@@ -5,7 +5,7 @@ module Primer
5
5
  #
6
6
  # - Set tag to one of `:h1`, `:h2`, `:h3`, `:h4`, `:h5`, `:h6` based on what is appropriate for the page context.
7
7
  # - Use `Heading` as the title of a section or sub section.
8
- # - Do not use `Heading` for styling alone. For simply styling text, consider using <%= link_to_component(Primer::TextComponent) %> with relevant <%= link_to_typography_docs %>
8
+ # - Do not use `Heading` for styling alone. For simply styling text, consider using <%= link_to_component(Primer::Beta::Text) %> with relevant <%= link_to_typography_docs %>
9
9
  # such as `font_size` and `font_weight`.
10
10
  # - Do not jump heading levels. For instance, do not follow a `<h1>` with an `<h3>`. Heading levels should increase by one in ascending order.
11
11
  #
@@ -10,14 +10,14 @@ module Primer
10
10
  # <%= render(Primer::HiddenTextExpander.new(inline: true)) %>
11
11
  #
12
12
  # @example Styling the button
13
- # <%= render(Primer::HiddenTextExpander.new(button_arguments: { p: 1, classes: "my-custom-class" })) %>
13
+ # <%= render(Primer::HiddenTextExpander.new(button_arguments: { p: 1, classes: "custom-class" })) %>
14
14
  #
15
15
  # @param inline [Boolean] Whether or not the expander is inline.
16
16
  # @param button_arguments [Hash] <%= link_to_system_arguments_docs %> for the button element.
17
17
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
18
18
  def initialize(inline: false, button_arguments: {}, **system_arguments)
19
19
  @system_arguments = system_arguments
20
- @system_arguments[:tag] ||= :span
20
+ @system_arguments[:tag] = :span
21
21
  @system_arguments[:classes] = class_names(
22
22
  "hidden-text-expander",
23
23
  @system_arguments[:classes],
@@ -31,7 +31,7 @@ module Primer
31
31
  #
32
32
  # <%= render(Primer::BorderBoxComponent.new) do |component| %>
33
33
  # <% component.body do %>
34
- # <%= render(Primer::TextComponent.new(pr: 2)) { "Body" } %>
34
+ # <%= render(Primer::Beta::Text.new(pr: 2)) { "Body" } %>
35
35
  # <%= render(Primer::IconButton.new(icon: :pencil, box: true, "aria-label": "Edit")) %>
36
36
  # <% end %>
37
37
  # <% end %>
@@ -6,7 +6,7 @@ module Primer
6
6
  # A loading indicator that is shown while the image is loading.
7
7
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
8
8
  renders_one :loading, lambda { |**system_arguments|
9
- system_arguments[:tag] ||= :div
9
+ system_arguments[:tag] = :div
10
10
  system_arguments[:"data-loading-slot"] = true
11
11
 
12
12
  Primer::BaseComponent.new(**system_arguments)
@@ -20,7 +20,7 @@ module Primer
20
20
  #
21
21
  # @example Cropper with a custom loader
22
22
  # <%= render(Primer::ImageCrop.new(src: "https://github.com/koddsson.png", rounded: false)) do |cropper| %>
23
- # <% cropper.loading(style: "width: 120px", tag: :img, src: "spinner.gif") %>
23
+ # <% cropper.loading(style: "width: 120px").with_content("Loading...") %>
24
24
  # <% end %>
25
25
  #
26
26
  # @param src [String] The path of the image to crop.
@@ -4,6 +4,9 @@ module Primer
4
4
  # Use `Markdown` to wrap markdown content
5
5
  class Markdown < Primer::Component
6
6
  status :beta
7
+
8
+ DEFAULT_TAG = :div
9
+ TAG_OPTIONS = [DEFAULT_TAG, :article, :td].freeze
7
10
  # @example Default
8
11
  # <%= render(Primer::Markdown.new) do %>
9
12
  # <p>Text can be <b>bold</b>, <i>italic</i>, or <s>strikethrough</s>. <a href="https://github.com">Links </a> should be blue with no underlines (unless hovered over).</p>
@@ -276,10 +279,11 @@ module Primer
276
279
  # <pre><code>This is the final element on the page and there should be no margin below this.</code></pre>
277
280
  # <% end %>
278
281
  #
282
+ # @param tag [Symbol] <%= one_of(Primer::Markdown::TAG_OPTIONS) %>
279
283
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
280
- def initialize(**system_arguments)
284
+ def initialize(tag: DEFAULT_TAG, **system_arguments)
281
285
  @system_arguments = system_arguments
282
- @system_arguments[:tag] ||= :div
286
+ @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG)
283
287
 
284
288
  @system_arguments[:classes] = class_names(
285
289
  "markdown-body",
@@ -3,11 +3,15 @@
3
3
  module Primer
4
4
  # Use `Menu` to create vertical lists of navigational links.
5
5
  class MenuComponent < Primer::Component
6
+ HEADING_TAG_OPTIONS = [:h1, :h2, :h3, :h4, :h5, :h6].freeze
7
+ HEADING_TAG_FALLBACK = :h2
8
+
6
9
  # Optional menu heading
7
10
  #
11
+ # @param tag [Symbol] <%= one_of(Primer::MenuComponent::HEADING_TAG_OPTIONS) %>
8
12
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
9
- renders_one :heading, lambda { |**system_arguments|
10
- system_arguments[:tag] ||= :span
13
+ renders_one :heading, lambda { |tag:, **system_arguments|
14
+ system_arguments[:tag] = fetch_or_fallback(HEADING_TAG_OPTIONS, tag, HEADING_TAG_FALLBACK)
11
15
  system_arguments[:classes] = class_names(
12
16
  "menu-heading",
13
17
  system_arguments[:classes]
@@ -35,7 +39,7 @@ module Primer
35
39
 
36
40
  # @example Default
37
41
  # <%= render(Primer::MenuComponent.new) do |c| %>
38
- # <% c.heading do %>
42
+ # <% c.heading(tag: :h2) do %>
39
43
  # Heading
40
44
  # <% end %>
41
45
  # <% c.item(selected: true, href: "#url") do %>