Extras
MessageBox
BitMessageBox is a pre-implemented box for showing a message with a title, a body, an optional severity icon and the set of buttons it is answered with (Ok, Ok/Cancel, Yes/No, Yes/No/Cancel, or none at all). It renders inline, inside a BitModal, or - the usual way - through the BitMessageBoxService, which shows it in a modal and hands back the BitMessageBoxResult it was answered with. Every part of it takes a template, the answer can be guarded before it is handed over, and the whole box scales with its size.
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.
Usage
Every example is live. Open its code to see exactly what produced the component running underneath.
Basic
It's a title
Buttons
Ok
OkCancel
YesNo
YesNoCancel
None
Order, focus & emphasis
Reversed
Default button
Delete the file?
Icon
IconName
IconTemplate
Close button
No close button
Custom close button
Templates
Delete the workspace?
- 18 projects
- 4 shared libraries
BitModal
BitModalService
BitMessageBoxService
Confirmation
Guarding the answer
Delete the file?
Color
Info
Success
Warning
SevereWarning
Error
Primary
External Icons
Css, Fa and Bi). When both are set, Icon wins.
Remember to reference the icon library's stylesheet in your app.
FontAwesome
Bootstrap Icons
Size
Small
Medium
Large
Style & Class
It's a title
It's a title
RTL
عنوان پیام
API
Every parameter, public member, sub-class and enum this component exposes.
BitMessageBox parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| AutoFocus | bool | false | Moves the focus onto the default action button once the message box is rendered, and marks it with the autofocus attribute the surrounding layer reads, so a message box kept mounted between showings lands the focus on it on every opening. The BitMessageBoxService defaults it to true for the message boxes it shows. |
| AutoLoading | bool | false | Enables the loading state of the action button that was pressed for as long as its callback runs. |
| Body | string? | null | The body of the message box. Line breaks in it are kept and long lines wrap. |
| BodyTemplate | RenderFragment? | null | The template of the body of the message box, which takes the place of Body. |
| Buttons | BitMessageBoxButtons | BitMessageBoxButtons.Ok | The set of buttons the message box renders in its footer. |
| ButtonColor | BitColor? | null | The color of the action buttons of the message box. Tertiary by default. |
| CancelText | string? | null | The text of the Cancel button. |
| ChildContent | RenderFragment? | null | The alias of BodyTemplate. |
| Classes | BitMessageBoxClassStyles? | null | Custom CSS classes for different parts of the message box. |
| CloseButtonTitle | string? | null | The title (and aria-label) of the close button, for accessibility and localization. Defaults to "Close". |
| CloseIcon | BitIconInfo? | null | The icon of the close button, provided as custom CSS classes of an external icon library. |
| CloseIconName | string? | null | The name of the icon of the close button, from the built-in Fluent UI icons. |
| Color | BitColor? | null | The general color of the message box, which paints its leading icon and - unless IconName says otherwise - picks the glyph. |
| DefaultButton | BitMessageBoxResult? | null | The action button that AutoFocus moves the focus onto, or None for the close button. Defaults to the affirmative button of the set (Ok, or Yes), and to the close button for a message box that renders no action buttons. |
| FooterTemplate | RenderFragment? | null | The template used to render the footer of the message box, which takes the place of its action buttons. The controls in it are the page's own, so AnswerAsync is what ends the message box with an answer. |
| HeaderTemplate | RenderFragment? | null | The template used to render the header of the message box, which takes the place of its icon, title and close button. |
| HideIcon | bool | false | Removes the leading icon of the message box, which a Color would otherwise bring with it. |
| Icon | BitIconInfo? | null | The leading icon of the message box, provided as custom CSS classes of an external icon library. |
| IconAriaLabel | string? | null | The accessible name of the leading icon, which turns it from decoration into an image that is announced. |
| IconName | string? | null | The name of the leading icon of the message box, from the built-in Fluent UI icons. If unset, the icon is selected automatically based on Color. |
| IconTemplate | RenderFragment? | null | The template used to render the leading icon of the message box. |
| NoText | string? | null | The text of the No button. |
| OkText | string? | null | The text of the Ok button. |
| OnBeforeResult | EventCallback<BitMessageBoxBeforeResultArgs> | The event callback asked before the message box hands over an answer. Setting Cancel on its arguments refuses the answer and keeps the message box open. It guards every button the message box draws, the close button included. | |
| OnCancel | EventCallback | The event callback for the Cancel button of the message box. | |
| OnClose | EventCallback | The event callback for closing the message box, raised by every button it renders of its own - after the callback of that button and after OnResult. | |
| OnNo | EventCallback | The event callback for the No button of the message box. | |
| OnOk | EventCallback | The event callback for the Ok button of the message box. | |
| OnResult | EventCallback<BitMessageBoxResult> | The event callback for the answer the message box was given. The close button answers with None, the others with the result they stand for. | |
| OnYes | EventCallback | The event callback for the Yes button of the message box. | |
| PrimaryButtonColor | BitColor? | null | The color of the affirmative action button (Ok, or Yes), which falls back to ButtonColor where it is not set. |
| Reversed | bool | false | Renders the action buttons in the reverse order, which also reverses the order the keyboard reaches them in. |
| ShowCloseButton | bool | true | Renders the close button in the header of the message box. |
| Size | BitSize? | null | The size of the message box, which scales its inset, its title, its body text and its leading icon together. |
| Styles | BitMessageBoxClassStyles? | null | Custom CSS styles for different parts of the message box. |
| Title | string? | null | The title of the message box. |
| YesText | string? | null | The text of the Yes button. |
BitMessageBox public members
| Name | Type | Default value | Description |
|---|---|---|---|
| AnswerAsync | Task | Answers the message box as though the button standing for that result had been pressed, down the same road: the guard is asked first, then the callback of that answer, OnResult and OnClose. This is how a footer of your own ends the message box with a real answer. | |
| Result | BitMessageBoxResult | BitMessageBoxResult.None | The answer the last showing of this message box was given, or None while it has not been answered. |
| FocusAsync | ValueTask | Moves the focus onto the default action button of the message box, or onto its close button where it renders no action buttons of its own. |
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. |
| 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. |
| Id | string? | null | Gets or sets the unique identifier for the component's root element. |
| IsEnabled | bool | true | Gets or sets a value indicating whether the component is enabled and can respond to user interaction. |
| 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. |
BitMessageBoxClassStyles properties
| Name | Type | Default value | Description |
|---|---|---|---|
| Root | string? | null | Custom CSS classes/styles for the root element of the BitMessageBox. |
| Container | string? | null | Custom CSS classes/styles for the container of the BitMessageBox. |
| Header | string? | null | Custom CSS classes/styles for the header of the BitMessageBox. |
| IconContainer | string? | null | Custom CSS classes/styles for the icon container of the BitMessageBox. |
| Icon | string? | null | Custom CSS classes/styles for the icon of the BitMessageBox. |
| Title | string? | null | Custom CSS classes/styles for the title of the BitMessageBox. |
| Spacer | string? | null | Custom CSS classes/styles for the BitSpacer of the BitMessageBox. |
| CloseButton | BitButtonClassStyles? | null | Custom CSS classes/styles for the CloseButton of the BitMessageBox. |
| Body | string? | null | Custom CSS classes/styles for the body of the BitMessageBox. |
| Footer | string? | null | Custom CSS classes/styles for the footer of the BitMessageBox. |
| ActionButton | BitButtonClassStyles? | null | Custom CSS classes/styles for every action button of the BitMessageBox that was given none of its own. |
| OkButton | BitButtonClassStyles? | null | Custom CSS classes/styles for the OkButton of the BitMessageBox. |
| CancelButton | BitButtonClassStyles? | null | Custom CSS classes/styles for the CancelButton of the BitMessageBox. |
| YesButton | BitButtonClassStyles? | null | Custom CSS classes/styles for the YesButton of the BitMessageBox. |
| NoButton | BitButtonClassStyles? | null | Custom CSS classes/styles for the NoButton of the BitMessageBox. |
BitMessageBoxBeforeResultArgs properties
The arguments of the OnBeforeResult callback, which is asked before a message box hands over the answer a button of its own was pressed for.
| Name | Type | Default value | Description |
|---|---|---|---|
| Result | BitMessageBoxResult | BitMessageBoxResult.None | The answer that is about to be handed over: the result of the button that was pressed, or None for the close button. Read-only - Cancel is the guard's say over it. |
| Cancel | bool | false | Set to true to keep the message box open and hand over no answer. |
BitMessageBoxParameters properties
The set of parameters a message box shown through the BitMessageBoxService is customized with. Every member is nullable and null means "not set", so the BitMessageBox default stands.
| Name | Type | Default value | Description |
|---|---|---|---|
| AutoFocus | bool? | null | Moves the focus onto the default action button. Defaults to true for a message box shown through the service. |
| AutoLoading | bool? | null | Enables the loading state of the action button that was pressed for as long as its callback runs. |
| Body | string? | null | The body of the message box, which is also what describes the dialog it is shown in. |
| BodyTemplate | RenderFragment? | null | The template of the body of the message box. |
| Buttons | BitMessageBoxButtons? | null | The set of buttons the message box renders in its footer. |
| ButtonColor | BitColor? | null | The color of the action buttons of the message box. |
| CancelText | string? | null | The text of the Cancel button. |
| Classes | BitMessageBoxClassStyles? | null | Custom CSS classes for different parts of the message box. |
| CloseButtonTitle | string? | null | The title (and aria-label) of the close button. |
| CloseIcon | BitIconInfo? | null | The icon of the close button, provided as custom CSS classes of an external icon library. |
| CloseIconName | string? | null | The name of the icon of the close button, from the built-in Fluent UI icons. |
| Color | BitColor? | null | The general color of the message box, which is the severity of its message. Warning, SevereWarning and Error are announced as alerts. |
| DefaultButton | BitMessageBoxResult? | null | The action button the focus is moved onto, or None for the close button. |
| Dir | BitDir? | null | The general directionality of the message box and of the modal it is shown in. |
| FooterTemplate | RenderFragment? | null | The template used to render the footer of the message box. |
| HeaderTemplate | RenderFragment? | null | The template used to render the header of the message box. |
| HideIcon | bool? | null | Removes the leading icon of the message box. |
| Icon | BitIconInfo? | null | The leading icon of the message box, provided as custom CSS classes of an external icon library. |
| IconAriaLabel | string? | null | The accessible name of the leading icon. |
| IconName | string? | null | The name of the leading icon of the message box, from the built-in Fluent UI icons. |
| IconTemplate | RenderFragment? | null | The template used to render the leading icon of the message box. |
| Id | string? | null | The id of the rendered message box. The service generates one when none is given, since the ids of the title and the body are derived from it. |
| Modal | BitModalParameters? | null | The parameters of the BitModal the message box is shown in. What is set here wins over the values the service works out on its own. |
| NoText | string? | null | The text of the No button. |
| OkText | string? | null | The text of the Ok button. |
| OnBeforeResult | EventCallback<BitMessageBoxBeforeResultArgs> | The event callback asked before the message box hands over an answer. Setting Cancel on its arguments keeps the message box open and leaves the caller of the service still waiting. | |
| Persistent | bool? | null | Keeps the message box alive through the lifecycle of the application until it is closed, rather than only for as long as the modal container that renders it. |
| PrimaryButtonColor | BitColor? | null | The color of the affirmative action button (Ok, or Yes), which falls back to ButtonColor. |
| Reversed | bool? | null | Renders the action buttons in the reverse order. |
| ShowCloseButton | bool? | null | Renders the close button in the header of the message box. |
| Size | BitSize? | null | The size of the message box. |
| Styles | BitMessageBoxClassStyles? | null | Custom CSS styles for different parts of the message box. |
| Title | string? | null | The title of the message box, which is also what names the dialog it is shown in. |
| YesText | string? | null | The text of the Yes button. |
BitMessageBoxResult enum
| Name | Value | Description |
|---|---|---|
| None | 0 | The message box was dismissed rather than answered: its close button, or - for one shown through the service - the Escape key, a click on the overlay, or the page closing the modal itself. |
| Ok | 1 | The Ok button ended the showing. |
| Cancel | 2 | The Cancel button ended the showing. |
| Yes | 3 | The Yes button ended the showing. |
| No | 4 | The No button ended the showing. |
BitSize enum
| Name | Value | Description |
|---|---|---|
| Small | 0 | The small size. |
| Medium | 1 | The medium size. |
| Large | 2 | The large size. |
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.