DiscreetWarningBanner.swift 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import SwiftUI
  2. // MARK: - DiscreetWarningBanner
  3. /// A highly minimalist, wireframe-style warning banner that displays system warnings discretely.
  4. /// Can be dismissed by the user.
  5. struct DiscreetWarningBanner: View {
  6. /// Warning message to display.
  7. let warning: String
  8. /// Triggered when the user taps the close button.
  9. let onDismiss: () -> Void
  10. var body: some View {
  11. HStack(spacing: 8) {
  12. Image(systemName: "exclamationmark.triangle")
  13. .font(.system(size: 11, weight: .light))
  14. .foregroundColor(.primary)
  15. Text(warning)
  16. .font(.system(size: 10, weight: .regular))
  17. .foregroundColor(.secondary)
  18. .lineLimit(1)
  19. Spacer()
  20. Button(action: onDismiss) {
  21. Image(systemName: "xmark")
  22. .font(.system(size: 8, weight: .light))
  23. .foregroundColor(.secondary.opacity(0.7))
  24. .frame(width: 16, height: 16)
  25. }
  26. .buttonStyle(.plain)
  27. }
  28. .padding(.horizontal, 12)
  29. .padding(.vertical, 8)
  30. .background(Color.cardBackground.opacity(0.1))
  31. .businessBorder(cornerRadius: 6)
  32. .transition(.move(edge: .top).combined(with: .opacity))
  33. }
  34. }
  35. // MARK: - Preview
  36. #Preview {
  37. VStack {
  38. DiscreetWarningBanner(
  39. warning: "⚠️ 检测到后台有其他音频播放中,建议关闭以防混入录音。"
  40. ) {
  41. print("Dismissed")
  42. }
  43. .padding()
  44. Spacer()
  45. }
  46. .background(Color.spaceBlack)
  47. }