diff --git a/AppleStoreProductKiosk/Features/ShoppingCart/CartView.swift b/AppleStoreProductKiosk/Features/ShoppingCart/CartView.swift new file mode 100644 index 0000000..44bd784 --- /dev/null +++ b/AppleStoreProductKiosk/Features/ShoppingCart/CartView.swift @@ -0,0 +1,39 @@ +// +// CartView.swift +// AppleStoreProductKiosk +// +// Created by 김민희 on 9/16/25. +// + +import SwiftUI + +struct CartView: View { + @State var item = CartItem() + var body: some View { + VStack(spacing: 0) { + CartHeaderView() + + Divider() + + ScrollView { + VStack(spacing: 15) { + CartItemRowView(item: $item) + } + .padding(.horizontal, 20) + .padding(.vertical, 30) + } + .scrollIndicators(.hidden) + + Divider() + + CartSummaryView(item: $item) + .padding(.vertical, 20) + + CartActionButtonsView() + } + } +} + +#Preview { + CartView() +} diff --git a/AppleStoreProductKiosk/Features/ShoppingCart/Components/CartActionButtonsView.swift b/AppleStoreProductKiosk/Features/ShoppingCart/Components/CartActionButtonsView.swift new file mode 100644 index 0000000..10c35b2 --- /dev/null +++ b/AppleStoreProductKiosk/Features/ShoppingCart/Components/CartActionButtonsView.swift @@ -0,0 +1,49 @@ +// +// CartActionButtonsView.swift +// AppleStoreProductKiosk +// +// Created by 김민희 on 9/17/25. +// + +import SwiftUI + +struct CartActionButtonsView: View { + var body: some View { + Grid(horizontalSpacing: 12) { + GridRow { + Button { + //전체 취소 + } label: { + Text("전체 취소") + .font(.system(size: 15, weight: .regular)) + .foregroundStyle(.black) + .frame(maxWidth: .infinity) + .padding(10) + .overlay { + Capsule(style: .continuous) + .stroke(.black.opacity(0.2), lineWidth: 1) + } + } + .gridCellColumns(4) + + Button { + //결제하기 + } label: { + Text("결제하기") + .font(.system(size: 15, weight: .semibold)) + .foregroundStyle(.white) + .frame(maxWidth: .infinity) + .padding(10) + .background(.blue) + .clipShape(.capsule(style: .continuous)) + } + .gridCellColumns(6) + } + } + .padding(.horizontal, 20) + } +} + + #Preview { + CartActionButtonsView() + } diff --git a/AppleStoreProductKiosk/Features/ShoppingCart/Components/CartHeaderView.swift b/AppleStoreProductKiosk/Features/ShoppingCart/Components/CartHeaderView.swift new file mode 100644 index 0000000..597b400 --- /dev/null +++ b/AppleStoreProductKiosk/Features/ShoppingCart/Components/CartHeaderView.swift @@ -0,0 +1,37 @@ +// +// CartHeaderView.swift +// AppleStoreProductKiosk +// +// Created by 김민희 on 9/16/25. +// + +import SwiftUI + +struct CartHeaderView: View { + @Environment(\.dismiss) var dismiss + + var body: some View { + HStack(spacing: 0) { + Text("장바구니") + .font(.system(size: 20, weight: .bold)) + Spacer() + + Button { + dismiss() + } label: { + Image(systemName: "xmark") + .foregroundColor(.black) + .font(.system(size: 15)) + .padding(8) + .background(.gray.opacity(0.15)) + .clipShape(Circle()) + } + } + .padding(.horizontal, 20) + .padding(.vertical, 25) + } +} + +#Preview { + CartHeaderView() +} diff --git a/AppleStoreProductKiosk/Features/ShoppingCart/Components/CartItemRowView.swift b/AppleStoreProductKiosk/Features/ShoppingCart/Components/CartItemRowView.swift new file mode 100644 index 0000000..68f70d7 --- /dev/null +++ b/AppleStoreProductKiosk/Features/ShoppingCart/Components/CartItemRowView.swift @@ -0,0 +1,108 @@ +// +// CartItemRowView.swift +// AppleStoreProductKiosk +// +// Created by 김민희 on 9/16/25. +// + +import SwiftUI + +//TODO: 데이터 작업할 때 없앨예정 +struct CartItem { + let name: String = "iphone17 pro" + let price: Int = 1000000 + let imageName: String = "iphone17pro" + var quantity: Int = 2 +} + +struct CartItemRowView: View { + @Binding var item: CartItem + + var body: some View { + HStack(spacing: 0) { + Image(item.imageName) + .resizable() + .scaledToFit() + .frame(width: 80, height: 80) + .cornerRadius(10) + + Spacer() + .frame(width: 20) + + VStack(alignment: .leading, spacing: 10) { + Text(item.name) + .font(.system(size: 17, weight: .semibold)) + + Text("₩\(item.price)") + .font(.system(size: 14, weight: .regular)) + .foregroundStyle(.black.opacity(0.7)) + + Text("소계: ₩\(item.price * item.quantity)") + .font(.system(size: 12, weight: .regular)) + .foregroundStyle(.blue) + } + + Spacer() + + HStack(spacing: 13) { + if item.quantity > 1 { + Button { + item.quantity -= 1 + } label: { + Image(systemName: "minus") + .font(.system(size: 15)) + .padding(12) + .foregroundStyle(.black) + .background(.white) + .clipShape(Circle()) + .overlay( + Circle() + .stroke(.gray.opacity(0.3), lineWidth: 0.7) + ) + } + } else { + Button { + //삭제 + } label: { + Image(systemName: "trash") + .font(.system(size: 13)) + .padding(8) + .foregroundStyle(.red) + .background(.white) + .clipShape(Circle()) + .overlay( + Circle() + .stroke(.gray.opacity(0.3), lineWidth: 0.7) + ) + } + } + + Text("\(item.quantity)").frame(minWidth: 20) + + Button { + item.quantity += 1 + } label: { + Image(systemName: "plus") + .font(.system(size: 15)) + .padding(7) + .foregroundStyle(.black) + .background(.white) + .clipShape(Circle()) + .overlay( + Circle() + .stroke(.gray.opacity(0.3), lineWidth: 0.7) + ) + } + } + } + .padding(.horizontal, 10) + .padding(.vertical, 20) + .background(.gray.opacity(0.05)) + .clipShape(RoundedRectangle(cornerRadius: 14)) + } +} + +#Preview { + @State var item = CartItem(quantity: 1) + CartItemRowView(item: $item) +} diff --git a/AppleStoreProductKiosk/Features/ShoppingCart/Components/CartSummaryView.swift b/AppleStoreProductKiosk/Features/ShoppingCart/Components/CartSummaryView.swift new file mode 100644 index 0000000..a278e11 --- /dev/null +++ b/AppleStoreProductKiosk/Features/ShoppingCart/Components/CartSummaryView.swift @@ -0,0 +1,41 @@ +// +// CartSummaryView.swift +// AppleStoreProductKiosk +// +// Created by 김민희 on 9/17/25. +// + +import SwiftUI + +struct CartSummaryView: View { + @Binding var item: CartItem + + var body: some View { + HStack(spacing: 0) { + VStack(alignment: .leading, spacing: 10) { + Text("상품 개수") + .font(.system(size: 14, weight: .regular)) + .foregroundStyle(.black.opacity(0.7)) + Text("총 결제금액") + .font(.system(size: 18, weight: .semibold)) + } + + Spacer() + + VStack(alignment: .trailing, spacing: 10) { + Text("\(item.quantity)개") + .font(.system(size: 14, weight: .semibold)) + Text("₩\(item.price * item.quantity)") + .font(.system(size: 20, weight: .bold)) + .foregroundStyle(.blue) + } + + } + .padding(.horizontal, 20) + } +} + +#Preview { + @State var item = CartItem() + CartSummaryView(item: $item) +} diff --git a/AppleStoreProductKiosk/Resources/Assets.xcassets/iphone17pro.imageset/Contents.json b/AppleStoreProductKiosk/Resources/Assets.xcassets/iphone17pro.imageset/Contents.json new file mode 100644 index 0000000..cac0264 --- /dev/null +++ b/AppleStoreProductKiosk/Resources/Assets.xcassets/iphone17pro.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "iphone17pro.jpeg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/AppleStoreProductKiosk/Resources/Assets.xcassets/iphone17pro.imageset/iphone17pro.jpeg b/AppleStoreProductKiosk/Resources/Assets.xcassets/iphone17pro.imageset/iphone17pro.jpeg new file mode 100644 index 0000000..0250b92 Binary files /dev/null and b/AppleStoreProductKiosk/Resources/Assets.xcassets/iphone17pro.imageset/iphone17pro.jpeg differ