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 — render a Material-style transient snackbar with an optional action link, color, screen position and auto-hide, in Delphi, C++ Builder and .NET.
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.
TsgcHTMLComponent_Snackbar
Scoped CSS + snackbar markup
Delphi, C++ Builder, .NET
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
The members you reach for most often.
Message is the text shown in the snackbar; SnackbarID assigns the element id used to dismiss it from JavaScript.
ActionText adds a trailing action button; set ActionHref to make it a link, otherwise it dismisses the snackbar on click.
Color takes a TsgcHTMLColor (default hcDark) and tints the snackbar background.
Position places it with sbBottom, sbTop, sbBottomLeft, sbBottomRight, sbTopLeft or sbTopRight (TsgcHTMLSnackbarPosition).
AutoHide removes the snackbar after Delay milliseconds (default 4000) via an emitted timeout script.
Build(message, color, actionText, position) returns a ready snackbar; HTML emits the scoped CSS, slide-in markup and auto-hide script.