Banner
Description
A notice strip with an icon tile, a title and badge, a message, an action and a dismiss button
A Banner is a notice the user should read but does not have to answer: an IconTile saying what kind of notice it is, a title with an optional badge, a message under it, an action at the far end and a dismiss button after that.
It is a plain IComponent, so it renders wherever you put it — at the top of a page, in a card, above a list. It is also what a Toast floats over the page: Toast().Show(banner) shows the same strip in both places.
For a larger, centred empty-state block with an illustration, use Message; for a persistent inbox of notices, Notification Center.
Usage
Create one with Banner(title, message) — either argument may be left out and filled in later with SetTitle / SetText, each of which also takes a component.
Secondary() (the default), Primary(), Success(), Warning() and Danger() pick the tone, or pass a BannerStyle to Style(...). Every colour the strip draws is derived from that one accent: the wash behind it, its border, the tile, the badge and the text. Each tone brings a default icon, which any SetIcon call replaces, and NoIcon() drops the tile altogether.
Action(text, onClick) puts a button at the far end in the banner's own tone; the Action(IComponent) overload takes whatever you build instead. OnDismiss(onDismiss, hide: true) shows the dismiss button and takes the banner out of the page when it is pressed — pass hide: false when something else removes it — and Dismiss() does the same from code. Compact() tightens the strip and Flat() drops the rounding and side rules, for one pinned edge to edge across a page.
A title or message with nothing the line breaker can break at — a path, a URL, an id — breaks mid-run rather than growing the strip past its content box and running under the dismiss button.
API reference
public enum BannerStyleThe tone a Banner is drawn in - the same set of tones a Button has, so a banner and the button that answers it can be told to mean the same thing.
- Namespace
- Tesserae
Values
| Name | Description |
|---|---|
| Secondary | The neutral tone: something the user should know, drawn in the page's own colors. |
| Primary | The accent tone: something worth pointing at, drawn in the theme's primary color. |
| Success | Something that went right. |
| Warning | Something that needs care but hasn't failed. |
| Danger | Something that failed, or that will if it is left alone. |
SecondaryThe neutral tone: something the user should know, drawn in the page's own colors.
PrimaryThe accent tone: something worth pointing at, drawn in the theme's primary color.
public sealed class Banner : ComponentBase<Banner, HTMLElement>A one-line-or-two notice strip: an IconTile, a title with an optional badge, a message under it, an action at the far end and a dismiss button after that. A banner is a plain IComponent, so it renders inline anywhere - at the top of a page, in a card, above a list. The same banner is also what Toast shows: pass one to Show and it is floated over the page instead, with its dismiss button hooked to the toast's own hiding.
Examples
Banner("3 items need your review", "They were flagged as high priority and are waiting in your queue.")
.Danger()
.SetIcon(UIcons.Fire)
.SetBadge("Priority")
.Action("Review now", () => OpenQueue())
.OnDismiss(() => Remember("queue-banner-dismissed"));
- Namespace
- Tesserae
- Inheritance
- ComponentBase<Banner, HTMLElement> → Banner
Constructors
| Name | Description |
|---|---|
| Banner | Initializes a new instance of this class, with the given title and message - either of which may be left out. |
Properties
| Name | Description |
|---|---|
| DismissHandler | Gets the handler the dismiss button runs, if one was set - so a host that wraps a banner (as Toast does) can chain its own hiding onto whatever the caller already asked for. |
| HidesOnDismiss | Gets whether dismissing takes the banner out of the DOM itself, which it does unless OnDismiss said otherwise. |
| CurrentStyle | Gets the tone the banner is drawn in. |
internal Action DismissHandler { get; private set; }Gets the handler the dismiss button runs, if one was set - so a host that wraps a banner (as Toast does) can chain its own hiding onto whatever the caller already asked for.
internal bool HidesOnDismiss { get; private set; }Gets whether dismissing takes the banner out of the DOM itself, which it does unless OnDismiss said otherwise.
Methods
| Name | Description |
|---|---|
| Style | Draws the banner in the given tone, and - unless the host has put an icon on the tile itself - puts that tone's own icon on it. |
| Secondary | Draws the banner in the neutral tone. |
| Primary | Draws the banner in the theme's primary color. |
| Success | Draws the banner in the success tone. |
| Warning | Draws the banner in the warning tone. |
| Danger | Draws the banner in the danger tone. |
| SetTitle | Sets the bold first line. A null or empty title drops the line entirely, leaving the message to stand on its own. |
| SetText | Sets the message under the title. A null or empty message drops the line. |
| SetBadge | Puts a badge beside the title - the reference the notice is about, what raised it. A null or empty value hides it. |
| SetIcon | Puts the given icon on the leading tile. Without a color the tile takes the banner's own tone; pass one to say something the tone doesn't. |
| NoIcon | Drops the leading tile, for a banner whose tone already says everything the icon would. |
| Action | Puts a button at the far end of the banner running the given handler - drawn in the banner's own tone, so the action reads as part of the notice rather than beside it. |
| OnDismiss | Shows a dismiss button after the action and runs the given handler when it is pressed. The banner takes itself out of the page as well unless hide says not to - which is what a host that removes the banner some other way (Toast) passes. |
| Dismiss | Dismisses the banner as though its dismiss button had been pressed: the handler set by OnDismiss runs, and the banner takes itself out of the page. |
| Compact | Tightens the banner, for one that sits inside something small. |
| Flat | Drops the rounded corners and the border, for a banner pinned edge to edge across a page. |
| Render | Renders the component's root HTML element. |
public Banner Style(BannerStyle style)Draws the banner in the given tone, and - unless the host has put an icon on the tile itself - puts that tone's own icon on it.
| Overload | |
|---|---|
| SetTitle(string) | Sets the bold first line. A null or empty title drops the line entirely, leaving the message to stand on its own. |
| SetTitle(IComponent) | Puts the given component on the first line in place of plain text. |
| Overload | |
|---|---|
| SetText(string) | Sets the message under the title. A null or empty message drops the line. |
| SetText(IComponent) | Puts the given component under the title in place of plain text. |
| Overload | |
|---|---|
| SetBadge(string) | Puts a badge beside the title - the reference the notice is about, what raised it. A null or empty value hides it. |
| SetBadge(IComponent) | Puts the given component beside the title in place of the plain badge. |
| Overload | |
|---|---|
| SetIcon(UIcons, string, UIconsWeight) | Puts the given icon on the leading tile. Without a color the tile takes the banner's own tone; pass one to say something the tone doesn't. |
| SetIcon(string, string, TextSize?) | Puts a few letters on the leading tile in place of a glyph - a code, a count, a file type. |
| SetIcon(IComponent, string) | Puts the given component on the leading tile - an Image, an Avatar, a Spinner. A null value takes the tile away, same as NoIcon. |
SetIcon(UIcons, string, UIconsWeight)
public Banner SetIcon(UIcons icon, string color = null, UIconsWeight weight = UIconsWeight.Regular)Puts the given icon on the leading tile. Without a color the tile takes the banner's own tone; pass one to say something the tone doesn't.
Parameters
- icon UIcons
- color string
- weight UIconsWeight
public Banner NoIcon()Drops the leading tile, for a banner whose tone already says everything the icon would.
| Overload | |
|---|---|
| Action(string, Action) | Puts a button at the far end of the banner running the given handler - drawn in the banner's own tone, so the action reads as part of the notice rather than beside it. |
| Action(IComponent) | Puts the given component at the far end of the banner - a button of the host's own, a link, a pair of them. A null value empties the slot. |
public Banner OnDismiss(Action onDismiss, bool hide = true)Shows a dismiss button after the action and runs the given handler when it is pressed. The banner takes itself out of the page as well unless hide says not to - which is what a host that removes the banner some other way (Toast) passes.
public Banner Dismiss()Dismisses the banner as though its dismiss button had been pressed: the handler set by OnDismiss runs, and the banner takes itself out of the page.
public Banner Compact(bool value = true)Tightens the banner, for one that sits inside something small.
public Banner Flat(bool value = true)Drops the rounded corners and the border, for a banner pinned edge to edge across a page.
See also
- Toast — floats a banner over the page
- Icon Tile — the leading tile
- Message — the larger empty-state block
- Notification Center — a persistent inbox rather than a strip
- Component catalog