Repository navigation
Expand file tree
/
Copy pathDesignSystem.swift
More file actions
151 lines (134 loc) · 4.96 KB
/
Copy pathDesignSystem.swift
File metadata and controls
151 lines (134 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import SwiftUI
// MARK: - Glass card
//
// Stand-in for Liquid Glass until Xcode 26 / the iOS 26 SDK is installed.
// `.glassEffect(in:)` and `GlassEffectContainer` don't exist in the iOS 18 SDK, so this
// uses `.ultraThinMaterial` to get the same translucent, floating-card look today.
// To upgrade later, wrap the `background` line below in:
// #if canImport(SwiftUI) && compiler(>=6.2)
// .glassEffect(.regular, in: RoundedRectangle(cornerRadius: cornerRadius, style: .continuous))
// #else
// .background(.ultraThinMaterial, in: RoundedRectangle(cornerRadius: cornerRadius, style: .continuous))
// #endif
struct GlassCard<Content: View>: View {
var cornerRadius: CGFloat = 20
var content: Content
init(cornerRadius: CGFloat = 20, @ViewBuilder content: () -> Content) {
self.cornerRadius = cornerRadius
self.content = content()
}
var body: some View {
VStack(alignment: .leading, spacing: 12) {
content
}
.padding(16)
.frame(maxWidth: .infinity, alignment: .leading)
.background(.ultraThinMaterial, in: RoundedRectangle(cornerRadius: cornerRadius, style: .continuous))
.overlay(
RoundedRectangle(cornerRadius: cornerRadius, style: .continuous)
.strokeBorder(Color.primary.opacity(0.06), lineWidth: 1)
)
}
}
// MARK: - Settings-style leading icon badge
struct IconBadge: View {
let systemName: String
var color: Color = .accentColor
var body: some View {
RoundedRectangle(cornerRadius: 7, style: .continuous)
.fill(color.gradient)
.frame(width: 28, height: 28)
.overlay(
Image(systemName: systemName)
.font(.system(size: 14, weight: .semibold))
.foregroundStyle(.white)
)
}
}
// MARK: - Hero header used at the top of each tab
struct HeroHeader: View {
let systemImage: String
let title: String
let subtitle: String
var tint: Color = .accentColor
var body: some View {
HStack(spacing: 16) {
ZStack {
RoundedRectangle(cornerRadius: 18, style: .continuous)
.fill(tint.gradient)
.frame(width: 64, height: 64)
Image(systemName: systemImage)
.font(.system(size: 28, weight: .semibold))
.foregroundStyle(.white)
}
VStack(alignment: .leading, spacing: 3) {
Text(title).font(.title2.bold())
Text(subtitle).font(.subheadline).foregroundStyle(.secondary)
}
Spacer(minLength: 0)
}
}
}
// MARK: - Circular ring gauge (RAM / battery / storage)
struct RingGauge: View {
var value: Double
var label: String
var valueText: String
var tint: Color = .accentColor
var lineWidth: CGFloat = 12
var diameter: CGFloat = 128
var body: some View {
ZStack {
Circle()
.stroke(Color.primary.opacity(0.08), lineWidth: lineWidth)
Circle()
.trim(from: 0, to: max(0.0006, min(value, 1)))
.stroke(tint.gradient, style: StrokeStyle(lineWidth: lineWidth, lineCap: .round))
.rotationEffect(.degrees(-90))
.animation(.easeInOut(duration: 0.5), value: value)
VStack(spacing: 2) {
Text(valueText)
.font(.title2.bold())
.monospacedDigit()
.minimumScaleFactor(0.7)
.lineLimit(1)
Text(label)
.font(.caption)
.foregroundStyle(.secondary)
}
.padding(8)
}
.frame(width: diameter, height: diameter)
}
}
// MARK: - Linear capacity bar (Settings-style "iPhone Storage")
struct CapacityBar: View {
var usedFraction: Double
var tint: Color = .blue
var height: CGFloat = 14
var body: some View {
GeometryReader { geo in
ZStack(alignment: .leading) {
RoundedRectangle(cornerRadius: height / 2, style: .continuous)
.fill(Color.primary.opacity(0.08))
RoundedRectangle(cornerRadius: height / 2, style: .continuous)
.fill(LinearGradient(colors: [tint, tint.opacity(0.7)], startPoint: .leading, endPoint: .trailing))
.frame(width: geo.size.width * CGFloat(max(0, min(usedFraction, 1))))
.animation(.easeInOut(duration: 0.5), value: usedFraction)
}
}
.frame(height: height)
}
}
// MARK: - "Your device" badge used in the Encyclopedia
struct HighlightBadge: View {
var text: String = "Your Device"
var body: some View {
Text(text)
.font(.caption2.bold())
.foregroundStyle(.white)
.padding(.horizontal, 8)
.padding(.vertical, 4)
.background(Color.accentColor.gradient, in: Capsule())
}
}