GlassBanner
Inline information, success, warning or error message with icon, text and dismissal.
- Content
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-banner
Content on an opaque, readable surface. Glass is kept for controls.
CaptureInstallation
spglass add glass-bannerCopies the sources and their dependencies into your project. Set up the CLI.
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")
import SPGlassKit| Identifier | glass-banner |
|---|---|
| Module | SPGlassComponents |
| Kind | content-component — opaque surface tinted with the severity colour; no glass |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Feedback/GlassBannerExample.swift |
Minimal usage
GlassBanner(.success, title: "Payment received")Variants
| Severity | Symbol | Word | Theme role |
|---|---|---|---|
.information | info.circle.fill | Information | accent |
.success | checkmark.circle.fill | Success | success |
.warning | exclamationmark.triangle.fill | Warning | warning |
.error | xmark.octagon.fill | Error | destructive |
Each severity is shown three ways: a symbol of a distinct shape, its name in text, and the tint. Options: message, action, onDismiss.
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
severity | GlassBannerSeverity | — | See Variants. |
title | LocalizedStringKey, verbatim: string or Text | — | Main line. |
message | String? (or Text?) | nil | Detail, shown as is. |
action | GlassBannerAction? | nil | One button (GlassBannerAction("Retry") { … } or verbatim:). |
onDismiss | (@MainActor () -> Void)? | nil | Shows a dismiss button. |
Appearance
The banner is an opaque surface barely tinted with the severity colour, with a hairline, an accent edge on the leading side and the severity symbol in a tinted tile. The severity word is an uppercase eyebrow label above the title; the optional action is a small capsule button.
States
The banner is stateless: the host shows or removes it. It stays in the layout (it is not transient like a toast).
Colours come from GlassTintedColors.resolve(tint:surface:text:): the background is the theme surface mixed with 14 % of the severity colour; the text is the theme's primary text colour when it reaches 4.5:1 against that background, otherwise black or white; the symbol and outline use the severity colour when it reaches 3:1, otherwise the text colour. Tests check these ratios for every built-in theme in light and dark.
Advanced example
if let failure = model.syncFailure {
GlassBanner(.error, verbatim: failure.localizedDescription,
message: failure.recoverySuggestion,
action: GlassBannerAction("Retry") { model.sync() },
onDismiss: { model.syncFailure = nil })
.transition(.opacity)
}Accessibility
- VoiceOver reads the severity word, the title and the message as one element; the symbol is hidden because the word says the same thing.
- The action and dismiss buttons are separate elements with labels and the minimum hit target; the action is underlined so that it is recognisable without colour.
- Text wraps and follows Dynamic Type; the symbol aligns to the top so long messages stay readable.
- For an error that appears while the user is elsewhere on screen, also post an announcement or move focus: the banner does not announce itself.
Limits
- With the System theme (roles left to the system) colours cannot be measured: the background is mixed by SwiftUI and text and symbol use the primary label colour.
- One action at most. For several choices use a
GlassAlert. - The severity word is GlassKit's (English and French); the title and message are the host's.
Example
import SwiftUI
import SPGlassKit
public struct GlassBannerExample: GlassExample {
public static let componentID = "glass-banner"
@State private var showsWarning = true
@State private var retryCount = 0
public init() {}
public var body: some View {
ScrollView {
VStack(spacing: 12) {
GlassBanner(.information, title: "Maintenance on Sunday", message: "The sample service will be read-only from 2:00 to 4:00.")
GlassBanner(.success, title: "Payment received")
if showsWarning {
GlassBanner(
.warning,
title: "Your card expires soon",
message: "Update your payment method before the end of the month to avoid an interruption.",
action: GlassBannerAction("Update card") { showsWarning = false },
onDismiss: { showsWarning = false }
)
}
GlassBanner(
.error,
verbatim: "Synchronisation failed (attempt \(retryCount + 1))",
message: "The server did not answer.",
action: GlassBannerAction("Retry") { retryCount += 1 }
)
}
.padding()
}
}
}
#Preview("GlassBanner") { GlassBannerExample().glassTheme(.emerald) }
Registry entry
| Identifier | glass-banner |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-components-support, glass-foundation |
| Frameworks | SwiftUI |
| Public symbols | GlassBannerSeverity, GlassBannerAction, GlassBanner |
| Licence | MIT |
| Manifest | manifest.json |
Files
Components/Feedback/GlassBanner.swift9141 bytes · sha256 8c46d51d07cb…