Repository Public MIT
1# GlassToolbar23| | |4|---|---|5| Identifier | `glass-toolbar` |6| Module | `SPGlassNavigation` |7| Kind | `native-wrapper` — `ToolbarContent` made of `ToolbarItemGroup`s with system placements |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/Navigation/GlassToolbarExample.swift` |1011## Minimal usage1213```swift14content.glassToolbar([15 GlassToolbarGroup(id: "main", placement: .trailing, actions: [16 GlassToolbarAction(id: "share", title: "Share", systemImage: "square.and.arrow.up") { share() },17 ]),18])19```2021`GlassToolbar(groups)` is the same thing as `ToolbarContent`, to combine with other items inside `.toolbar { }`.2223## Variants2425| Placement | System placement |26|---|---|27| `.automatic` | `.automatic` |28| `.leading` | `.topBarLeading` (iOS), `.navigation` (macOS) |29| `.trailing` | `.topBarTrailing` (iOS), `.primaryAction` (macOS) |30| `.primary` | `.primaryAction` |31| `.secondary` | `.secondaryAction` — the system collects these in its own overflow menu |32| `.bottom` | `.bottomBar` (iOS), `.automatic` (macOS) |33| `.cancellation` / `.confirmation` | `.cancellationAction` / `.confirmationAction` |3435## Parameters3637`GlassToolbarAction`3839| Parameter | Type | Default | Meaning |40|---|---|---|---|41| `id` | `String` | — | Stable identifier. |42| `title` / `verbatim` / `text` | `LocalizedStringKey` / `StringProtocol` / `Text` | — | Label, tooltip and menu title. |43| `systemImage` | `String` | — | SF Symbol shown in the bar. |44| `role` | `ButtonRole?` | `nil` | `.destructive`, `.cancel`. |45| `shortcut` | `KeyboardShortcut?` | `nil` | Keyboard shortcut. |46| `isEnabled` | `Bool` | `true` | Disabled state. |47| `priority` | `GlassToolbarActionPriority` | `.normal` | `.low` overflows first, `.high` last. |48| `action` | `@MainActor () -> Void` | — | Called on activation. |4950`GlassToolbarGroup`5152| Parameter | Type | Default | Meaning |53|---|---|---|---|54| `id` | `String` | — | Stable identifier. |55| `placement` | `GlassToolbarPlacement` | `.automatic` | Where the group goes. |56| `capacity` | `Int?` | `nil` | Controls shown before overflow. `nil`: two on a compact width or at accessibility text sizes, five otherwise. |57| `actions` | `[GlassToolbarAction]` | — | Actions in order. |5859## States6061Enabled and disabled per action. Overflow is decided by the pure function `GlassToolbarLayout.split(_:capacity:)`: when everything fits, everything is visible; otherwise the "More actions" menu takes one place and the rest goes to the actions of highest priority, the earliest first among equals. Order is kept on both sides.6263## Advanced example6465```swift66.toolbar {67 GlassToolbar([68 GlassToolbarGroup(id: "edit", placement: .trailing, capacity: 3, actions: [69 GlassToolbarAction(id: "share", title: "Share", systemImage: "square.and.arrow.up",70 shortcut: KeyboardShortcut("s", modifiers: [.command, .shift]), priority: .high) { share() },71 GlassToolbarAction(id: "duplicate", title: "Duplicate", systemImage: "plus.square.on.square",72 shortcut: KeyboardShortcut("d")) { duplicate() },73 GlassToolbarAction(id: "archive", title: "Archive", systemImage: "archivebox", priority: .low) { archive() },74 GlassToolbarAction(id: "delete", title: "Delete", systemImage: "trash", role: .destructive, priority: .low) { delete() },75 ]),76 GlassToolbarGroup(id: "export", placement: .secondary, actions: [exportPDF, print]),77 ])78 ToolbarItem(placement: .principal) { DocumentTitle() }79}80```8182With a capacity of three, Share and Duplicate stay in the bar; Archive and Delete are in the menu.8384## Accessibility8586- Each button is a `Label`: the bar shows the symbol, VoiceOver reads the title, macOS shows it as a tooltip.87- The overflow menu is labelled "More actions" (localised) and lists titles with symbols; the destructive role is conveyed by the system.88- Shortcuts are attached to the buttons themselves, in the bar or in the menu.89- At accessibility text sizes fewer controls are kept in the bar.9091## Limits9293- The system may still rearrange or collapse items of its own accord; the capacity is an upper bound, not a promise.94- Capacity is a count of controls, not a measured width.95- `.bottom` has no bottom bar on macOS and falls back to the automatic placement.96- That shortcuts of actions inside the overflow menu fire on every platform was not verified on a running device.97