Skip to content

Commit 2f51435

Browse files
committed
better ux
1 parent cddbb45 commit 2f51435

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

src/components/github-star-button.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
---
33

44
<button
5-
class="items-center justify-center whitespace-nowrap rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group relative animate-rainbow cursor-pointer border-0 bg-[linear-gradient(#fff,#fff),linear-gradient(#fff_50%,rgba(255,255,255,0.6)_80%,rgba(0,0,0,0)),linear-gradient(90deg,hsl(0,100%,63%),hsl(90,100%,63%),hsl(210,100%,63%),hsl(195,100%,63%),hsl(270,100%,63%))] bg-[length:200%] text-foreground [background-clip:padding-box,border-box,border-box] [background-origin:border-box] [border:calc(0.08*1rem)_solid_transparent] before:absolute before:bottom-[-20%] before:left-1/2 before:z-[0] before:h-[20%] before:w-[60%] before:-translate-x-1/2 before:animate-rainbow before:bg-[linear-gradient(90deg,hsl(0,100%,63%),hsl(90,100%,63%),hsl(210,100%,63%),hsl(195,100%,63%),hsl(270,100%,63%))] before:[filter:blur(calc(0.8*1rem))] dark:bg-[linear-gradient(#121213,#121213),linear-gradient(#121213_50%,rgba(18,18,19,0.6)_80%,rgba(18,18,19,0)),linear-gradient(90deg,hsl(0,100%,63%),hsl(90,100%,63%),hsl(210,100%,63%),hsl(195,100%,63%),hsl(270,100%,63%))] h-8 px-3 py-1.5 text-xs inline-flex"
5+
class="items-center justify-center whitespace-nowrap font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group relative animate-rainbow cursor-pointer border-0 bg-[linear-gradient(#fff,#fff),linear-gradient(#fff_50%,rgba(255,255,255,0.6)_80%,rgba(0,0,0,0)),linear-gradient(90deg,hsl(0,100%,63%),hsl(90,100%,63%),hsl(210,100%,63%),hsl(195,100%,63%),hsl(270,100%,63%))] bg-[length:200%] text-foreground [background-clip:padding-box,border-box,border-box] [background-origin:border-box] [border:calc(0.08*1rem)_solid_transparent] before:absolute before:bottom-[-20%] before:left-1/2 before:z-[0] before:h-[20%] before:w-[60%] before:-translate-x-1/2 before:animate-rainbow before:bg-[linear-gradient(90deg,hsl(0,100%,63%),hsl(90,100%,63%),hsl(210,100%,63%),hsl(195,100%,63%),hsl(270,100%,63%))] before:[filter:blur(calc(0.8*1rem))] dark:bg-[linear-gradient(#121213,#121213),linear-gradient(#121213_50%,rgba(18,18,19,0.6)_80%,rgba(18,18,19,0)),linear-gradient(90deg,hsl(0,100%,63%),hsl(90,100%,63%),hsl(210,100%,63%),hsl(195,100%,63%),hsl(270,100%,63%))] h-8 px-3 py-1.5 text-xs inline-flex"
66
onclick="window.open('https://github.com/ThinhPhoenix/github-pages', '_blank')"
77
>
88
<div class="flex items-center">

src/components/install-code-block.astro

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<code class="font-mono text-sm text-gray-300">
2222
npx <span class="text-blue-400">@thinhphoenix/github-pages</span>
2323
</code>
24-
<button onclick="copyCode('npm-cmd')" class="text-gray-500 hover:text-white transition-colors ml-4">
24+
<button onclick="copyCode(this, 'npm-cmd')" class="copy-btn text-gray-500 hover:text-white transition-colors ml-4">
2525
<i class="ph ph-copy"></i>
2626
</button>
2727
</div>
@@ -34,7 +34,7 @@
3434
<code class="font-mono text-sm text-gray-300">
3535
bunx <span class="text-blue-400">@thinhphoenix/github-pages</span>
3636
</code>
37-
<button onclick="copyCode('bun-cmd')" class="text-gray-500 hover:text-white transition-colors ml-4">
37+
<button onclick="copyCode(this, 'bun-cmd')" class="copy-btn text-gray-500 hover:text-white transition-colors ml-4">
3838
<i class="ph ph-copy"></i>
3939
</button>
4040
</div>
@@ -50,6 +50,12 @@
5050
</div>
5151
</div>
5252

53+
<!-- Toast Container -->
54+
<div id="toast" class="fixed bottom-8 left-1/2 -translate-x-1/2 bg-[#1a1a1a] border border-white/10 text-white px-5 py-3 shadow-2xl flex items-center gap-3 opacity-0 translate-y-4 transition-all duration-300 pointer-events-none z-50">
55+
<i class="ph ph-check-circle text-emerald-400 text-lg"></i>
56+
<span class="text-sm font-medium">Copied to clipboard!</span>
57+
</div>
58+
5359
<script is:inline>
5460
function switchPmTab(pmId) {
5561
document.querySelectorAll('.pm-tab').forEach(function(tab) {
@@ -71,10 +77,32 @@
7177
}
7278
}
7379

74-
function copyCode(elementId) {
80+
function copyCode(btn, elementId) {
7581
var el = document.getElementById(elementId);
7682
if (el && el.textContent) {
77-
navigator.clipboard.writeText(el.textContent);
83+
navigator.clipboard.writeText(el.textContent).then(function() {
84+
showToast();
85+
86+
var icon = btn.querySelector('i');
87+
if (icon) {
88+
icon.classList.remove('ph-copy');
89+
icon.classList.add('ph-check');
90+
setTimeout(function() {
91+
icon.classList.remove('ph-check');
92+
icon.classList.add('ph-copy');
93+
}, 2000);
94+
}
95+
});
96+
}
97+
}
98+
99+
function showToast() {
100+
var toast = document.getElementById('toast');
101+
if (toast) {
102+
toast.classList.remove('opacity-0', 'translate-y-4');
103+
setTimeout(function() {
104+
toast.classList.add('opacity-0', 'translate-y-4');
105+
}, 2000);
78106
}
79107
}
80108
</script>

0 commit comments

Comments
 (0)