Skip to content
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
3 changes: 3 additions & 0 deletions app/assets/images/icons/information.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions app/components/link_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<span class='flex'>
<% if @icon.present? %>
<%= image_tag icon_image_path, alt: icon_alt_text, class: "size-[20px]" %>
<% end %>
<%= link_to @label, @url, target: "_blank", rel: "noopener noreferrer" %>
</span>
30 changes: 30 additions & 0 deletions app/components/link_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

class LinkComponent < ViewComponent::Base
def initialize(label:, url:, icon: nil)
@label = label
@url = url
@icon = icon
end

private

def icon_image_path
case @icon
when "info"
"icons/information.svg"
else
""
end
end

def icon_alt_text
descriptor = case @icon
when "info"
"info"
else
""
end
descriptor + " icon"
end
end
3 changes: 2 additions & 1 deletion cfa_ui_components.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
"lib/cfa_ui_components/**/*",
"app/components/**/*",
"app/assets/stylesheets/cfa_ui_components.tailwind.css",
"lib/tasks/cfa_ui_components.rake"
"lib/tasks/cfa_ui_components.rake",
"app/assets/images/icons/*"
]
spec.require_paths = [ "lib" ]

Expand Down
12 changes: 12 additions & 0 deletions test/components/link_component_test.rb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEBBLE: if we're not putting a real test here, I'd prefer this file to not exist to not clutter the codebase. Curious how CFA feels though!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently repo has no tests and stubs for all tests - talked over this w Mike/Kat and I'm fine leaving as is

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require "test_helper"

class LinkComponentTest < ViewComponent::TestCase
def test_component_renders_something_useful
# assert_equal(
# %(<span>Hello, components!</span>),
# render_inline(LinkComponent.new(message: "Hello, components!")).css("span").to_html
# )
end
end
9 changes: 9 additions & 0 deletions test/components/previews/link_component_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class LinkComponentPreview < ViewComponent::Preview
def default
render(LinkComponent.new(label: I18n.t("continue"), url: "/continue"))
end

def with_icon
render(LinkComponent.new(label: I18n.t("continue"), url: "/continue", icon: "info"))
end
end