GlassPanel
Floating panel of actions, resizable on macOS, with managed focus.
- Custom glass
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-panel
Draws its own Liquid Glass surface, with an opaque form when Reduce Transparency is on.
CaptureInstallation
spglass add glass-panelCopies 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-panel |
|---|---|
| Module | SPGlassComponents |
| Kind | custom-glass — one glassSurface; the controls inside are plain system controls |
| Platforms | iOS 26, iPadOS 26, macOS 26 (resizing and focus scope on macOS only) |
| Example | Examples/Gallery/Containers/GlassPanelExample.swift |
Minimal usage
GlassPanel("Layers") {
Toggle("Transit", isOn: $showsTransit)
}Variants
| Variant | Use |
|---|---|
| Fixed | No size: the panel takes the size of its content. |
| Resizable (macOS) | size: $panelSize: a handle in the trailing-bottom corner resizes within sizeLimits. |
| Closable | onClose: adds a close button; Escape calls it. |
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
title | LocalizedStringKey or Text | — | Heading and accessibility label of the panel. |
size | Binding<CGSize>? | nil | Controlled size on macOS. Ignored on iOS and iPadOS. |
sizeLimits | GlassPanelSizeLimits | .standard (240 × 160 to 720 × 640) | Bounds applied to size. |
onClose | (@MainActor () -> Void)? | nil | Shows the close button and handles Escape. |
content | @ViewBuilder | — | Controls of the panel. |
GlassPanelSizeLimits.clamp(_:) and resized(from:translation:isRightToLeft:) are pure and can be reused by the host, for example to restore a saved size.
Appearance
The title bar is separated from the content by a hairline and the close button is a small circular control. The panel uses neutral glass (never the theme's glass tint) so that its text and controls stay legible in every theme.
States
The panel itself has no state. The host decides whether it is shown; size is the host's state. While the handle is dragged the size follows the pointer immediately, without animation.
Advanced example
@State private var size = CGSize(width: 320, height: 240)
let limits = GlassPanelSizeLimits(minimum: CGSize(width: 260, height: 180), maximum: CGSize(width: 520, height: 420))
GlassPanel("Inspector", size: $size, sizeLimits: limits, onClose: { showsInspector = false }) {
Picker("Blend", selection: $blend) { ForEach(Blend.allCases) { Text($0.name).tag($0) } }
Slider(value: $opacity, in: 0...1) { Text("Opacity") }
}
.onChange(of: size) { _, new in settings.inspectorSize = limits.clamp(new) }Accessibility
- The panel is an accessibility container named by its title; the title has the header trait.
- The close button is labelled "Close" (localised) and has the minimum hit target.
- macOS: the panel is a focus scope and a focus section, so Tab and arrow keys move among its controls as a group. Escape calls
onClosewhile focus is inside the panel. - iOS and iPadOS with a hardware keyboard: Escape triggers the close button (
.keyboardShortcut(.cancelAction)). - The resize handle is focusable (arrow keys resize by one spacing step), is announced as "Resize panel" with the current size as its value, and supports the VoiceOver adjustable action.
- With Reduce Transparency the surface is opaque (handled by
glassSurface).
Limits
- The panel does not move itself: place it with
overlay,safeAreaInsetor your own drag logic. - Resizing exists on macOS only; on iPadOS use a sheet with detents or
GlassMapPanelfor an extensible panel. - Keep the content to controls and short labels; long or dense content belongs in an opaque
GlassCard. - Do not put glass buttons (
GlassButton) inside the panel: glass must not sit inside glass. Use plain or bordered system buttons. - The behaviour of focus and Escape was compiled but not exercised in a running application by the automated tests.
Example
import SwiftUI
import SPGlassKit
public struct GlassPanelExample: GlassExample {
public static let componentID = "glass-panel"
@State private var isShown = true
@State private var showsTransit = true
@State private var showsTraffic = false
@State private var size = CGSize(width: 300, height: 220)
public init() {}
public var body: some View {
ZStack {
LinearGradient(colors: [.teal, .indigo], startPoint: .topLeading, endPoint: .bottomTrailing)
.ignoresSafeArea()
.accessibilityHidden(true)
if isShown {
GlassPanel(
"Layers",
size: $size,
sizeLimits: GlassPanelSizeLimits(minimum: CGSize(width: 240, height: 180), maximum: CGSize(width: 480, height: 360)),
onClose: { isShown = false }
) {
Toggle("Transit", isOn: $showsTransit)
Toggle("Traffic", isOn: $showsTraffic)
}
.padding()
} else {
GlassButton("Show layers", systemImage: "square.3.layers.3d") { isShown = true }
}
}
}
}
#Preview("GlassPanel") { GlassPanelExample() }
Registry entry
| Identifier | glass-panel |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-foundation |
| Frameworks | SwiftUI |
| Public symbols | GlassPanelSizeLimits, GlassPanel |
| Licence | MIT |
| Manifest | manifest.json |
Files
Components/Containers/GlassPanel.swift11370 bytes · sha256 1405660c6925…