Skip to content

Toast ​

An ink-colored pill overlay that owns its own visibility and timing. It supports semantic types, auto-hide, and positioning.

Spec source: lh-ui-core/specs/toast.json · Golden cases: lh-ui-core/cases/toast.json (6 cases, translated into xUnit tests)

Basic usage ​

The imperative interface (the spec's show / hide / tick) lands on this end as methods plus an internal timer: Show(text) makes the toast visible and resets the timer; Hide() hides it immediately without firing Close. The timer is carried by a DispatcherTimer; when it expires the toast auto-hides and fires Close.

9:41Toast basics
Saved

HTML mock preview (Windows / WinUI 3 appearance), not an on-device render

csharp
var controller = new LhToastController();
var toast = new LhToast
{
    Duration = 2000,
    Position = LhToastPosition.Center,
    Controller = controller,
};
toast.Close += () => { /* Fired after the timer expires and the toast auto-hides */ };

// The host must mount the toast as the last child of the page Grid (elevation zIndex.toast)
controller.Show("Saved");

Semantic types ​

When Type is not default, a dot in the matching semantic color is drawn before the text (its diameter equals the font size).

9:41Toast types
Saved successfully
Please check your network connection
Deletion failed

HTML mock preview (Windows / WinUI 3 appearance), not an on-device render

Positioning ​

Position decides the placement inside the available area; the top and bottom ends keep a spacing.xl margin (center has none).

9:41Toast positions
Top toast
Bottom toast

HTML mock preview (Windows / WinUI 3 appearance), not an on-device render

API ​

Props ​

PropDescriptionTypeDefault
CloseFired when the timer expires and the toast auto-hides; not fired by an explicit Hide()event Action—
TypeSemantic type; when not default a dot in the matching semantic color is drawn before the textLhToastTypeDefault
DurationAuto-hide duration (milliseconds)int2000
PositionPlacement inside the available areaLhToastPositionCenter
ControllerHost-side handle (optional; registers Show / Hide after Loaded)LhToastController?null

Methods ​

MethodDescription
Show(string text)Shows the toast text and resets the auto-hide timer
Hide()Hides immediately without firing Close

LhToastType ​

ValueDot color
DefaultNo dot drawn
Successcolor.success.default
Warningcolor.warning.default
Dangercolor.danger.default
Infocolor.info.default

LhToastPosition ​

ValuePlacement
TopTop (a spacing.xl margin at the top end)
CenterCentered (no margin)
BottomBottom (a spacing.xl margin at the bottom end)

Token Reference ​

TokenUsage
toast.fontSizeText font size (also the dot diameter)
toast.paddingHorizontal / paddingVerticalPill paddings
toast.borderRadiusPill corner radius
toast.gapSpacing between the dot and the text
color.inkPill background color
color.onPrimaryText color
color.{success,warning,danger,info}.defaultSemantic dots
zIndex.toastOverlay elevation
spacing.xlTop and bottom end margins
typography.fontFamilyChinese-style serif font stack

Golden Case Reference ​

How the 6 assertions of cases/toast.json map to xUnit tests (tests/LhToastTests.cs):

case idAssertionLocal test
show-makes-visibleshow makes it visible and renders the textShow_Makes_Visible
auto-hides-after-durationThe timer expiring auto-hides it and fires onCloseAuto_Hides_After_Duration
tick-before-duration-keeps-visibleStaying before the timer keeps it visibleTick_Before_Duration_Keeps_Visible
hide-is-silentAn explicit hide does not fire onCloseHide_Is_Silent
success-type-uses-success-tokenThe success type consumes the semantic and ink tokensSuccess_Type_Uses_Success_Token
hidden-emits-no-commandsWhen invisible no draw commands are emittedHidden_Emits_No_Commands

Plus dark-mode suites: Dark_Colors_Come_From_Dark_Tokens / Dimensions_Are_Identical_In_Dark_Mode. Run: cd lh-ui-windows && dotnet test.

lh-ui native bloodline · Windows (C# + WinUI 3)