Snackbar

TsgcHTMLComponent_Snackbar — render a Material-style transient snackbar with an optional action link, color, screen position and auto-hide, in Delphi, C++ Builder and .NET.

TsgcHTMLComponent_Snackbar

A snackbar component that emits scoped CSS plus a positioned markup block. Set the message, color and position, then read the HTML property — or call the static Build helper for a one-liner.

Component class

TsgcHTMLComponent_Snackbar

Renders

Scoped CSS + snackbar markup

Languages

Delphi, C++ Builder, .NET

Build it in one line, or configure it fully

Call Build(message, color, actionText, position) for a quick snackbar, or create the component, set ActionHref, AutoHide and Delay, then read HTML.

uses
  sgcHTML_Enums, sgcHTML_Component_Snackbar;

// One-line static helper (primary form):
var
  vHTML: string;
begin
  vHTML := TsgcHTMLComponent_Snackbar.Build('Message sent.',
    hcSuccess, 'Undo', sbBottomRight);
  WebModule.Response := vHTML;
end;

// Or configure it fully:
var
  oSB: TsgcHTMLComponent_Snackbar;
begin
  oSB := TsgcHTMLComponent_Snackbar.Create(nil);
  try
    oSB.Message := 'Message sent.';
    oSB.Color := hcSuccess;
    oSB.Position := sbBottomRight;
    oSB.ActionText := 'Undo';
    oSB.ActionHref := '/undo';
    oSB.AutoHide := True;
    oSB.Delay := 4000;

    WebModule.Response := oSB.HTML;   // scoped CSS + snackbar markup
  finally
    oSB.Free;
  end;
end;
// includes: sgcHTML_Enums.hpp, sgcHTML_Component_Snackbar.hpp

// One-line static helper (primary form):
String html = TsgcHTMLComponent_Snackbar::Build("Message sent.",
  hcSuccess, "Undo", sbBottomRight);

// Or configure it fully:
TsgcHTMLComponent_Snackbar *oSB = new TsgcHTMLComponent_Snackbar(NULL);
try
{
  oSB->Message = "Message sent.";
  oSB->Color = hcSuccess;
  oSB->Position = sbBottomRight;
  oSB->ActionText = "Undo";
  oSB->ActionHref = "/undo";
  oSB->AutoHide = true;
  oSB->Delay = 4000;

  String html = oSB->HTML;   // scoped CSS + snackbar markup
}
__finally
{
  delete oSB;
}
using esegece.sgcWebSockets;

// One-line static helper (primary form):
string html = TsgcHTMLComponent_Snackbar.Build("Message sent.",
    TsgcHTMLColor.hcSuccess, "Undo", TsgcHTMLSnackbarPosition.sbBottomRight);

// Or configure it fully:
var sb = new TsgcHTMLComponent_Snackbar();
sb.Message = "Message sent.";
sb.Color = TsgcHTMLColor.hcSuccess;
sb.Position = TsgcHTMLSnackbarPosition.sbBottomRight;
sb.ActionText = "Undo";
sb.ActionHref = "/undo";
sb.AutoHide = true;
sb.Delay = 4000;

string html = sb.HTML;   // scoped CSS + snackbar markup

Key properties & methods

The members you reach for most often.

Content

Message is the text shown in the snackbar; SnackbarID assigns the element id used to dismiss it from JavaScript.

Action

ActionText adds a trailing action button; set ActionHref to make it a link, otherwise it dismisses the snackbar on click.

Color

Color takes a TsgcHTMLColor (default hcDark) and tints the snackbar background.

Position

Position places it with sbBottom, sbTop, sbBottomLeft, sbBottomRight, sbTopLeft or sbTopRight (TsgcHTMLSnackbarPosition).

Auto-hide

AutoHide removes the snackbar after Delay milliseconds (default 4000) via an emitted timeout script.

Static helper & output

Build(message, color, actionText, position) returns a ready snackbar; HTML emits the scoped CSS, slide-in markup and auto-hide script.

Keep exploring

All sgcHTML ComponentsBrowse the full feature matrix of 60+ components.
Download Free TrialThe 30-day trial ships the 60.HTML demo projects.
PricingSingle, Team and Site licenses with full source code.

Ready to Get Started?

Download the free trial and start building web UIs in Delphi, C++ Builder and .NET.