|
| 1 | +import SwiftUI |
| 2 | + |
| 3 | +/// Shared gradient tile used by suggestions widget and shop discover |
| 4 | +struct SuggestionCard: View { |
| 5 | + let title: String |
| 6 | + let description: String |
| 7 | + let imageName: String |
| 8 | + let accentColor: Color |
| 9 | + let onTap: () -> Void |
| 10 | + let onDismiss: (() -> Void)? |
| 11 | + |
| 12 | + init( |
| 13 | + title: String, |
| 14 | + description: String, |
| 15 | + imageName: String, |
| 16 | + accentColor: Color, |
| 17 | + onTap: @escaping () -> Void, |
| 18 | + onDismiss: (() -> Void)? = nil |
| 19 | + ) { |
| 20 | + self.title = title |
| 21 | + self.description = description |
| 22 | + self.imageName = imageName |
| 23 | + self.accentColor = accentColor |
| 24 | + self.onTap = onTap |
| 25 | + self.onDismiss = onDismiss |
| 26 | + } |
| 27 | + |
| 28 | + var body: some View { |
| 29 | + ZStack(alignment: .topTrailing) { |
| 30 | + Button(action: onTap) { |
| 31 | + VStack(alignment: .leading, spacing: 0) { |
| 32 | + Spacer() |
| 33 | + |
| 34 | + Image(imageName) |
| 35 | + .resizable() |
| 36 | + .scaledToFit() |
| 37 | + .frame(width: 96, height: 96) |
| 38 | + .frame(maxWidth: .infinity, alignment: .center) |
| 39 | + |
| 40 | + Text(title) |
| 41 | + .font(.custom(Fonts.black, size: 20)) |
| 42 | + .lineLimit(1) |
| 43 | + .kerning(-0.5) |
| 44 | + .textCase(.uppercase) |
| 45 | + .padding(.top, 4) |
| 46 | + |
| 47 | + CaptionBText(description) |
| 48 | + } |
| 49 | + .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) |
| 50 | + .padding(.vertical, 12) |
| 51 | + .padding(.horizontal, 16) |
| 52 | + .background( |
| 53 | + RoundedRectangle(cornerRadius: 16) |
| 54 | + .fill( |
| 55 | + LinearGradient( |
| 56 | + gradient: Gradient(stops: [ |
| 57 | + .init(color: accentColor, location: 0.0), |
| 58 | + .init(color: Color.black.opacity(0.1), location: 0.9), |
| 59 | + .init(color: Color.black, location: 1.0), |
| 60 | + ]), |
| 61 | + startPoint: .top, |
| 62 | + endPoint: .bottom |
| 63 | + ) |
| 64 | + ) |
| 65 | + ) |
| 66 | + } |
| 67 | + .buttonStyle(.plain) |
| 68 | + .zIndex(0) |
| 69 | + |
| 70 | + if let onDismiss { |
| 71 | + Button(action: onDismiss) { |
| 72 | + Image("x-mark") |
| 73 | + .resizable() |
| 74 | + .aspectRatio(contentMode: .fit) |
| 75 | + .foregroundColor(.textSecondary) |
| 76 | + .frame(width: 16, height: 16) |
| 77 | + .padding(8) |
| 78 | + .contentShape(Rectangle()) |
| 79 | + } |
| 80 | + .padding(8) |
| 81 | + .contentShape(Rectangle()) |
| 82 | + .accessibilityIdentifier("SuggestionDismiss") |
| 83 | + .accessibility(label: Text("Dismiss \(title)")) |
| 84 | + .buttonStyle(.plain) |
| 85 | + .zIndex(1) |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | +} |
0 commit comments