Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

feat(ui): use the shared copy button component everywhere

peaklabs-dev0e35eb2aa3e6
diff --git a/resources/views/components/forms/copy-button.blade.php b/resources/views/components/forms/copy-button.blade.php
index e299610eb2..d31fac0bca 100644
--- a/resources/views/components/forms/copy-button.blade.php
+++ b/resources/views/components/forms/copy-button.blade.php
@@ -1,6 +1,6 @@
@props(['text', 'label' => null])
-<div class="w-full" x-data="{ copied: false }">
+<div class="w-full">
@if ($label)
<label class="flex gap-1 items-center mb-1 text-sm font-medium text-black dark:text-white">{{ $label }}</label>
@endif
@@ -10,19 +10,6 @@
readonly
@keydown.prevent @paste.prevent @cut.prevent @drop.prevent
@focus="$event.target.select()">
- <button
- type="button"
- @click.prevent="await window.copyToClipboard({{ Js::from($text) }}); copied = true; setTimeout(() => copied = false, 1000)"
- class="copy-button flex absolute inset-y-0 right-0 z-10 items-center pr-2 cursor-pointer text-neutral-500 transition-colors hover:text-black focus-visible:ring-2 focus-visible:ring-coollabs focus-visible:ring-offset-2 dark:text-neutral-400 dark:hover:text-white dark:focus-visible:ring-warning dark:focus-visible:ring-offset-base"
- title="Copy to clipboard"
- aria-label="Copy to clipboard">
- <svg x-show="!copied" class="size-[18px]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
- d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" />
- </svg>
- <svg x-show="copied" class="size-[18px] text-green-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
- </svg>
- </button>
+ <x-copy-button :value="$text" class="absolute top-1/2 right-2 -translate-y-1/2" />
</div>
</div>
diff --git a/resources/views/components/modal-confirmation.blade.php b/resources/views/components/modal-confirmation.blade.php
index 0e4350f50f..f9b8bd98de 100644
--- a/resources/views/components/modal-confirmation.blade.php
+++ b/resources/views/components/modal-confirmation.blade.php
@@ -287,17 +287,8 @@
<div class="relative mb-2" x-data="{ decodedText: confirmationText }">
<div class="relative">
<input type="text" x-model="decodedText" readonly class="input">
- <button x-show="window.isSecureContext"
- @click.prevent="navigator.clipboard.writeText(decodedText); $el.innerHTML = '<svg class=\'w-5 h-5 text-green-500\' fill=\'none\' stroke=\'currentColor\' viewBox=\'0 0 24 24\'><path stroke-linecap=\'round\' stroke-linejoin=\'round\' stroke-width=\'2\' d=\'M5 13l4 4L19 7\' /></svg>'; setTimeout(() => $el.innerHTML = '<svg class=\'w-5 h-5\' fill=\'none\' stroke=\'currentColor\' viewBox=\'0 0 24 24\'><path stroke-linecap=\'round\' stroke-linejoin=\'round\' stroke-width=\'2\' d=\'M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\' /></svg>', 1000)"
- class="absolute right-2 top-1/2 -translate-y-1/2 p-1.5 text-gray-400 hover:text-gray-300 transition-colors"
- title="Copy to clipboard">
- <svg class="w-5 h-5" fill="none" stroke="currentColor"
- viewBox="0 0 24 24">
- <path stroke-linecap="round" stroke-linejoin="round"
- stroke-width="2"
- d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" />
- </svg>
- </button>
+ <x-copy-button resolve="decodedText"
+ class="absolute top-1/2 right-2 -translate-y-1/2" />
</div>
</div>
diff --git a/resources/views/livewire/project/shared/partials/dns-copy-cell.blade.php b/resources/views/livewire/project/shared/partials/dns-copy-cell.blade.php
index 7394cbd8bd..be1cbf4ca7 100644
--- a/resources/views/livewire/project/shared/partials/dns-copy-cell.blade.php
+++ b/resources/views/livewire/project/shared/partials/dns-copy-cell.blade.php
@@ -2,44 +2,7 @@
$break = $break ?? false;
$label = $label ?? 'Copy';
@endphp
-<div class="flex min-w-0 items-center gap-1.5"
- x-data="{
- copied: false,
- async copy(text) {
- try {
- if (navigator.clipboard?.writeText) {
- await navigator.clipboard.writeText(text);
- } else {
- const el = document.createElement('textarea');
- el.value = text;
- el.setAttribute('readonly', '');
- el.style.position = 'fixed';
- el.style.left = '-9999px';
- document.body.appendChild(el);
- el.select();
- document.execCommand('copy');
- document.body.removeChild(el);
- }
- this.copied = true;
- setTimeout(() => this.copied = false, 1000);
- } catch (e) {
- console.error('Copy failed', e);
- }
- }
- }">
+<div class="flex min-w-0 items-center gap-1.5">
<span @class(['min-w-0', 'break-all' => $break])>{{ $text }}</span>
- <button type="button"
- @click.prevent.stop="copy(@js($text))"
- class="inline-flex size-7 shrink-0 items-center justify-center rounded-md text-neutral-500 transition-colors hover:bg-neutral-100 hover:text-black dark:text-fg-dim dark:hover:bg-coolgray-200 dark:hover:text-white"
- title="{{ $label }}"
- aria-label="{{ $label }}">
- <svg x-show="!copied" class="size-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
- d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" />
- </svg>
- <svg x-show="copied" x-cloak class="size-3.5 text-green-500" fill="none" stroke="currentColor"
- viewBox="0 0 24 24" aria-hidden="true">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
- </svg>
- </button>
+ <x-copy-button :value="$text" :label="$label" />
</div>
diff --git a/resources/views/livewire/security/api-tokens.blade.php b/resources/views/livewire/security/api-tokens.blade.php
index 38db6aa3a6..80647458df 100644
--- a/resources/views/livewire/security/api-tokens.blade.php
+++ b/resources/views/livewire/security/api-tokens.blade.php
@@ -109,7 +109,12 @@
@if (session()->has('token'))
<x-application.settings-section title="Copy your token"
description="This value will not be shown again after you leave this page.">
- <x-forms.copy-button :text="session('token')" />
+ <div class="relative">
+ <input type="text" value="{{ session('token') }}" readonly
+ class="input w-full pr-12! font-mono text-[12px] text-black dark:text-fg">
+ <x-copy-button :value="session('token')" label="Copy token"
+ class="absolute top-1/2 right-2 -translate-y-1/2" />
+ </div>
</x-application.settings-section>
@endif
diff --git a/resources/views/livewire/team/invitations.blade.php b/resources/views/livewire/team/invitations.blade.php
index e777ae058e..f9a3f2442e 100644
--- a/resources/views/livewire/team/invitations.blade.php
+++ b/resources/views/livewire/team/invitations.blade.php
@@ -29,14 +29,7 @@
<span
class="min-w-0 truncate font-mono text-[12px] text-neutral-500 dark:text-fg-dim"
title="{{ $invite->link }}">{{ $invite->link }}</span>
- <button type="button"
- class="button h-7! shrink-0 px-2!"
- title="Copy invitation link"
- aria-label="Copy invitation link"
- x-data
- x-on:click.prevent="window.copyToClipboard(@js($invite->link))">
- <x-reicon name="file-content" class="size-3.5" />
- </button>
+ <x-copy-button :value="$invite->link" label="Copy invitation link" />
</div>
<div class="text-right">
<button type="button"