Repository Public MIT
1import SwiftUI2import SPGlassKit34public struct GlassChatBubbleExample: GlassExample {5 public static let componentID = "glass-chat-bubble"67 /// Fictitious conversation: no model produced these messages.8 @State private var messages = [9 GlassChatMessage(id: "1", role: .system, text: "Sample data — this conversation is fictitious."),10 GlassChatMessage(id: "2", role: .user, text: "Can you summarise the sample quarterly note in two sentences? 🙂"),11 GlassChatMessage(id: "3", role: .assistant, text: "Certainly. The sample note reports steady demand and a slightly lower margin. It expects the next quarter to look similar, with one new product line."),12 GlassChatMessage(id: "4", role: .tool, text: "{\n \"tool\": \"sample_lookup\",\n \"rows\": 3,\n \"a_very_long_key_without_any_space_to_test_wrapping_inside_the_bubble\": true\n}"),13 GlassChatMessage(id: "4b", role: .assistant, text: "The note says:\n> Demand stayed steady over the quarter.\nAs a filter:\n```swift\nlet steady = notes.filter { $0.demand == .steady }\n```"),14 GlassChatMessage(id: "5", role: .user, text: "هل يمكنك كتابة الخلاصة بالعربية؟"),15 GlassChatMessage(id: "6", role: .assistant, text: "The sample answer is still being writ", state: .streaming),16 GlassChatMessage(id: "7", role: .assistant, text: "", state: .streaming),17 GlassChatMessage(id: "8", role: .assistant, text: "A partial sample answer that stopped.", state: .failed(reason: "Sample failure: the connection was interrupted.")),18 ]19 @State private var lastCopied = "Nothing copied yet"20 @State private var retryCount = 02122 public init() {}2324 public var body: some View {25 ScrollView {26 LazyVStack(spacing: 12) {27 ForEach(messages) { message in28 GlassChatBubble(29 message,30 usesMonospacedFont: message.role == .tool,31 onCopy: { text in lastCopied = "Copied \(text.count) characters (kept inside the example)" },32 onRetry: { retryCount += 1 }33 )34 }35 Text("\(lastCopied) · retried \(retryCount) times")36 .font(.caption)37 .foregroundStyle(.secondary)38 }39 .padding()40 }41 }42}4344#Preview("GlassChatBubble") { GlassChatBubbleExample().glassTheme(.aurora) }45