SPB Git

Repository Public MIT

GlassTimelineExample.swift 3.8 KB 88 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP GlassKit7// File             : Examples/Gallery/Data/GlassTimelineExample.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 GlassTimelineExample: GlassExample {45    public static let componentID = "glass-timeline"4647    // Fictitious delivery log, relative to a fixed instant so that the example is reproducible.48    private static let events: [GlassTimelineEvent] = {49        let start = Date(timeIntervalSince1970: 1_780_300_800)50        func at(_ hours: Double) -> Date { start.addingTimeInterval(hours * 3600) }51        return [52            GlassTimelineEvent(id: "ordered", date: at(0), title: "Order placed", detail: "Order A-1042, three items", systemImage: "cart"),53            GlassTimelineEvent(id: "paid", date: at(0.2), title: "Payment confirmed"),54            GlassTimelineEvent(id: "packed", date: at(21), title: "Parcel packed", detail: "Warehouse 4, aisle 12 — a long note that wraps over several lines on a narrow screen without being cut off."),55            GlassTimelineEvent(id: "shipped", date: at(27.5), title: "Handed to the carrier", systemImage: "shippingbox"),56            GlassTimelineEvent(id: "transit", date: at(52), title: "In transit 🚚", detail: "مركز الفرز · Centre de tri"),57            GlassTimelineEvent(id: "delivered", date: at(76), title: "Delivered", systemImage: "checkmark.circle"),58        ]59    }()6061    @State private var order = GlassTimelineOrder.descending62    @State private var showsEmpty = false6364    public init() {}6566    public var body: some View {67        ScrollView {68            VStack(alignment: .leading, spacing: 16) {69                Picker("Order", selection: $order) {70                    Text("Newest first").tag(GlassTimelineOrder.descending)71                    Text("Oldest first").tag(GlassTimelineOrder.ascending)72                }73                .pickerStyle(.segmented)74                Toggle("Show the empty state", isOn: $showsEmpty)75                GlassTimeline(showsEmpty ? [] : Self.events, order: order, emptyTitle: "Nothing has happened yet")76            }77            .padding()78        }79    }80}8182#Preview("GlassTimeline") { GlassTimelineExample() }83#Preview("GlassTimeline — français, Tokyo") {84    GlassTimelineExample()85        .environment(\.locale, Locale(identifier: "fr_CA"))86        .environment(\.timeZone, TimeZone(identifier: "Asia/Tokyo") ?? .gmt)87}88
Files main
Menu

Theme