Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Examples/Gallery/Navigation/GlassSidebarExample.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 GlassSidebarExample: GlassExample {45 public static let componentID = "glass-sidebar"46 @State private var selection: String? = "inbox"47 @State private var columnVisibility: NavigationSplitViewVisibility = .automatic4849 public init() {}5051 private let sections: [GlassSidebarSection<String>] = [52 GlassSidebarSection(id: "mailboxes", title: "Mailboxes", items: [53 GlassSidebarItem(id: "inbox", title: "Inbox", systemImage: "tray", badge: 12, keywords: ["unread"]),54 GlassSidebarItem(id: "drafts", title: "Drafts", systemImage: "doc", badge: 2),55 GlassSidebarItem(id: "sent", title: "Sent", systemImage: "paperplane"),56 GlassSidebarItem(id: "archive", title: "Archive", systemImage: "archivebox"),57 ]),58 GlassSidebarSection(id: "labels", title: "Labels", items: [59 GlassSidebarItem(id: "travel", title: "Voyages et séjours", systemImage: "airplane", keywords: ["travel", "trips"]),60 GlassSidebarItem(id: "receipts", title: "Reçus", systemImage: "receipt", keywords: ["receipts"]),61 GlassSidebarItem(id: "long", title: "A label with a deliberately long name to check wrapping", systemImage: "tag"),62 ]),63 ]6465 public var body: some View {66 GlassSidebar("Mail", sections: sections, selection: $selection, columnVisibility: $columnVisibility, searchPrompt: "Search mailboxes") { id in67 if let id {68 VStack(spacing: 12) {69 Text(verbatim: title(of: id)).font(.title2)70 Button(columnVisibility == .detailOnly ? "Show sidebar" : "Hide sidebar") {71 columnVisibility = columnVisibility == .detailOnly ? .all : .detailOnly72 }73 }74 .padding()75 .navigationTitle(Text(verbatim: title(of: id)))76 } else {77 ContentUnavailableView("Select a mailbox", systemImage: "sidebar.left")78 }79 }80 }8182 private func title(of id: String) -> String {83 sections.flatMap(\.items).first { $0.id == id }?.title ?? id84 }85}8687#Preview("GlassSidebar") { GlassSidebarExample() }88