A SwiftUI library for dynamically registering and displaying panel views from anywhere in your view hierarchy.
Panels enables any view in your hierarchy to dynamically register content that can be displayed elsewhere in your UI - whether in an inspector, sidebar, or custom container. Views can contribute their own panels that automatically appear and disappear as they enter and exit the scene.
The key benefit: deeply nested views can contribute to inspectors or sidebars without threading state through the entire view hierarchy. Your detail view 10 levels deep can add its own inspector panel without the root view knowing it exists.
Add Panels to your Swift package dependencies:
dependencies: [
.package(url: "https://github.com/schwa/Panels.git", branch: "main")
]Then add it to your target:
.target(name: "YourTarget", dependencies: ["Panels"])import Panels
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
// Register panels from any view in the hierarchy
SettingsView()
.panel(id: "settings", label: "Settings") {
SettingsPanel()
}
DetailView()
.panel(id: "details", label: "Details") {
DetailPanel()
}
}
.inspector(isPresented: .constant(true)) {
// Display all registered panels
Panels { panel in
DisclosureGroup(panel.label) {
panel.body
}
}
}
.panelsHost() // Required: Sets up the panels environment
}
}Requirements are mostly arbitrary at this point and could be lowered if needed.
- Swift 6.2+
- macOS 15.0+ / iOS 18.0+ / tvOS 26.0+ / watchOS 26.0+ / visionOS 26.0+
This project is licensed under the MIT License - see the LICENSE file for details
