Skip to content

Commit 612307d

Browse files
authoredAug 29, 2024··
Revert "Add support for trailing and leading visual icons in Primer::Beta::Link (#2982)" (#3040)
1 parent 0cec693 commit 612307d

File tree

9 files changed

+24
-109
lines changed

9 files changed

+24
-109
lines changed
 

‎.changeset/odd-dots-laugh.md

-5
This file was deleted.

‎.changeset/quiet-kids-sort.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/view-components': patch
3+
---
4+
5+
Revert leading/trailing visuals for link component

‎app/components/primer/base_component.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,13 @@ class BaseComponent < Primer::Component
151151
# | :- | :- | :- |
152152
# | classes | String | CSS class name value to be concatenated with generated Primer CSS classes. |
153153
# | test_selector | String | Adds `data-test-selector='given value'` in non-Production environments for testing purposes. |
154-
# | trim | Boolean | Calls `strip` on the content to remove trailing and leading white spaces. |
155154
def initialize(tag:, classes: nil, **system_arguments)
156155
@tag = tag
157156

158157
@system_arguments = validate_arguments(tag: tag, **system_arguments)
159158

160159
@result = Primer::Classify.call(**@system_arguments.merge(classes: classes))
161160

162-
@trim = !!@system_arguments.delete(:trim)
163-
164161
@system_arguments[:"data-view-component"] = true
165162
# Filter out Primer keys so they don't get assigned as HTML attributes
166163
@content_tag_args = add_test_selector(@system_arguments).except(*Primer::Classify::Utilities::UTILITIES.keys)
@@ -170,7 +167,7 @@ def call
170167
if SELF_CLOSING_TAGS.include?(@tag)
171168
tag(@tag, @content_tag_args.merge(@result))
172169
else
173-
content_tag(@tag, @trim ? trimmed_content : content, @content_tag_args.merge(@result))
170+
content_tag(@tag, content, @content_tag_args.merge(@result))
174171
end
175172
end
176173
end

‎app/components/primer/beta/link.html.erb

-16
This file was deleted.

‎app/components/primer/beta/link.rb

+14-26
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,6 @@ class Link < Primer::Component
3030
Primer::Alpha::Tooltip.new(**system_arguments)
3131
}
3232

33-
# Leading visuals appear to the left of the link text.
34-
#
35-
# Use:
36-
#
37-
# - `leading_visual_icon` which accepts the arguments accepted by <%= link_to_component(Primer::Beta::Octicon) %>.
38-
#
39-
# @param system_arguments [Hash] Same arguments as <%= link_to_component(Primer::Beta::Octicon) %>.
40-
renders_one :leading_visual, types: {
41-
icon: lambda { |**system_arguments|
42-
Primer::Beta::Octicon.new(**system_arguments)
43-
}
44-
}
45-
46-
# Trailing visuals appear to the right of the link text.
47-
#
48-
# Use:
49-
#
50-
# - `trailing_visual_icon` which accepts the arguments accepted by <%= link_to_component(Primer::Beta::Octicon) %>.
51-
#
52-
# @param system_arguments [Hash] Same arguments as <%= link_to_component(Primer::Beta::Octicon) %>.
53-
renders_one :trailing_visual, types: {
54-
icon: lambda { |**system_arguments|
55-
Primer::Beta::Octicon.new(**system_arguments)
56-
}
57-
}
58-
5933
# @param href [String] URL to be used for the Link. Required. If the requirements are not met an error will be raised in non production environments. In production, an empty link element will be rendered.
6034
# @param scheme [Symbol] <%= one_of(Primer::Beta::Link::SCHEME_MAPPINGS.keys) %>
6135
# @param muted [Boolean] Uses light gray for Link color, and blue on hover.
@@ -80,6 +54,20 @@ def initialize(href: nil, scheme: DEFAULT_SCHEME, muted: false, underline: false
8054
def before_render
8155
raise ArgumentError, "href is required" if @system_arguments[:href].nil? && !Rails.env.production?
8256
end
57+
58+
def call
59+
if tooltip.present?
60+
render Primer::BaseComponent.new(tag: :span, position: :relative) do
61+
render(Primer::BaseComponent.new(**@system_arguments)) do
62+
content
63+
end.to_s + tooltip.to_s
64+
end
65+
else
66+
render(Primer::BaseComponent.new(**@system_arguments)) do
67+
content
68+
end
69+
end
70+
end
8371
end
8472
end
8573
end

‎app/components/primer/component.rb

-7
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,5 @@ def should_raise_error?
144144
def should_raise_aria_error?
145145
!Rails.env.production? && raise_on_invalid_aria? && !ENV["PRIMER_WARNINGS_DISABLED"]
146146
end
147-
148-
def trimmed_content
149-
return content unless content.present?
150-
151-
# strip unsets `html_safe`, so we have to set it back again to guarantee that HTML blocks won't break
152-
content.html_safe? ? content.strip.html_safe : content.strip # rubocop:disable Rails/OutputSafety
153-
end
154147
end
155148
end

‎app/components/primer/conditional_wrapper.rb

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@ class ConditionalWrapper < Primer::Component
1010
def initialize(condition:, **base_component_arguments)
1111
@condition = condition
1212
@base_component_arguments = base_component_arguments
13-
@trim = !!@base_component_arguments.delete(:trim)
1413
end
1514

1615
def call
17-
unless @condition
18-
return @trim ? trimmed_content : content
19-
end
16+
return content unless @condition
2017

21-
BaseComponent.new(trim: @trim, **@base_component_arguments).render_in(self) { content }
18+
BaseComponent.new(**@base_component_arguments).render_in(self) { content }
2219
end
2320
end
2421
end

‎previews/primer/beta/link_preview.rb

+2-24
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,8 @@ class LinkPreview < ViewComponent::Preview
99
# @param underline [Boolean]
1010
# @param muted [Boolean]
1111
# @param scheme [Symbol] select [default, primary, secondary]
12-
# @param leading_visual_icon [Symbol] octicon
13-
# @param trailing_visual_icon [Symbol] octicon
14-
def playground(scheme: :default, muted: false, underline: true, leading_visual_icon: nil, trailing_visual_icon: nil)
15-
render(Primer::Beta::Link.new(href: "#", scheme: scheme, muted: muted, underline: underline)) do |link|
16-
link.with_leading_visual_icon(icon: leading_visual_icon) if leading_visual_icon && leading_visual_icon != :none
17-
link.with_trailing_visual_icon(icon: trailing_visual_icon) if trailing_visual_icon && trailing_visual_icon != :none
18-
"This is a link!"
19-
end
12+
def playground(scheme: :default, muted: false, underline: true)
13+
render(Primer::Beta::Link.new(href: "#", scheme: scheme, muted: muted, underline: underline)) { "This is a link!" }
2014
end
2115

2216
# @label Default Options
@@ -72,22 +66,6 @@ def color_scheme_secondary_muted
7266
render(Primer::Beta::Link.new(href: "#", scheme: :secondary, muted: true)) { "This is a muted secondary link color." }
7367
end
7468
# @!endgroup
75-
76-
# @label With leading icon
77-
def with_leading_icon
78-
render(Primer::Beta::Link.new(href: "#")) do |component|
79-
component.with_leading_visual_icon(icon: :"mark-github")
80-
"Link with leading icon"
81-
end
82-
end
83-
84-
# @label With trailing icon
85-
def with_trailing_icon
86-
render(Primer::Beta::Link.new(href: "#")) do |component|
87-
component.with_trailing_visual_icon(icon: :"link-external")
88-
"Link with trailing icon"
89-
end
90-
end
9169
end
9270
end
9371
end

‎test/components/beta/link_test.rb

-22
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,4 @@ def test_renders_with_tooltip_sibling
9292

9393
assert_selector("a[href='http://google.com'] + tool-tip", text: "Tooltip text", visible: false)
9494
end
95-
96-
def test_renders_leading_visual_icon
97-
render_inline(Primer::Beta::Link.new(href: "http://google.com")) do |component|
98-
component.with_leading_visual_icon(icon: "plus")
99-
"content"
100-
end
101-
102-
assert_selector("a[href='http://google.com']")
103-
assert_selector(".octicon-plus")
104-
end
105-
106-
def test_renders_trailing_visual_icon
107-
render_inline(Primer::Beta::Link.new(href: "http://google.com")) do |component|
108-
component.with_leading_visual_icon(icon: "plus")
109-
component.with_trailing_visual_icon(icon: "alert")
110-
"content"
111-
end
112-
113-
assert_selector("a[href='http://google.com']")
114-
assert_selector("a span:first-child .octicon-plus")
115-
assert_selector("a span:nth-child(2) .octicon-alert")
116-
end
11795
end

0 commit comments

Comments
 (0)
Please sign in to comment.