Skip to content
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

Add copy content to clipboard for share modal #1833

Merged
merged 2 commits into from
Nov 28, 2023
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: 2 additions & 1 deletion app/assets/stylesheets/media.scss
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
input[type="text"], textarea {
margin-bottom: 1rem;
padding: .375rem .75rem;
width: 100%;
width: calc(100% - 2rem);
}

fieldset {
Expand Down Expand Up @@ -154,6 +154,7 @@
text-decoration: underline;
cursor: pointer;
}

}
}

Expand Down
22 changes: 18 additions & 4 deletions app/components/embed/media/embed_this_form_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
<div class='sul-embed-embed-this-form'>
<label for="sul-embed-purl-link" class="form-label" readonly>Share link</label>
<input type="text" name="sul-embed-purl-link" id='sul-embed-purl-link' value="<%= purl_url %>" readonly>
<div data-controller="clipboard">
<label for="sul-embed-purl-link" class="form-label" readonly>Share link</label>
<input type="text" name="sul-embed-purl-link" id='sul-embed-purl-link' data-clipboard-target="value" value="<%= purl_url %>" readonly>
<button class="button copy-to-clipboard" data-action="clipboard#copy" aria-label="Copy purl link to clipboard">
<svg class="MuiSvgIcon-root" focusable="false" aria-hidden="true" viewBox="0 0 24 24">
<path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"></path>
</svg>
</button>
</div>

<label for='sul-embed-iframe-code' class="form-label">Embed</label>
<textarea id='sul-embed-iframe-code' data-behavior='iframe-code' readonly><%= render IframeComponent.new(viewer:) %></textarea>
<div data-controller="clipboard">
<label for='sul-embed-iframe-code' class="form-label">Embed</label>
<textarea id='sul-embed-iframe-code' data-behavior='iframe-code' data-clipboard-target="value" readonly><%= render IframeComponent.new(viewer:) %></textarea>
<button class="button copy-to-clipboard" data-action="clipboard#copy" aria-label="Copy iframe code to clipboard">
<svg class="MuiSvgIcon-root" focusable="false" aria-hidden="true" viewBox="0 0 24 24">
<path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"></path>
</svg>
</button>
</div>

<fieldset>
<legend>Select options:</legend>
Expand Down
9 changes: 9 additions & 0 deletions app/javascript/src/controllers/clipboard_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
static targets = ['value']

copy () {
navigator.clipboard.writeText(this.valueTarget.value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
expect(page).to have_css('input#sul-embed-embed-title[type="checkbox"]')
expect(page).to have_css('input#sul-embed-embed[type="checkbox"]')
expect(page).to have_css('textarea#sul-embed-iframe-code')
expect(page).to have_css('button.copy-to-clipboard')
end
end