SPB Git

Repository Public MIT

GlassMetricCardExample.swift 3.4 KB 81 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP GlassKit7// File             : Examples/Gallery/Data/GlassMetricCardExample.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 GlassMetricCardExample: GlassExample {45    public static let componentID = "glass-metric-card"4647    // Fictitious figures.48    @State private var latency: GlassLoadState<GlassMetric> = .loaded(49        GlassMetric(value: 182, unit: "ms", change: -0.062, period: "vs last week", tone: .negativeIsGood)50    )5152    public init() {}5354    public var body: some View {55        ScrollView {56            LazyVGrid(columns: [GridItem(.adaptive(minimum: 220), spacing: 12)], spacing: 12) {57                GlassMetricCard("Response time", state: latency) {58                    latency = .loaded(GlassMetric(value: 175, unit: "ms", change: -0.098, period: "vs last week", tone: .negativeIsGood))59                }60                GlassMetricCard("Monthly revenue", state: .loaded(61                    GlassMetric(value: 48_250.5, unit: "$", change: 0.042, period: "vs last month", fractionDigits: 2...2, tone: .positiveIsGood)62                ))63                GlassMetricCard("Open tickets", state: .loaded(GlassMetric(value: 37, change: 0, period: "since yesterday")))64                GlassMetricCard("Active sessions", state: .loading)65                GlassMetricCard("Conversion", state: .empty)66                GlassMetricCard("Forecast", state: .idle)67                GlassMetricCard("Churn", state: .failed(message: "The report could not be loaded.")) {}68            }69            .padding()7071            HStack {72                GlassButton("Simulate a failure", size: .small) { latency = .failed(message: "The probe did not answer.") }73                GlassButton("Reload", size: .small) { latency = .loading }74            }75            .padding(.bottom)76        }77    }78}7980#Preview("GlassMetricCard") { GlassMetricCardExample().glassTheme(.emerald) }81
Files main
Menu

Theme