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
ButtonGroup component #185
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
97ca002
update view_component version
manuelpuyol 6000f53
create ButtonGroup component
manuelpuyol 285a4e0
add story to buttongroup
manuelpuyol ad1a02d
add docs for buttongroup
manuelpuyol 27c58b7
add tests to button group
manuelpuyol d777d30
Apply suggestions from code review
manuelpuyol 7854cc0
update stories to use custom buttons
manuelpuyol 411825c
don't render if no buttons are added
manuelpuyol 9a6b138
update docs
manuelpuyol dbbbc8f
ignore .orig files
manuelpuyol af156a7
update group spec using slot
manuelpuyol d4e7861
lint
manuelpuyol c5b0c1a
Merge branch 'main' into btn-group-component
manuelpuyol f0a34c9
fix merge conflicts
manuelpuyol ce812b2
use group_item: true instead of manually adding class
manuelpuyol 8f8a83d
Merge branch 'main' into btn-group-component
manuelpuyol 19d60d0
Merge branch 'main' into btn-group-component
manuelpuyol File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
**/*.stories.json | ||
**/node_modules/ | ||
*.log | ||
*.orig | ||
demo/public/packs/ | ||
demo/tmp/ | ||
demo/config/master.key | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%= render Primer::BaseComponent.new(**@system_arguments) do %> | ||
<% buttons.each do |button| %> | ||
<%= button %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
module Primer | ||
# Use ButtonGroupComponent to render a series of buttons. | ||
class ButtonGroupComponent < Primer::Component | ||
include ViewComponent::SlotableV2 | ||
|
||
renders_many :buttons, ->(**kwargs) { Primer::ButtonComponent.new(group_item: true, **kwargs) } | ||
|
||
# @example 50|Default | ||
# <%= render(Primer::ButtonGroupComponent.new) do |component| | ||
# component.button { "Default" } | ||
# component.button(button_type: :primary) { "Primary" } | ||
# component.button(button_type: :danger) { "Danger" } | ||
# component.button(button_type: :outline) { "Outline" } | ||
# component.button(classes: "my-class") { "Custom class" } | ||
# end %> | ||
# | ||
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %> | ||
def initialize(**system_arguments) | ||
@system_arguments = system_arguments | ||
@system_arguments[:tag] ||= :div | ||
|
||
@system_arguments[:classes] = class_names( | ||
"BtnGroup", | ||
system_arguments[:classes] | ||
) | ||
end | ||
|
||
def render? | ||
buttons.any? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
title: ButtonGroup | ||
status: Experimental | ||
source: https://github.com/primer/view_components/tree/main/app/components/primer/button_group_component.rb | ||
--- | ||
|
||
<!-- Warning: AUTO-GENERATED file, do not edit. Add code comments to your Ruby instead <3 --> | ||
|
||
Use ButtonGroupComponent to render a series of buttons. | ||
|
||
## Examples | ||
|
||
### Default | ||
|
||
<iframe style="width: 100%; border: 0px; height: 50px;" srcdoc="<html><head><link href='https://unpkg.com/@primer/css/dist/primer.css' rel='stylesheet'></head><body><div class='BtnGroup '> <button type='button' class='btn BtnGroup-item '>Default</button> <button type='button' class='btn BtnGroup-item btn-primary '>Primary</button> <button type='button' class='btn BtnGroup-item btn-danger '>Danger</button> <button type='button' class='btn BtnGroup-item btn-outline '>Outline</button> <button type='button' class='btn BtnGroup-item my-class '>Custom class</button></div></body></html>"></iframe> | ||
|
||
```erb | ||
<%= render(Primer::ButtonGroupComponent.new) do |component| | ||
component.button { "Default" } | ||
component.button(button_type: :primary) { "Primary" } | ||
component.button(button_type: :danger) { "Danger" } | ||
component.button(button_type: :outline) { "Outline" } | ||
component.button(classes: "my-class") { "Custom class" } | ||
end %> | ||
``` | ||
|
||
## Arguments | ||
|
||
| Name | Type | Default | Description | | ||
| :- | :- | :- | :- | | ||
| `system_arguments` | `Hash` | N/A | [System arguments](/system-arguments) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class Primer::ButtonGroupComponentStories < ViewComponent::Storybook::Stories | ||
layout "storybook_preview" | ||
|
||
story(:button_group) do | ||
content do |c| | ||
c.button { "Button" } | ||
c.button(button_type: :primary) { "Primary" } | ||
c.button(button_type: :danger) { "Danger" } | ||
c.button(button_type: :outline) { "Outline" } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class PrimerButtonGroupComponentTest < Minitest::Test | ||
include Primer::ComponentTestHelpers | ||
|
||
def test_does_not_render_without_buttons | ||
render_inline(Primer::ButtonGroupComponent.new) | ||
|
||
refute_selector("div.BtnGroup") | ||
end | ||
|
||
def test_renders_button_items | ||
render_inline(Primer::ButtonGroupComponent.new) { |c| c.button { "Button" } } | ||
|
||
assert_selector("div.BtnGroup") do | ||
assert_selector("button.btn.BtnGroup-item", text: "Button") | ||
end | ||
end | ||
|
||
def test_renders_button_with_props | ||
render_inline(Primer::ButtonGroupComponent.new) do |c| | ||
c.button { "Button" } | ||
c.button(button_type: :primary) { "Primary" } | ||
c.button(button_type: :danger) { "Danger" } | ||
c.button(button_type: :outline) { "Outline" } | ||
c.button(classes: "my-class") { "Custom class" } | ||
end | ||
|
||
assert_selector("div.BtnGroup") do | ||
assert_selector("button.btn.BtnGroup-item", text: "Button") | ||
assert_selector("button.btn.BtnGroup-item.btn-primary", text: "Primary") | ||
assert_selector("button.btn.BtnGroup-item.btn-danger", text: "Danger") | ||
assert_selector("button.btn.BtnGroup-item.btn-outline", text: "Outline") | ||
assert_selector("button.btn.BtnGroup-item.my-class", text: "Custom class") | ||
end | ||
end | ||
|
||
def test_does_not_render_content | ||
render_inline(Primer::ButtonGroupComponent.new) { "content" } | ||
|
||
refute_text("content") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this extension?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a file that sometimes is generated by my difftool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally you'd handle this in a global .gitignore on your machine, but I'm cool merging this in ❤️