64 lines
2.0 KiB
Swift
64 lines
2.0 KiB
Swift
import SwiftUI
|
|
|
|
struct TodoRowView: View {
|
|
let item: TodoItem
|
|
let onToggle: () -> Void
|
|
var subtitle: String?
|
|
var onTap: (() -> Void)?
|
|
|
|
var body: some View {
|
|
HStack {
|
|
Button(action: onToggle) {
|
|
Image(systemName: item.isCompleted ? "checkmark.circle.fill" : "circle")
|
|
.foregroundStyle(item.isCompleted ? .green : .secondary)
|
|
.imageScale(.large)
|
|
}
|
|
.buttonStyle(.borderless)
|
|
|
|
Button(action: { onTap?() }) {
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text(item.title)
|
|
.strikethrough(item.isCompleted)
|
|
.foregroundStyle(item.isCompleted ? .secondary : .primary)
|
|
|
|
if let notes = item.notes, !notes.isEmpty {
|
|
Text(noteSnippet(notes))
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
.lineLimit(1)
|
|
}
|
|
|
|
if let subtitle {
|
|
Text(subtitle)
|
|
.font(.caption2)
|
|
.foregroundStyle(.tertiary)
|
|
}
|
|
}
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.contentShape(Rectangle())
|
|
}
|
|
.buttonStyle(.plain)
|
|
|
|
if let priority = item.priority {
|
|
Image(systemName: "circle.fill")
|
|
.font(.system(size: 10))
|
|
.foregroundStyle(priority.color)
|
|
}
|
|
|
|
if item.isOverdue {
|
|
Image(systemName: "exclamationmark.circle.fill")
|
|
.font(.system(size: 14))
|
|
.foregroundStyle(.red)
|
|
}
|
|
}
|
|
.listRowBackground(item.isOverdue ? Color.red.opacity(0.08) : nil)
|
|
}
|
|
|
|
private func noteSnippet(_ text: String) -> String {
|
|
if text.count > 50 {
|
|
return String(text.prefix(50)) + "..."
|
|
}
|
|
return text
|
|
}
|
|
}
|