primer_view_components 0.0.61 → 0.0.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +746 -613
  3. data/app/components/primer/alpha/border_box/header.rb +1 -2
  4. data/app/components/primer/alpha/button_marketing.rb +4 -4
  5. data/app/components/primer/alpha/tab_nav.rb +1 -1
  6. data/app/components/primer/alpha/tab_panels.rb +2 -2
  7. data/app/components/primer/alpha/underline_nav.rb +2 -1
  8. data/app/components/primer/alpha/underline_panels.rb +2 -2
  9. data/app/components/primer/base_component.rb +8 -36
  10. data/app/components/primer/beta/auto_complete/item.rb +1 -1
  11. data/app/components/primer/beta/auto_complete.rb +4 -2
  12. data/app/components/primer/beta/avatar.rb +1 -1
  13. data/app/components/primer/beta/blankslate.html.erb +2 -2
  14. data/app/components/primer/beta/blankslate.rb +7 -6
  15. data/app/components/primer/beta/breadcrumbs.rb +2 -2
  16. data/app/components/primer/beta/text.rb +1 -1
  17. data/app/components/primer/border_box_component.rb +1 -1
  18. data/app/components/primer/box_component.rb +3 -2
  19. data/app/components/primer/button_component.html.erb +3 -9
  20. data/app/components/primer/button_component.rb +61 -28
  21. data/app/components/primer/button_group.rb +9 -15
  22. data/app/components/primer/clipboard_copy.rb +1 -1
  23. data/app/components/primer/close_button.rb +1 -1
  24. data/app/components/primer/component.rb +77 -0
  25. data/app/components/primer/counter_component.rb +1 -1
  26. data/app/components/primer/details_component.rb +1 -1
  27. data/app/components/primer/dropdown/menu.rb +1 -1
  28. data/app/components/primer/dropdown.html.erb +0 -1
  29. data/app/components/primer/dropdown.rb +2 -1
  30. data/app/components/primer/dropdown_menu_component.rb +1 -1
  31. data/app/components/primer/flash_component.rb +3 -2
  32. data/app/components/primer/flex_component.rb +16 -16
  33. data/app/components/primer/flex_item_component.rb +1 -1
  34. data/app/components/primer/hellip_button.rb +1 -1
  35. data/app/components/primer/hidden_text_expander.rb +1 -1
  36. data/app/components/primer/image.rb +3 -3
  37. data/app/components/primer/image_crop.rb +2 -1
  38. data/app/components/primer/label_component.rb +23 -13
  39. data/app/components/primer/layout_component.rb +1 -0
  40. data/app/components/primer/local_time.rb +1 -1
  41. data/app/components/primer/markdown.rb +1 -1
  42. data/app/components/primer/menu_component.rb +2 -1
  43. data/app/components/primer/navigation/tab_component.rb +1 -0
  44. data/app/components/primer/octicon_component.rb +4 -2
  45. data/app/components/primer/octicon_symbols_component.rb +2 -2
  46. data/app/components/primer/popover_component.rb +3 -3
  47. data/app/components/primer/progress_bar_component.rb +7 -6
  48. data/app/components/primer/spinner_component.html.erb +4 -7
  49. data/app/components/primer/spinner_component.rb +1 -1
  50. data/app/components/primer/subhead_component.rb +3 -1
  51. data/app/components/primer/tab_container_component.rb +1 -1
  52. data/app/components/primer/time_ago_component.rb +1 -1
  53. data/app/components/primer/timeline_item_component.rb +4 -3
  54. data/app/components/primer/tooltip.rb +1 -0
  55. data/app/lib/primer/octicon/cache.rb +4 -10
  56. data/lib/primer/classify/utilities.rb +17 -44
  57. data/lib/primer/classify/utilities.yml +298 -68
  58. data/lib/primer/classify.rb +92 -178
  59. data/lib/primer/view_components/engine.rb +1 -0
  60. data/lib/primer/view_components/linters/argument_mappers/button.rb +4 -4
  61. data/lib/primer/view_components/linters/blankslate_api_migration.rb +11 -5
  62. data/lib/primer/view_components/version.rb +1 -1
  63. data/lib/rubocop/cop/primer/deprecated_arguments.rb +1 -1
  64. data/lib/rubocop/cop/primer/deprecated_button_arguments.rb +51 -0
  65. data/lib/rubocop/cop/primer/deprecated_label_schemes.rb +68 -0
  66. data/lib/rubocop/cop/primer/deprecated_layout_component.rb +30 -0
  67. data/lib/rubocop/cop/primer/primer_octicon.rb +1 -3
  68. data/lib/tasks/custom_utilities.yml +298 -0
  69. data/lib/tasks/docs.rake +1 -1
  70. data/lib/tasks/utilities.rake +21 -4
  71. data/static/arguments.yml +16 -7
  72. data/static/classes.yml +19 -18
  73. data/static/constants.json +25 -15
  74. metadata +10 -12
  75. data/app/components/primer/auto_complete/auto_complete.d.ts +0 -1
  76. data/app/components/primer/auto_complete/auto_complete.js +0 -1
  77. data/app/components/primer/auto_complete/auto_component.d.ts +0 -1
  78. data/app/components/primer/auto_complete/auto_component.js +0 -1
  79. data/lib/primer/classify/cache.rb +0 -109
  80. data/lib/primer/classify/flex.rb +0 -111
@@ -3,8 +3,7 @@
3
3
  module Primer
4
4
  module Alpha
5
5
  module BorderBox
6
- # BorderBox::Header: used inside the BorderBoxComponent to render its header slot
7
- # Optional title slot
6
+ # `BorderBox::Header` is used inside `BorderBox` to render its header slot.
8
7
  #
9
8
  # @accessibility When using `header.title`, set `tag` to one of `h1`, `h2`, `h3`, etc. based on what is appropriate for the page context. <%= link_to_heading_practices %>
10
9
  class Header < Primer::Component
@@ -7,9 +7,9 @@ module Primer
7
7
  DEFAULT_SCHEME = :default
8
8
  SCHEME_MAPPINGS = {
9
9
  DEFAULT_SCHEME => "",
10
- :primary => "btn-primary-mktg",
11
- :outline => "btn-outline-mktg",
12
- :transparent => "btn-transparent"
10
+ :primary => "btn-signup-mktg",
11
+ :outline => "btn-muted-mktg",
12
+ :transparent => "btn-subtle-mktg"
13
13
  }.freeze
14
14
  SCHEME_OPTIONS = SCHEME_MAPPINGS.keys
15
15
 
@@ -30,7 +30,7 @@ module Primer
30
30
  # <%= render(Primer::Alpha::ButtonMarketing.new(mr: 2)) { "Default" } %>
31
31
  # <%= render(Primer::Alpha::ButtonMarketing.new(scheme: :primary, mr: 2)) { "Primary" } %>
32
32
  # <%= render(Primer::Alpha::ButtonMarketing.new(scheme: :outline)) { "Outline" } %>
33
- # <div class="color-bg-canvas-inverse">
33
+ # <div class="color-bg-emphasis">
34
34
  # <%= render(Primer::Alpha::ButtonMarketing.new(scheme: :transparent)) { "Transparent" } %>
35
35
  # </div>
36
36
  #
@@ -101,7 +101,7 @@ module Primer
101
101
  # <% end %>
102
102
  #
103
103
  # @example Customizing the body
104
- # <%= render(Primer::Alpha::TabNav.new(label: "Default", body_arguments: { classes: "custom-class", border: true, border_color: :info })) do |c| %>
104
+ # <%= render(Primer::Alpha::TabNav.new(label: "Default", body_arguments: { classes: "custom-class", border: true, border_color: :accent_emphasis })) do |c| %>
105
105
  # <% c.tab(selected: true, href: "#") { "Tab 1" }%>
106
106
  # <% c.tab(href: "#") { "Tab 2" } %>
107
107
  # <% c.tab(href: "#") { "Tab 3" } %>
@@ -66,11 +66,11 @@ module Primer
66
66
  @align = EXTRA_ALIGN_DEFAULT
67
67
  @wrapper_arguments = wrapper_arguments
68
68
 
69
- @system_arguments = system_arguments
69
+ @system_arguments = deny_tag_argument(**system_arguments)
70
70
  @system_arguments[:tag] = :div
71
71
  @system_arguments[:classes] = tab_nav_classes(@system_arguments[:classes])
72
72
 
73
- @body_arguments = body_arguments
73
+ @body_arguments = deny_tag_argument(**body_arguments)
74
74
  @body_arguments[:tag] = :ul
75
75
  @body_arguments[:classes] = tab_nav_body_classes(@body_arguments[:classes])
76
76
 
@@ -5,6 +5,7 @@ module Primer
5
5
  # Use `UnderlineNav` to style navigation links with a minimal
6
6
  # underlined selected state, typically placed at the top
7
7
  # of the page.
8
+ #
8
9
  # For panel navigation, use <%= link_to_component(Primer::Alpha::UnderlinePanels) %> instead.
9
10
  #
10
11
  # @accessibility
@@ -102,7 +103,7 @@ module Primer
102
103
  # <% end %>
103
104
  #
104
105
  # @example Customizing the body
105
- # <%= render(Primer::Alpha::UnderlineNav.new(label: "Default", body_arguments: { classes: "custom-class", border: true, border_color: :info })) do |c| %>
106
+ # <%= render(Primer::Alpha::UnderlineNav.new(label: "Default", body_arguments: { classes: "custom-class", border: true, border_color: :accent_emphasis })) do |c| %>
106
107
  # <% c.tab(selected: true, href: "#") { "Tab 1" }%>
107
108
  # <% c.tab(href: "#") { "Tab 2" } %>
108
109
  # <% c.tab(href: "#") { "Tab 3" } %>
@@ -64,11 +64,11 @@ module Primer
64
64
  @align = fetch_or_fallback(ALIGN_OPTIONS, align, ALIGN_DEFAULT)
65
65
  @wrapper_arguments = wrapper_arguments
66
66
 
67
- @system_arguments = system_arguments
67
+ @system_arguments = deny_tag_argument(**system_arguments)
68
68
  @system_arguments[:tag] = :div
69
69
  @system_arguments[:classes] = underline_nav_classes(@system_arguments[:classes], @align)
70
70
 
71
- @body_arguments = body_arguments
71
+ @body_arguments = deny_tag_argument(**body_arguments)
72
72
  @body_arguments[:tag] = :ul
73
73
  @body_arguments[:classes] = underline_nav_body_classes(@body_arguments[:classes])
74
74
 
@@ -72,14 +72,14 @@ module Primer
72
72
  #
73
73
  # | Name | Type | Description |
74
74
  # | :- | :- | :- |
75
- # | `align_items` | Symbol | <%= one_of(Primer::Classify::Flex::ALIGN_ITEMS_VALUES) %> |
76
- # | `align_self` | Symbol | <%= one_of(Primer::Classify::Flex::ALIGN_SELF_VALUES) %> |
77
- # | `direction` | Symbol | <%= one_of(Primer::Classify::Flex::DIRECTION_VALUES) %> |
78
- # | `flex` | Integer, Symbol | <%= one_of(Primer::Classify::Flex::FLEX_VALUES) %> |
75
+ # | `align_items` | Symbol | <%= one_of(Primer::Classify::FLEX_ALIGN_ITEMS_VALUES) %> |
76
+ # | `align_self` | Symbol | <%= one_of(Primer::Classify::FLEX_ALIGN_SELF_VALUES) %> |
77
+ # | `direction` | Symbol | <%= one_of(Primer::Classify::FLEX_DIRECTION_VALUES) %> |
78
+ # | `flex` | Integer, Symbol | <%= one_of(Primer::Classify::FLEX_VALUES) %> |
79
79
  # | `flex_grow` | Integer | To enable, set to `0`. |
80
80
  # | `flex_shrink` | Integer | To enable, set to `0`. |
81
- # | `flex_wrap` | Symbol | <%= one_of(Primer::Classify::Flex::WRAP_MAPPINGS.keys) %> |
82
- # | `justify_content` | Symbol | <%= one_of(Primer::Classify::Flex::JUSTIFY_CONTENT_VALUES) %> |
81
+ # | `flex_wrap` | Symbol | <%= one_of(Primer::Classify::FLEX_WRAP_MAPPINGS.keys) %> |
82
+ # | `justify_content` | Symbol | <%= one_of(Primer::Classify::FLEX_JUSTIFY_CONTENT_VALUES) %> |
83
83
  #
84
84
  # ## Grid
85
85
  #
@@ -151,42 +151,14 @@ module Primer
151
151
  # | test_selector | String | Adds `data-test-selector='given value'` in non-Production environments for testing purposes. |
152
152
  def initialize(tag:, classes: nil, **system_arguments)
153
153
  @tag = tag
154
- @system_arguments = system_arguments
155
154
 
156
- raise ArgumentError, "`class` is an invalid argument. Use `classes` instead." if system_arguments.key?(:class) && !Rails.env.production?
157
-
158
- if (denylist = system_arguments[:system_arguments_denylist])
159
- if raise_on_invalid_options? && !ENV["PRIMER_WARNINGS_DISABLED"]
160
- # Convert denylist from:
161
- # { [:p, :pt] => "message" } to:
162
- # { p: "message", pt: "message" }
163
- unpacked_denylist =
164
- denylist.each_with_object({}) do |(keys, value), memo|
165
- keys.each { |key| memo[key] = value }
166
- end
167
-
168
- violations = unpacked_denylist.keys & @system_arguments.keys
169
-
170
- if violations.any?
171
- message = "Found #{violations.count} #{'violation'.pluralize(violations)}:"
172
- violations.each do |violation|
173
- message += "\n The #{violation} system argument is not allowed here. #{unpacked_denylist[violation]}"
174
- end
175
-
176
- raise(ArgumentError, message)
177
- end
178
- end
179
-
180
- # Remove :system_arguments_denylist key and any denied keys from system arguments
181
- @system_arguments.except!(:system_arguments_denylist)
182
- @system_arguments.except!(*denylist.keys.flatten)
183
- end
155
+ @system_arguments = validate_arguments(tag: tag, **system_arguments)
184
156
 
185
157
  @result = Primer::Classify.call(**@system_arguments.merge(classes: classes))
186
158
 
187
159
  @system_arguments[:"data-view-component"] = true
188
160
  # Filter out Primer keys so they don't get assigned as HTML attributes
189
- @content_tag_args = add_test_selector(@system_arguments).except(*Primer::Classify::VALID_KEYS)
161
+ @content_tag_args = add_test_selector(@system_arguments).except(*Primer::Classify::Utilities::UTILITIES.keys)
190
162
  end
191
163
 
192
164
  def call
@@ -20,7 +20,7 @@ module Primer
20
20
  # @param disabled [Boolean] Whether the item is disabled.
21
21
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
22
22
  def initialize(value:, selected: false, disabled: false, **system_arguments)
23
- @system_arguments = system_arguments
23
+ @system_arguments = deny_tag_argument(**system_arguments)
24
24
  @system_arguments[:tag] = :li
25
25
  @system_arguments[:role] = :option
26
26
  @system_arguments[:"data-autocomplete-value"] = value
@@ -19,6 +19,7 @@ module Primer
19
19
  #
20
20
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
21
21
  renders_one :label, lambda { |**system_arguments|
22
+ deny_tag_argument(**system_arguments)
22
23
  system_arguments[:for] = @input_id
23
24
  system_arguments[:tag] = :label
24
25
  Primer::BaseComponent.new(**system_arguments)
@@ -47,6 +48,7 @@ module Primer
47
48
  #
48
49
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
49
50
  renders_one :results, lambda { |**system_arguments|
51
+ deny_tag_argument(**system_arguments)
50
52
  system_arguments[:tag] = :ul
51
53
  system_arguments[:id] = @list_id
52
54
  system_arguments[:classes] = class_names(
@@ -110,7 +112,7 @@ module Primer
110
112
 
111
113
  system_arguments.delete(:"aria-label") && system_arguments[:aria]&.delete(:label)
112
114
 
113
- @system_arguments = system_arguments
115
+ @system_arguments = deny_tag_argument(**system_arguments)
114
116
  @system_arguments[:tag] = "auto-complete"
115
117
  @system_arguments[:src] = src
116
118
  @system_arguments[:for] = list_id
@@ -133,7 +135,7 @@ module Primer
133
135
  # @param type [Symbol] <%= one_of(Primer::Beta::AutoComplete::Input::TYPE_OPTIONS) %>
134
136
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
135
137
  def initialize(type: DEFAULT_TYPE, **system_arguments)
136
- @system_arguments = system_arguments
138
+ @system_arguments = deny_tag_argument(**system_arguments)
137
139
  @system_arguments[:tag] = :input
138
140
 
139
141
  @aria_label = system_arguments[:"aria-label"]
@@ -53,7 +53,7 @@ module Primer
53
53
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
54
54
  def initialize(src:, alt:, size: DEFAULT_SIZE, shape: DEFAULT_SHAPE, href: nil, **system_arguments)
55
55
  @href = href
56
- @system_arguments = system_arguments
56
+ @system_arguments = deny_tag_argument(**system_arguments)
57
57
  @system_arguments[:tag] = :img
58
58
  @system_arguments[:src] = src
59
59
  @system_arguments[:alt] = alt
@@ -7,9 +7,9 @@
7
7
 
8
8
  <%= primary_action %>
9
9
  <% if secondary_action.present? %>
10
- <p>
10
+ <div class="mt-3">
11
11
  <%= secondary_action %>
12
- </p>
12
+ </div>
13
13
  <% end %>
14
14
  <% end %>
15
15
  <% end %>
@@ -9,8 +9,6 @@ module Primer
9
9
  # - `secondary_action` can be set to provide more information that is relevant in the context of the `Blankslate`.
10
10
  # - `secondary_action` text should be meaningful out of context and clearly describe the destination. Avoid using vague text like, "Learn more" or "Click here".
11
11
  class Blankslate < Primer::Component
12
- include ViewComponent::PolymorphicSlots
13
-
14
12
  status :beta
15
13
 
16
14
  VISUAL_OPTIONS = %i[icon spinner image].freeze
@@ -50,6 +48,7 @@ module Primer
50
48
  # @param tag [String] <%= one_of(Primer::HeadingComponent::TAG_OPTIONS) %>
51
49
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
52
50
  renders_one :heading, lambda { |tag:, **system_arguments|
51
+ deny_tag_argument(**system_arguments)
53
52
  system_arguments[:tag] = tag
54
53
  system_arguments[:mb] = 1
55
54
  system_arguments[:classes] = class_names("h2", system_arguments[:classes])
@@ -64,7 +63,8 @@ module Primer
64
63
  #
65
64
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
66
65
  renders_one :description, lambda { |**system_arguments|
67
- system_arguments[:tag] = :p
66
+ deny_tag_argument(**system_arguments)
67
+ system_arguments[:tag] = :div
68
68
 
69
69
  Primer::BaseComponent.new(**system_arguments)
70
70
  }
@@ -77,10 +77,11 @@ module Primer
77
77
  # @param href [String] URL to be used for the primary action.
78
78
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
79
79
  renders_one :primary_action, lambda { |href:, **system_arguments|
80
+ deny_tag_argument(**system_arguments)
80
81
  system_arguments[:tag] = :a
81
82
  system_arguments[:href] = href
82
- system_arguments[:my] = 3
83
- system_arguments[:variant] = :medium
83
+ system_arguments[:mt] = 5
84
+ system_arguments[:size] = :medium
84
85
  system_arguments[:scheme] ||= :primary
85
86
 
86
87
  Primer::ButtonComponent.new(**system_arguments)
@@ -211,7 +212,7 @@ module Primer
211
212
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
212
213
  def initialize(narrow: false, spacious: false, border: false, **system_arguments)
213
214
  @border = border
214
- @system_arguments = system_arguments
215
+ @system_arguments = deny_tag_argument(**system_arguments)
215
216
  @system_arguments[:tag] = :div
216
217
  @system_arguments[:classes] = class_names(
217
218
  @system_arguments[:classes],
@@ -40,7 +40,7 @@ module Primer
40
40
  #
41
41
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
42
42
  def initialize(**system_arguments)
43
- @system_arguments = system_arguments
43
+ @system_arguments = deny_tag_argument(**system_arguments)
44
44
  @system_arguments[:tag] = :nav
45
45
  @system_arguments[:aria] = ARIA_LABEL
46
46
  @system_arguments[:system_arguments_denylist] = ARGS_DENYLIST
@@ -57,7 +57,7 @@ module Primer
57
57
 
58
58
  def initialize(href:, **system_arguments)
59
59
  @href = href
60
- @system_arguments = system_arguments
60
+ @system_arguments = deny_tag_argument(**system_arguments)
61
61
  @selected = false
62
62
 
63
63
  @system_arguments[:tag] = :li
@@ -10,7 +10,7 @@ module Primer
10
10
 
11
11
  # @example Default
12
12
  # <%= render(Primer::Beta::Text.new(tag: :p, font_weight: :bold)) { "Bold Text" } %>
13
- # <%= render(Primer::Beta::Text.new(tag: :p, color: :text_danger)) { "Danger Text" } %>
13
+ # <%= render(Primer::Beta::Text.new(tag: :p, color: :danger)) { "Danger Text" } %>
14
14
  #
15
15
  # @param tag [Symbol]
16
16
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
@@ -127,7 +127,7 @@ module Primer
127
127
  # @param padding [Symbol] <%= one_of(Primer::BorderBoxComponent::PADDING_MAPPINGS.keys) %>
128
128
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
129
129
  def initialize(padding: DEFAULT_PADDING, **system_arguments)
130
- @system_arguments = system_arguments
130
+ @system_arguments = deny_tag_argument(**system_arguments)
131
131
  @system_arguments[:tag] = :div
132
132
  @system_arguments[:classes] = class_names(
133
133
  "Box",
@@ -9,11 +9,12 @@ module Primer
9
9
  # <%= render(Primer::BoxComponent.new) { "Your content here" } %>
10
10
  #
11
11
  # @example Color and padding
12
- # <%= render(Primer::BoxComponent.new(bg: :tertiary, p: 3)) { "Hello world" } %>
12
+ # <%= render(Primer::BoxComponent.new(bg: :subtle, p: 3)) { "Hello world" } %>
13
13
  #
14
14
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
15
15
  def initialize(**system_arguments)
16
- @system_arguments = system_arguments
16
+ @system_arguments = deny_tag_argument(**system_arguments)
17
+
17
18
  @system_arguments[:tag] = :div
18
19
  end
19
20
 
@@ -1,9 +1,3 @@
1
- <%= render Primer::BaseButton.new(**@system_arguments) do %>
2
- <%= icon %>
3
- <%= content %>
4
- <%= counter %>
5
-
6
- <% if @caret %>
7
- <%= primer_octicon("triangle-down") %>
8
- <% end %>
9
- <% end %>
1
+ <%= render Primer::BaseButton.new(**@system_arguments) do -%>
2
+ <%= leading_visual %><%= trimmed_content %><%= trailing_visual %><%= primer_octicon("triangle-down", ml: 2, mr: -1) if @dropdown %>
3
+ <% end -%>
@@ -17,23 +17,44 @@ module Primer
17
17
  }.freeze
18
18
  SCHEME_OPTIONS = SCHEME_MAPPINGS.keys
19
19
 
20
- DEFAULT_VARIANT = :medium
21
- VARIANT_MAPPINGS = {
20
+ DEFAULT_SIZE = :medium
21
+ SIZE_MAPPINGS = {
22
22
  :small => "btn-sm",
23
- DEFAULT_VARIANT => "",
24
- :large => "btn-large"
23
+ DEFAULT_SIZE => ""
25
24
  }.freeze
26
- VARIANT_OPTIONS = VARIANT_MAPPINGS.keys
25
+ SIZE_OPTIONS = SIZE_MAPPINGS.keys
27
26
 
28
- # Icon to be rendered in the button.
27
+ # Leading visuals appear to the left of the button text.
28
+ #
29
+ # Use:
30
+ #
31
+ # - `leading_visual_icon` for a <%= link_to_component(Primer::OcticonComponent) %>.
29
32
  #
30
33
  # @param system_arguments [Hash] Same arguments as <%= link_to_component(Primer::OcticonComponent) %>.
31
- renders_one :icon, Primer::OcticonComponent
34
+ renders_one :leading_visual, types: {
35
+ icon: lambda { |**system_arguments|
36
+ system_arguments[:mr] = 2
37
+
38
+ Primer::OcticonComponent.new(**system_arguments)
39
+ }
40
+ }
41
+ alias icon leading_visual_icon # remove alias when all buttons are migrated to new slot names
32
42
 
33
- # Counter to be rendered in the button.
43
+ # Trailing visuals appear to the right of the button text.
44
+ #
45
+ # Use:
46
+ #
47
+ # - `trailing_visual_counter` for a <%= link_to_component(Primer::CounterComponent) %>.
34
48
  #
35
49
  # @param system_arguments [Hash] Same arguments as <%= link_to_component(Primer::CounterComponent) %>.
36
- renders_one :counter, Primer::CounterComponent
50
+ renders_one :trailing_visual, types: {
51
+ counter: lambda { |**system_arguments|
52
+ system_arguments[:ml] = 2
53
+
54
+ Primer::CounterComponent.new(**system_arguments)
55
+ }
56
+ }
57
+ alias counter trailing_visual_counter # remove alias when all buttons are migrated to new slot names
37
58
 
38
59
  # @example Schemes
39
60
  # <%= render(Primer::ButtonComponent.new) { "Default" } %>
@@ -43,63 +64,64 @@ module Primer
43
64
  # <%= render(Primer::ButtonComponent.new(scheme: :invisible)) { "Invisible" } %>
44
65
  # <%= render(Primer::ButtonComponent.new(scheme: :link)) { "Link" } %>
45
66
  #
46
- # @example Variants
47
- # <%= render(Primer::ButtonComponent.new(variant: :small)) { "Small" } %>
48
- # <%= render(Primer::ButtonComponent.new(variant: :medium)) { "Medium" } %>
49
- # <%= render(Primer::ButtonComponent.new(variant: :large)) { "Large" } %>
67
+ # @example Sizes
68
+ # <%= render(Primer::ButtonComponent.new(size: :small)) { "Small" } %>
69
+ # <%= render(Primer::ButtonComponent.new(size: :medium)) { "Medium" } %>
50
70
  #
51
71
  # @example Block
52
72
  # <%= render(Primer::ButtonComponent.new(block: :true)) { "Block" } %>
53
73
  # <%= render(Primer::ButtonComponent.new(block: :true, scheme: :primary)) { "Primary block" } %>
54
74
  #
55
- # @example With icons
75
+ # @example With leading visual
56
76
  # <%= render(Primer::ButtonComponent.new) do |c| %>
57
- # <% c.icon(icon: :star) %>
77
+ # <% c.leading_visual_icon(icon: :star) %>
58
78
  # Button
59
79
  # <% end %>
60
80
  #
61
- # @example With counter
81
+ # @example With trailing visual
62
82
  # <%= render(Primer::ButtonComponent.new) do |c| %>
63
- # <% c.counter(count: 15) %>
83
+ # <% c.trailing_visual_counter(count: 15) %>
64
84
  # Button
65
85
  # <% end %>
66
86
  #
67
- # @example With icons and counter
87
+ # @example With leading and trailing visuals
68
88
  # <%= render(Primer::ButtonComponent.new) do |c| %>
69
- # <% c.icon(icon: :star) %>
70
- # <% c.counter(count: 15) %>
89
+ # <% c.leading_visual_icon(icon: :star) %>
90
+ # <% c.trailing_visual_counter(count: 15) %>
71
91
  # Button
72
92
  # <% end %>
73
93
  #
74
- # @example With caret
75
- # <%= render(Primer::ButtonComponent.new(caret: true)) do %>
94
+ # @example With dropdown caret
95
+ # <%= render(Primer::ButtonComponent.new(dropdown: true)) do %>
76
96
  # Button
77
97
  # <% end %>
78
98
  #
79
99
  # @param scheme [Symbol] <%= one_of(Primer::ButtonComponent::SCHEME_OPTIONS) %>
80
- # @param variant [Symbol] <%= one_of(Primer::ButtonComponent::VARIANT_OPTIONS) %>
100
+ # @param variant [Symbol] DEPRECATED. <%= one_of(Primer::ButtonComponent::SIZE_OPTIONS) %>
101
+ # @param size [Symbol] <%= one_of(Primer::ButtonComponent::SIZE_OPTIONS) %>
81
102
  # @param tag [Symbol] (Primer::BaseButton::DEFAULT_TAG) <%= one_of(Primer::BaseButton::TAG_OPTIONS) %>
82
103
  # @param type [Symbol] (Primer::BaseButton::DEFAULT_TYPE) <%= one_of(Primer::BaseButton::TYPE_OPTIONS) %>
83
104
  # @param group_item [Boolean] Whether button is part of a ButtonGroup.
84
105
  # @param block [Boolean] Whether button is full-width with `display: block`.
85
- # @param caret [Boolean] Whether or not to render a caret.
106
+ # @param dropdown [Boolean] Whether or not to render a dropdown caret.
86
107
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
87
108
  def initialize(
88
109
  scheme: DEFAULT_SCHEME,
89
- variant: DEFAULT_VARIANT,
110
+ variant: nil,
111
+ size: DEFAULT_SIZE,
90
112
  group_item: false,
91
113
  block: false,
92
- caret: false,
114
+ dropdown: false,
93
115
  **system_arguments
94
116
  )
95
117
  @scheme = scheme
96
- @caret = caret
118
+ @dropdown = dropdown
97
119
 
98
120
  @system_arguments = system_arguments
99
121
  @system_arguments[:classes] = class_names(
100
122
  system_arguments[:classes],
101
123
  SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME)],
102
- VARIANT_MAPPINGS[fetch_or_fallback(VARIANT_OPTIONS, variant, DEFAULT_VARIANT)],
124
+ SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, variant || size, DEFAULT_SIZE)],
103
125
  "btn" => !link?,
104
126
  "btn-block" => block,
105
127
  "BtnGroup-item" => group_item
@@ -111,5 +133,16 @@ module Primer
111
133
  def link?
112
134
  @scheme == LINK_SCHEME
113
135
  end
136
+
137
+ def trimmed_content
138
+ return if content.blank?
139
+
140
+ trimmed_content = content.strip
141
+
142
+ return trimmed_content unless content.html_safe?
143
+
144
+ # strip unsets `html_safe`, so we have to set it back again to guarantee that HTML blocks won't break
145
+ trimmed_content.html_safe # rubocop:disable Rails/OutputSafety
146
+ end
114
147
  end
115
148
  end
@@ -7,10 +7,10 @@ module Primer
7
7
 
8
8
  # Required list of buttons to be rendered.
9
9
  #
10
- # @param kwargs [Hash] The same arguments as <%= link_to_component(Primer::ButtonComponent) %> except for `variant` and `group_item`.
10
+ # @param kwargs [Hash] The same arguments as <%= link_to_component(Primer::ButtonComponent) %> except for `size` and `group_item`.
11
11
  renders_many :buttons, lambda { |**kwargs|
12
12
  kwargs[:group_item] = true
13
- kwargs[:variant] = @variant
13
+ kwargs[:size] = @size
14
14
 
15
15
  Primer::ButtonComponent.new(**kwargs)
16
16
  }
@@ -25,27 +25,21 @@ module Primer
25
25
  # <% component.button(classes: "custom-class") { "Custom class" } %>
26
26
  # <% end %>
27
27
  #
28
- # @example Variants
28
+ # @example Sizes
29
29
  #
30
- # <%= render(Primer::ButtonGroup.new(variant: :small)) do |component| %>
30
+ # <%= render(Primer::ButtonGroup.new(size: :small)) do |component| %>
31
31
  # <% component.button { "Default" } %>
32
32
  # <% component.button(scheme: :primary) { "Primary" } %>
33
33
  # <% component.button(scheme: :danger) { "Danger" } %>
34
34
  # <% component.button(scheme: :outline) { "Outline" } %>
35
35
  # <% end %>
36
36
  #
37
- # <%= render(Primer::ButtonGroup.new(variant: :large)) do |component| %>
38
- # <% component.button { "Default" } %>
39
- # <% component.button(scheme: :primary) { "Primary" } %>
40
- # <% component.button(scheme: :danger) { "Danger" } %>
41
- # <% component.button(scheme: :outline) { "Outline" } %>
42
- # <% end %>
43
- #
44
- # @param variant [Symbol] <%= one_of(Primer::ButtonComponent::VARIANT_OPTIONS) %>
37
+ # @param variant [Symbol] DEPRECATED. <%= one_of(Primer::ButtonComponent::SIZE_OPTIONS) %>
38
+ # @param size [Symbol] <%= one_of(Primer::ButtonComponent::SIZE_OPTIONS) %>
45
39
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
46
- def initialize(variant: Primer::ButtonComponent::DEFAULT_VARIANT, **system_arguments)
47
- @variant = variant
48
- @system_arguments = system_arguments
40
+ def initialize(variant: nil, size: Primer::ButtonComponent::DEFAULT_SIZE, **system_arguments)
41
+ @size = variant || size
42
+ @system_arguments = deny_tag_argument(**system_arguments)
49
43
  @system_arguments[:tag] = :div
50
44
 
51
45
  @system_arguments[:classes] = class_names(
@@ -25,7 +25,7 @@ module Primer
25
25
  # @param for [String] Element id from where to get the copied value.
26
26
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
27
27
  def initialize(value: nil, **system_arguments)
28
- @system_arguments = system_arguments
28
+ @system_arguments = deny_tag_argument(**system_arguments)
29
29
  @value = value
30
30
 
31
31
  validate!
@@ -19,7 +19,7 @@ module Primer
19
19
  # @param type [Symbol] <%= one_of(Primer::CloseButton::TYPE_OPTIONS) %>
20
20
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
21
21
  def initialize(type: DEFAULT_TYPE, **system_arguments)
22
- @system_arguments = system_arguments
22
+ @system_arguments = deny_tag_argument(**system_arguments)
23
23
  @system_arguments[:tag] = :button
24
24
  @system_arguments[:block] = false
25
25
  @system_arguments[:type] = fetch_or_fallback(TYPE_OPTIONS, type, DEFAULT_TYPE)