Reportage/Views/Theme/Theme.swift (5351B)
1import SwiftUI
2import UIKit
3
4
5
6enum Theme {
7 static let paper = Color(light: 0xF5F0E4, dark: 0x171513)
8 static let ink = Color(light: 0x1B1C1F, dark: 0xECEBE6)
9
10 static let muted = Color(light: 0x605B53, dark: 0xA29C93)
11
12 static let rule = Color(light: 0xDAD2C3, dark: 0x38342E)
13 static let accent = Color(light: 0x8E3B22, dark: 0xE39577)
14
15 static let onAccent = Color(light: 0xFFFFFF, dark: 0x171513)
16
17
18
19 static let mark = Color(light: 0xC4481A, dark: 0xF2724A)
20
21
22 static let titleInk = Color(light: 0x4A433B, dark: 0xC4BDB2)
23
24
25 static let field = Color(light: 0xE8E3D8, dark: 0x242220)
26
27
28
29
30
31
32
33
34 static let margin: CGFloat = 24
35
36 static let pageTop: CGFloat = 28
37
38 static let promptGap: CGFloat = 24
39
40
41 static let blockGap: CGFloat = 20
42
43
44 static let itemGap: CGFloat = 12
45
46 static let iconGap: CGFloat = 10
47
48 static let chipGap: CGFloat = 8
49
50 static let lineGap: CGFloat = 2
51
52 static let headingTop: CGFloat = 16
53
54 static let rowPadding: CGFloat = 18
55
56
57 static func serif(_ style: Font.TextStyle, weight: Font.Weight = .regular) -> Font {
58 .system(style, design: .serif, weight: weight)
59 }
60
61
62
63 static func capHeight(
64 _ style: UIFont.TextStyle, weight: UIFont.Weight,
65 design: UIFontDescriptor.SystemDesign = .default
66 ) -> CGFloat {
67 let traits = UITraitCollection(preferredContentSizeCategory: .large)
68 let base = UIFontDescriptor.preferredFontDescriptor(withTextStyle: style, compatibleWith: traits)
69 .addingAttributes([.traits: [UIFontDescriptor.TraitKey.weight: weight]])
70 let descriptor = base.withDesign(design) ?? base
71 return UIFont(descriptor: descriptor, size: 0).capHeight
72 }
73}
74
75extension VerticalAlignment {
76 private enum CapTop: AlignmentID {
77 static func defaultValue(in dimensions: ViewDimensions) -> CGFloat {
78 dimensions[.top]
79 }
80 }
81
82
83
84
85 static let capTop = VerticalAlignment(CapTop.self)
86}
87
88extension Color {
89
90 init(light: UInt32, dark: UInt32) {
91 self.init(
92 uiColor: UIColor { traits in
93 UIColor(rgb: traits.userInterfaceStyle == .dark ? dark : light)
94 })
95 }
96}
97
98extension UIColor {
99 fileprivate convenience init(rgb: UInt32) {
100 self.init(
101 red: CGFloat((rgb >> 16) & 0xFF) / 255,
102 green: CGFloat((rgb >> 8) & 0xFF) / 255,
103 blue: CGFloat(rgb & 0xFF) / 255,
104 alpha: 1
105 )
106 }
107}
108
109extension View {
110
111
112 func screenTitle() -> some View {
113 font(Theme.serif(.largeTitle, weight: .medium))
114 .foregroundStyle(Theme.titleInk)
115 .accessibilityAddTraits(.isHeader)
116 }
117
118
119
120 func tabBarClearance() -> some View {
121 contentMargins(.bottom, Theme.blockGap, for: .scrollContent)
122 }
123
124
125
126 func eyebrow(_ color: Color = Theme.muted) -> some View {
127 font(.caption.weight(.semibold))
128 .tracking(1.4)
129 .textCase(.uppercase)
130 .foregroundStyle(color)
131 }
132}