ClipLazor 4.0.0
dotnet add package ClipLazor --version 4.0.0
NuGet\Install-Package ClipLazor -Version 4.0.0
<PackageReference Include="ClipLazor" Version="4.0.0" />
<PackageVersion Include="ClipLazor" Version="4.0.0" />
<PackageReference Include="ClipLazor" />
paket add ClipLazor --version 4.0.0
#r "nuget: ClipLazor, 4.0.0"
#:package ClipLazor@4.0.0
#addin nuget:?package=ClipLazor&version=4.0.0
#tool nuget:?package=ClipLazor&version=4.0.0
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+).
✨ 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 automaticCopied! ✔feedback. - 📋
<ClipboardPasteZone>Component: Paste & dropzone container for capturingCtrl+Vand 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
WriteHtmlAsyncandReadHtmlAsyncwith automatic plain text fallback. - 🖼️ Binary & Image Streams: Read and write binary data using
ReadOnlyMemory<byte>orStream. - ⚡ Cancellation Support: Full
CancellationTokensupport across all async methods.
📦 Installation
- Install ClipLazor via the .NET CLI:
dotnet add package ClipLazor
- 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
| Product | Versions 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. |
-
net10.0
- Microsoft.AspNetCore.Components.Web (>= 10.0.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.