Skip to content

Commit

Permalink
🌲 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Aug 13, 2023
1 parent 87d0c9d commit 937bcae
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 161 deletions.
183 changes: 47 additions & 136 deletions Development/Demo/MyBook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,161 +66,72 @@ let myBook2 = BookContainer(

}

}
)
)

let myBook: some BookType = Book(title: "MyUI") {

Text("MyBook")

Text("This is BookText")
BookNavigationLink(title: "AlertController") {

BookSection(title: "Features") {

BookNavigationLink(title: "Preview UI") {
BookPage(title: "Typography") {

Text(
"""
Here is `BookHeadline`, It allows us to describe something big picture.
"""
)

Text(
"""
Here is `BookParagpraph`
It allows us to display multiple lines.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
"""
)

Text(
"""
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
"""
)

BookSection(title: "Section") {

Text(
"""
Something description about this section.
"""
BookPresent(title: "Pop") {
let alert = UIAlertController(
title: "Hi Storybook",
message: "As like this, you can present any view controller to check the behavior.",
preferredStyle: .alert
)

BookPreview { _ in
let view = UIView(frame: .init(x: 0, y: 0, width: 80, height: 80))
view.backgroundColor = .systemPurple
NSLayoutConstraint.activate([
view.widthAnchor.constraint(equalToConstant: 80),
view.heightAnchor.constraint(equalToConstant: 80),
])
return view
}

BookPreview(title: "A component") { _ in
let view = UIView(frame: .null)
view.backgroundColor = .systemPurple
return view
}
.previewFrame(width: 80, height: 80)

BookPreview { _ in
let view = UIView(frame: .init(x: 0, y: 0, width: 80, height: 80))
view.backgroundColor = .systemPurple
return view
}
.previewFrame(maxWidth: .greatestFiniteMagnitude, idealHeight: 10)

alert.addAction(.init(title: "Got it", style: .default, handler: { _ in }))
return alert
}

BookSection(title: "Section") {

BookPreview { _ in
let view = UIView(frame: .init(x: 0, y: 0, width: 80, height: 80))
view.backgroundColor = .systemPurple
NSLayoutConstraint.activate([
view.widthAnchor.constraint(equalToConstant: 80),
view.heightAnchor.constraint(equalToConstant: 80),
])
return view
}

BookPresent(title: "Another Pop") {
let alert = UIAlertController(
title: "Hi Storybook",
message: "As like this, you can present any view controller to check the behavior.",
preferredStyle: .alert
)
alert.addAction(.init(title: "Got it", style: .default, handler: { _ in }))
return alert
}

}

}

BookNavigationLink(title: "AlertController") {

BookPresent(title: "Pop") {
let alert = UIAlertController(
title: "Hi Storybook",
message: "As like this, you can present any view controller to check the behavior.",
preferredStyle: .alert
)
alert.addAction(.init(title: "Got it", style: .default, handler: { _ in }))
return alert
BookNavigationLink(title: "Test Push") {
BookPush(title: "Test") {
UIViewController()
}
}

BookPresent(title: "Another Pop") {
let alert = UIAlertController(
title: "Hi Storybook",
message: "As like this, you can present any view controller to check the behavior.",
preferredStyle: .alert
)
alert.addAction(.init(title: "Got it", style: .default, handler: { _ in }))
return alert
}
BookNavigationLink(title: "State") {
BookPreview(title: "State: Success") { _ in
MySuccessView()
}

}
BookPreview(title: "State: Loading") { _ in
MyLoadingView()
}

BookNavigationLink(title: "Test Push") {
BookPush(title: "Test") {
UIViewController()
BookPreview(title: "State: Error") { _ in
MyErrorView()
}
}
}

}

labelExpandingTestBook()

BookNavigationLink(title: "State") {
BookPreview(title: "State: Success") { _ in
MySuccessView()
}

BookPreview(title: "State: Loading") { _ in
MyLoadingView()
}

BookPreview(title: "State: Error") { _ in
MyErrorView()
}
}
BookNavigationLink(title: "Pattern") {

BookNavigationLink(title: "Pattern") {
BookPattern.make(
["A", "AAA", "AAAAAA"],
[UIColor.blue, UIColor.red, UIColor.orange]
)
.makeBody { args in
BookPreview { _ in
let (text, color) = args
let label = UILabel()
label.text = text
label.textColor = color
return label
}
}

BookPattern.make(
["A", "AAA", "AAAAAA"],
[UIColor.blue, UIColor.red, UIColor.orange]
)
.makeBody { args in
BookPreview { _ in
let (text, color) = args
let label = UILabel()
label.text = text
label.textColor = color
return label
}
}

}

}
}
)
)

private func labelExpandingTestBook() -> some View {

Expand Down
25 changes: 0 additions & 25 deletions Sources/StorybookKit/Primitives/Book.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,6 @@ public protocol BookType: View {

}

public struct Book<Content: View>: BookType {

public let content: Content
public let title: String

public init(
title: String,
@ViewBuilder content: () -> Content
) {
self.title = title
self.content = content()
}

public var body: some View {
NavigationView {
ScrollView(.vertical) {
content
}
}
.navigationTitle(title)

}

}

public final class BookStore: ObservableObject {

@Published var historyLinks: [BookNavigationLink] = []
Expand Down

0 comments on commit 937bcae

Please sign in to comment.