ClipLazor 4.0.0

dotnet add package ClipLazor --version 4.0.0
                    
NuGet\Install-Package ClipLazor -Version 4.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ClipLazor" Version="4.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ClipLazor" Version="4.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ClipLazor" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ClipLazor --version 4.0.0
                    
#r "nuget: ClipLazor, 4.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ClipLazor@4.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ClipLazor&version=4.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ClipLazor&version=4.0.0
                    
Install as a Cake Tool

ClipLazor: Clipboard API Interop for Blazor

ClipLazor is a modern, high-performance library providing full Clipboard API interop and UI components for Blazor applications (both Blazor WebAssembly and Blazor Server on .NET 10+).

ClipboardLazor Logo

NuGet

✨ Features

  • 🚀 Zero Configuration: Uses Blazor JavaScript Isolation (ES Modules). No manual <script> tags required!
  • 🔘 <CopyButton> Component: Instant copy button with embedded Lucide icons, customizable slots, and automatic Copied! ✔ feedback.
  • 📋 <ClipboardPasteZone> Component: Paste & dropzone container for capturing Ctrl+V and drag-and-drop screenshots/files.
  • ✂️ <ClipboardTextAction> Component: Declarative button to copy or cut text from DOM elements by ID.
  • 📝 Plain Text: Copy and paste strings or memory buffers (string, ReadOnlyMemory<char>).
  • 🎨 Rich HTML: First-class WriteHtmlAsync and ReadHtmlAsync with automatic plain text fallback.
  • 🖼️ Binary & Image Streams: Read and write binary data using ReadOnlyMemory<byte> or Stream.
  • Cancellation Support: Full CancellationToken support across all async methods.

📦 Installation

  1. Install ClipLazor via the .NET CLI:
dotnet add package ClipLazor
  1. Register the service in your dependency injection container (Program.cs):
using ClipLazor.Extensions;

builder.Services.AddClipboard();

Zero Configuration: No <script> tags are needed in index.html or App.razor! ClipLazor automatically loads its isolated ES module on demand.


🎨 UI Components

1. <CopyButton> (Automatic Feedback Button)

A button with built-in Lucide SVG icons, temporary feedback states (Copied! ✔), error handling, and rich customization slots:

@* Simple copy button with auto 2-second checkmark *@
<CopyButton Text="dotnet add package ClipLazor" Class="btn btn-primary" CopiedClass="btn btn-success" />

@* Customized copy button *@
<CopyButton Text="https://github.com/p6laris/ClipLazor" 
            ButtonText="Copy Link" 
            CopiedText="Link Copied! 🎉" 
            FeedbackTimeoutMs="3000" 
            Class="btn btn-outline-info" />

@* Icon-only button *@
<CopyButton Text="npm install cliplazor" ShowText="false" IconSize="20px" Class="btn btn-sm btn-dark" />
<CopyButton> Parameters
Parameter Type Default Description
Text string "" Plain text to copy to the clipboard.
Html string? null Rich HTML string to copy.
TargetId string? null DOM element ID to copy text from.
ButtonText string? "Copy" Default label.
CopiedText string? "Copied!" Label shown in copied state.
ErrorText string? "Failed" Label shown in failed state.
ShowIcon bool true Whether to show the icon.
ShowText bool true Whether to show text.
IconPlacement IconPlacement Start IconPlacement.Start (left) or IconPlacement.End (right).
IconSize string "1em" Size of the icon.
Class string? "btn btn-outline-secondary" Button class for default state.
CopiedClass string? "btn btn-success" Button class for copied state.
ErrorClass string? "btn btn-danger" Button class for failed state.
FeedbackTimeoutMs int 2000 Duration (ms) before resetting back.
Disabled bool false Whether button is disabled.
DefaultIcon RenderFragment? null Custom icon slot for default state.
CopiedIcon RenderFragment? null Custom icon slot for copied state.
ErrorIcon RenderFragment? null Custom icon slot for failed state.
DefaultTemplate RenderFragment? null Full custom markup for default state.
CopiedTemplate RenderFragment? null Full custom markup for copied state.
ChildContent RenderFragment<CopyButtonContext>? null Contextual template with full markup control.
OnCopy EventCallback<bool> - Fired when copy action completes.

2. <ClipboardPasteZone> (Paste & Drag-and-Drop Dropzone)

A container component that captures keyboard paste events (Ctrl+V / Cmd+V) and drag-and-drop file uploads:

<ClipboardPasteZone Class="border border-dashed rounded p-4 text-center" 
                    DragOverClass="border-primary bg-light shadow-sm"
                    AcceptedMimeTypes='new[] { "image/png", "image/jpeg" }'
                    OnPaste="HandlePaste">
</ClipboardPasteZone>

@code {
    void HandlePaste(ClipboardPasteEventArgs e)
    {
        if (e.HasImage)
        {
            byte[] imageBytes = e.ImageData.ToArray();
            // Process screenshot or dropped image
        }
        else if (e.HasText)
        {
            Console.WriteLine($"Pasted text: {e.Text}");
        }
    }
}
<ClipboardPasteZone> Parameters
Parameter Type Default Description
Title string? "Paste or Drop Content Here" Default title text.
Subtitle string? "Click and press Ctrl+V, or drag and drop files directly." Default subtitle text.
IconSize string "32px" Size of the default Lucide paste icon.
Class string? "border border-2 border-dashed rounded p-4 text-center" Container CSS class.
DragOverClass string? "border-primary bg-primary-subtle shadow-sm" CSS class added during drag-over.
AcceptedMimeTypes string[]? null Array of accepted MIME patterns (e.g. "image/*").
PreventDefault bool true Prevent browser default paste action.
IconTemplate RenderFragment? null Custom icon template slot.
ChildContent RenderFragment<ClipboardPasteZoneContext>? null Custom container content template.
OnPaste EventCallback<ClipboardPasteEventArgs> - Fired on any paste or drop with all extracted data.
OnImagePasted EventCallback<ReadOnlyMemory<byte>> - Fired specifically when an image is pasted or dropped.
OnTextPasted EventCallback<string> - Fired specifically when text is pasted or dropped.
OnHtmlPasted EventCallback<string> - Fired specifically when HTML is pasted or dropped.

3. <ClipboardTextAction> (DOM Element Action)

Perform copy or cut actions targeting specific DOM element IDs:

<input id="myInput" value="Sample text" />
<ClipboardTextAction TargetId="myInput" Action="ClipboardAction.Copy" Class="btn btn-dark">
    Copy Input Value
</ClipboardTextAction>

🚀 Service API Usage (IClipLazor)

Inject IClipLazor into any Razor component or service:

@using ClipLazor.Components
@inject IClipLazor Clipboard

1. Plain Text

// Write string
await Clipboard.WriteTextAsync("Hello World!");

// Read string
string? text = await Clipboard.ReadTextAsync();

2. Rich HTML

// Write HTML with automatic plain text fallback
await Clipboard.WriteHtmlAsync("<strong>ClipLazor</strong> is <em>awesome</em>!");

// Read HTML
string? html = await Clipboard.ReadHtmlAsync();

3. Binary & Images

// Write byte array
byte[] bytes = ...;
await Clipboard.WriteDataAsync(bytes, "image/png");

// Write from Stream
using var stream = File.OpenRead("image.png");
await Clipboard.WriteDataAsync(stream, "image/png");

// Read as byte buffer or Stream
ReadOnlyMemory<byte> data = await Clipboard.ReadDataAsync("image/png");
using Stream? imageStream = await Clipboard.ReadDataStreamAsync("image/png");

📄 License

MIT License

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.0 129 8/22/2026
3.0.2 6,533 11/27/2024
2.1.2 309 11/15/2024 2.1.2 is deprecated because it has critical bugs.
2.1.1 10,466 2/9/2024
2.1.0 1,016 11/20/2023
2.0.0 678 9/23/2023
1.2.0 1,273 10/8/2022