Skip to content

Latest commit

 

History

History
82 lines (56 loc) · 2.49 KB

README.md

File metadata and controls

82 lines (56 loc) · 2.49 KB

bClipboard

bClipboard is a Blazor library that simplifies clipboard operations for Blazor applications. It provides methods to copy text to and read text from the clipboard using JavaScript interop.

Nuget Nuget .NET 6 .NET 7 .NET 8

Features

  • Copy to Clipboard: Easily copy text to the clipboard.
  • Read from Clipboard: Read text from the clipboard.

Installation

To install bClipboard, you need to add the NuGet package to your Blazor project:

dotnet add package bClipboard

Usage

Register the Clipboard Service

In your Program.cs file, register the ClipboardService with the dependency injection container.

[...]
using bClipboard.Extensions;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");

builder.Services.AddBClipboardService();

await builder.Build().RunAsync();

Use the Clipboard Service in Your Blazor Component

Inject the IClipboardService into your Blazor component and use its methods to copy to and read from the clipboard.

@page "/clipboard"
@inject IClipboardService ClipboardService

<h3>Clipboard Example</h3>

<input @bind="textToCopy" placeholder="Enter text to copy" />
<button @onclick="CopyToClipboard">Copy Text</button>

<p>Clipboard Content: @clipboardContent</p>
<button @onclick="ReadFromClipboard">Read Clipboard</button>

@code {
    private string textToCopy;
    private string clipboardContent;

    private async Task CopyToClipboard()
    {
        await ClipboardService.CopyToClipboardAsync(textToCopy);
    }

    private async Task ReadFromClipboard()
    {
        clipboardContent = await ClipboardService.ReadFromClipboardAsync();
    }
}

JavaScript Interop

The library uses a JavaScript file (bclipboard.js) for clipboard operations.

Contributing

We welcome contributions! Please see our contributing guidelines for more details.