Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting an id attribute on the BorderBox's ul element #57

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/strong-lamps-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@openproject/primer-view-components": patch
---

Allow setting an `id` attribute on the BorderBox's `ul` element

<!-- Changed components: Primer::Beta::BorderBox -->
3 changes: 3 additions & 0 deletions app/components/primer/beta/border_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class BorderBox < Primer::Component
# @param padding [Symbol] <%= one_of(Primer::Beta::BorderBox::PADDING_MAPPINGS.keys) %>
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(padding: DEFAULT_PADDING, **system_arguments)
list_id = system_arguments.delete(:list_id)

@system_arguments = deny_tag_argument(**system_arguments)
@system_arguments[:tag] = :div
@system_arguments[:classes] = class_names(
Expand All @@ -83,6 +85,7 @@ def initialize(padding: DEFAULT_PADDING, **system_arguments)

@system_arguments[:system_arguments_denylist] = { [:p, :pt, :pb, :pr, :pl] => PADDING_SUGGESTION }
@list_arguments = { tag: :ul }
@list_arguments[:id] = list_id if list_id
end

def render?
Expand Down
5 changes: 3 additions & 2 deletions previews/primer/beta/border_box_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ class BorderBoxPreview < ViewComponent::Preview
#
# @param padding [Symbol] select [default, condensed, spacious]
# @param scheme [Symbol] select [default, neutral, info, warning]
def playground(padding: :default, scheme: :default)
render(Primer::Beta::BorderBox.new(padding: padding)) do |component|
# @param list_id [String] text
def playground(padding: :default, scheme: :default, list_id: nil)
render(Primer::Beta::BorderBox.new(padding: padding, list_id: list_id)) do |component|
component.with_header { "Header" }
component.with_body { "Body" }
component.with_row(scheme: scheme) { "#{scheme.to_s.capitalize} row one" }
Expand Down
9 changes: 9 additions & 0 deletions test/components/beta/border_box_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ def test_renders_multiple_rows
assert_selector("li.Box-row", count: 3)
end

def test_renders_the_list_element_with_an_id_if_provided
render_inline(Primer::Beta::BorderBox.new(list_id: "an-id")) do |component|
component.with_row { "First" }
end

assert_selector("ul#an-id", count: 1)
assert_selector("li.Box-row", count: 1)
end

def test_renders_condensed
render_inline(Primer::Beta::BorderBox.new(padding: :condensed)) do |component|
component.with_body { "Body" }
Expand Down
Loading