SPB Git

Repository Public MIT

glass-chat-bubble.md 3.5 KB 77 lines markdown

1# GlassChatBubble23| | |4|---|---|5| Identifier | `glass-chat-bubble` |6| Module | `SPGlassAI` |7| Kind | `content-component` — text on an opaque bubble; no glass |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/AI/GlassChatBubbleExample.swift` |1011UI only: the component displays a message value. It contains no AI provider, no key and no network code.1213## Minimal usage1415```swift16GlassChatBubble(GlassChatMessage(id: "1", role: .assistant, text: "Hello."))17```1819## Variants2021| Variant | Use |22|---|---|23| `role: .user` | Trailing edge, filled with the theme's `primary` colour, labelled "You". |24| `role: .assistant`, `.system`, `.tool` | Leading edge, opaque themed surface, labelled "Assistant", "System", "Tool". |25| `state: .streaming` | A "Receiving response" indicator follows the text; the copy button is hidden until the text is final. |26| `state: .failed(reason:)` | A warning symbol with the reason (or a generic message) under the bubble, and "Retry" when `onRetry` is given. |27| `usesMonospacedFont: true` | Code-like content such as tool output. |2829## Parameters3031| Parameter | Type | Default | Meaning |32|---|---|---|---|33| `message` | `GlassChatMessage` | — | `id`, `role`, `text`, `state`. |34| `maxWidthFraction` | `Double` | `0.8` | Largest share of the container's width the bubble takes; clamped to 0.4…1. |35| `usesMonospacedFont` | `Bool` | `false` | Monospaced text. |36| `onCopy` | `(@MainActor (String) -> Void)?` | `nil` | Receives the text on copy. When `nil` the text is written to the system pasteboard. |37| `onRetry` | `(@MainActor () -> Void)?` | `nil` | Shows "Retry" on failed messages. |3839## States4041Complete, streaming, failed. A streaming message with empty text shows the indicator alone. After a copy the button shows a checkmark and "Copied" for 1.5 seconds.4243## Advanced example4445```swift46ScrollView {47    LazyVStack(spacing: 12) {48        ForEach(conversation.messages) { message in      // [GlassChatMessage], updated by the host while streaming49            GlassChatBubble(50                message,51                maxWidthFraction: 0.75,52                usesMonospacedFont: message.role == .tool,53                onRetry: message.role == .assistant ? { conversation.regenerate(message.id) } : nil54            )55        }56    }57    .padding()58}59.defaultScrollAnchor(.bottom)60```6162## Accessibility6364- The role is written above the bubble and read with the text ("Assistant, …"): it never depends on colour or side.65- The text is selectable (`textSelection(.enabled)`); copy is also in the context menu.66- While streaming the element has the "updates frequently" trait and the indicator has a text label; its symbol animation stops with Reduce Motion.67- Failure is a symbol plus text. The copy button is labelled "Copy" / "Copied" and has a 44-point target on iOS.68- Alignment uses leading and trailing, so the layout mirrors in right-to-left languages; right-to-left text inside a bubble keeps its natural direction.6970## Limits7172- Plain text only: no Markdown rendering, no syntax highlighting, no images. `usesMonospacedFont` applies to the whole message.73- Very long messages are laid out in full; put the bubbles in a lazy stack and keep the conversation in the host.74- Unbroken strings (long URLs, identifiers) wrap by character.75- The bubble does not scroll the conversation or keep it pinned to the bottom: that is the container's role.76- Layout with long, code-like, emoji and right-to-left text is in the example and compiles; it was not inspected in a running application during verification.77
Files main
Menu

Theme