SPB Git

Repository Public MIT

doc-glass-panel.md 3.6 KB 76 lines markdown

1# GlassPanel23| | |4|---|---|5| Identifier | `glass-panel` |6| Module | `SPGlassComponents` |7| Kind | `custom-glass` — one `glassSurface`; the controls inside are plain system controls |8| Platforms | iOS 26, iPadOS 26, macOS 26 (resizing and focus scope on macOS only) |9| Example | `Examples/Gallery/Containers/GlassPanelExample.swift` |1011## Minimal usage1213```swift14GlassPanel("Layers") {15    Toggle("Transit", isOn: $showsTransit)16}17```1819## Variants2021| Variant | Use |22|---|---|23| Fixed | No `size`: the panel takes the size of its content. |24| Resizable (macOS) | `size: $panelSize`: a handle in the trailing-bottom corner resizes within `sizeLimits`. |25| Closable | `onClose:` adds a close button; Escape calls it. |2627## Parameters2829| Parameter | Type | Default | Meaning |30|---|---|---|---|31| `title` | `LocalizedStringKey` or `Text` | — | Heading and accessibility label of the panel. |32| `size` | `Binding<CGSize>?` | `nil` | Controlled size on macOS. Ignored on iOS and iPadOS. |33| `sizeLimits` | `GlassPanelSizeLimits` | `.standard` (240 × 160 to 720 × 640) | Bounds applied to `size`. |34| `onClose` | `(@MainActor () -> Void)?` | `nil` | Shows the close button and handles Escape. |35| `content` | `@ViewBuilder` | — | Controls of the panel. |3637`GlassPanelSizeLimits.clamp(_:)` and `resized(from:translation:isRightToLeft:)` are pure and can be reused by the host, for example to restore a saved size.3839### Appearance4041The 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.4243## States4445The 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.4647## Advanced example4849```swift50@State private var size = CGSize(width: 320, height: 240)51let limits = GlassPanelSizeLimits(minimum: CGSize(width: 260, height: 180), maximum: CGSize(width: 520, height: 420))5253GlassPanel("Inspector", size: $size, sizeLimits: limits, onClose: { showsInspector = false }) {54    Picker("Blend", selection: $blend) { ForEach(Blend.allCases) { Text($0.name).tag($0) } }55    Slider(value: $opacity, in: 0...1) { Text("Opacity") }56}57.onChange(of: size) { _, new in settings.inspectorSize = limits.clamp(new) }58```5960## Accessibility6162- The panel is an accessibility container named by its title; the title has the header trait.63- The close button is labelled "Close" (localised) and has the minimum hit target.64- 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 `onClose` while focus is inside the panel.65- iOS and iPadOS with a hardware keyboard: Escape triggers the close button (`.keyboardShortcut(.cancelAction)`).66- 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.67- With Reduce Transparency the surface is opaque (handled by `glassSurface`).6869## Limits7071- The panel does not move itself: place it with `overlay`, `safeAreaInset` or your own drag logic.72- Resizing exists on macOS only; on iPadOS use a sheet with detents or `GlassMapPanel` for an extensible panel.73- Keep the content to controls and short labels; long or dense content belongs in an opaque `GlassCard`.74- Do not put glass buttons (`GlassButton`) inside the panel: glass must not sit inside glass. Use plain or bordered system buttons.75- The behaviour of focus and Escape was compiled but not exercised in a running application by the automated tests.76
Files main
Menu

Theme