Skip to content

Commit

Permalink
Use system arguments instead of utility classes for NavList's "show m…
Browse files Browse the repository at this point in the history
…ore" item (#1845)
  • Loading branch information
camertron authored Feb 27, 2023
1 parent 04b75c7 commit 98792bd
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/tasty-rules-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Use system arguments instead of utility classes for NavList's "show more" item
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Naming/MethodParameterName:
Rails/RefuteMethods:
Enabled: false

Rails/FilePath:
EnforcedStyle: arguments

Style/MultipleComparison:
Enabled: true
Exclude:
Expand Down
4 changes: 4 additions & 0 deletions app/components/primer/alpha/action_list/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class Item < Primer::Component
# @param parent [Primer::Alpha::ActionList::Item] This item's parent item. `nil` if this item is at the root. Used internally.
# @param label [String] Item label.
# @param label_classes [String] CSS classes that will be added to the label.
# @param label_arguments [Hash] <%= link_to_system_arguments_docs %> used to construct the label.
# @param content_arguments [Hash] <%= link_to_system_arguments_docs %> used to construct the item's anchor or button tag.
# @param truncate_label [Boolean] Truncate label with ellipsis.
# @param href [String] Link URL.
Expand All @@ -144,6 +145,7 @@ def initialize(
list:,
label:,
label_classes: nil,
label_arguments: {},
content_arguments: {},
parent: nil,
truncate_label: false,
Expand Down Expand Up @@ -191,8 +193,10 @@ def initialize(
@system_arguments[:data][:targets] = "#{list_class.custom_element_name}.items"

@label_arguments = {
**label_arguments,
classes: class_names(
label_classes,
label_arguments[:classes],
"ActionListItem-label",
"ActionListItem-label--truncate" => @truncate_label
)
Expand Down
8 changes: 4 additions & 4 deletions app/components/primer/alpha/nav_list/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class Section < ActionList
system_arguments[:data][:action] = "click:nav-list#showMore"
system_arguments[:data][:"current-page"] = "1"
system_arguments[:data][:"total-pages"] = pages.to_s
system_arguments[:label_classes] = class_names(
system_arguments[:label_classes],
"color-fg-accent"
)
system_arguments[:label_arguments] = {
**system_arguments[:label_arguments] || {},
color: :accent
}

component_klass.new(list: self, src: src, **system_arguments)
}
Expand Down
2 changes: 1 addition & 1 deletion demo/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# Raises error for missing translations.
# config.action_view.raise_on_missing_translations = true
config.primer_view_components.silence_deprecations = true
config.primer_view_components.raise_on_invalid_options = false
config.primer_view_components.raise_on_invalid_options = true

config.autoload_paths << Rails.root.join("..", "test", "forms")
config.view_component.preview_paths << Rails.root.join("..", "test", "previews")
Expand Down
4 changes: 3 additions & 1 deletion test/lib/classify_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,9 @@ def test_does_not_raise_error_when_passing_in_a_primer_css_class_name_in_develop
end

def test_does_not_raise_error_when_passing_in_a_primer_css_class_otherwise
assert_generated_class("color-bg-primary text-center float-left ml-1", { classes: "color-bg-primary text-center float-left ml-1" })
with_raise_on_invalid_options(false) do
assert_generated_class("color-bg-primary text-center float-left ml-1", { classes: "color-bg-primary text-center float-left ml-1" })
end
end

def test_does_include_leading_trailing_whitespace_in_class
Expand Down

0 comments on commit 98792bd

Please sign in to comment.