Exhibition

main

A framework and generator for displaying SwiftUI component libraries
mjarvis/Exhibition

Exhibition

CI

Exhibition is a framework and generator for displaying and debugging a SwiftUI component library.

Inspired by Storybook and Showkase

Installation

Swift Package Manager

  1. Add https://github.com/mjarvis/Exhibition to your project via Xcode.
  2. Install Sourcery
  3. Copy Exhibition.swifttemplate into your project

Usage

  1. Modify your SwiftUI previews to use ExhibitProvider
    import Exhibition
    
    struct Foo_Previews: ExhibitProvider, PreviewProvider {
        static var exhibitName: String = "Foo"
        static var exhibitSection: String = "Bar"
        
        static func exhibitContent(context: Context) -> some View {
            Foo(
                title: context.parameter(name: "title", defaultValue: "Title"),
                content: context.parameter(name: "content")
            )
        }
    }
  2. Run Sourcery to generate your Exhibition: sourcery --sources Your/Source/Path --templates Exhibition.swifttemplate --output ./Sources/Generated
  3. Show Exhibition() in a swift view

Custom Layout

If you would like your exhibit to have some custom layout, there is an optional function in ExhibitProvider you can implement.

Here is an example of embeding the exhibit within a List:

static func exhibitLayout(content: AnyView) -> some View {
    List {
        content
    }
}

You can also provide a custom View here to provide presentation samples:

struct CustomLayout<Content: View>: View {
    let content: Content
    
    @State var isPresented: Bool = false
    
    var body: some View {
        Button("Open") {
            isPresented = true
        }
        .sheet(isPresented: $isPresented) {
            content
        }
    }
}

static func exhibitLayout(content: AnyView) -> some View {
    CustomLayout(content: content)
}

Custom Parameter views

Exhibition supports a number of types in the parameter list of the debug menu. You can add your own arbitrary types along with a view to modify the parameter, or override the views for existing types. Conform to ParameterView, and pass the type in via the .parameterView modifier on Exhibition.

struct DoublingStringParameterView: ParameterView {
    let key: String
    @Binding var value: String
    
    var body: some View {
        Button(key) {
            value += value
        }
    }
}

Exhibition()
    .parameterView(DoublingStringParameterView.self)

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

  • None
Last updated: Thu Nov 07 2024 07:51:26 GMT-1000 (Hawaii-Aleutian Standard Time)