Skip to content

bClipboard is a Blazor library that simplifies clipboard operations in your Blazor applications. With bClipboard, developers can easily copy text to and read text from the clipboard using simple and intuitive APIs. This library leverages JavaScript interop to provide seamless clipboard functionality within Blazor.

License

Notifications You must be signed in to change notification settings

mabroukmahdhi/bClipboard

Repository files navigation

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.

About

bClipboard is a Blazor library that simplifies clipboard operations in your Blazor applications. With bClipboard, developers can easily copy text to and read text from the clipboard using simple and intuitive APIs. This library leverages JavaScript interop to provide seamless clipboard functionality within Blazor.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published