SPB Git

Repository Public MIT

doc-glass-banner.md 3.1 KB 68 lines markdown

1# GlassBanner23| | |4|---|---|5| Identifier | `glass-banner` |6| Module | `SPGlassComponents` |7| Kind | `content-component` — opaque surface tinted with the severity colour; no glass |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/Feedback/GlassBannerExample.swift` |1011## Minimal usage1213```swift14GlassBanner(.success, title: "Payment received")15```1617## Variants1819| Severity | Symbol | Word | Theme role |20|---|---|---|---|21| `.information` | `info.circle.fill` | Information | `accent` |22| `.success` | `checkmark.circle.fill` | Success | `success` |23| `.warning` | `exclamationmark.triangle.fill` | Warning | `warning` |24| `.error` | `xmark.octagon.fill` | Error | `destructive` |2526Each severity is shown three ways: a symbol of a distinct shape, its name in text, and the tint. Options: `message`, `action`, `onDismiss`.2728## Parameters2930| Parameter | Type | Default | Meaning |31|---|---|---|---|32| `severity` | `GlassBannerSeverity` | — | See Variants. |33| `title` | `LocalizedStringKey`, `verbatim:` string or `Text` | — | Main line. |34| `message` | `String?` (or `Text?`) | `nil` | Detail, shown as is. |35| `action` | `GlassBannerAction?` | `nil` | One button (`GlassBannerAction("Retry") { … }` or `verbatim:`). |36| `onDismiss` | `(@MainActor () -> Void)?` | `nil` | Shows a dismiss button. |3738## States3940The banner is stateless: the host shows or removes it. It stays in the layout (it is not transient like a toast).4142Colours 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.4344## Advanced example4546```swift47if let failure = model.syncFailure {48    GlassBanner(.error, verbatim: failure.localizedDescription,49                message: failure.recoverySuggestion,50                action: GlassBannerAction("Retry") { model.sync() },51                onDismiss: { model.syncFailure = nil })52        .transition(.opacity)53}54```5556## Accessibility5758- VoiceOver reads the severity word, the title and the message as one element; the symbol is hidden because the word says the same thing.59- 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.60- Text wraps and follows Dynamic Type; the symbol aligns to the top so long messages stay readable.61- 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.6263## Limits6465- 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.66- One action at most. For several choices use a `GlassAlert`.67- The severity word is GlassKit's (English and French); the title and message are the host's.68
Files main
Menu

Theme