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

Adding optional wrapper arguments to IconButton #1394

Merged
merged 4 commits into from
Sep 21, 2022
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
5 changes: 5 additions & 0 deletions .changeset/wicked-jokes-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/view-components": patch
---

Adding optional wrapper arguments to IconButton
2 changes: 1 addition & 1 deletion app/components/primer/beta/icon_button.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= render Primer::ConditionalWrapper.new(condition: render_tooltip?, tag: :div, classes: "Button-withTooltip") do %>
<%= render Primer::ConditionalWrapper.new(condition: render_tooltip?, tag: :div, classes: "Button-withTooltip", **@wrapper_arguments) do %>
<%= render Primer::Beta::BaseButton.new(**@system_arguments) do -%>
<%= render Primer::OcticonComponent.new(icon: @icon, classes: "Button-visual") %>
<% end -%>
Expand Down
4 changes: 3 additions & 1 deletion app/components/primer/beta/icon_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class IconButton < Primer::Component
# <%= render(Primer::Beta::IconButton.new(icon: :search, "aria-label": "Search", tooltip_direction: :e)) %>
#
# @param icon [String] Name of <%= link_to_octicons %> to use.
# @param wrapper_arguments [Hash] Optional keyword arguments to be passed to the wrapper `<div>` tag.
# @param scheme [Symbol] <%= one_of(Primer::Beta::IconButton::SCHEME_OPTIONS) %>
# @param size [Symbol] <%= one_of(Primer::Beta::Button::SIZE_OPTIONS) %>
# @param tag [Symbol] <%= one_of(Primer::Beta::BaseButton::TAG_OPTIONS) %>
Expand All @@ -55,9 +56,10 @@ class IconButton < Primer::Component
# @param aria-description [String] String that can be read by assistive technology. A description can be longer as it is intended to provide more context and information. See the accessibility section for more information.
# @param tooltip_direction [Symbol] (Primer::Alpha::Tooltip::DIRECTION_DEFAULT) <%= one_of(Primer::Alpha::Tooltip::DIRECTION_OPTIONS) %>
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(icon:, scheme: DEFAULT_SCHEME, tooltip_direction: Primer::Alpha::Tooltip::DIRECTION_DEFAULT, size: Primer::Beta::Button::DEFAULT_SIZE, **system_arguments)
def initialize(icon:, scheme: DEFAULT_SCHEME, wrapper_arguments: {}, tooltip_direction: Primer::Alpha::Tooltip::DIRECTION_DEFAULT, size: Primer::Beta::Button::DEFAULT_SIZE, **system_arguments)
@icon = icon

@wrapper_arguments = wrapper_arguments
@system_arguments = system_arguments
@system_arguments[:id] ||= "icon-button-#{SecureRandom.hex(4)}"

Expand Down
2 changes: 2 additions & 0 deletions docs/src/@primer/gatsby-theme-doctocat/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,5 @@
url: "/adr/0250-developing-and-publishing-clientside-behaviours"
- title: 251. Use Catalyst for client-side behaviours
url: "/adr/0251-use-catalyst-for-client-side-behaviours"
- title: 252. Build component css with ruby code
url: "/adr/0252-build-component-css-with-ruby-code"
6 changes: 6 additions & 0 deletions static/arguments.json
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,12 @@
"default": "N/A",
"description": "Name of [Octicon](https://primer.style/octicons/) to use."
},
{
"name": "wrapper_arguments",
"type": "Hash",
"default": "`{}`",
"description": "Optional keyword arguments to be passed to the wrapper `<div>` tag."
},
{
"name": "scheme",
"type": "Symbol",
Expand Down
6 changes: 6 additions & 0 deletions test/components/primer/beta/icon_button_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ def test_renders
end
assert_selector("tool-tip", text: "Star", visible: :all)
end

def test_adds_wrapper_arguments
render_inline(Primer::Beta::IconButton.new(icon: :star, "aria-label": "Star", wrapper_arguments: { id: "foo" }))

assert_selector(".Button-withTooltip#foo")
end
end