Improve page and post detail views
This commit is contained in:
40
CHDataManagement/Views/Generic/DescriptionField.swift
Normal file
40
CHDataManagement/Views/Generic/DescriptionField.swift
Normal 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)
|
||||
}
|
||||
}
|
36
CHDataManagement/Views/Generic/IconButton.swift
Normal file
36
CHDataManagement/Views/Generic/IconButton.swift
Normal 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))
|
||||
}
|
||||
}
|
||||
}
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user