A Swift library for documenting, isolating, and testing SwiftUI, UIKit & AppKit components.
Minimal Example
An example demonstrated with the Slider
ui element.
// Create a "doc" that conforms to View.
struct SliderDoc: View {
@State private var value: Double = 0.0
// Use the markup components provided with SwiftBook to
// describe your components.
//
// Wrap your component in `SwiftBookComponent` to get the snapshot
// testing and more.
var body: some View {
H1("Slider")
P("A Slider element provided by Apple for SwiftUI.")
SwiftBookComponent {
Slider(value: $value)
}
}
}
// Add your "doc" to the SwiftBook documents table.
struct ContentView: View {
var body: some View {
SwiftBook([
("Slider", AnyView(SliderDoc())),
])
}
}
An example demonstrating the "controls" provided with SwiftBook
struct CircleView: View {
let color: Color
let label: String
let labelColor: Color
var body: some View {
ZStack {
Circle()
.frame(width: 300, height: 300, alignment: .center)
.foregroundColor(color)
Text(label)
.foregroundColor(labelColor)
.font(.headline)
}
}
}
struct CircleDoc: View {
@State private var color: Color = .red
@State private var label: String = "Red Circle"
@State private var labelColor: Color = .primary
var body: some View {
H2("A red circle")
H3("This is a description of a red circle.")
SwiftBookComponent {
CircleView(color: color, label: label, labelColor: labelColor)
}
SwiftBookControlTable {
SwiftBookControlColor(color: $color, title: "color")
SwiftBookControlColor(color: $labelColor, title: "labelColor")
SwiftBookControlText(text: $label, label: "label")
}
}
}