Improve page and post detail views

This commit is contained in:
Christoph Hagen
2024-12-07 00:09:35 +01:00
parent 42a5d01480
commit 394cf7a2e4
13 changed files with 355 additions and 109 deletions

View File

@ -0,0 +1,40 @@
import SwiftUI
struct DescriptionField: View {
@Binding
var text: String
var body: some View {
TextEditor(text: $text)
.font(.body)
.lineLimit(5, reservesSpace: true)
.frame(maxWidth: 400, minHeight: 50, maxHeight: 500)
.textEditorStyle(.plain)
.padding(.vertical, 8)
.padding(.leading, 3)
.background(Color.gray.opacity(0.1))
.cornerRadius(8)
}
}
struct OptionalDescriptionField: View {
@Binding
var text: String?
var body: some View {
TextEditor(text: Binding(
get: { text ?? "" },
set: { text = $0.isEmpty ? nil : $0 }
))
.font(.body)
.lineLimit(5, reservesSpace: true)
.frame(maxWidth: 400, minHeight: 50, maxHeight: 500)
.textEditorStyle(.plain)
.padding(.vertical, 8)
.padding(.leading, 3)
.background(Color.gray.opacity(0.1))
.cornerRadius(8)
}
}

View File

@ -0,0 +1,36 @@
import SwiftUI
import SFSafeSymbols
struct IconButton: View {
let symbol: SFSymbol
let action: () -> Void
let size: CGFloat
let color: Color
let background: Color
init(symbol: SFSymbol, size: CGFloat, color: Color, background: Color = .white, action: @escaping () -> Void) {
self.symbol = symbol
self.action = action
self.size = size
self.color = color
self.background = background
}
var body: some View {
Button(action: action) {
Image(systemSymbol: symbol)
.resizable()
.aspectRatio(1, contentMode: .fit)
.frame(width: size, height: size)
.foregroundStyle(color)
.background(Circle()
.fill(background)
.padding(1))
}
}
}

View File

@ -8,9 +8,12 @@ struct OptionalTextField: View {
// The optional text that will be passed in and out of the component
@Binding var text: String?
init(_ titleKey: LocalizedStringKey, text: Binding<String?>) {
let prompt: String?
init(_ titleKey: LocalizedStringKey, text: Binding<String?>, prompt: String? = nil) {
self.titleKey = titleKey
self._text = text
self.prompt = prompt
}
var body: some View {
@ -23,6 +26,6 @@ struct OptionalTextField: View {
// Convert an empty string to `nil`
text = newValue.isEmpty ? nil : newValue
}
))
), prompt: prompt.map(Text.init))
}
}