Skip to content

Commit

Permalink
feat(ui): add demo for form
Browse files Browse the repository at this point in the history
  • Loading branch information
dirtyhenry committed Dec 27, 2024
1 parent 8c2bd34 commit 3d8f2db
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 19 deletions.
4 changes: 4 additions & 0 deletions Examples/BlocksApp/BlocksApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
008D62CE2A56C96E00254FD9 /* MailComposeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 008D62CD2A56C96E00254FD9 /* MailComposeView.swift */; };
008D62D02A56EA1500254FD9 /* UniformTypeIdentifiers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 008D62CF2A56EA1500254FD9 /* UniformTypeIdentifiers.framework */; };
00A12BF42CC0F84B0006D9F7 /* TransportDemoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00A12BF32CC0F8450006D9F7 /* TransportDemoView.swift */; };
00A274EA2D1EC88B00A2DD67 /* FormPlaygroundView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00A274E92D1EC88B00A2DD67 /* FormPlaygroundView.swift */; };
00A37E302B1911A800FA4B5F /* FileSystemExplorerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00A37E2F2B1911A800FA4B5F /* FileSystemExplorerView.swift */; };
00A37E322B19135400FA4B5F /* ObjectiveBlocks in Frameworks */ = {isa = PBXBuildFile; productRef = 00A37E312B19135400FA4B5F /* ObjectiveBlocks */; };
00D1E2482A36327100E8D275 /* BlocksApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00D1E2472A36327100E8D275 /* BlocksApp.swift */; };
Expand Down Expand Up @@ -63,6 +64,7 @@
008D62CD2A56C96E00254FD9 /* MailComposeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MailComposeView.swift; sourceTree = "<group>"; };
008D62CF2A56EA1500254FD9 /* UniformTypeIdentifiers.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UniformTypeIdentifiers.framework; path = System/Library/Frameworks/UniformTypeIdentifiers.framework; sourceTree = SDKROOT; };
00A12BF32CC0F8450006D9F7 /* TransportDemoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransportDemoView.swift; sourceTree = "<group>"; };
00A274E92D1EC88B00A2DD67 /* FormPlaygroundView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormPlaygroundView.swift; sourceTree = "<group>"; };
00A37E2F2B1911A800FA4B5F /* FileSystemExplorerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileSystemExplorerView.swift; sourceTree = "<group>"; };
00D1E2442A36327100E8D275 /* BlocksApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BlocksApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
00D1E2472A36327100E8D275 /* BlocksApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlocksApp.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -127,6 +129,7 @@
002136DE2B57DDD40031AE9A /* TaskStateDemoView.swift */,
0038EF672C00F1F0004BF4FB /* LoggingPlaygroundView.swift */,
00333CCA2C45682900A58365 /* SlugifyView.swift */,
00A274E92D1EC88B00A2DD67 /* FormPlaygroundView.swift */,
);
path = Features;
sourceTree = "<group>";
Expand Down Expand Up @@ -333,6 +336,7 @@
002136DF2B57DDD40031AE9A /* TaskStateDemoView.swift in Sources */,
003995752AFBF4680051BFCE /* BackgroundTaskView.swift in Sources */,
008D62CE2A56C96E00254FD9 /* MailComposeView.swift in Sources */,
00A274EA2D1EC88B00A2DD67 /* FormPlaygroundView.swift in Sources */,
002136DD2B57C2570031AE9A /* PlainDateDemoView.swift in Sources */,
00A12BF42CC0F84B0006D9F7 /* TransportDemoView.swift in Sources */,
00333CCB2C45682900A58365 /* SlugifyView.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Examples/BlocksApp/BlocksApp/BlocksApp.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
import OSLog
import SwiftUI

@main
Expand Down
3 changes: 3 additions & 0 deletions Examples/BlocksApp/BlocksApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import UniformTypeIdentifiers

struct ContentView: View {
enum Section: String, Identifiable, CaseIterable {
case formPlayground = "Form Playground"
case taskStateDemo = "TaskState demo"
case misc = "Misc"
case fonts = "Fonts"
Expand Down Expand Up @@ -109,6 +110,8 @@ struct ContentView: View {
SlugifyView()
case .transportDemo:
TransportDemoView()
case .formPlayground:
FormPlaygroundView()
}
} else {
Text("Select a section")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if os(iOS)
import Blocks
import os
import OSLog
import SwiftUI

class BackgroundRunnerSingleton {
Expand Down
23 changes: 23 additions & 0 deletions Examples/BlocksApp/BlocksApp/Features/FormPlaygroundView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Blocks
import OSLog
import SwiftUI

struct FormPlaygroundView: View {
private let logger = Logger(subsystem: "net.mickf.BlocksDemoApp", category: "FormPlayground")

@State var text: String = ""

var body: some View {
Form {
Section(header: Text("Section")) {
TextField("Standard", text: $text)
LabeledTextField("Title", text: $text, prompt: Text("Prompt"))
}
}
.navigationTitle("Form Playground")
}
}

#Preview {
FormPlaygroundView()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Blocks
import os
import OSLog
import SwiftUI

Expand Down
1 change: 0 additions & 1 deletion Examples/BlocksApp/BlocksApp/Features/SlugifyView.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Blocks
import os
import OSLog
import SwiftUI

Expand Down
27 changes: 13 additions & 14 deletions Sources/Blocks/UIComponents/LabeledTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,29 @@ public struct LabeledTextField: View {
public var body: some View {
#if os(iOS)
ZStack(alignment: .leading) {
if !text.isEmpty || fieldIsFocused {
Text(title)
.foregroundColor(text.isEmpty ? Color(.placeholderText) : .accentColor)
.offset(y: text.isEmpty ? 0 : -25)
.scaleEffect(text.isEmpty ? 1 : 0.8, anchor: .leading)
}
Text(title)
.foregroundColor((text.isEmpty && !fieldIsFocused) ? Color(.placeholderText) : .accentColor)
.offset(y: (text.isEmpty && !fieldIsFocused) ? 0 : -20)
.scaleEffect((text.isEmpty && !fieldIsFocused) ? 1 : 0.6, anchor: .leading)
TextField("", text: $text, prompt: prompt)
.focused($fieldIsFocused)
.offset(y: (text.isEmpty && !fieldIsFocused) ? 0 : 4)
}
.padding(.top, 16)
.animation(.default, value: text)
.padding(.vertical, 4)
.animation(.default)
#else
TextField(title, text: $text, prompt: prompt)
#endif
}
}

@available(iOS 18.0, *)
@available(macOS 14.0, *)
#Preview {
Form {
if #available(iOS 15.0, macOS 12.0, *) {
LabeledTextField("Input", text: .constant("Value"))
} else {
Text("macOS 12 is required.")
}
@Previewable @State var text = ""
return Form {
LabeledTextField("Input 1", text: $text)
TextField("Input to blur", text: $text)
}
}
#endif
2 changes: 1 addition & 1 deletion Sources/Blocks/Watch/WatchPairingUtil.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if os(iOS)
import Combine
import os
import OSLog
import SwiftUI
import WatchConnectivity

Expand Down

0 comments on commit 3d8f2db

Please sign in to comment.