AI
AiCopyButton
Bit.BlazorUI.AICopyToClipboard
BitAiCopyButton copies a text to the clipboard and confirms it, because a copy button that gives no feedback leaves the user guessing whether it worked: for a moment after the copy its glyph is a check mark, its name says Copied, and a polite live region announces it. It is an icon button by default, with its label beside the icon on request, and is disabled while it has no Content.
Notes
To use this component, you need to install the
Bit.BlazorUI.AI(opens in a new tab)
nuget package, as described in the Optional steps of the
Getting started page.
The button needs no service. It writes through the Clipboard API of the browser, which only works in a secure context
(https, or localhost); elsewhere, and where the browser refuses it, it falls back to the copy command of the page, and
it only confirms a copy that happened. Its texts (Copy, Copied) come from the strings in force, which a
BitAiOptionsProvider localizes. The code blocks and the
message actions of a chat carry one; see the basic scenario.
Usage
Every example is live. Open its code to see exactly what produced the component running underneath.
Basic
Give it the Content to copy. Press it: for two seconds the glyph is a check mark and the name of the button
says Copied, and a screen reader hears it.
dotnet add package Bit.BlazorUI.AI
Label & ShowLabel
Label renames the button - its tooltip and its accessible name - and ShowLabel shows the name beside the
icon, Copied included while the confirmation lasts.
ConfirmationDuration & OnCopied
ConfirmationDuration is how long the confirmation stays on the button (two seconds by default); a copy while it
is showing starts it over. OnCopied is raised once the text is on the clipboard - never for a copy the browser
refused.
Copied 0 time(s)
Content
Content is read when the button is pressed, so it can follow what changes - here what is typed. While it is
null the button is disabled: here until something is typed, and again once the field is cleared, which sets the
bound value back to null. An empty text that is given as such (Content="") is still copied.
Disabled
A Disabled copy button copies nothing, whoever presses it - the click a screen reader or a script still
delivers to a disabled button included - and raises no OnCopied. A button with no Content is disabled
the same way.
Cascading parameters
BitParams with a BitAiCopyButtonParams sets ShowLabel, ConfirmationDuration and the look of
every copy button inside it; a parameter of the button itself still wins (the third hides its label).
Style & Class
Style and Class reach the root, Styles and Classes its button (BitButtonClassStyles) and its
visually hidden live region. The copy button has no CSS variables of its own: the button is a neutral BitButton of
the Text variant, restyled through the public --bit-Button-* variables, from :root, an ancestor or
Style.
RTL
In right-to-left text the label of the button stands at the left of its icon, whether the direction comes from
Dir or from a dir attribute around it.
API
Every parameter, public member, sub-class and enum this component exposes.
BitAiCopyButton parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Classes | BitAiCopyButtonClassStyles? | null | Custom CSS classes for different parts of the copy button. |
| ConfirmationDuration | TimeSpan | TimeSpan.FromSeconds(2) | How long the confirmation - the check mark and the Copied name - stays on the button after a copy. Another copy while it shows starts it over. |
| Content | string? | null | The text to copy, read when the button is pressed. A null value disables the button; an empty text is copied like any other. |
| Label | string? | null | The name of the button: its tooltip, its accessible name, and its text when ShowLabel is set. While the confirmation lasts the Copied text of the strings in force takes its place. When null, the Copy text of the strings in force is used (BitAiStrings.Copy, "Copy"). |
| OnCopied | EventCallback | Raised after the text has been put on the clipboard - never for a copy the browser refused. | |
| ShowLabel | bool | false | Shows the name of the button beside its icon. |
| Styles | BitAiCopyButtonClassStyles? | null | Custom CSS styles for different parts of the copy button. |
BitComponentBase parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| AriaLabel | string? | null | Gets or sets the accessible label for the component, used by assistive technologies. |
| Class | string? | null | Gets or sets the CSS class name(s) to apply to the rendered element. |
| Dir | BitDir? | null | Gets or sets the text directionality for the component's content. |
| Disabled | bool | false | Gets or sets a value indicating whether the component is disabled and cannot respond to user interaction. |
| ForceAnimation | bool | false | Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested. |
| HtmlAttributes | Dictionary<string, object> | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. An attribute written on the component wins over an entry of the same name. |
| Id | string? | null | Gets or sets the unique identifier for the component's root element. |
| Style | string? | null | Gets or sets the CSS style string to apply to the rendered element. |
| TabIndex | string? | null | Gets or sets the tab order index for the component when navigating with the keyboard. |
| Visibility | BitVisibility | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. |
BitComponentBase public members
| Name | Type | Default value | Description |
|---|---|---|---|
| UniqueId | Guid | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. |
| RootElement | ElementReference | Gets the reference to the root HTML element associated with this component. |
BitAiCopyButtonClassStyles properties
| Name | Type | Default value | Description |
|---|---|---|---|
| Root | string? | null | Custom CSS classes/styles for the root element of the BitAiCopyButton. |
| Button | BitButtonClassStyles? | null | Custom CSS classes/styles for the BitButton of the BitAiCopyButton. |
| LiveRegion | string? | null | Custom CSS classes/styles for the visually hidden live region of the BitAiCopyButton, which announces the copy. |
BitVisibility enum
| Name | Value | Description |
|---|---|---|
| Visible | 0 | The content of the component is visible. |
| Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). |
| Collapsed | 2 | The component is hidden (display:none). |
BitDir enum
| Name | Value | Description |
|---|---|---|
| Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). |
| Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). |
| Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. |
Feedback
Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.