-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
206 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
import { cn } from '@/lib/utils' | ||
import { buttonVariants } from '@/registry/new-york/ui/button' | ||
export interface Props { | ||
class: string | ||
value: string | ||
} | ||
const { value, class: className } = Astro.props | ||
--- | ||
|
||
<button | ||
class={cn( | ||
buttonVariants({ | ||
variant: 'ghost', | ||
size: 'icon', | ||
class: cn( | ||
'relative z-10 h-6 w-6 text-zinc-50 hover:bg-zinc-700 hover:text-zinc-50 [&_svg]:h-3 [&_svg]:w-3', | ||
className, | ||
), | ||
}), | ||
)} | ||
x-data={`{ | ||
copyText: \`${value.replace(/`/g, '\\`')}\`, | ||
copyNotification: false, | ||
copyToClipboard() { | ||
navigator.clipboard.writeText(this.copyText); | ||
this.copyNotification = true; | ||
let that = this; | ||
setTimeout(function(){ | ||
that.copyNotification = false; | ||
}, 2000);} | ||
}`} | ||
@click="copyToClipboard();" | ||
> | ||
<span class="sr-only">Copy</span> | ||
|
||
<svg | ||
x-show="!copyNotification" | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
stroke-width="2" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
class="lucide lucide-clipboard" | ||
> | ||
<rect width="8" height="4" x="8" y="2" rx="1" ry="1"></rect> | ||
<path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"></path> | ||
</svg> | ||
|
||
<svg | ||
x-show="copyNotification" | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
stroke-width="2" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
class="lucide lucide-check" | ||
> | ||
<path d="M20 6 9 17l-5-5"></path> | ||
</svg> | ||
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
--- | ||
import { cn } from '@/lib/utils' | ||
import { buttonVariants } from '@/registry/new-york/ui/button' | ||
export interface Props { | ||
commands: { | ||
__npmCommand__: string | ||
__pnpmCommand__: string | ||
__yarnCommand__: string | ||
__bunCommand__: string | ||
} | ||
class: string | ||
} | ||
const { class: className, commands } = Astro.props | ||
--- | ||
|
||
<div | ||
x-data={`{ | ||
dropdownOpen: false, | ||
copyNotification: false, | ||
commands: ${JSON.stringify(commands)}, | ||
copyToClipboard(copyText) { | ||
this.dropdownOpen = false; | ||
navigator.clipboard.writeText(copyText); | ||
this.copyNotification = true; | ||
let that = this; | ||
setTimeout(function(){ | ||
that.copyNotification = false; | ||
}, 2000);} | ||
}`} | ||
> | ||
<button | ||
@click="dropdownOpen=true" | ||
class={cn( | ||
buttonVariants({ | ||
variant: 'ghost', | ||
size: 'icon', | ||
class: cn( | ||
'relative z-10 h-6 w-6 text-zinc-50 hover:bg-zinc-700 hover:text-zinc-50 [&_svg]:h-3 [&_svg]:w-3', | ||
className, | ||
), | ||
}), | ||
)} | ||
> | ||
<span class="sr-only">Copy</span> | ||
|
||
<svg | ||
x-show="!copyNotification" | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
stroke-width="2" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
class="lucide lucide-clipboard" | ||
> | ||
<rect width="8" height="4" x="8" y="2" rx="1" ry="1"></rect> | ||
<path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"></path> | ||
</svg> | ||
|
||
<svg | ||
x-show="copyNotification" | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
stroke-width="2" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
class="lucide lucide-check" | ||
> | ||
<path d="M20 6 9 17l-5-5"></path> | ||
</svg> | ||
</button> | ||
|
||
<div | ||
x-show="dropdownOpen" | ||
@click.away="dropdownOpen=false" | ||
x-transition:enter="ease-out duration-200" | ||
x-transition:enter-start="-translate-y-2" | ||
x-transition:enter-end="translate-y-0" | ||
class="absolute top-0 z-50 mt-12 -translate-x-4 right-0 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md" | ||
x-cloak | ||
> | ||
<div | ||
class="relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground hover:bg-accent hover:text-accent-foreground" | ||
@click="copyToClipboard(commands.__npmCommand__)" | ||
> | ||
npm | ||
</div> | ||
<div | ||
class="relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground hover:bg-accent hover:text-accent-foreground" | ||
@click="copyToClipboard(commands.__yarnCommand__)" | ||
> | ||
yarn | ||
</div> | ||
<div | ||
class="relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground hover:bg-accent hover:text-accent-foreground" | ||
@click="copyToClipboard(commands.__pnpmCommand__)" | ||
> | ||
pnpm | ||
</div> | ||
<div | ||
class="relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground hover:bg-accent hover:text-accent-foreground" | ||
@click="copyToClipboard(commands.__bunCommand__)" | ||
> | ||
bun | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters