Repository Public
1// SP Notes iOS2// File: Components/Theme.swift3// Description: Colours, haptics and small shared view helpers, on the Note Visual System 2.0 tokens (graphite neutrals,4// ultramarine accent, violet for AI; amber survives only as the warning hue).5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import SPNotesDesign9import SwiftUI10import UIKit1112/// The 1.0 colour names, now aliases of the Note Visual System 2.0 tokens (`SPNotesDesign`, SPEC §7 exact values). New code uses13/// `NVColor` directly. The asset catalog colour sets of the same names hold the same values for UIKit (`UIColor(named:)`),14/// the launch screen and the widget background; `Tests/DesignTokenTests` checks that the two never drift.15extension Color {16 static let spBackground = NVColor.bg17 static let spSurface = NVColor.bgElevated18 static let spSurface2 = NVColor.bgSunken19 static let spBorder = NVColor.line20 static let spText = NVColor.fg21 static let spTextSecondary = NVColor.fgMuted22 /// Metadata that must stay readable: `fgMuted` (SPEC §7: `fgFaint` is for placeholders and decoration only).23 static let spMuted = NVColor.fgMuted24 /// Status hues as *text* (darker in light mode, SPEC §7); fills and icons use `NVColor.danger / success / warning`.25 static let spDanger = NVColor.dangerText26 static let spSuccess = NVColor.successText27 static let spWarning = NVColor.warningText28}2930/// The haptic vocabulary of the app, in one place: `selection` (a choice changed, a block type morphed), `tap` (a light31/// confirmation of a direct manipulation), `success` (something was saved, captured, filed), `warning` (a refusal, a conflict).32enum Haptics {33 @MainActor static func selection() { UISelectionFeedbackGenerator().selectionChanged() }34 @MainActor static func tap() { UIImpactFeedbackGenerator(style: .light).impactOccurred() }35 @MainActor static func success() { UINotificationFeedbackGenerator().notificationOccurred(.success) }36 @MainActor static func warning() { UINotificationFeedbackGenerator().notificationOccurred(.warning) }37}3839/// The app mark (sheet and spark) used on the welcome, lock and empty screens.40struct BrandMark: View {41 var size: CGFloat = 9642 var body: some View {43 Image("Mark").resizable().scaledToFit().frame(width: size, height: size).accessibilityHidden(true)44 }45}4647/// A full-width primary action.48struct PrimaryButtonStyle: ButtonStyle {49 @Environment(\.isEnabled) private var isEnabled50 func makeBody(configuration: Configuration) -> some View {51 configuration.label52 .font(.headline)53 .frame(maxWidth: .infinity, minHeight: 50)54 .foregroundStyle(NVColor.accentFg)55 .background(NVColor.accent.opacity(isEnabled ? (configuration.isPressed ? 0.8 : 1) : 0.4), in: RoundedRectangle(cornerRadius: NVRadius.lg, style: .continuous))56 .contentShape(RoundedRectangle(cornerRadius: NVRadius.lg, style: .continuous))57 }58}5960/// An empty state: symbol, title, explanation and an optional action.61struct EmptyStateView: View {62 let symbol: String63 let title: LocalizedStringKey64 var message: LocalizedStringKey?65 var actionTitle: LocalizedStringKey?66 var action: (() -> Void)?6768 var body: some View {69 VStack(spacing: 12) {70 Image(systemName: symbol).font(.system(size: 44, weight: .light)).foregroundStyle(Color.spMuted).accessibilityHidden(true)71 Text(title).nvFont(.h3).foregroundStyle(Color.spText).multilineTextAlignment(.center)72 if let message { Text(message).font(.subheadline).foregroundStyle(Color.spTextSecondary).multilineTextAlignment(.center) }73 if let actionTitle, let action { Button(actionTitle, action: action).buttonStyle(.borderedProminent).padding(.top, 6) }74 }75 .padding(32)76 .frame(maxWidth: 420)77 .frame(maxWidth: .infinity, maxHeight: .infinity)78 }79}8081extension Date {82 /// Short, human date for lists: time today, weekday this week, otherwise the date.83 var listLabel: String {84 let calendar = Calendar.current85 if calendar.isDateInToday(self) { return formatted(date: .omitted, time: .shortened) }86 if calendar.isDateInYesterday(self) { return String(localized: "Hier") }87 if let days = calendar.dateComponents([.day], from: self, to: .now).day, days < 7 { return formatted(.dateTime.weekday(.wide)) }88 return formatted(date: .abbreviated, time: .omitted)89 }90}91