← All libraries

SugarToast

SugarToast

Floating notification overlays

port of DaltonSW/bubbleup notificationtoastalertoverlay

Non-blocking floating notifications at 9 screen positions. Info, Success, Warning, Error types. Auto-dismiss, ESC-to-close, and stacked multi-toast support.

Install

composer require sugarcraft/sugar-toast

Quickstart

use SugarCraft\Toast\{Toast, ToastType, Position};

$toast = Toast::new(50)  // max width 50
    ->withPosition(Position::MiddleRight)
    ->withAllowEscToClose(true);

$toast = $toast->alert(ToastType::Success, 'File saved!');
$toast = $toast->alert(ToastType::Error, 'Connection failed');

$bg = str_repeat("background content\n", 20);
echo $toast->view($bg);

What's in the box

Four typesInfo, Success, Warning, Error — each with a distinct symbol and color.
Positions9 positions: TopLeft, TopCenter, TopRight, MiddleLeft, MiddleCenter, MiddleRight, BottomLeft, BottomCenter, BottomRight.
Auto-dismissConfigurable duration; null for persistent (never expires).
Symbol setsNerdFont, Unicode, or ASCII.
Overflow controlDropOldest, DropNewest, or Enqueue when maxConcurrent is exceeded.
Progress toastsInline progress bar (0–100%) beneath the message body.
Action buttonsClickable [Label] buttons with closure callbacks attached to an alert.
History logImmutable record of every dismissed alert via getHistory().
AnimationswithAnimationDuration() fade stub (CubicBezier deferred to future phase).

Source & demos

Try the quickstart →

API

ClassMethodDescription
Toastnew(int $maxWidth = 50)Factory — max width in cells
ToastwithPosition(Position)Set screen position (9 positions)
ToastwithDuration(?float $seconds)Auto-dismiss after N seconds (null to disable)
ToastwithAllowEscToClose(bool)Allow Escape key to dismiss active alert
ToastwithMaxWidth(int)Set maximum alert width in cells
ToastwithMinWidth(int)Set minimum alert width in cells
ToastwithSymbolSet(SymbolSet)NerdFont, Unicode, or ASCII symbol sets
ToastwithMaxConcurrent(?int)Cap concurrent alerts (null = unlimited)
ToastwithOverflow(Overflow)Strategy when cap exceeded: DropOldest, DropNewest, Enqueue
ToastwithAnimationDuration(float)Fade animation duration in seconds (stub; CubicBezier deferred)
Toastalert(ToastType|string, string, ?float $expiresAt)Add alert; string type = case-insensitive lookup; null expiry = never auto-dismisses
ToastprogressToast(ToastType|string, string, float $progress, ?float $expiresAt)Add alert with progress bar (0.0–1.0, clamped); same expiry semantics as alert()
Toasterror(string), warning(string), info(string), success(string)Convenience alert helpers
ToasthasActiveAlert(): boolReturns true if non-expired alerts are queued
Toastdismiss(), clear(), pruneExpired()Manage alert lifecycle; dismiss() records non-expired alerts to history
ToastgetHistory(): list<Alert>Return all dismissed alerts recorded since last dismiss()
Toastview(string $background, int $w, int $h): stringRender toast layer over background view
AlertwithProgress(float)Attach progress bar (0.0–1.0, clamped)
AlertwithActions(list<Action>)Attach action buttons
AlertisExpired(): boolCheck expiry
AlertwithExpiry(float $duration)Set expiry from now
Actionmake(string $label, \Closure(): void $callback)Factory
Action$label: non-empty-stringUser-visible button label (readonly)
Action$callback: \Closure(): voidInvoked when action is triggered (readonly)
HistoryLogpush(Alert): selfAppend alert, return new immutable log
HistoryLogall(): list<Alert>Return all recorded alerts
HistoryLogcount(): intNumber of recorded entries
ToastTypeInfo, Success, Warning, ErrorToast type constants
ToastTypelabel()Translated label via Lang::t() (i18n-aware)
PositionTopLeft, TopCenter, TopRight, MiddleLeft, MiddleCenter, MiddleRight, BottomLeft, BottomCenter, BottomRight9 screen positions
OverflowDropOldest, DropNewest, EnqueueOverflow strategy when maxConcurrent is exceeded
SymbolSetNerdFont, Unicode, ASCIISymbol set for alert icons
Langt(key, params)Translate a string: 'dismiss', 'count', 'type.*'

Internationalization

User-facing strings use SugarCraft\Toast\Lang::t(). All keys are in lang/en.php under the toast namespace.

KeyDefaultParameters
type.info / type.warning / type.error / type.successInfo / Warning / Error / Success
dismissPress any key to dismiss
count{count} notification(s){count}

To localize, copy lang/en.php to lang/<code>.php and translate the values.

Demos.

VHS-recorded GIFs of every example shipped with the library. Regenerated automatically on every push that touches the source.

All toast types

All toast types

Info / Success / Warning / Error rendered side-by-side.
Basic toast

Basic toast

A single Info toast — title, body, dismiss timer.