Skip to content
/ Panels Public

A SwiftUI library for dynamically registering and displaying panel views from anywhere in your view hierarchy.

License

Notifications You must be signed in to change notification settings

schwa/Panels

Repository files navigation

Panels

A SwiftUI library for dynamically registering and displaying panel views from anywhere in your view hierarchy.

Why Panels?

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.

Installation

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"])

Usage

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
    }
}

Panels library in action showing settings and details panels in the inspector

Requirements

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+

License

This project is licensed under the MIT License - see the LICENSE file for details

About

A SwiftUI library for dynamically registering and displaying panel views from anywhere in your view hierarchy.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages