-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Woo POS] [Variable Products] Add variation to POSItem enum with vari…
…ation card UI (#14782)
- Loading branch information
Showing
6 changed files
with
103 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
WooCommerce/Classes/POS/Presentation/VariationCardView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import struct Yosemite.POSVariation | ||
import SwiftUI | ||
|
||
struct VariationCardView: View { | ||
private let variation: POSVariation | ||
|
||
@ScaledMetric private var scale: CGFloat = 1.0 | ||
|
||
init(variation: POSVariation) { | ||
self.variation = variation | ||
} | ||
|
||
var body: some View { | ||
HStack(spacing: Constants.cardSpacing) { | ||
POSItemImageView(imageSource: variation.productImageSource, | ||
imageSize: Constants.productCardSize * scale, | ||
scale: scale) | ||
.frame(width: min(Constants.productCardSize * scale, Constants.maximumProductCardSize), | ||
height: Constants.productCardSize * scale) | ||
.clipped() | ||
|
||
VStack(alignment: .leading, spacing: Constants.textSpacing) { | ||
Text(variation.name) | ||
.lineLimit(2) | ||
.foregroundStyle(Color.posPrimaryText) | ||
.multilineTextAlignment(.leading) | ||
.font(Constants.itemNameFont) | ||
|
||
Text(variation.formattedPrice) | ||
.foregroundStyle(Color.posPrimaryText) | ||
.font(Constants.itemPriceFont) | ||
} | ||
.padding(.horizontal, Constants.horizontalTextPadding * (1 / scale)) | ||
.padding(.vertical, Constants.verticalTextPadding * (1 / scale)) | ||
Spacer() | ||
} | ||
.frame(maxWidth: .infinity, idealHeight: Constants.productCardSize * scale) | ||
.background(Color.posSecondaryBackground) | ||
.posItemCardBorderStyles() | ||
} | ||
} | ||
|
||
private extension VariationCardView { | ||
enum Constants { | ||
static let productCardSize: CGFloat = 112 | ||
static let maximumProductCardSize: CGFloat = Constants.productCardSize * 2 | ||
static let cardSpacing: CGFloat = 0 | ||
static let textSpacing: CGFloat = 8 | ||
static let horizontalTextPadding: CGFloat = 32 | ||
static let verticalTextPadding: CGFloat = 8 | ||
static let itemNameFont: POSFontStyle = .posBodyEmphasized | ||
static let itemPriceFont: POSFontStyle = .posBodyRegular | ||
} | ||
} | ||
|
||
#Preview("Variation without image") { | ||
let variation = POSVariation(id: .init(), name: "500ml, double shot", formattedPrice: "$5.00") | ||
VariationCardView(variation: variation) | ||
} | ||
|
||
#Preview("Variation with image") { | ||
let variation = POSVariation(id: .init(), | ||
name: "500ml, double shot", | ||
formattedPrice: "$5.00", | ||
productImageSource: "https://pd.w.org/2024/12/986762d0d4d4cf17.82435881-scaled.jpeg") | ||
VariationCardView(variation: variation) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Foundation | ||
|
||
public struct POSVariation: Equatable, Hashable, Identifiable { | ||
// Identifiable | ||
public let id: UUID | ||
|
||
public let name: String | ||
public let formattedPrice: String | ||
public var productImageSource: String? | ||
|
||
public init(id: UUID, name: String, formattedPrice: String, productImageSource: String? = nil) { | ||
self.id = id | ||
self.name = name | ||
self.formattedPrice = formattedPrice | ||
self.productImageSource = productImageSource | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters