Skip to content

Commit 230c9fe

Browse files
author
Nicholas Newberry
committed
add copy button to message
1 parent e7a8c23 commit 230c9fe

4 files changed

Lines changed: 16 additions & 5 deletions

File tree

app/javascript/controllers/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ eagerLoadControllersFrom("controllers", application)
99
// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!)
1010
// import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
1111
// lazyLoadControllersFrom("controllers", application)
12+
13+
import Clipboard from "stimulus-clipboard"
14+
application.register('clipboard', Clipboard)

app/views/messages/_message.html.erb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
<div>
44
<div class="flex justify-start items-start">
55
<div class="flex-1 whitespace-prewrap" data-controller="markdown-text">
6-
<%= raw(message.content) %>
6+
<%= raw(message.content) %>
77
</div>
8-
<div class="flex flex-col ms-4">
9-
<p class="py-1 text-xs text-right text-secondary-500 dark:text-secondary-400"><%= author_name_for(message) %></p>
10-
<p class="py-1 text-xs text-right text-secondary-500 dark:text-secondary-400"><%= time_ago_in_words(message.created_at) %> ago</p>
8+
9+
<div class="flex flex-col ms-4 text-right text-secondary-500 dark:text-secondary-400">
10+
<p class="py-1 text-xs"><%= author_name_for(message) %></p>
11+
<p class="py-1 text-xs"><%= time_ago_in_words(message.created_at) %> ago</p>
12+
<%= render "shared/copy_button", content: message.content.strip %>
1113
</div>
1214
</div>
1315

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div data-controller="clipboard" data-clipboard-success-content-value="Copied!">
2+
<input readonly type="hidden" value="<%= content %>" data-clipboard-target="source">
3+
4+
<button type="button" data-action="clipboard#copy" data-clipboard-target="button"><i class="fa fa-copy"></i></button>
5+
</div>

config/importmap.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
pin "application"
44
pin "@hotwired/turbo-rails", to: "turbo.min.js"
5-
pin "@hotwired/stimulus", to: "stimulus.min.js"
5+
pin "@hotwired/stimulus", to: "@hotwired--stimulus.js" # @3.2.2
66
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
77
pin_all_from "app/javascript/controllers", under: "controllers"
88
pin "trix"
99
pin "@rails/actiontext", to: "actiontext.esm.js"
1010
pin "marked", to: "https://ga.jspm.io/npm:marked@12.0.0/lib/marked.esm.js"
1111
pin "highlight.js", to: "https://ga.jspm.io/npm:highlight.js@11.9.0/es/index.js"
12+
pin "stimulus-clipboard" # @4.0.1

0 commit comments

Comments
 (0)