-
-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: copyable
field option
#3468
Merged
Merged
Changes from 15 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
f266554
add new feature, copy field value
Nevelito 9de04cc
make display changes
Nevelito 00e4929
fix bug in text_area field
Nevelito f6b0de6
Merge branch 'main' into feature/click_to_copy
Nevelito 4bfb9a2
run rubocop, and make small changes
Nevelito b502d18
Fix sugestion by Rubocop and include buttons text in test_helpers_spec
Nevelito b16dc7c
Request changes
Nevelito 89b17d7
Fix failing checks
Nevelito 265d3f6
Fix specs
Nevelito 38562a0
fix failing check
Nevelito c964d47
Self code review
Nevelito 013c526
Fix copy firld content spec
Nevelito e43dd7a
Fix spec
Nevelito 58e5aec
Final fix spec
Nevelito 3510a15
Self check changes and fix what user can copy
Nevelito d031548
Merge branch 'main' into feature/click_to_copy
Paul-Bob 78888d5
refactor
Paul-Bob 333cfeb
re-organize imports
Paul-Bob ca79975
revert dependencies downgrade
Paul-Bob 2fb3742
revert schema
Paul-Bob 79cf807
rm unwanted styles
Paul-Bob 24d290a
lint
Paul-Bob faceb47
fix test
Paul-Bob dafca00
adjust position
Paul-Bob c6a6d15
Merge branch 'main' into feature/click_to_copy
Paul-Bob 0385385
tippy
Paul-Bob 223a19e
tippy
Paul-Bob ecab4d5
bundle
Paul-Bob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div class="flex flex-row justify-between opacity-0 group-hover:opacity-100 transition-opacity duration-200" data-controller="clipboard"> | ||
<div class="hidden" data-clipboard-target="source"><%= @value %></div> | ||
<div class="text-xs xl:text-sm"> | ||
<button type="button" data-action="clipboard#copy" data-clipboard-target="icon"> | ||
<a href="javascript:void(0)"> | ||
<%= helpers.svg "heroicons/outline/clipboard", class: "h-4 inline" %> | ||
</a> | ||
</button> | ||
<div class="hidden" data-clipboard-target="iconCopied"> | ||
<a href="javascript:void(0)"> | ||
<%= helpers.svg "heroicons/outline/clipboard-document-check", class: "h-4 inline" %> | ||
</a> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class Avo::ClipboardComponent < Avo::BaseComponent | ||
prop :value | ||
|
||
def render? | ||
@value.present? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Clipboard from '@stimulus-components/clipboard' | ||
|
||
export default class extends Clipboard { | ||
static targets = ['icon', 'iconCopied'] | ||
|
||
connect() { | ||
super.connect() | ||
} | ||
|
||
copied() { | ||
this.iconTarget.classList.add('hidden') | ||
this.iconCopiedTarget.classList.remove('hidden') | ||
|
||
// Reset the icon after a 2 seconds delay | ||
setTimeout(() => { | ||
this.iconTarget.classList.remove('hidden') | ||
this.iconCopiedTarget.classList.add('hidden') | ||
}, 2000) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "CopyFieldContent", type: :system do | ||
let!(:user) { User.first } | ||
|
||
def test_copy_to_clipboard(path) | ||
visit path | ||
|
||
element = find('div[data-controller="clipboard"]', visible: :all) | ||
expect(element).to be_present | ||
element.hover | ||
|
||
copy_button = element.find('button[data-action="clipboard#copy"]', visible: :visible) | ||
copy_button.click | ||
|
||
expect(element).to have_css('div[data-clipboard-target="iconCopied"]', visible: :all, wait: 1) | ||
end | ||
|
||
def test_button_visability(path) | ||
visit path | ||
|
||
element = find('div[data-controller="clipboard"]', visible: :all) | ||
expect(element).to be_present | ||
end | ||
|
||
describe "index view" do | ||
let(:path) { "/admin/resources/users" } | ||
|
||
it "shows copy to clipboard icon" do | ||
test_button_visability(path) | ||
end | ||
|
||
it "copies to clipboard after clicking button" do | ||
test_copy_to_clipboard(path) | ||
end | ||
end | ||
|
||
describe "show view" do | ||
let(:path) { "/admin/resources/users/#{user.id}" } | ||
|
||
it "shows copy to clipboard icon" do | ||
test_button_visability(path) | ||
end | ||
|
||
it "copies to clipboard after clicking button" do | ||
test_copy_to_clipboard(path) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be configured with
data-clipboard-success-duration-value
From: https://www.stimulus-components.com/docs/stimulus-clipboard
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not that easy, It works with data-clipboard-success-content-value (this work only with plain text) , we want to show another object so we can not probably use data-clipboard-success-duration-value. I tried use that but it do not work.