hyprland-website/src/routes/InstallButton.svelte

88 lines
2.3 KiB
Svelte
Raw Normal View History

2023-08-05 20:33:07 +02:00
<script>
import { onDestroy } from 'svelte'
import ClipboardIcon from '~icons/mingcute/copy-2-line'
/** @type {string} */
export let command
/** @type {string} */
export let image
/** @type {string} */
export let name
let isShowingCopied = false
let timeoutId
async function copyCommand() {
await navigator.clipboard.writeText(command).then(() => (isShowingCopied = true))
clearTimeout(timeoutId)
timeoutId = setTimeout(() => (isShowingCopied = false), 1400)
}
onDestroy(() => {
clearTimeout(timeoutId)
})
</script>
2023-09-13 14:27:13 +02:00
<div class="group flex flex-col items-center gap-2 md:flex-row md:gap-4">
2023-08-05 20:33:07 +02:00
<div
2023-09-13 14:27:13 +02:00
class="flex h-32 w-32 flex-col items-center justify-center gap-3 rounded-full text-lg font-medium text-primary transition-transform group-focus-within:-translate-y-1"
2023-08-05 20:33:07 +02:00
>
2023-09-13 14:27:13 +02:00
<img
src={image}
class="h-20 w-32 object-contain"
alt="Distrubution Logo"
loading="lazy"
/>{name}
2023-08-05 20:33:07 +02:00
</div>
2023-09-13 14:27:13 +02:00
<div class="relative mb-2 flex flex-col font-mono">
2023-08-05 20:33:07 +02:00
<button
2023-09-13 14:27:13 +02:00
class="flex min-w-[18rem] items-center justify-center gap-4 rounded-full border border-primary py-3 pl-6 pr-6 text-base font-medium transition-transform active:scale-[1.01]"
2023-08-05 20:33:07 +02:00
on:click={$$slots.default ? undefined : copyCommand}
>
<slot>
2023-09-13 14:27:13 +02:00
<div class="relative flex w-full justify-between gap-4">
2023-08-05 20:33:07 +02:00
<div class="flex gap-4">
2023-09-13 14:27:13 +02:00
<div class="select-none font-bold text-primary">></div>
2023-08-05 20:33:07 +02:00
<span>{command}</span>
</div>
<ClipboardIcon
2023-09-13 14:27:13 +02:00
class="h-6 w-6 text-white opacity-0 transition-opacity duration-100 hover:!opacity-100 group-hover:opacity-80 group-active:opacity-100"
2023-08-05 20:33:07 +02:00
/>
2023-08-17 16:45:47 +02:00
</div>
</slot>
2023-08-05 20:33:07 +02:00
</button>
2023-08-07 19:59:22 +02:00
2023-08-05 20:33:07 +02:00
<div
2023-09-13 14:27:13 +02:00
class="pointer-events-none absolute left-1/2 z-20 hidden w-full max-w-max select-none rounded-full bg-black/10 px-2 text-green-400 backdrop-blur [translate:-50%_0px] max-md:-bottom-6 md:-top-8"
2023-08-05 20:33:07 +02:00
class:copy={isShowingCopied}
>
Copied to clipboard ✔
</div>
2023-08-07 19:59:22 +02:00
2023-08-05 20:33:07 +02:00
{#if $$slots.extra}
2023-09-13 14:27:13 +02:00
<div class="absolute -bottom-6 flex w-full justify-center font-sans text-xs opacity-80">
2023-08-05 20:33:07 +02:00
<slot name="extra" />
</div>
{/if}
</div>
</div>
<style lang="postcss">
.copy {
animation: 80ms cubic-bezier(0.5, 0.2, 0, 1.5) 1 copy;
display: block;
}
@keyframes copy {
from {
opacity: 0.8;
scale: 0.98;
}
to {
opacity: 1;
scale: 1;
}
}
</style>