Skip to content

feat(gateway): add cid copy button to directory listings - #899

Merged
lidel merged 5 commits into
ipfs:mainfrom
VersaliXis:gateway-feature
Apr 8, 2025
Merged

lidel merged 5 commits into
ipfs:mainfrom
VersaliXis:gateway-feature

Conversation

@VersaliXis

Copy link
Copy Markdown
Contributor

Fixes: #895

@VersaliXis
VersaliXis requested a review from lidel as a code owner March 26, 2025 10:12
@welcome

This comment was marked as outdated.

@gammazero gammazero added the need/maintainers-input Needs input from the current maintainer(s) label Apr 1, 2025
@gammazero

Copy link
Copy Markdown
Contributor

Could you upload a screenshot with this PR?

@VersaliXis

Copy link
Copy Markdown
Contributor Author

Sure! Here is what it looks like. If you want to change anything in the style, feel free to ask.

Copy button proposal

The code is pretty simple, here is a diff:

diff --git a/gateway/assets/directory.html b/gateway/assets/directory.html
index 888ecabf..9201ce83 100644
--- a/gateway/assets/directory.html
+++ b/gateway/assets/directory.html
@@ -59,6 +59,7 @@
             <a class="ipfs-hash" translate="no" href={{ if $root.DNSLink }}"https://cid.ipfs.tech/#{{ .Hash | urlEscape}}" target="_blank" rel="noreferrer noopener"{{ else }}"{{ $root.GatewayURL }}/ipfs/{{ .Hash | urlEscape}}?filename={{ .Name | urlEscape }}"{{ end }}>
               {{- .ShortHash -}}
             </a>
+            <button class="copy-button" onclick="navigator.clipboard.writeText('{{ .Hash }}')">Copy</button>
             {{ end }}
           </div>
           <div class="nowrap" title="Cumulative size of IPFS DAG (data + metadata)">{{ .Size }}</div>
diff --git a/gateway/assets/style.css b/gateway/assets/style.css
index a8dfdaf7..7e4512e7 100644
--- a/gateway/assets/style.css
+++ b/gateway/assets/style.css
@@ -66,6 +66,23 @@ a:visited {
        font-family: var(--monospace);
 }
 
+.copy-button {
+       color: #7f8491;
+       background-color: inherit;
+       border: 1px solid var(--dark-white);;
+       border-radius: 2px;
+       padding: 1px 2px;
+       cursor: copy;
+}
+
+.copy-button:hover {
+       background-color: var(--light-white);
+}
+
+.copy-button:active {
+       color: #00b0e9;
+}
+
 #header {
        align-items: center;
        background: var(--navy);

Comment thread gateway/assets/style.css Resolved
Comment thread gateway/assets/style.css Resolved
Comment thread gateway/assets/directory.html Resolved
Including Adding the copy-icon in assets/icon.css
and Adding the description "Copy Hash" on mouse hover
lidel added 3 commits April 8, 2025 01:38
- hand on hover
- remove background-based feedback, switch to opacity on click
- add copy option to the top
@lidel
lidel requested a review from a team as a code owner April 7, 2025 23:41
@lidel lidel changed the title [skip changelog] gateway: hash copy button feature in the directory listing feat(gateway): add cid copy button to directory listings Apr 7, 2025
@lidel
lidel merged commit 58771d8 into ipfs:main Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

need/maintainers-input Needs input from the current maintainer(s)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gateway: more responsive directory listing

5 participants