Skip to content

Commit cde2cad

Browse files
authored
feat: add copy button for install commands (#128)
* Added copy button for install commands (#124) * signed commit * Addressed requested changes for PR #128 * 11:58 PR #128 * 12:09 PR #128 * remade fixes disabling prettier PR #128 * reformatted script for better readability
1 parent 679fdeb commit cde2cad

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

src/static/css/release.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,34 @@ header .latest-beta {
7878
color: #9feaf9;
7979
padding: 8px 32px;
8080
text-align: center;
81+
position: relative;
8182
}
8283

8384
.install-commands .command:not(:first-child) {
8485
margin-left: 16px;
8586
}
8687

88+
.copy-button {
89+
position: absolute;
90+
right: 8px;
91+
top: 50%;
92+
transform: translateY(-50%);
93+
background: none;
94+
border: none;
95+
color: #9feaf9;
96+
cursor: pointer;
97+
padding: 4px;
98+
transition: color 0.2s ease;
99+
}
100+
101+
.copy-button:hover {
102+
color: #ffffff;
103+
}
104+
105+
.copy-button i {
106+
font-size: 16px;
107+
}
108+
87109
@media screen and (max-width: 767px) {
88110
.install-commands {
89111
flex-direction: column;

src/views/release.handlebars

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
<div>
22
<div class="install-commands">
33

4-
{{#ifEquals prerelease "nightly"}}
5-
<pre class="command">npm install electron-nightly@{{ version }}</pre>
6-
<pre class="command">yarn add electron-nightly@{{ version }}</pre>
4+
{{#ifEquals prerelease 'nightly'}}
5+
<pre class='command'>npm install electron-nightly@{{version}}<button
6+
class='copy-button'
7+
title='Copy to Clipboard'
8+
onclick='copyCommand(this)'
9+
><i class='fas fa-copy'></i></button></pre>
10+
<pre class='command'>yarn add electron-nightly@{{version}}<button
11+
class='copy-button'
12+
title='Copy to Clipboard'
13+
onclick='copyCommand(this)'
14+
><i class='fas fa-copy'></i></button></pre>
715
{{else}}
8-
<pre class="command">npm install electron@{{ version }}</pre>
9-
<pre class="command">yarn add electron@{{ version }}</pre>
16+
<pre class='command'>npm install electron@{{version}}<button
17+
class='copy-button'
18+
title='Copy to Clipboard'
19+
onclick='copyCommand(this)'
20+
><i class='fas fa-copy'></i></button></pre>
21+
<pre class='command'>yarn add electron@{{version}}<button
22+
class='copy-button'
23+
title='Copy to Clipboard'
24+
onclick='copyCommand(this)'
25+
><i class='fas fa-copy'></i></button></pre>
1026
{{/ifEquals}}
1127
</div>
1228
{{#ifEquals prerelease "nightly"}}
@@ -61,3 +77,21 @@
6177
<option>PDBS</option>
6278
</select> --}}
6379
</div>
80+
<script>
81+
function copyCommand(button) {
82+
const command = button.parentElement.textContent.trim();
83+
84+
navigator.clipboard.writeText(command).then(() => {
85+
const icon = button.querySelector('i');
86+
icon.className = 'fas fa-check';
87+
button.style.color = '#4CAF50';
88+
89+
setTimeout(() => {
90+
icon.className = 'fas fa-copy';
91+
button.style.color = '';
92+
}, 1000);
93+
});
94+
}
95+
</script>
96+
97+

0 commit comments

Comments
 (0)