SPB Git

Repository Public MIT

GlassAlertExample.swift 3.2 KB 84 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP GlassKit7// File             : Examples/Gallery/Feedback/GlassAlertExample.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 GlassAlertExample: GlassExample {45    public static let componentID = "glass-alert"46    @State private var alert: GlassAlert?47    @State private var outcome = "Nothing chosen yet"4849    public init() {}5051    public var body: some View {52        VStack(spacing: 16) {53            GlassButton("Show information") {54                alert = GlassAlert(title: "Export finished", message: "The sample file was written to Documents.")55            }56            GlassButton("Unsaved changes…") {57                alert = GlassAlert(58                    title: "Save changes?",59                    message: "Your edits to “Budget 2027” will be lost otherwise.",60                    buttons: [61                        GlassAlertButton("Save") { outcome = "Saved" },62                        .destructive("Discard") { outcome = "Discarded" },63                        .cancel { outcome = "Cancelled" },64                    ]65                )66            }67            GlassButton("Delete draft…", systemImage: "trash", role: .destructive) {68                // No cancel button is given: validation adds one because the only action is destructive.69                alert = GlassAlert(70                    title: "Delete this draft?",71                    message: "This cannot be undone.",72                    style: .confirmation,73                    buttons: [.destructive("Delete draft") { outcome = "Deleted" }]74                )75            }76            Text(outcome).font(.callout).foregroundStyle(.secondary)77        }78        .padding()79        .glassAlert($alert)80    }81}8283#Preview("GlassAlert") { GlassAlertExample() }84
Files main
Menu

Theme