Skip to content

Commit

Permalink
Add browser tooltip to Copy Game (URL) button
Browse files Browse the repository at this point in the history
Add "Copy URL to Clipboard" browser tooltip to the Game Number + Copy
button.

Also, DRY up this view code so the change can be made in just one place.
We do so by creating a layout partial in app/view/application so that
it is highly reusable.
  • Loading branch information
pdobb committed Mar 9, 2025
1 parent 3b514a8 commit 960702a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 39 deletions.
20 changes: 20 additions & 0 deletions app/views/application/_copy_button.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<%# locals: (value:, title: "Copy to Clipboard") %>

<span
data-controller="clipboard"
data-clipboard-source-value="<%= value %>"
data-clipboard-highlight-class="text-green-500 animate-ping-once origin-center"
class="flex gap-x-2 items-center"
>
<%= yield %>

<%= inline_svg_tag(
"heroicons/clipboard-document.svg",
title:,
data: {
action:
"click->clipboard#copy "\
"animationend->clipboard#dehighlight",
},
class: "btn-basic") %>
</span>
23 changes: 5 additions & 18 deletions app/views/games/_title.html.erb
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
<%# locals: (title:) %>

<h3 class="flex justify-center gap-x-8">
<span
data-controller="clipboard"
data-clipboard-source-value="<%= title.game_absolute_url %>"
data-clipboard-highlight-class="
text-green-500 animate-ping-once origin-center
"
class="flex gap-x-2 items-center"
>
<h3 class="flex justify-center items-baseline gap-x-8">
<%= render(
layout: "copy_button",
locals: { value: title.game_absolute_url, title: title.title_text }) do %>
<%= link_to(
title.game_number,
title.game_url,
data: { turbo_frame: :_top }) %>
<%= inline_svg_tag(
"heroicons/clipboard-document.svg",
class: "btn-basic",
data: {
action:
"click->clipboard#copy "\
"animationend->clipboard#dehighlight",
}) %>
</span>
<% end %>

<span aria-label="Engagement Date">
<%= title.engagement_date %>
Expand Down
21 changes: 4 additions & 17 deletions app/views/games/just_ended/_title.html.erb
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
<%# locals: (title:) %>

<h3 class="flex justify-center items-baseline gap-x-8">
<span
data-controller="clipboard"
data-clipboard-source-value="<%= title.game_absolute_url %>"
data-clipboard-highlight-class="
text-green-500 animate-ping-once origin-center
"
class="flex gap-x-2 items-center"
>
<%= render(
layout: "copy_button",
locals: { value: title.game_absolute_url, title: title.title_text }) do %>
<%= link_to(
title.game_number,
title.game_url,
data: { turbo_frame: :_top }) %>
<%= inline_svg_tag(
"heroicons/clipboard-document.svg",
class: "btn-basic",
data: {
action:
"click->clipboard#copy "\
"animationend->clipboard#dehighlight",
}) %>
</span>
<% end %>

<span aria-label="Engagement Date">
<%= title.engagement_date %>
Expand Down
6 changes: 4 additions & 2 deletions app/views/games/just_ended/title.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ def initialize(game:)
@game = game
end

def game_number = game.display_id

def game_absolute_url
Router.game_url(game)
end

def title_text = "Copy URL to Clipboard"

def game_number = game.display_id

def game_url
Router.game_path(game)
end
Expand Down
6 changes: 4 additions & 2 deletions app/views/games/title.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ def initialize(game:)
@game = game
end

def game_number = game.display_id

def game_absolute_url
Router.game_url(game)
end

def title_text = "Copy URL to Clipboard"

def game_number = game.display_id

def game_url
Router.game_path(game)
end
Expand Down

0 comments on commit 960702a

Please sign in to comment.