From 937bcae91a9f547fd31234c1af584dc726e3aaa9 Mon Sep 17 00:00:00 2001 From: Muukii Date: Sun, 13 Aug 2023 18:52:28 +0900 Subject: [PATCH] :evergreen_tree: Update --- Development/Demo/MyBook.swift | 183 ++++++--------------- Sources/StorybookKit/Primitives/Book.swift | 25 --- 2 files changed, 47 insertions(+), 161 deletions(-) diff --git a/Development/Demo/MyBook.swift b/Development/Demo/MyBook.swift index 9a52c6e..b9d8f24 100644 --- a/Development/Demo/MyBook.swift +++ b/Development/Demo/MyBook.swift @@ -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 { diff --git a/Sources/StorybookKit/Primitives/Book.swift b/Sources/StorybookKit/Primitives/Book.swift index 730e69d..78ce664 100644 --- a/Sources/StorybookKit/Primitives/Book.swift +++ b/Sources/StorybookKit/Primitives/Book.swift @@ -26,31 +26,6 @@ public protocol BookType: View { } -public struct Book: 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] = []