SP GlassKit1.1.0

GlassPromptBar

Multiline prompt editor with send and stop, attachments through callbacks and keyboard shortcuts.

  • Custom glass
  • iOS 26 · iPadOS 26 · macOS 26
  • Version 1.1.0
  • glass-prompt-bar

Draws its own Liquid Glass surface, with an opaque form when Reduce Transparency is on.

GlassPromptBar running in SP Glass Studio.Capture
Capture of the component running in SP Glass Studio on the iOS 26.5 simulator. Liquid Glass is rendered by the system; this is an image, not a live preview.

Installation

spglass add glass-prompt-bar

Copies the sources and their dependencies into your project. Set up the CLI.

Swift
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")

import SPGlassKit
Identifierglass-prompt-bar
ModuleSPGlassAI
Kindcustom-glass — one untinted glassSurface holding a system TextField, an accessory slot and filled round buttons
PlatformsiOS 26, iPadOS 26, macOS 26
ExampleExamples/Gallery/AI/GlassPromptBarExample.swift

UI only: the bar reports what the user wants through closures. It sends nothing, opens no file and contacts no model.

Minimal usage

Swift
@State private var draft = ""

GlassPromptBar(text: $draft) { prompt in send(prompt) }

Variants

VariantUse
DefaultThe editor, and under it a row that ends with the send button.
isResponding: trueThe stop button replaces the send button; onStop is called by the button and by Escape.
onAttach:Adds the attachment button ("+"). The host presents its own importer or picker.
attachments: + onRemoveAttachment:Chips above the editor, each with a remove button.
lineLimit:Visible lines before the editor scrolls (default 1…6).
accessory:A trailing view builder: small controls placed in the bottom row between the attach and send buttons, such as a GlassModelPicker or a context chip.

Parameters

ParameterTypeDefaultMeaning
textBinding<String>—The draft.
placeholderLocalizedStringKey?"Message"Prompt shown while the draft is empty.
isRespondingBoolfalseA response is in progress.
attachments[GlassPromptAttachment][]Items already attached (id, name, systemImage).
lineLimitClosedRange<Int>1...6Smallest and largest number of visible lines.
onSend@MainActor (String) -> Void—Receives the trimmed text; the bar then clears the draft.
onStop@MainActor () -> Void{}Stop the response.
onAttach(@MainActor () -> Void)?nilThe user asked to attach something.
onRemoveAttachment(@MainActor (GlassPromptAttachment) -> Void)?nilThe user removed a chip.
accessory@ViewBuildernoneControls shown in the bottom row. GlassPromptBar is generic over this view; without it the type is GlassPromptBar<EmptyView>.

States

  • Empty or blank draft: the send button is disabled; Return does nothing.
  • Ready: the send button takes the theme's primary colour.
  • Responding: stop button; the editor stays editable so that the next prompt can be prepared, but nothing can be sent.
  • Disabled: the standard .disabled(_:) modifier.

Keyboard

What the code does, verified against the SDK's API surface (onKeyPress(_:phases:action:), KeyPress.modifiers, onSubmit, submitLabel, TextField(_:text:selection:prompt:axis:)):

KeyBehaviourMechanism
Return (hardware keyboard, macOS and iPad)Sends when the draft is not blank and no response is in progress; otherwise consumed without effect.onKeyPress(.return, phases: .down) returns .handled
Shift-Return or Option-ReturnInserts a line break at the insertion point (replacing the selection).Same handler; the text and the TextSelection binding are updated
Return on the software keyboardSends. The key is labelled "Send".TextField(axis: .vertical) submits on Return; onSubmit + submitLabel(.send)
Escape, while respondingStops.keyboardShortcut(.cancelAction) on the stop button

The decisions are pure functions (GlassPromptInput.canSend, returnKeyAction, insertingNewline) covered by tests. The key handling itself was compiled for macOS and iOS but not exercised in a running application during verification.

Advanced example

Swift
GlassPromptBar(
    text: $model.draft,
    placeholder: "Ask about this document",
    isResponding: model.isResponding,
    attachments: model.attachments,
    lineLimit: 1...10
) { prompt in
    model.send(prompt)
} onStop: {
    model.cancel()
} onAttach: {
    isImporterPresented = true
} onRemoveAttachment: { attachment in
    model.remove(attachment.id)
}
.fileImporter(isPresented: $isImporterPresented, allowedContentTypes: [.pdf, .image]) { result in
    model.attach(result)                                   // the host reads the file, not the bar
}
.safeAreaPadding(.horizontal)

Accessibility

  • The editor is labelled "Message"; the buttons are labelled "Attach", "Send" and "Stop" with tooltips on macOS and 44-point targets on iOS.
  • Chips sit in a container labelled "Attachments"; each remove button reads "Remove <name>".
  • The text follows Dynamic Type and the bar grows with the number of lines up to the limit.
  • With Reduce Transparency the bar is an opaque themed surface.

Limits

  • On a software keyboard a line break cannot be typed with Return (it sends); pasting multi-line text works.
  • Return is handled on key-down: with an input method that confirms a composition with Return (for example Japanese or Chinese input), the confirmation key may be taken as "send". Hosts with such users should test this path; it could not be verified here.
  • The bar does not expose the editor's focus. Wrap it and use defaultFocus or place it where the system focuses it.
  • The bar has no knowledge of the content of attachments, their size or their type: validation belongs to the host.
  • Attaching by drag and drop or paste is not handled.

Example

Complete example (compiled with the package)
import SwiftUI
import SPGlassKit

public struct GlassPromptBarExample: GlassExample {
    public static let componentID = "glass-prompt-bar"
    @State private var draft = ""
    @State private var isResponding = false
    @State private var sent: [String] = []
    @State private var attachments = [
        GlassPromptAttachment(id: "a1", name: "sample-report.pdf", systemImage: "doc.richtext"),
        GlassPromptAttachment(id: "a2", name: "a-sample-image-with-a-rather-long-file-name.png", systemImage: "photo"),
    ]
    @State private var nextAttachment = 3
    @State private var modelID: String? = "sample-large"
    /// Fictitious models.
    private let models = [
        GlassModelInfo(id: "sample-large", name: "Sample Large", provider: "Example Cloud (sample)", capabilities: [.text, .tools], availability: .remote),
        GlassModelInfo(id: "sample-nano", name: "Sample Nano", provider: "On this device (sample)", availability: .local),
    ]

    public init() {}

    public var body: some View {
        VStack(alignment: .leading, spacing: 12) {
            Text("Sample data · nothing is sent anywhere; prompts are only listed below.")
                .font(.caption)
                .foregroundStyle(.secondary)
            ScrollView {
                VStack(alignment: .leading, spacing: 8) {
                    ForEach(Array(sent.enumerated()), id: \.offset) { _, prompt in
                        Text(prompt)
                            .frame(maxWidth: .infinity, alignment: .leading)
                    }
                    if isResponding {
                        GlassThinkingIndicator(.writing, label: "Simulating a response")
                    }
                }
            }
            GlassPromptBar(text: $draft, placeholder: "Ask the sample assistant", isResponding: isResponding, attachments: attachments) { prompt in
                sent.append(prompt)
                isResponding = true
            } onStop: {
                isResponding = false
            } onAttach: {
                // A real host presents its own file importer or photo picker here.
                attachments.append(GlassPromptAttachment(id: "a\(nextAttachment)", name: "sample-\(nextAttachment).txt"))
                nextAttachment += 1
            } onRemoveAttachment: { attachment in
                attachments.removeAll { $0.id == attachment.id }
            } accessory: {
                // Any small control fits here: a model picker, a context chip.
                GlassModelPicker(models: models, selection: $modelID)
            }
        }
        .padding()
        .task(id: isResponding) {
            guard isResponding else { return }
            try? await Task.sleep(for: .seconds(3))
            if !Task.isCancelled { isResponding = false }
        }
    }
}

#Preview("GlassPromptBar") { GlassPromptBarExample().glassTheme(.aurora) }

Registry entry

Identifierglass-prompt-bar
Version1.1.0
Depends onglass-foundation
FrameworksSwiftUI
Public symbolsGlassPromptAttachment, GlassPromptInput, ReturnKeyAction, GlassPromptBar
LicenceMIT
Manifestmanifest.json

Files