BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/optics/code-snippet

Code Snippet

optics/code-snippet
FreeComponent

A code snippet component with tabs and copy functionality.

See it running

Open the demo on optics

optics.agusmayol.com.ar/components/code-snippet
Open
This registry sends X-Frame-Options, so its page cannot be embedded here. The link is the same page the frame would have shown.

Install it

npx shadcn@latest add https://optics.agusmayol.com.ar/r/code-snippet.json

Source

registry/optics/code-snippet.jsxoptics.agusmayol.com.ar/r/code-snippet.json
1"use client";
2
3import { CheckIcon, CopyIcon } from "lucide-react";
4import { useState } from "react";
5import { Button } from "@/registry/optics/button";
6import { useRender } from "@base-ui/react/use-render";
7import { mergeProps } from "@base-ui/react/merge-props";
8import {
9 Tabs,
10 TabsContent,
11 TabsContents,
12 TabsList,
13 TabsTrigger,
14} from "@/registry/optics/tabs";
15import { ScrollArea } from "@/registry/optics/scroll-area";
16import { cn } from "@/registry/optics/lib/utils";
17
18export const Snippet = ({ className = "", ...props }) => (
19 <Tabs
20 className={cn(
21 "group w-full gap-0 overflow-hidden rounded-md border border-input",
22 className,
23 )}
24 {...props}
25 />
26);
27
28export const SnippetHeader = ({ className = "", ...props }) => (
29 <div
30 className={cn(
31 "flex flex-row items-center justify-between border-b bg-secondary p-1",
32 className,
33 )}
34 {...props}
35 />
36);
37
38export const SnippetCopyButton = ({
39 render = undefined,
40 value = "",
41 onCopy = undefined,
42 onError = undefined,
43 timeout = 2000,
44 ...props
45}) => {
46 const [isCopied, setIsCopied] = useState(false);
47
48 const copyToClipboard = async () => {
49 if (typeof window === "undefined" || !value) return;
50
51 try {
52 // Try modern clipboard API first
53 if (navigator.clipboard?.writeText) {
54 await navigator.clipboard.writeText(value);
55 } else {
56 // Fallback for iOS and older browsers
57 const textArea = document.createElement("textarea");
58 textArea.value = value;
59 textArea.style.position = "fixed";
60 textArea.style.opacity = "0";
61 document.body.appendChild(textArea);
62 textArea.select();
63 document.execCommand("copy");
64 document.body.removeChild(textArea);
65 }
66 setIsCopied(true);
67 onCopy?.();
68 setTimeout(() => setIsCopied(false), timeout);
69 } catch (error) {
70 onError?.(error);
71 }
72 };
73
74 const buttonContent = (
75 <>
76 <div className="relative">
77 <div
78 className={cn(
79 "absolute inset-0 flex items-center justify-center transition-all duration-300 ease-in-out will-change-[transform,opacity,filter]",
80 isCopied
81 ? "scale-100 opacity-100 blur-0"
82 : "blur-xs scale-[0.25] opacity-0",
83 )}
84 >
85 <CheckIcon className="text-muted-foreground" size={14} />
86 </div>
87 <div
88 className={cn(
89 "transition-[transform, opacity, filter] duration-300 ease-in-out will-change-[transform,opacity,filter]",
90 isCopied
91 ? "blur-xs scale-[0.25] opacity-0"
92 : "scale-100 opacity-100 blur-0",
93 )}
94 >
95// … truncated

What it pulls in

npm packages

  • lucide-react
  • @base-ui/react
  • clsx
  • tailwind-merge

Other registry items

  • https://optics.agusmayol.com.ar/r/button.json
  • https://optics.agusmayol.com.ar/r/tabs.json
  • https://optics.agusmayol.com.ar/r/scroll-area.json
  • https://optics.agusmayol.com.ar/r/utils.json

Files it writes

  • registry/optics/code-snippet.jsx

Facts

Registry
optics
Type
registry:component
Access
Free
Files written
1
Licence
MIT
First indexed
2026-08-04
Last confirmed
today

Go to the source

Docs on optics optics.agusmayol.com.ar AgusMayol/optics on GitHub Raw registry item This item as JSON

More from optics

All 79 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
AccordionaccordionopticsComponentsFree5 deps
AlertalertopticsComponentsFree4 deps
Alert Dialogalert-dialogopticsComponentsFree4 deps
Aspect Ratioaspect-ratioopticsComponentsFree2 deps
Auto Heightauto-heightopticsComponentsFree3 deps
AvataravataropticsComponentsFree3 deps
BadgebadgeopticsComponentsFree4 deps
BreadcrumbbreadcrumbopticsComponentsFree4 deps
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex