-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b76761
commit 9c6a4f2
Showing
10 changed files
with
104 additions
and
0 deletions.
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
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,6 @@ | ||
<%= render Polaris::BaseComponent.new(**system_arguments) do %> | ||
<span class="Polaris-TagText"> | ||
<%= content %> | ||
</span> | ||
<%= remove_button %> | ||
<% 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,35 @@ | ||
# frozen_string_literal: true | ||
|
||
module Polaris | ||
class TagComponent < Polaris::NewComponent | ||
renders_one :remove_button, lambda { |**system_arguments| | ||
render Polaris::BaseButton.new( | ||
classes: "Polaris-Tag__Button", | ||
disabled: @disabled, | ||
**system_arguments | ||
) do |button| | ||
polaris_icon(name: "CancelSmallMinor") | ||
end | ||
} | ||
|
||
def initialize(clickable: false, disabled: false, **system_arguments) | ||
@clickable = clickable | ||
@disabled = disabled | ||
|
||
@system_arguments = system_arguments | ||
end | ||
|
||
def system_arguments | ||
@system_arguments.tap do |opts| | ||
opts[:tag] = @clickable ? "button" : "span" | ||
opts[:classes] = class_names( | ||
@system_arguments[:classes], | ||
"Polaris-Tag", | ||
"Polaris-Tag--clickable" => @clickable, | ||
"Polaris-Tag--disabled" => @disabled, | ||
"Polaris-Tag--removable" => remove_button.present? | ||
) | ||
end | ||
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
13 changes: 13 additions & 0 deletions
13
demo/test/components/previews/forms/tag_component_preview.rb
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,13 @@ | ||
class Forms::TagComponentPreview < ViewComponent::Preview | ||
def default | ||
end | ||
|
||
def disabled | ||
end | ||
|
||
def with_remove_button | ||
end | ||
|
||
def clickable | ||
end | ||
end |
1 change: 1 addition & 0 deletions
1
demo/test/components/previews/forms/tag_component_preview/clickable.html.erb
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 @@ | ||
<%= polaris_tag(clickable: true) { "Rustic" } %> |
1 change: 1 addition & 0 deletions
1
demo/test/components/previews/forms/tag_component_preview/default.html.erb
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 @@ | ||
<%= polaris_tag { "Rustic" } %> |
1 change: 1 addition & 0 deletions
1
demo/test/components/previews/forms/tag_component_preview/disabled.html.erb
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 @@ | ||
<%= polaris_tag(disabled: true) { "Rustic" } %> |
4 changes: 4 additions & 0 deletions
4
demo/test/components/previews/forms/tag_component_preview/with_remove_button.html.erb
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,4 @@ | ||
<%= polaris_tag do |tag| %> | ||
<% tag.remove_button(data: {}) %> | ||
Rustic | ||
<% 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,39 @@ | ||
require "test_helper" | ||
|
||
class ButtonComponentTest < Minitest::Test | ||
include Polaris::ComponentTestHelpers | ||
|
||
def test_default_tag | ||
render_inline(Polaris::TagComponent.new) { "Content" } | ||
|
||
assert_selector "span.Polaris-Tag" do | ||
assert_selector "span.Polaris-TagText", text: "Content" | ||
end | ||
end | ||
|
||
def test_disabled_tag | ||
render_inline(Polaris::TagComponent.new(disabled: true)) { "Content" } | ||
assert_selector "button.Polaris-Tag.Polaris-Tag--clickable" | ||
end | ||
|
||
def test_disabled_tag | ||
render_inline(Polaris::TagComponent.new(disabled: true)) { "Content" } | ||
|
||
assert_selector "span.Polaris-Tag.Polaris-Tag--disabled" | ||
end | ||
|
||
def test_with_removable_button | ||
render_inline Polaris::TagComponent.new do |tag| | ||
tag.remove_button(data: {}) | ||
"Content" | ||
end | ||
|
||
assert_selector "span.Polaris-Tag.Polaris-Tag--removable" do | ||
assert_selector "button.Polaris-Tag__Button" do | ||
assert_selector "span.Polaris-Icon" | ||
end | ||
assert_selector "span.Polaris-TagText", text: "Content" | ||
end | ||
end | ||
|
||
end |