Toast
TsgcHTMLComponent_Toast — 渲染一个 Bootstrap 5 toast 通知,带有标题、主体、时间戳、颜色和自动隐藏,由定位容器在屏幕上放置,适用于 Delphi、C++ Builder 和 .NET。
TsgcHTMLComponent_Toast — 渲染一个 Bootstrap 5 toast 通知,带有标题、主体、时间戳、颜色和自动隐藏,由定位容器在屏幕上放置,适用于 Delphi、C++ Builder 和 .NET。
一个 toast 组件,发出 Bootstrap 5 toast 标记。设置标题、主体和颜色,然后读取 HTML 属性 — 或调用静态 Build 辅助方法,并将 toast 包装在定位的 BuildContainer 中。
调用 Build(title, body, color, timestamp) 可快速创建 toast,并用 BuildContainer(toasts, position) 将其包装,或创建组件、设置 AutoHide 和 Delay,然后读取 HTML。
uses
sgcHTML_Enums, sgcHTML_Component_Toast;
// One-line static helper (primary form):
var
vToast: string;
begin
vToast := TsgcHTMLComponent_Toast.Build('Saved',
'Your changes were stored.', hcSuccess, 'just now');
WebModule.Response := TsgcHTMLComponent_Toast.BuildContainer(vToast,
tpTopEnd);
end;
// Or configure it fully:
var
oToast: TsgcHTMLComponent_Toast;
begin
oToast := TsgcHTMLComponent_Toast.Create(nil);
try
oToast.ToastID := 'saveToast';
oToast.Title := 'Saved';
oToast.Body := 'Your changes were stored.';
oToast.ColorStyle := hcSuccess;
oToast.Timestamp := 'just now';
oToast.AutoHide := True;
oToast.Delay := 4000;
WebModule.Response := oToast.HTML; // Bootstrap toast markup
finally
oToast.Free;
end;
end;
// includes: sgcHTML_Enums.hpp, sgcHTML_Component_Toast.hpp
// One-line static helper (primary form):
String toast = TsgcHTMLComponent_Toast::Build("Saved",
"Your changes were stored.", hcSuccess, "just now");
String html = TsgcHTMLComponent_Toast::BuildContainer(toast, tpTopEnd);
// Or configure it fully:
TsgcHTMLComponent_Toast *oToast = new TsgcHTMLComponent_Toast(NULL);
try
{
oToast->ToastID = "saveToast";
oToast->Title = "Saved";
oToast->Body = "Your changes were stored.";
oToast->ColorStyle = hcSuccess;
oToast->Timestamp = "just now";
oToast->AutoHide = true;
oToast->Delay = 4000;
String body = oToast->HTML; // Bootstrap toast markup
}
__finally
{
delete oToast;
}
using esegece.sgcWebSockets;
// One-line static helper (primary form):
string toast = TsgcHTMLComponent_Toast.Build("Saved",
"Your changes were stored.", TsgcHTMLColor.hcSuccess, "just now");
string html = TsgcHTMLComponent_Toast.BuildContainer(toast,
TsgcHTMLToastPosition.tpTopEnd);
// Or configure it fully:
var t = new TsgcHTMLComponent_Toast();
t.ToastID = "saveToast";
t.Title = "Saved";
t.Body = "Your changes were stored.";
t.ColorStyle = TsgcHTMLColor.hcSuccess;
t.Timestamp = "just now";
t.AutoHide = true;
t.Delay = 4000;
string body = t.HTML; // Bootstrap toast markup
您最常使用的成员。
Title 设置页眉文本,Body 设置消息,Timestamp 设置小时间标签,Icon 设置标题前的内联图标。
ColorStyle 接受一个 TsgcHTMLColor(如 hcSuccess 或 hcDanger);Color 接受原始的 Bootstrap 颜色名称字符串。
AutoHide 在 Delay 毫秒(默认 5000)后自动关闭 toast;将 AutoHide 设为 False 可使其保持固定。
ToastID 分配元素 id,以便您可以从 JavaScript 显示或隐藏特定的 toast。
Build(title, body, color, timestamp) 返回一个 toast;BuildContainer(toasts, position) 将它们包装在固定的 toast-container(TsgcHTMLToastPosition)中。
HTML 返回完整的 Bootstrap toast 标记 — 直接提供服务,或将其赋给页面模板的 BodyContent。