Skip to content

Commit

Permalink
Revert "Add support for trailing and leading visual icons in Primer::…
Browse files Browse the repository at this point in the history
…Beta::Link (primer#2982)" (primer#3040)
  • Loading branch information
camertron authored Aug 29, 2024
1 parent 0cec693 commit 612307d
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 109 deletions.
5 changes: 0 additions & 5 deletions .changeset/odd-dots-laugh.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/quiet-kids-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Revert leading/trailing visuals for link component
5 changes: 1 addition & 4 deletions app/components/primer/base_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,13 @@ class BaseComponent < Primer::Component
# | :- | :- | :- |
# | classes | String | CSS class name value to be concatenated with generated Primer CSS classes. |
# | test_selector | String | Adds `data-test-selector='given value'` in non-Production environments for testing purposes. |
# | trim | Boolean | Calls `strip` on the content to remove trailing and leading white spaces. |
def initialize(tag:, classes: nil, **system_arguments)
@tag = tag

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

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

@trim = !!@system_arguments.delete(:trim)

@system_arguments[:"data-view-component"] = true
# Filter out Primer keys so they don't get assigned as HTML attributes
@content_tag_args = add_test_selector(@system_arguments).except(*Primer::Classify::Utilities::UTILITIES.keys)
Expand All @@ -170,7 +167,7 @@ def call
if SELF_CLOSING_TAGS.include?(@tag)
tag(@tag, @content_tag_args.merge(@result))
else
content_tag(@tag, @trim ? trimmed_content : content, @content_tag_args.merge(@result))
content_tag(@tag, content, @content_tag_args.merge(@result))
end
end
end
Expand Down
16 changes: 0 additions & 16 deletions app/components/primer/beta/link.html.erb

This file was deleted.

40 changes: 14 additions & 26 deletions app/components/primer/beta/link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,6 @@ class Link < Primer::Component
Primer::Alpha::Tooltip.new(**system_arguments)
}

# Leading visuals appear to the left of the link text.
#
# Use:
#
# - `leading_visual_icon` which accepts the arguments accepted by <%= link_to_component(Primer::Beta::Octicon) %>.
#
# @param system_arguments [Hash] Same arguments as <%= link_to_component(Primer::Beta::Octicon) %>.
renders_one :leading_visual, types: {
icon: lambda { |**system_arguments|
Primer::Beta::Octicon.new(**system_arguments)
}
}

# Trailing visuals appear to the right of the link text.
#
# Use:
#
# - `trailing_visual_icon` which accepts the arguments accepted by <%= link_to_component(Primer::Beta::Octicon) %>.
#
# @param system_arguments [Hash] Same arguments as <%= link_to_component(Primer::Beta::Octicon) %>.
renders_one :trailing_visual, types: {
icon: lambda { |**system_arguments|
Primer::Beta::Octicon.new(**system_arguments)
}
}

# @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.
# @param scheme [Symbol] <%= one_of(Primer::Beta::Link::SCHEME_MAPPINGS.keys) %>
# @param muted [Boolean] Uses light gray for Link color, and blue on hover.
Expand All @@ -80,6 +54,20 @@ def initialize(href: nil, scheme: DEFAULT_SCHEME, muted: false, underline: false
def before_render
raise ArgumentError, "href is required" if @system_arguments[:href].nil? && !Rails.env.production?
end

def call
if tooltip.present?
render Primer::BaseComponent.new(tag: :span, position: :relative) do
render(Primer::BaseComponent.new(**@system_arguments)) do
content
end.to_s + tooltip.to_s
end
else
render(Primer::BaseComponent.new(**@system_arguments)) do
content
end
end
end
end
end
end
7 changes: 0 additions & 7 deletions app/components/primer/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,5 @@ def should_raise_error?
def should_raise_aria_error?
!Rails.env.production? && raise_on_invalid_aria? && !ENV["PRIMER_WARNINGS_DISABLED"]
end

def trimmed_content
return content unless content.present?

# strip unsets `html_safe`, so we have to set it back again to guarantee that HTML blocks won't break
content.html_safe? ? content.strip.html_safe : content.strip # rubocop:disable Rails/OutputSafety
end
end
end
7 changes: 2 additions & 5 deletions app/components/primer/conditional_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ class ConditionalWrapper < Primer::Component
def initialize(condition:, **base_component_arguments)
@condition = condition
@base_component_arguments = base_component_arguments
@trim = !!@base_component_arguments.delete(:trim)
end

def call
unless @condition
return @trim ? trimmed_content : content
end
return content unless @condition

BaseComponent.new(trim: @trim, **@base_component_arguments).render_in(self) { content }
BaseComponent.new(**@base_component_arguments).render_in(self) { content }
end
end
end
26 changes: 2 additions & 24 deletions previews/primer/beta/link_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ class LinkPreview < ViewComponent::Preview
# @param underline [Boolean]
# @param muted [Boolean]
# @param scheme [Symbol] select [default, primary, secondary]
# @param leading_visual_icon [Symbol] octicon
# @param trailing_visual_icon [Symbol] octicon
def playground(scheme: :default, muted: false, underline: true, leading_visual_icon: nil, trailing_visual_icon: nil)
render(Primer::Beta::Link.new(href: "#", scheme: scheme, muted: muted, underline: underline)) do |link|
link.with_leading_visual_icon(icon: leading_visual_icon) if leading_visual_icon && leading_visual_icon != :none
link.with_trailing_visual_icon(icon: trailing_visual_icon) if trailing_visual_icon && trailing_visual_icon != :none
"This is a link!"
end
def playground(scheme: :default, muted: false, underline: true)
render(Primer::Beta::Link.new(href: "#", scheme: scheme, muted: muted, underline: underline)) { "This is a link!" }
end

# @label Default Options
Expand Down Expand Up @@ -72,22 +66,6 @@ def color_scheme_secondary_muted
render(Primer::Beta::Link.new(href: "#", scheme: :secondary, muted: true)) { "This is a muted secondary link color." }
end
# @!endgroup

# @label With leading icon
def with_leading_icon
render(Primer::Beta::Link.new(href: "#")) do |component|
component.with_leading_visual_icon(icon: :"mark-github")
"Link with leading icon"
end
end

# @label With trailing icon
def with_trailing_icon
render(Primer::Beta::Link.new(href: "#")) do |component|
component.with_trailing_visual_icon(icon: :"link-external")
"Link with trailing icon"
end
end
end
end
end
22 changes: 0 additions & 22 deletions test/components/beta/link_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,4 @@ def test_renders_with_tooltip_sibling

assert_selector("a[href='http://google.com'] + tool-tip", text: "Tooltip text", visible: false)
end

def test_renders_leading_visual_icon
render_inline(Primer::Beta::Link.new(href: "http://google.com")) do |component|
component.with_leading_visual_icon(icon: "plus")
"content"
end

assert_selector("a[href='http://google.com']")
assert_selector(".octicon-plus")
end

def test_renders_trailing_visual_icon
render_inline(Primer::Beta::Link.new(href: "http://google.com")) do |component|
component.with_leading_visual_icon(icon: "plus")
component.with_trailing_visual_icon(icon: "alert")
"content"
end

assert_selector("a[href='http://google.com']")
assert_selector("a span:first-child .octicon-plus")
assert_selector("a span:nth-child(2) .octicon-alert")
end
end

0 comments on commit 612307d

Please sign in to comment.