Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Examples/Gallery/Feedback/GlassToastExample.swift8// Module : Examples9// Repository : https://git.spboucher.ai/sp-glasskit10// Project Website : https://glass.spboucher.ai11// Created : 2026-12-0212// Last Modified : 2026-12-0213//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI42import SPGlassKit4344public struct GlassToastExample: GlassExample {45 public static let componentID = "glass-toast"46 @State private var toasts = GlassToastCenter(capacity: 3)47 @State private var savedCount = 048 @State private var restored = false4950 public init() {}5152 public var body: some View {53 VStack(spacing: 16) {54 GlassButton("Save draft", systemImage: "tray.and.arrow.down") {55 savedCount += 156 // A stable identifier: saving twice replaces the toast instead of stacking a duplicate.57 toasts.show(GlassToast("Draft saved (\(savedCount))", systemImage: "checkmark.circle", id: "saved"))58 }59 GlassButton("Delete message", systemImage: "trash", role: .destructive) {60 restored = false61 toasts.show(GlassToast("Message deleted", systemImage: "trash", action: GlassToastAction("Undo") { restored = true }))62 }63 GlassButton("Show offline notice", systemImage: "wifi.slash") {64 toasts.show(.persistent("You are offline", title: "Connection", systemImage: "wifi.slash", id: "offline"))65 }66 GlassButton("Dismiss all") { toasts.dismissAll() }67 Text(restored ? "Message restored" : "\(toasts.toasts.count) toasts on screen")68 .font(.callout)69 .foregroundStyle(.secondary)70 }71 .padding()72 .frame(maxWidth: .infinity, maxHeight: .infinity)73 .glassToastHost(toasts)74 }75}7677#Preview("GlassToast") { GlassToastExample() }78