| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import SwiftUI
- // MARK: - DiscreetWarningBanner
- /// A highly minimalist, wireframe-style warning banner that displays system warnings discretely.
- /// Can be dismissed by the user.
- struct DiscreetWarningBanner: View {
-
- /// Warning message to display.
- let warning: String
-
- /// Triggered when the user taps the close button.
- let onDismiss: () -> Void
-
- var body: some View {
- HStack(spacing: 8) {
- Image(systemName: "exclamationmark.triangle")
- .font(.system(size: 11, weight: .light))
- .foregroundColor(.primary)
-
- Text(warning)
- .font(.system(size: 10, weight: .regular))
- .foregroundColor(.secondary)
- .lineLimit(1)
-
- Spacer()
-
- Button(action: onDismiss) {
- Image(systemName: "xmark")
- .font(.system(size: 8, weight: .light))
- .foregroundColor(.secondary.opacity(0.7))
- .frame(width: 16, height: 16)
- }
- .buttonStyle(.plain)
- }
- .padding(.horizontal, 12)
- .padding(.vertical, 8)
- .background(Color.cardBackground.opacity(0.1))
- .businessBorder(cornerRadius: 6)
- .transition(.move(edge: .top).combined(with: .opacity))
- }
- }
- // MARK: - Preview
- #Preview {
- VStack {
- DiscreetWarningBanner(
- warning: "⚠️ 检测到后台有其他音频播放中,建议关闭以防混入录音。"
- ) {
- print("Dismissed")
- }
- .padding()
- Spacer()
- }
- .background(Color.spaceBlack)
- }
|