Extras
CopyButton
Bit.BlazorUI.ExtrasClipboardButtonCopyToClipboardButton
BitCopyButton puts a value on the clipboard and confirms it, because a copy button that gives no feedback leaves the user guessing whether it worked: for CopiedDuration after the copy its glyph is a check mark, its text says Copied, and a polite live region announces it. It is a BitButton, with the button's variants, sizes and colors, an icon button when it is given no Text, and is disabled while it has no Value.
Notes
To use this component, you need to install the
Bit.BlazorUI.Extras(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. It
only confirms a copy that happened: one that still fails confirms nothing (taking off a confirmation still showing)
and raises OnCopyFailed. Its
default texts (Copy, Copied) come from BitStrings, which translates them for the whole app.
Usage
Every example is live. Open its code to see exactly what produced the component running underneath.
Basic
Give it the Value to copy. Without a Text it is an icon button named Copy. Press it: for two seconds
the glyph is a check mark and its name says Copied, and a screen reader hears it.
dotnet add package Bit.BlazorUI.Extras
Text & CopiedText
Text shows a text beside the icon, and CopiedText takes its place while the copy is confirmed
(Copied by default). The live region announces the copied text too. Without a Text, AriaLabel names
the icon button (and is its tooltip) in place of Copy.
Icons
IconName replaces the Copy glyph, and CopiedIconName the check mark the button shows once it copied.
Variant
The button's three variants: Fill (the default), Outline and Text.
CopiedDuration & OnCopy
CopiedDuration is how long the copied state stays on the button (two seconds by default); a copy while it
is showing starts it over. OnCopy is raised with the value once it is on the clipboard, and
OnCopyFailed with the error when the browser could not put it there - never both.
Copied 0 time(s)
Value
Value 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. An empty text that is given as such
(Value="") 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 OnCopy.
Cascading parameters
BitParams with a BitCopyButtonParams sets the look, the texts and the CopiedDuration of every
copy button inside it; a parameter of the button itself still wins (the third has its own variant).
Color
The button's general colors, Primary being the default.
External Icons
The built-in icon set is not a requirement. Icon and CopiedIcon take a BitIconInfo that
renders whatever CSS classes you give it, so any icon font works - BitIconInfo.Fa for FontAwesome,
BitIconInfo.Bi for Bootstrap Icons, or BitIconInfo.Css for anything else. Just remember to
reference the library's stylesheet yourself.
Size
The button's three sizes: Small, Medium (the default) and Large.
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 BitButton,
restyled through the public --bit-Button-* variables, from :root, an ancestor or Style.
RTL
Use BitCopyButton in right-to-left (RTL).
API
Every parameter, public member, sub-class and enum this component exposes.
BitCopyButton parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Classes | BitCopyButtonClassStyles? | null | Custom CSS classes for different parts of the copy button. |
| Color | BitColor? | null | The general color of the button. Left unset, the button is primary unless the --bit-Button-* variables say otherwise. |
| CopiedDuration | TimeSpan | TimeSpan.FromSeconds(2) | How long the copied state - the copied glyph and text - stays on the button after a copy, before it goes back to what it was. Another copy while it shows starts it over. A zero or negative duration confirms nothing: the copy is made and OnCopy raised, but the copied state is never shown or announced. |
| CopiedIcon | BitIconInfo? | null | The icon the button shows while it is in the copied state, using custom CSS classes for external icon libraries. Takes precedence over CopiedIconName when both are set. With neither set, the button shows a check mark (Accept). |
| CopiedIconName | string? | null | The name of the built-in Fluent UI icon the button shows while it is in the copied state. With neither this nor CopiedIcon set, the button shows a check mark (Accept). |
| CopiedText | string? | null | The text the button carries, and the live region announces, while it is in the copied state. When null, the Copied text of the strings in force is used (BitStrings.Copied, "Copied"). |
| Icon | BitIconInfo? | null | The icon of the button, using custom CSS classes for external icon libraries. Takes precedence over IconName when both are set. With neither set, the button shows the Copy glyph. |
| IconName | string? | null | The name of the built-in Fluent UI icon of the button. With neither this nor Icon set, the button shows the Copy glyph. |
| OnCopy | EventCallback<string> | The callback raised once the value is on the clipboard, with the value that was copied. | |
| OnCopyFailed | EventCallback<Exception> | The callback raised when the browser could not put the value on the clipboard (a permission denied, a copy command refused), with the error it gave. The button confirms nothing, and a confirmation of an earlier copy still showing is taken off. | |
| Size | BitSize? | null | The size of the button. Left unset, the button is medium unless the --bit-Button-* variables say otherwise. |
| Styles | BitCopyButtonClassStyles? | null | Custom CSS styles for different parts of the copy button. |
| Text | string? | null | The text of the button; CopiedText takes its place while the button is in the copied state. When null, the button is an icon button named by the Copy text of the strings in force (BitStrings.Copy, "Copy") - or by AriaLabel - which is also its tooltip. |
| Value | string? | null | The text to put on the clipboard, read when the button is pressed. A null value disables the button, the way Disabled does; an empty text is copied like any other. A confirmation still showing is taken off once the value changes. |
| Variant | BitVariant? | null | The visual variant of the button. Left unset, the button is Fill. |
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. |
BitCopyButtonClassStyles properties
| Name | Type | Default value | Description |
|---|---|---|---|
| Root | string? | null | Custom CSS classes/styles for the root element of the BitCopyButton. |
| Button | BitButtonClassStyles? | null | Custom CSS classes/styles for the BitButton of the BitCopyButton. |
| LiveRegion | string? | null | Custom CSS classes/styles for the visually hidden live region of the BitCopyButton, which announces the copy. |
BitColor enum
| Name | Value | Description |
|---|---|---|
| Primary | 0 | Primary general color. |
| Secondary | 1 | Secondary general color. |
| Tertiary | 2 | Tertiary general color. |
| Info | 3 | Info general color. |
| Success | 4 | Success general color. |
| Warning | 5 | Warning general color. |
| SevereWarning | 6 | SevereWarning general color. |
| Error | 7 | Error general color. |
| PrimaryBackground | 8 | Primary background color. |
| SecondaryBackground | 9 | Secondary background color. |
| TertiaryBackground | 10 | Tertiary background color. |
| PrimaryForeground | 11 | Primary foreground color. |
| SecondaryForeground | 12 | Secondary foreground color. |
| TertiaryForeground | 13 | Tertiary foreground color. |
| PrimaryBorder | 14 | Primary border color. |
| SecondaryBorder | 15 | Secondary border color. |
| TertiaryBorder | 16 | Tertiary border color. |
BitSize enum
| Name | Value | Description |
|---|---|---|
| Small | 0 | The small size. |
| Medium | 1 | The medium size. |
| Large | 2 | The large size. |
BitVariant enum
| Name | Value | Description |
|---|---|---|
| Fill | 0 | Fill styled variant. |
| Outline | 1 | Outline styled variant. |
| Text | 2 | Text styled variant. |
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.