SPB Git

Repository Public MIT

doc-glass-chat-bubble.md 4.1 KB 80 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| Copy | A copy button sits under finished messages of the assistant, the system and tools. The user's own messages keep the context menu only (`GlassChatBubbleMetrics.showsCopyButton`). |27| `state: .failed(reason:)` | A warning symbol with the reason (or a generic message) under the bubble, and "Retry" when `onRetry` is given. |28| `usesMonospacedFont: true` | Code-like content such as tool output. |29| Fenced code and quotes | A block between two lines of three backticks is set in a monospaced inset that scrolls sideways (the word after the opening fence is shown as its language); consecutive lines starting with `>` are set as a quote. Nothing else is interpreted: no inline styles, no links, no HTML. `rendersBlocks: false` shows the text as it is. |3031## Parameters3233| Parameter | Type | Default | Meaning |34|---|---|---|---|35| `message` | `GlassChatMessage` | — | `id`, `role`, `text`, `state`. |36| `maxWidthFraction` | `Double` | `0.8` | Largest share of the container's width the bubble takes; clamped to 0.4…1. |37| `usesMonospacedFont` | `Bool` | `false` | Monospaced text. |38| `rendersBlocks` | `Bool` | `true` | Sets fenced code and quotes apart. Ignored with `usesMonospacedFont`. |39| `onCopy` | `(@MainActor (String) -> Void)?` | `nil` | Receives the text on copy. When `nil` the text is written to the system pasteboard. |40| `onRetry` | `(@MainActor () -> Void)?` | `nil` | Shows "Retry" on failed messages. |4142## States4344Complete, 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.4546## Advanced example4748```swift49ScrollView {50    LazyVStack(spacing: 12) {51        ForEach(conversation.messages) { message in      // [GlassChatMessage], updated by the host while streaming52            GlassChatBubble(53                message,54                maxWidthFraction: 0.75,55                usesMonospacedFont: message.role == .tool,56                onRetry: message.role == .assistant ? { conversation.regenerate(message.id) } : nil57            )58        }59    }60    .padding()61}62.defaultScrollAnchor(.bottom)63```6465## Accessibility6667- The role is written above the bubble and read with the text ("Assistant, …"): it never depends on colour or side.68- The text is selectable (`textSelection(.enabled)`); copy is also in the context menu.69- While streaming the element has the "updates frequently" trait and the indicator has a text label; its symbol animation stops with Reduce Motion.70- Failure is a symbol plus text. The copy button is labelled "Copy" / "Copied" and has a 44-point target on iOS.71- 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.7273## Limits7475- Plain text only: no Markdown rendering, no syntax highlighting, no images. `usesMonospacedFont` applies to the whole message.76- Very long messages are laid out in full; put the bubbles in a lazy stack and keep the conversation in the host.77- Unbroken strings (long URLs, identifiers) wrap by character.78- The bubble does not scroll the conversation or keep it pinned to the bottom: that is the container's role.79- 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.80
Files main
Menu

Theme